From 4d6decf628af9b19ed6381cc2fa9b91823c47bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 15 Aug 2022 10:38:24 +0200 Subject: [PATCH] wasm: always build asyncify tests for eventloop_auto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a runtime test for asyncify availability; skip tests if asyncify is not available. Add new build target which builds with asyncify enabled. Change-Id: Idaeff0a24aa01525927b012af2a0ba135c7839c3 Reviewed-by: Tor Arne Vestbø --- .../eventloop/eventloop_auto/CMakeLists.txt | 26 +++++++++++++-- .../eventloop_auto_asyncify.html | 10 ++++++ .../wasm/eventloop/eventloop_auto/main.cpp | 32 +++++++++++++++---- 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 tests/manual/wasm/eventloop/eventloop_auto/eventloop_auto_asyncify.html diff --git a/tests/manual/wasm/eventloop/eventloop_auto/CMakeLists.txt b/tests/manual/wasm/eventloop/eventloop_auto/CMakeLists.txt index 4212cb832b6..f8669c20300 100644 --- a/tests/manual/wasm/eventloop/eventloop_auto/CMakeLists.txt +++ b/tests/manual/wasm/eventloop/eventloop_auto/CMakeLists.txt @@ -1,13 +1,14 @@ +include_directories(../../qtwasmtestlib/) + +# default buid qt_internal_add_manual_test(eventloop_auto SOURCES main.cpp ../../qtwasmtestlib/qtwasmtestlib.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Core ) -include_directories(../../qtwasmtestlib/) - add_custom_command( TARGET eventloop_auto POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy @@ -19,3 +20,22 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../../qtwasmtestlib/qtwasmtestlib.js ${CMAKE_CURRENT_BINARY_DIR}/qtwasmtestlib.js) + +# asyncify enabled build +qt_internal_add_manual_test(eventloop_auto_asyncify + SOURCES + main.cpp + ../../qtwasmtestlib/qtwasmtestlib.cpp + LIBRARIES + Qt::Core +) + +target_link_options(eventloop_auto_asyncify PRIVATE -sASYNCIFY -Os) + +add_custom_command( + TARGET eventloop_auto_asyncify POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_SOURCE_DIR}/eventloop_auto_asyncify.html + ${CMAKE_CURRENT_BINARY_DIR}/eventloop_auto_asyncify.html) + + diff --git a/tests/manual/wasm/eventloop/eventloop_auto/eventloop_auto_asyncify.html b/tests/manual/wasm/eventloop/eventloop_auto/eventloop_auto_asyncify.html new file mode 100644 index 00000000000..a277c9b9e04 --- /dev/null +++ b/tests/manual/wasm/eventloop/eventloop_auto/eventloop_auto_asyncify.html @@ -0,0 +1,10 @@ + + + + +

Running event dispatcher auto test.

+
diff --git a/tests/manual/wasm/eventloop/eventloop_auto/main.cpp b/tests/manual/wasm/eventloop/eventloop_auto/main.cpp index c6e8bad987e..b6de2310ade 100644 --- a/tests/manual/wasm/eventloop/eventloop_auto/main.cpp +++ b/tests/manual/wasm/eventloop/eventloop_auto/main.cpp @@ -10,8 +10,14 @@ #include +#include "emscripten.h" + const int timerTimeout = 10; +EM_JS(bool, have_asyncify, (), { + return typeof Asyncify != "undefined"; +}); + class WasmEventDispatcherTest: public QObject { Q_OBJECT @@ -27,16 +33,14 @@ private slots: void timerSecondaryThread(); #endif -#ifdef QT_HAVE_EMSCRIPTEN_ASYNCIFY void postEventAsyncify(); void timerAsyncify(); void postEventAsyncifyLoop(); -#endif private: // Disabled test function: Asyncify wait on pthread_join is not supported, // see https://github.com/emscripten-core/emscripten/issues/9910 -#if QT_CONFIG(thread) && defined(QT_HAVE_EMSCRIPTEN_ASYNCIFY) +#if QT_CONFIG(thread) void threadAsyncifyWait(); #endif }; @@ -235,11 +239,14 @@ void WasmEventDispatcherTest::timerSecondaryThread() #endif -#ifdef QT_HAVE_EMSCRIPTEN_ASYNCIFY - // Post an event to the main thread and asyncify wait for it void WasmEventDispatcherTest::postEventAsyncify() { + if (!have_asyncify()) { + QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify"); + return; + } + QEventLoop loop; QCoreApplication::postEvent(EventTarget::create([&loop](){ loop.quit(); @@ -252,6 +259,11 @@ void WasmEventDispatcherTest::postEventAsyncify() // Create a timer on the main thread and asyncify wait for it void WasmEventDispatcherTest::timerAsyncify() { + if (!have_asyncify()) { + QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify"); + return; + } + QEventLoop loop; QTimer::singleShot(timerTimeout, [&loop](){ loop.quit(); @@ -264,6 +276,11 @@ void WasmEventDispatcherTest::timerAsyncify() // Asyncify wait in a loop void WasmEventDispatcherTest::postEventAsyncifyLoop() { + if (!have_asyncify()) { + QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify"); + return; + } + for (int i = 0; i < 10; ++i) { QEventLoop loop; QCoreApplication::postEvent(EventTarget::create([&loop]() { @@ -279,6 +296,9 @@ void WasmEventDispatcherTest::postEventAsyncifyLoop() // Asyncify wait for QThread::wait() / pthread_join() void WasmEventDispatcherTest::threadAsyncifyWait() { + if (!have_asyncify()) + QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify"); + const int threadCount = 15; QVector threads; @@ -300,8 +320,6 @@ void WasmEventDispatcherTest::threadAsyncifyWait() } #endif -#endif // QT_HAVE_EMSCRIPTEN_ASYNCIFY - int main(int argc, char **argv) { auto testObject = std::make_shared();