wasm: Fix test runner for asynchronous tests

Test runner was not properly handling tests which
return the control back to browser event loop.
It was treating such tests as if they exited with
code 0, marking them as succesfull even if they were
eventually failing or hanging.
This commit adds a callback to TestCase so the runner
is notified when a test truly has finished.
As a side effect, two tests need to be disabled for now
as they are failing for wasm, which was not properly
detected previously.

Change-Id: I0eb9383e5bb9cd660431c18747b9e94413629d1e
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Piotr Wierciński 2023-09-18 15:24:20 +02:00
parent d1f40ea087
commit 4f168621d2
4 changed files with 31 additions and 13 deletions

View File

@ -115,6 +115,10 @@
#include <CoreFoundation/CFPreferences.h>
#endif
#if defined(Q_OS_WASM)
#include <emscripten.h>
#endif
#include <vector>
QT_BEGIN_NAMESPACE
@ -2274,6 +2278,14 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
qInit(testObject, argc, argv);
int ret = qRun();
qCleanup();
#if defined(Q_OS_WASM)
EM_ASM({
if (typeof Module != "undefined" && typeof Module.notifyTestFinished != "undefined")
Module.notifyTestFinished($0);
}, ret);
#endif // Q_OS_WASM
return ret;
}

View File

@ -10,7 +10,7 @@ if(TARGET Qt::Gui)
add_subdirectory(qdatastream)
add_subdirectory(qdatastream_core_pixmap)
endif()
if(TARGET Qt::Network)
if(TARGET Qt::Network AND NOT WASM)
add_subdirectory(qtextstream)
endif()
if(TARGET Qt::Gui AND TARGET Qt::Network AND TARGET Qt::Xml AND NOT INTEGRITY AND NOT QNX AND NOT WASM)

View File

@ -6,7 +6,6 @@ if(WASM) # not all tests currently work in WebAssembly
add_subdirectory(qatomicinteger)
add_subdirectory(qatomicpointer)
add_subdirectory(qfuturesynchronizer)
add_subdirectory(qfuturewatcher)
add_subdirectory(qmutexlocker)
add_subdirectory(qreadlocker)
add_subdirectory(qresultstore)

View File

@ -129,16 +129,9 @@ export class CompiledModule {
return await new Promise(async (resolve, reject) => {
let instance = undefined;
let result = undefined;
const continuation = () => {
if (!(instance && result))
return;
resolve({
stdout: result.stdout,
exitCode: result.exitCode,
instance,
});
};
let testFinished = false;
const testFinishedEvent = new CustomEvent('testFinished');
instance = await this.#createQtAppInstanceFn((() => {
const params = this.#makeDefaultExecParams({
onInstantiationError: (error) => { reject(error); },
@ -154,12 +147,26 @@ export class CompiledModule {
params.quit = (code, exception) => {
if (exception && exception.name !== 'ExitStatus')
reject(exception);
};
params.notifyTestFinished = (code) => {
result = { stdout: data, exitCode: code };
continuation();
testFinished = true;
window.dispatchEvent(testFinishedEvent);
};
return params;
})());
continuation();
if (!testFinished) {
await new Promise((resolve) => {
window.addEventListener('testFinished', () => {
resolve();
});
});
}
resolve({
stdout: result.stdout,
exitCode: result.exitCode,
instance,
});
});
}