wasm: add test for QWAsmSuspendResumeControl
Test via QWasmTimer and native timers. Change-Id: Ie1ad8517de83e4ad50a7cdc7c391c34226261aef Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
This commit is contained in:
parent
de2a29a1fe
commit
b80deb2628
@ -3,6 +3,7 @@
|
||||
|
||||
add_subdirectory(asyncify_exec)
|
||||
add_subdirectory(eventloop_auto)
|
||||
add_subdirectory(suspendresumecontrol_auto)
|
||||
add_subdirectory(main_exec)
|
||||
add_subdirectory(main_noexec)
|
||||
add_subdirectory(thread_exec)
|
||||
|
@ -0,0 +1,24 @@
|
||||
# Copyright (C) 2024 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
include_directories(../../qtwasmtestlib/)
|
||||
|
||||
qt_internal_add_manual_test(suspendresumecontrol_auto
|
||||
SOURCES
|
||||
main.cpp
|
||||
../../qtwasmtestlib/qtwasmtestlib.cpp
|
||||
LIBRARIES
|
||||
Qt::Core
|
||||
Qt::CorePrivate
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
TARGET suspendresumecontrol_auto POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/suspendresumecontrol_auto.html
|
||||
${CMAKE_CURRENT_BINARY_DIR}/suspendresumecontrol_auto.html)
|
||||
|
||||
add_custom_command(
|
||||
TARGET suspendresumecontrol_auto POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../qtwasmtestlib/qtwasmtestlib.js
|
||||
${CMAKE_CURRENT_BINARY_DIR}/qtwasmtestlib.js)
|
148
tests/manual/wasm/eventloop/suspendresumecontrol_auto/main.cpp
Normal file
148
tests/manual/wasm/eventloop/suspendresumecontrol_auto/main.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
// Copyright (C) 2024 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
#include <QtCore/private/qwasmsuspendresumecontrol_p.h>
|
||||
#include <qtwasmtestlib.h>
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
const int timerTimeout = 10;
|
||||
|
||||
// Test QWasmSuspendResumeControl suspend/resume and event processing,
|
||||
// via QWasmTimer native timer events.
|
||||
class WasmSuspendResumeControlTest: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void timer();
|
||||
void multipleTimers();
|
||||
void reuseTimer();
|
||||
void cancelTimer();
|
||||
void deleteTimer();
|
||||
};
|
||||
|
||||
// Verify that a single timer fires
|
||||
void WasmSuspendResumeControlTest::timer()
|
||||
{
|
||||
QWasmSuspendResumeControl suspendResume;
|
||||
bool timerFired = false;
|
||||
|
||||
QWasmTimer timer(&suspendResume, [&timerFired](){
|
||||
timerFired = true;
|
||||
});
|
||||
timer.setTimeout(timerTimeout);
|
||||
|
||||
while (!timerFired) {
|
||||
suspendResume.suspend();
|
||||
suspendResume.sendPendingEvents();
|
||||
}
|
||||
|
||||
QWASMSUCCESS();
|
||||
}
|
||||
|
||||
// Verify that multiple parallel timers fire
|
||||
void WasmSuspendResumeControlTest::multipleTimers()
|
||||
{
|
||||
QWasmSuspendResumeControl suspendResume;
|
||||
const int expectedTimers = 10;
|
||||
int compledtedTimers = 0;
|
||||
|
||||
std::unique_ptr<QWasmTimer> timers[expectedTimers];
|
||||
for (int i = 0; i < expectedTimers; ++i) {
|
||||
timers[i] = std::make_unique<QWasmTimer>(&suspendResume, [&compledtedTimers](){
|
||||
++compledtedTimers;
|
||||
});
|
||||
timers[i]->setTimeout(timerTimeout * i);
|
||||
}
|
||||
|
||||
while (compledtedTimers < expectedTimers) {
|
||||
suspendResume.suspend();
|
||||
suspendResume.sendPendingEvents();
|
||||
}
|
||||
|
||||
QWASMSUCCESS();
|
||||
}
|
||||
|
||||
// Verify that a reused timer fires again
|
||||
void WasmSuspendResumeControlTest::reuseTimer()
|
||||
{
|
||||
QWasmSuspendResumeControl suspendResume;
|
||||
const int expectedTimers = 10;
|
||||
int compledtedTimers = 0;
|
||||
|
||||
QWasmTimer timer(&suspendResume, [&compledtedTimers](){
|
||||
++compledtedTimers;
|
||||
});
|
||||
|
||||
while (compledtedTimers < expectedTimers) {
|
||||
timer.setTimeout(timerTimeout);
|
||||
suspendResume.suspend();
|
||||
suspendResume.sendPendingEvents();
|
||||
}
|
||||
|
||||
QWASMSUCCESS();
|
||||
}
|
||||
|
||||
// Verify that a cancelled timer does not fire
|
||||
void WasmSuspendResumeControlTest::cancelTimer()
|
||||
{
|
||||
QWasmSuspendResumeControl suspendResume;
|
||||
|
||||
// controlTimer checks that the cancelled testTimer didn't fire
|
||||
bool controlFired = false;
|
||||
QWasmTimer controlTimer(&suspendResume, [&controlFired](){
|
||||
controlFired = true;
|
||||
});
|
||||
|
||||
QWasmTimer testTimer(&suspendResume, [](){
|
||||
QWASMFAIL("Cancelled timer did fire");
|
||||
});
|
||||
|
||||
controlTimer.setTimeout(timerTimeout * 4);
|
||||
testTimer.setTimeout(timerTimeout);
|
||||
testTimer.clearTimeout();
|
||||
|
||||
while (!controlFired) {
|
||||
suspendResume.suspend();
|
||||
suspendResume.sendPendingEvents();
|
||||
}
|
||||
|
||||
QWASMSUCCESS();
|
||||
}
|
||||
|
||||
// Verify that a deleted timer does not fire
|
||||
void WasmSuspendResumeControlTest::deleteTimer()
|
||||
{
|
||||
QWasmSuspendResumeControl suspendResume;
|
||||
|
||||
// controlTimer checks that the deleted testTimer didn't fire
|
||||
bool controlFired = false;
|
||||
QWasmTimer controlTimer(&suspendResume, [&controlFired](){
|
||||
controlFired = true;
|
||||
});
|
||||
controlTimer.setTimeout(timerTimeout * 4);
|
||||
|
||||
{
|
||||
QWasmTimer testTimer(&suspendResume, [](){
|
||||
QWASMFAIL("Deleted timer did fire");
|
||||
});
|
||||
testTimer.setTimeout(timerTimeout);
|
||||
}
|
||||
|
||||
while (!controlFired) {
|
||||
suspendResume.suspend();
|
||||
suspendResume.sendPendingEvents();
|
||||
}
|
||||
|
||||
QWASMSUCCESS();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
auto testObject = std::make_shared<WasmSuspendResumeControlTest>();
|
||||
QtWasmTest::initTestCase<QCoreApplication>(argc, argv, testObject);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "main.moc"
|
@ -0,0 +1,10 @@
|
||||
<!doctype html>
|
||||
<script type="text/javascript" src="qtwasmtestlib.js"></script>
|
||||
<script type="text/javascript" src="suspendresumecontrol_auto.js"></script>
|
||||
<script>
|
||||
window.onload = () => {
|
||||
runTestCase(suspendresumecontrol_auto_entry, document.getElementById("log"));
|
||||
};
|
||||
</script>
|
||||
<p>Running event dispatcher auto test.</p>
|
||||
<div id="log"></div>
|
Loading…
x
Reference in New Issue
Block a user