From 4f168621d2da5c9f99e232a6ea24980302cb01b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wierci=C5=84ski?= Date: Mon, 18 Sep 2023 15:24:20 +0200 Subject: [PATCH] wasm: Fix test runner for asynchronous tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Qt CI Bot --- src/testlib/qtestcase.cpp | 12 ++++++++ .../auto/corelib/serialization/CMakeLists.txt | 2 +- tests/auto/corelib/thread/CMakeLists.txt | 1 - util/wasm/batchedtestrunner/qwasmjsruntime.js | 29 ++++++++++++------- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 7ab5e2553c4..1ea6c30a48c 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -115,6 +115,10 @@ #include #endif +#if defined(Q_OS_WASM) +#include +#endif + #include 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; } diff --git a/tests/auto/corelib/serialization/CMakeLists.txt b/tests/auto/corelib/serialization/CMakeLists.txt index ef40e78d249..7fd9a336391 100644 --- a/tests/auto/corelib/serialization/CMakeLists.txt +++ b/tests/auto/corelib/serialization/CMakeLists.txt @@ -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) diff --git a/tests/auto/corelib/thread/CMakeLists.txt b/tests/auto/corelib/thread/CMakeLists.txt index 64c0f47ca5e..5889f4249f2 100644 --- a/tests/auto/corelib/thread/CMakeLists.txt +++ b/tests/auto/corelib/thread/CMakeLists.txt @@ -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) diff --git a/util/wasm/batchedtestrunner/qwasmjsruntime.js b/util/wasm/batchedtestrunner/qwasmjsruntime.js index 716a461576f..99d9c41c710 100644 --- a/util/wasm/batchedtestrunner/qwasmjsruntime.js +++ b/util/wasm/batchedtestrunner/qwasmjsruntime.js @@ -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, + }); }); }