summaryrefslogtreecommitdiffstats
path: root/tests/manual/wasm/eventloop/eventloop_auto/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/wasm/eventloop/eventloop_auto/main.cpp')
-rw-r--r--tests/manual/wasm/eventloop/eventloop_auto/main.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/tests/manual/wasm/eventloop/eventloop_auto/main.cpp b/tests/manual/wasm/eventloop/eventloop_auto/main.cpp
index c6e8bad987..32af372b62 100644
--- a/tests/manual/wasm/eventloop/eventloop_auto/main.cpp
+++ b/tests/manual/wasm/eventloop/eventloop_auto/main.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QCoreApplication>
#include <QtCore/QEvent>
@@ -7,9 +7,12 @@
#include <QtCore/QObject>
#include <QtCore/QThread>
#include <QtCore/QTimer>
+#include <QtCore/private/qstdweb_p.h>
#include <qtwasmtestlib.h>
+#include "emscripten.h"
+
const int timerTimeout = 10;
class WasmEventDispatcherTest: public QObject
@@ -27,16 +30,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 +236,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 (!qstdweb::haveAsyncify()) {
+ QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
+ return;
+ }
+
QEventLoop loop;
QCoreApplication::postEvent(EventTarget::create([&loop](){
loop.quit();
@@ -252,6 +256,11 @@ void WasmEventDispatcherTest::postEventAsyncify()
// Create a timer on the main thread and asyncify wait for it
void WasmEventDispatcherTest::timerAsyncify()
{
+ if (!qstdweb::haveAsyncify()) {
+ QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
+ return;
+ }
+
QEventLoop loop;
QTimer::singleShot(timerTimeout, [&loop](){
loop.quit();
@@ -264,6 +273,11 @@ void WasmEventDispatcherTest::timerAsyncify()
// Asyncify wait in a loop
void WasmEventDispatcherTest::postEventAsyncifyLoop()
{
+ if (!qstdweb::haveAsyncify()) {
+ QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
+ return;
+ }
+
for (int i = 0; i < 10; ++i) {
QEventLoop loop;
QCoreApplication::postEvent(EventTarget::create([&loop]() {
@@ -279,6 +293,9 @@ void WasmEventDispatcherTest::postEventAsyncifyLoop()
// Asyncify wait for QThread::wait() / pthread_join()
void WasmEventDispatcherTest::threadAsyncifyWait()
{
+ if (!qstdweb::haveAsyncify())
+ QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
+
const int threadCount = 15;
QVector<QThread *> threads;
@@ -300,8 +317,6 @@ void WasmEventDispatcherTest::threadAsyncifyWait()
}
#endif
-#endif // QT_HAVE_EMSCRIPTEN_ASYNCIFY
-
int main(int argc, char **argv)
{
auto testObject = std::make_shared<WasmEventDispatcherTest>();