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
|
qt_internal_add_manual_test(eventloop_auto
|
||||||
SOURCES
|
SOURCES
|
||||||
main.cpp
|
main.cpp
|
||||||
../../qtwasmtestlib/qtwasmtestlib.cpp
|
../../qtwasmtestlib/qtwasmtestlib.cpp
|
||||||
PUBLIC_LIBRARIES
|
LIBRARIES
|
||||||
Qt::Core
|
Qt::Core
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(../../qtwasmtestlib/)
|
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET eventloop_auto POST_BUILD
|
TARGET eventloop_auto POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
@ -19,3 +20,22 @@ add_custom_command(
|
|||||||
COMMAND ${CMAKE_COMMAND} -E copy
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/../../qtwasmtestlib/qtwasmtestlib.js
|
${CMAKE_CURRENT_SOURCE_DIR}/../../qtwasmtestlib/qtwasmtestlib.js
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/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 <qtwasmtestlib.h>
|
||||||
|
|
||||||
|
#include "emscripten.h"
|
||||||
|
|
||||||
const int timerTimeout = 10;
|
const int timerTimeout = 10;
|
||||||
|
|
||||||
|
EM_JS(bool, have_asyncify, (), {
|
||||||
|
return typeof Asyncify != "undefined";
|
||||||
|
});
|
||||||
|
|
||||||
class WasmEventDispatcherTest: public QObject
|
class WasmEventDispatcherTest: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -27,16 +33,14 @@ private slots:
|
|||||||
void timerSecondaryThread();
|
void timerSecondaryThread();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef QT_HAVE_EMSCRIPTEN_ASYNCIFY
|
|
||||||
void postEventAsyncify();
|
void postEventAsyncify();
|
||||||
void timerAsyncify();
|
void timerAsyncify();
|
||||||
void postEventAsyncifyLoop();
|
void postEventAsyncifyLoop();
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Disabled test function: Asyncify wait on pthread_join is not supported,
|
// Disabled test function: Asyncify wait on pthread_join is not supported,
|
||||||
// see https://github.com/emscripten-core/emscripten/issues/9910
|
// see https://github.com/emscripten-core/emscripten/issues/9910
|
||||||
#if QT_CONFIG(thread) && defined(QT_HAVE_EMSCRIPTEN_ASYNCIFY)
|
#if QT_CONFIG(thread)
|
||||||
void threadAsyncifyWait();
|
void threadAsyncifyWait();
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
@ -235,11 +239,14 @@ void WasmEventDispatcherTest::timerSecondaryThread()
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef QT_HAVE_EMSCRIPTEN_ASYNCIFY
|
|
||||||
|
|
||||||
// Post an event to the main thread and asyncify wait for it
|
// Post an event to the main thread and asyncify wait for it
|
||||||
void WasmEventDispatcherTest::postEventAsyncify()
|
void WasmEventDispatcherTest::postEventAsyncify()
|
||||||
{
|
{
|
||||||
|
if (!have_asyncify()) {
|
||||||
|
QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QCoreApplication::postEvent(EventTarget::create([&loop](){
|
QCoreApplication::postEvent(EventTarget::create([&loop](){
|
||||||
loop.quit();
|
loop.quit();
|
||||||
@ -252,6 +259,11 @@ void WasmEventDispatcherTest::postEventAsyncify()
|
|||||||
// Create a timer on the main thread and asyncify wait for it
|
// Create a timer on the main thread and asyncify wait for it
|
||||||
void WasmEventDispatcherTest::timerAsyncify()
|
void WasmEventDispatcherTest::timerAsyncify()
|
||||||
{
|
{
|
||||||
|
if (!have_asyncify()) {
|
||||||
|
QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QTimer::singleShot(timerTimeout, [&loop](){
|
QTimer::singleShot(timerTimeout, [&loop](){
|
||||||
loop.quit();
|
loop.quit();
|
||||||
@ -264,6 +276,11 @@ void WasmEventDispatcherTest::timerAsyncify()
|
|||||||
// Asyncify wait in a loop
|
// Asyncify wait in a loop
|
||||||
void WasmEventDispatcherTest::postEventAsyncifyLoop()
|
void WasmEventDispatcherTest::postEventAsyncifyLoop()
|
||||||
{
|
{
|
||||||
|
if (!have_asyncify()) {
|
||||||
|
QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QCoreApplication::postEvent(EventTarget::create([&loop]() {
|
QCoreApplication::postEvent(EventTarget::create([&loop]() {
|
||||||
@ -279,6 +296,9 @@ void WasmEventDispatcherTest::postEventAsyncifyLoop()
|
|||||||
// Asyncify wait for QThread::wait() / pthread_join()
|
// Asyncify wait for QThread::wait() / pthread_join()
|
||||||
void WasmEventDispatcherTest::threadAsyncifyWait()
|
void WasmEventDispatcherTest::threadAsyncifyWait()
|
||||||
{
|
{
|
||||||
|
if (!have_asyncify())
|
||||||
|
QtWasmTest::completeTestFunction(QtWasmTest::TestResult::Skip, "requires asyncify");
|
||||||
|
|
||||||
const int threadCount = 15;
|
const int threadCount = 15;
|
||||||
|
|
||||||
QVector<QThread *> threads;
|
QVector<QThread *> threads;
|
||||||
@ -300,8 +320,6 @@ void WasmEventDispatcherTest::threadAsyncifyWait()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // QT_HAVE_EMSCRIPTEN_ASYNCIFY
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
auto testObject = std::make_shared<WasmEventDispatcherTest>();
|
auto testObject = std::make_shared<WasmEventDispatcherTest>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user