From 922da1fbb3d0480e78080c53a87550a694b9664e Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 10 Aug 2023 11:10:57 +0200 Subject: [PATCH] Process test: Prevent empty loop from being optimized out This should fix the macOS "Run tests" on GitHub Build Bot. Change-Id: Iae185d47fa33c97c63480b10d5a25a1d4c13f532 Reviewed-by: Eike Ziller Reviewed-by: Reviewed-by: Qt CI Bot --- .../utils/process/processtestapp/processtestapp.cpp | 10 ++++++++-- tests/auto/utils/process/tst_process.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/auto/utils/process/processtestapp/processtestapp.cpp b/tests/auto/utils/process/processtestapp/processtestapp.cpp index 6cf7510eb78..77f36a362ec 100644 --- a/tests/auto/utils/process/processtestapp/processtestapp.cpp +++ b/tests/auto/utils/process/processtestapp/processtestapp.cpp @@ -161,10 +161,16 @@ int ProcessTestApp::BlockingProcess::main() { std::cout << "Blocking process successfully executed." << std::endl; const BlockType blockType = BlockType(qEnvironmentVariableIntValue(envVar())); + bool dummy = true; switch (blockType) { case BlockType::EndlessLoop: - while (true) - ; + while (true) { + if (dummy) { + // Note: Keep these lines, otherwise the compiler may optimize out the empty loop. + std::cout << "EndlessLoop started" << std::endl; + dummy = false; + } + } break; case BlockType::InfiniteSleep: QThread::sleep(INT_MAX); diff --git a/tests/auto/utils/process/tst_process.cpp b/tests/auto/utils/process/tst_process.cpp index 589adbb6fa8..52e4658778f 100644 --- a/tests/auto/utils/process/tst_process.cpp +++ b/tests/auto/utils/process/tst_process.cpp @@ -1216,7 +1216,6 @@ void tst_Process::mergedChannels_data() << false << false << false << true; QTest::newRow("ForwardedErrorChannel") << QProcess::ForwardedErrorChannel << true << false << false << false; - } void tst_Process::mergedChannels() @@ -1265,6 +1264,7 @@ void tst_Process::destroyBlockingProcess() subConfig.setupSubProcess(&process); process.start(); QVERIFY(process.waitForStarted()); + QVERIFY(process.isRunning()); QVERIFY(!process.waitForFinished(1000)); }