Skip to content

Commit

Permalink
wasm: Fix test runner for asynchronous tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Qt CI Bot <[email protected]>
  • Loading branch information
Piotr Wierciński committed Oct 26, 2023
1 parent d1f40ea commit 4f16862
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
12 changes: 12 additions & 0 deletions src/testlib/qtestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
#include <CoreFoundation/CFPreferences.h>
#endif

#if defined(Q_OS_WASM)
#include <emscripten.h>
#endif

#include <vector>

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/auto/corelib/serialization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/auto/corelib/thread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 18 additions & 11 deletions util/wasm/batchedtestrunner/qwasmjsruntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); },
Expand All @@ -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,
});
});
}

Expand Down

0 comments on commit 4f16862

Please sign in to comment.