wasm: always build asyncify tests for eventloop_auto
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ø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
ad0cb1f32d
commit
4d6decf628
@ -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)
|
||||
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
<!doctype html>
|
||||
<script type="text/javascript" src="qtwasmtestlib.js"></script>
|
||||
<script type="text/javascript" src="eventloop_auto_asyncify.js"></script>
|
||||
<script>
|
||||
window.onload = () => {
|
||||
runTestCase(document.getElementById("log"));
|
||||
};
|
||||
</script>
|
||||
<p>Running event dispatcher auto test.</p>
|
||||
<div id="log"></div>
|
@ -10,8 +10,14 @@
|
||||
|
||||
#include <qtwasmtestlib.h>
|
||||
|
||||
#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<QThread *> 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<WasmEventDispatcherTest>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user