Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5#include "hdc.h"
6#include "shellhelpers.h"
8
9#include <QtCore/qcoreapplication.h>
10#include <QtCore/qcommandlineparser.h>
11#include <QtCore/qdatetime.h>
12#include <QtCore/qdeadlinetimer.h>
13#include <QtCore/qfileinfo.h>
14#include <QtCore/qthread.h>
15#include <QtCore/qelapsedtimer.h>
16#include <QtCore/qjsonarray.h>
17#include <QtCore/qjsondocument.h>
18#include <QtCore/qjsonobject.h>
19#include <QtCore/qtemporarydir.h>
20#if QT_CONFIG(systemsemaphore)
21# include <QtCore/qsystemsemaphore.h>
22# include <QtCore/qtipccommon.h>
23#endif
24
25#include <atomic>
26#include <chrono>
27#include <csignal>
28#include <cstdio>
29#include <optional>
30
31using namespace Qt::StringLiterals;
32using namespace std::chrono_literals;
33
34// HarmonyOS sandbox: the app's writable /data/storage/el2/base/files/ maps to
35// /data/app/el2/100/base/<bundleName>/files/ in the hdc shell namespace, which
36// shell can read but not write (SELinux). "tail -f" / inotify are blocked on
37// that path too, so the stdout file is copied to the host with hdc file recv on
38// every poll.
39
40// QTest normal exit code range is 0-127; use 251-254 for runner-level failures.
41static constexpr int EXIT_ERROR = 254;
42static constexpr int EXIT_NOEXITCODE = 253;
43static constexpr int EXIT_CRASH = 252;
44static constexpr int EXIT_TIMEOUT = 251;
45
46static QString shellSingleQuote(const QString &value)
47{
48 QString escaped = value;
49 escaped.replace(u"'"_s, uR"('\'')"_s);
50 return u"'"_s + escaped + u"'"_s;
51}
52
53static constexpr auto quietBeforeDialogCheck = 3s;
54static constexpr auto quietBeforeDialogCheckWhileStarting = 1s;
55static constexpr auto dialogsExpectedWhileStarting = 10s;
56
57#if QT_CONFIG(systemsemaphore)
58static constexpr auto semaphoreAcquireTimeout = 30s;
59static constexpr auto semaphoreResetWait = 5s;
60
61struct TestRunnerSystemSemaphore
62{
63 explicit TestRunnerSystemSemaphore(const QString &key)
64 : nativeKey(QSystemSemaphore::platformSafeKey(key)),
65 semaphore(nativeKey, 1, QSystemSemaphore::Open)
66 {}
67 ~TestRunnerSystemSemaphore() { release(); }
68
69 // Acquire with a 30 s deadline: if a previous runner died -9 without
70 // releasing, reset the semaphore via Create-mode and retry.
71 void acquire()
72 {
73 std::atomic<bool> acquireResult { false };
74 QThread *worker = QThread::create([this, &acquireResult]() {
75 acquireResult.store(semaphore.acquire());
76 });
77 worker->start();
78 if (!worker->wait(semaphoreAcquireTimeout)) {
79 fprintf(stderr, "harmonyostestrunner: semaphore stuck (previous runner "
80 "may have crashed) — resetting\n");
81 {
82 QSystemSemaphore reset{ nativeKey, 1, QSystemSemaphore::Create };
83 } // destructor unblocks the worker
84 worker->wait(semaphoreResetWait);
85 }
86 delete worker;
87 isAcquired.store(acquireResult.load());
88 }
89
90 void release()
91 {
92 bool expected = true;
93 if (isAcquired.compare_exchange_strong(expected, false))
94 isAcquired.store(!semaphore.release());
95 }
96
97 std::atomic<bool> isAcquired { false };
98 QNativeIpcKey nativeKey;
99 QSystemSemaphore semaphore;
100};
101
102static TestRunnerSystemSemaphore *g_runnerLock = nullptr;
103
104static QString runnerLockKey(const QString &deviceKey, const QString &bundleName)
105{
106 const QString device = deviceKey.isEmpty() ? u"local"_s : deviceKey;
107 return u"harmonyostestrunner_"_s + device + u'_' + bundleName;
108}
109#endif // QT_CONFIG(systemsemaphore)
110
111static std::atomic<bool> g_interrupted { false };
112
113static void sigHandler(int sig)
114{
115 std::signal(sig, SIG_DFL);
116 // Not async-signal-safe; best effort so Ctrl-C doesn't strand the semaphore.
117 // The next runner's 30 s deadline resets it anyway.
118#if QT_CONFIG(systemsemaphore)
119 if (g_runnerLock)
120 g_runnerLock->release();
121#endif
122 g_interrupted.store(true);
123}
124
125// Without this, OHOS may deliver the new test's Want to the still-dying
126// previous process via onNewWant instead of creating a fresh one.
127static void waitForProcessDeath(const Hdc &hdc, const QString &bundleName,
128 std::chrono::seconds timeout = 15s)
129{
130 constexpr auto pollInterval = 200ms;
131 const QDeadlineTimer deadline(timeout);
132 while (!deadline.hasExpired()) {
133 if (g_interrupted.load())
134 return;
135 if (queryProcessState(hdc, bundleName) == ProcessState::NotRunning)
136 return;
137 QThread::sleep(pollInterval);
138 }
139 fprintf(stderr, "harmonyostestrunner: warning: bundle process still alive after %lld s "
140 "force-stop wait — proceeding anyway\n", static_cast<long long>(timeout.count()));
141}
142
143static void removeFilesByName(const Hdc &hdc, const QString &directory,
144 const QStringList &namePatterns)
145{
146 QStringList command = { u"rm"_s, u"-f"_s };
147 for (const QString &pattern : namePatterns)
148 command += directory + u"/"_s + pattern;
149
150 if (!hdc.shell(command).trimmed().isEmpty()) {
151 fprintf(stderr, "harmonyostestrunner: warning: cannot remove files from %s\n",
152 qPrintable(directory));
153 }
154}
155
156// aa start prints errors (screen locked, ability not found, ...) to stdout.
157static bool runAaStart(const Hdc &hdc, const QStringList &aaStartCommand)
158{
159 const std::optional<QString> aaOut = answeredShell(hdc, aaStartCommand);
160 if (!aaOut) {
161 fprintf(stderr, "harmonyostestrunner: warning: hdc did not answer aa start\n");
162 return false;
163 }
164 if (!aaOut->startsWith(u"start ability successfully"_s))
165 fprintf(stderr, "harmonyostestrunner: aa start: %s\n", qPrintable(*aaOut));
166 return true;
167}
168
169static q23::expected<void, QString> startAbility(const Hdc &hdc,
170 const QStringList &aaStartCommand,
171 const QString &bundleName,
172 const QString &shellExitCodePath,
173 std::chrono::seconds timeout = 30s)
174{
175 constexpr auto pollInterval = 250ms;
176 constexpr auto aaStartRetryInterval = 5s;
177 const qint64 maxIterations = timeout / pollInterval;
178 std::optional<QDeadlineTimer> aaStartRetry;
179 if (!runAaStart(hdc, aaStartCommand))
180 aaStartRetry = QDeadlineTimer(aaStartRetryInterval);
181 const QDeadlineTimer hdcOutageDeadline(hdcOutageTolerance);
182 for (qint64 i = 0; i < maxIterations && !hdcOutageDeadline.hasExpired(); ++i) {
183 if (g_interrupted.load())
184 return q23::unexpected(u"interrupted"_s);
185 const ProcessState processState = queryProcessState(hdc, bundleName);
186 if (processState == ProcessState::Running)
187 return {};
188 // Fast test may have finished before pidof could see it.
189 const QString exitContent = readDeviceFile(hdc, shellExitCodePath);
190 bool ok = false;
191 exitContent.trimmed().toInt(&ok);
192 if (ok)
193 return {};
194 if (aaStartRetry && aaStartRetry->hasExpired()
195 && processState == ProcessState::NotRunning
196 && queryDeviceFileState(hdc, shellExitCodePath) == DeviceFileState::Absent) {
197 fprintf(stderr, "harmonyostestrunner: the app did not start, retrying aa start\n");
198 if (runAaStart(hdc, aaStartCommand))
199 aaStartRetry.reset();
200 else
201 aaStartRetry = QDeadlineTimer(aaStartRetryInterval);
202 }
203 QThread::sleep(pollInterval);
204 }
205 if (aaStartRetry)
206 return q23::unexpected(u"hdc did not answer aa start"_s);
207 return q23::unexpected(u"timed out waiting for process to start"_s);
208}
209
210static bool waitForStdoutFile(const Hdc &hdc, const QString &shellStdoutPath,
211 std::chrono::seconds timeout = 10s)
212{
213 constexpr auto pollInterval = 100ms;
214 const qint64 maxIterations = timeout / pollInterval;
215 const QDeadlineTimer hdcOutageDeadline(hdcOutageTolerance);
216 for (qint64 i = 0; i < maxIterations && !hdcOutageDeadline.hasExpired(); ++i) {
217 if (g_interrupted.load())
218 return false;
219 if (queryDeviceFileState(hdc, shellStdoutPath) == DeviceFileState::Present)
220 return true;
221 QThread::sleep(pollInterval);
222 }
223 return false;
224}
225
226static void answerBlockingDialogsIfStalled(BlockingTestDialogs &blockingTestDialogs,
227 const QElapsedTimer &elapsed, std::chrono::nanoseconds lastOutputAt)
228{
229 static std::chrono::nanoseconds lastDialogCheckAt {};
230
231 if (blockingTestDialogs.isEmpty())
232 return;
233
234 const std::chrono::nanoseconds now = elapsed.durationElapsed();
235 const auto quietRequired = now < dialogsExpectedWhileStarting
236 ? quietBeforeDialogCheckWhileStarting
237 : quietBeforeDialogCheck;
238 if (now - lastOutputAt < quietRequired || now - lastDialogCheckAt < quietRequired)
239 return;
240
241 blockingTestDialogs.answerVisibleDialog();
242 lastDialogCheckAt = now;
243}
244
245int main(int argc, char *argv[])
246{
247 std::signal(SIGINT, sigHandler);
248 std::signal(SIGTERM, sigHandler);
249
250 QCoreApplication app(argc, argv);
251 app.setApplicationName(u"harmonyostestrunner"_s);
252 app.setApplicationVersion(QString::fromLatin1(QT_VERSION_STR));
253
254 QCommandLineParser parser;
255 parser.setApplicationDescription(
256 u"Runs a single Qt auto test from an installed HarmonyOS test bundle HAP."_s);
257 parser.addHelpOption();
258 parser.addVersionOption();
259
260 parser.addPositionalArgument(
261 u"test-binary"_s,
262 u"Path to the test shared library (e.g. /path/to/libtst_qobject.so)"_s);
263
264 QCommandLineOption bundleNameOpt(
265 u"bundle-name"_s,
266 u"HarmonyOS bundle name of the installed test HAP (env: QT_HARMONYOS_BUNDLE_NAME)"_s,
267 u"name"_s,
268 qEnvironmentVariable("QT_HARMONYOS_BUNDLE_NAME", u"org.qtproject.autotests"_s));
269 parser.addOption(bundleNameOpt);
270
271 QCommandLineOption abilityNameOpt(
272 u"ability-name"_s,
273 u"HarmonyOS ability name inside the test HAP (env: QT_HARMONYOS_ABILITY_NAME)"_s,
274 u"name"_s,
275 qEnvironmentVariable("QT_HARMONYOS_ABILITY_NAME", u"QAbility"_s));
276 parser.addOption(abilityNameOpt);
277
278 QCommandLineOption hdcOpt(
279 u"hdc"_s,
280 u"Path to the hdc tool (env: QT_HARMONYOS_HDC)"_s,
281 u"path"_s,
282 qEnvironmentVariable("QT_HARMONYOS_HDC", u"hdc"_s));
283 parser.addOption(hdcOpt);
284
285 QCommandLineOption timeoutOpt(
286 u"timeout"_s,
287 u"Seconds to wait for a test to complete before aborting (env: QT_HARMONYOS_TEST_TIMEOUT)"_s,
288 u"seconds"_s,
289 qEnvironmentVariable("QT_HARMONYOS_TEST_TIMEOUT", u"300"_s));
290 parser.addOption(timeoutOpt);
291
292 QCommandLineOption noProgressTimeoutOpt(
293 u"no-progress-timeout"_s,
294 u"Seconds without a PASS/FAIL test case result before declaring the test hung "
295 u"(env: QT_HARMONYOS_NO_PROGRESS_TIMEOUT, 0 = disabled)"_s,
296 u"seconds"_s,
297 qEnvironmentVariable("QT_HARMONYOS_NO_PROGRESS_TIMEOUT", u"60"_s));
298 parser.addOption(noProgressTimeoutOpt);
299
300 QCommandLineOption deviceOpt(
301 u"device"_s,
302 u"hdc connect key (-t) for the target device — required when multiple devices "
303 u"are attached (env: QT_HARMONYOS_DEVICE)"_s,
304 u"key"_s,
305 qEnvironmentVariable("QT_HARMONYOS_DEVICE"));
306 parser.addOption(deviceOpt);
307
308 QCommandLineOption testConfigOpt(
309 u"test-config"_s,
310 u"Generated test bundle deployment settings, read for the system dialogs the runner has "
311 u"to answer (env: QT_HARMONYOS_TEST_CONFIG)"_s,
312 u"path"_s,
313 qEnvironmentVariable("QT_HARMONYOS_TEST_CONFIG"));
314 parser.addOption(testConfigOpt);
315
316 QCommandLineOption testEnvOpt(
317 u"test-env"_s,
318 u"Semicolon-separated NAME=VALUE pairs to set in the test environment "
319 u"(env: QT_HARMONYOS_TEST_ENV)"_s,
320 u"vars"_s,
321 qEnvironmentVariable("QT_HARMONYOS_TEST_ENV"));
322 parser.addOption(testEnvOpt);
323
324 parser.process(app);
325
326
327 const QStringList positional = parser.positionalArguments();
328 if (positional.isEmpty()) {
329 fprintf(stderr, "harmonyostestrunner: no test binary specified\n");
330 parser.showHelp(EXIT_ERROR);
331 }
332
333 const QString testBinaryPath = positional.first();
334 const QString testLibName = QFileInfo(testBinaryPath).fileName();
335 // Extra positionals (test function names, -v2, etc.) forwarded to the test.
336 const QStringList testArgs = positional.mid(1);
337 const QString bundleName = parser.value(bundleNameOpt);
338 const QString abilityName = parser.value(abilityNameOpt);
339 const Hdc hdc(parser.value(hdcOpt), parser.value(deviceOpt));
340 if (hdc.version().isEmpty()) {
341 fprintf(stderr, "harmonyostestrunner: cannot run hdc '%s', set --hdc or "
342 "QT_HARMONYOS_HDC\n", qPrintable(parser.value(hdcOpt)));
343 return EXIT_ERROR;
344 }
345 const std::chrono::seconds timeout{ parser.value(timeoutOpt).toInt() };
346 const std::chrono::seconds noProgressTimeout{ parser.value(noProgressTimeoutOpt).toInt() };
347
348 // Unique per-run ID, so a stale file that the cleanup below failed to
349 // remove is never matched.
350 const QString runId = QString::number(QDateTime::currentMSecsSinceEpoch());
351
352 const QString stdoutFilePrefix = u"qt_stdout_"_s;
353 const QString exitCodeFilePrefix = u"qt_exitcode_"_s;
354
355 const QString appBase = u"/data/storage/el2/base/files"_s;
356 const QString appStdoutPath = appBase + u"/"_s + stdoutFilePrefix + runId + u".txt"_s;
357 const QString appExitCodePath = appBase + u"/"_s + exitCodeFilePrefix + runId + u".txt"_s;
358
359 const QString shellBase = u"/data/app/el2/100/base/"_s + bundleName + u"/files"_s;
360 const QString shellStdoutPath = shellBase + u"/"_s + stdoutFilePrefix + runId + u".txt"_s;
361 const QString shellExitCodePath = shellBase + u"/"_s + exitCodeFilePrefix + runId + u".txt"_s;
362
363 const QTemporaryDir localCopyDir;
364 if (!localCopyDir.isValid()) {
365 fprintf(stderr, "harmonyostestrunner: cannot create a local directory for the test "
366 "output: %s\n", qPrintable(localCopyDir.errorString()));
367 return EXIT_ERROR;
368 }
369 TestOutputForwarder outputForwarder(
370 hdc, shellStdoutPath, localCopyDir.filePath(u"stdout.txt"_s));
371
372 const BundleState bundleState = queryBundleState(hdc, bundleName);
373 if (bundleState == BundleState::Unknown) {
374 fprintf(stderr, "harmonyostestrunner: warning: hdc did not answer the bundle check, "
375 "continuing without it\n");
376 }
377 if (bundleState == BundleState::NotInstalled) {
378 fprintf(stderr,
379 "harmonyostestrunner: bundle '%s' is not installed on the device.\n"
380 " Build and sign the test HAP, then install it with:\n"
381 " hdc install <path/to/autotests-signed.hap>\n",
382 qPrintable(bundleName));
383 return EXIT_ERROR;
384 }
385
386#if QT_CONFIG(systemsemaphore)
387 TestRunnerSystemSemaphore runnerLock(runnerLockKey(hdc.connectKey(), bundleName));
388 g_runnerLock = &runnerLock;
389 runnerLock.acquire();
390#endif
391
392 forceStopBundle(hdc, bundleName);
393 waitForProcessDeath(hdc, bundleName);
394 // Not after the run: a crashed or aborted runner would skip that cleanup.
395 removeFilesByName(hdc, shellBase,
396 { stdoutFilePrefix + u"*.txt"_s, exitCodeFilePrefix + u"*.txt"_s });
397
398 // --ps for string want.parameters, --pb for boolean.
399 QStringList aaStartCommand = {
400 u"aa"_s, u"start"_s,
401 u"-b"_s, bundleName,
402 u"-a"_s, abilityName,
403 u"--ps"_s, u"io.qt.appSharedLibNameOverride"_s, testLibName,
404 u"--ps"_s, u"io.qt.debug.redirectedStdoutPath"_s, appStdoutPath,
405 u"--ps"_s, u"io.qt.debug.exitCodePath"_s, appExitCodePath,
406 // Keep main alive across window destroy/create for visual tests.
407 u"--pb"_s, u"io.qt.useDefaultUiAbilityInstanceInQt"_s, u"false"_s,
408 };
409
410 aaStartCommand << u"--pb"_s << u"io.qt.watchdogEnabled"_s << u"false"_s;
411
412 if (!testArgs.isEmpty()) {
413 const QString json = QString::fromUtf8(
414 QJsonDocument(QJsonArray::fromStringList(testArgs)).toJson(QJsonDocument::Compact));
415 aaStartCommand += {u"--ps"_s, u"io.qt.appArgsJson"_s, shellSingleQuote(json)};
416 }
417
418 const QString testEnv = parser.value(testEnvOpt);
419 if (!testEnv.isEmpty()) {
420 QJsonObject envVarsObject;
421 for (const QString &pair : testEnv.split(u';', Qt::SkipEmptyParts)) {
422 const qsizetype eq = pair.indexOf(u'=');
423 if (eq < 0) {
424 fprintf(stderr, "harmonyostestrunner: ignoring malformed --test-env entry "
425 "(expected NAME=VALUE): %s\n", qPrintable(pair));
426 continue;
427 }
428 envVarsObject.insert(pair.left(eq), pair.mid(eq + 1));
429 }
430 const QString json = QString::fromUtf8(
431 QJsonDocument(envVarsObject).toJson(QJsonDocument::Compact));
432 aaStartCommand += {u"--ps"_s, u"io.qt.envVarsJson"_s, shellSingleQuote(json)};
433 }
434
435 const q23::expected<void, QString> started =
436 startAbility(hdc, aaStartCommand, bundleName, shellExitCodePath);
437 if (!started) {
438 fprintf(stderr, "harmonyostestrunner: %s: %s\n", qPrintable(testLibName),
439 qPrintable(started.error()));
440#if QT_CONFIG(systemsemaphore)
441 runnerLock.release();
442#endif
443 return EXIT_ERROR;
444 }
445
446 waitForStdoutFile(hdc, shellStdoutPath);
447
448 // hdc shell always returns 0; can't use `test -f`. Cat the file and check
449 // whether the contents parse as int.
450 constexpr auto pollInterval = 500ms;
451 constexpr auto loopStallThreshold = 30s;
452 constexpr auto heartbeatInterval = 30s;
453
454 QElapsedTimer elapsed;
455 elapsed.start();
456 int testExitCode = -1;
457 bool completed = false;
458 int aliveCheckCounter = 0;
459 std::optional<std::chrono::nanoseconds> lastTestProgressAt;
460 std::chrono::nanoseconds lastSuccessfulCopyAt {};
461 std::chrono::seconds lastHeartbeatAt {};
462 std::chrono::nanoseconds lastLoopPassAt {};
463 BlockingTestDialogs blockingTestDialogs(parser.value(testConfigOpt), hdc);
464 std::chrono::nanoseconds lastOutputAt {};
465
466 while (!g_interrupted.load() && elapsed.durationElapsed() < timeout) {
467 const std::chrono::nanoseconds loopPassAt = elapsed.durationElapsed();
468 if (loopPassAt - lastLoopPassAt > loopStallThreshold) {
469 fprintf(stderr, "harmonyostestrunner: %s: poll loop stalled for %lld ms\n",
470 qPrintable(testLibName),
471 static_cast<long long>((loopPassAt - lastLoopPassAt) / 1ms));
472 }
473 lastLoopPassAt = loopPassAt;
474
475 {
476 const q23::expected<QByteArray, QString> chunk = outputForwarder.forwardAvailable();
477 if (chunk) {
478 lastSuccessfulCopyAt = elapsed.durationElapsed();
479 } else {
480 fprintf(stderr, "harmonyostestrunner: warning: could not copy the test output "
481 "(%s)\n", qPrintable(chunk.error()));
482 }
483 if (chunk && !chunk->isEmpty()) {
484 // Markers match QPlainTestLogger output in qtestlog.cpp. If
485 // QTest's format ever changes, the no-progress watchdog silently
486 // stops firing — hung tests only trip the overall timeout.
487 lastOutputAt = elapsed.durationElapsed();
488 if (chunk->contains("PASS :") || chunk->contains("FAIL! :")
489 || chunk->contains("Totals:"))
490 lastTestProgressAt = elapsed.durationElapsed();
491 }
492 }
493
494 // Primary completion signal: exit-code file becomes parseable as int.
495 {
496 const QString exitContent =
497 readDeviceFile(hdc, shellExitCodePath);
498 bool ok = false;
499 const int code = exitContent.trimmed().toInt(&ok);
500 if (ok) {
501 testExitCode = code;
502 completed = true;
503 break;
504 }
505 }
506
507 answerBlockingDialogsIfStalled(blockingTestDialogs, elapsed, lastOutputAt);
508
509 // Liveness check every ~1.5 s. Re-read the exit-code file to cover the
510 // race where the process exits cleanly between checks.
511 if (++aliveCheckCounter % 3 == 0
512 && queryProcessState(hdc, bundleName) == ProcessState::NotRunning) {
513 const QString exitContent =
514 readDeviceFile(hdc, shellExitCodePath);
515 bool ok = false;
516 const int code = exitContent.trimmed().toInt(&ok);
517 if (ok) {
518 testExitCode = code;
519 completed = true;
520 break;
521 }
522
523 fprintf(stderr, "harmonyostestrunner: %s: process exited without writing "
524 "exit code — likely crashed\n", qPrintable(testLibName));
525 testExitCode = EXIT_NOEXITCODE;
526 completed = true;
527 break;
528 }
529
530 if (noProgressTimeout > 0s && lastTestProgressAt
531 && lastSuccessfulCopyAt - *lastTestProgressAt > noProgressTimeout)
532 {
533 fprintf(stderr,
534 "harmonyostestrunner: %s: no test case progress for %lld seconds (limit %lld) "
535 "— main thread likely deadlocked, force-stopping\n",
536 qPrintable(testLibName),
537 static_cast<long long>((lastSuccessfulCopyAt - *lastTestProgressAt) / 1s),
538 static_cast<long long>(noProgressTimeout.count()));
539 forceStopBundle(hdc, bundleName);
540 testExitCode = EXIT_CRASH;
541 completed = true;
542 break;
543 }
544
545 const auto elapsedSeconds =
546 std::chrono::duration_cast<std::chrono::seconds>(elapsed.durationElapsed());
547 if (elapsedSeconds >= lastHeartbeatAt + heartbeatInterval) {
548 fprintf(stderr, "harmonyostestrunner: %s still running (%lld s elapsed)\n",
549 qPrintable(testLibName), static_cast<long long>(elapsedSeconds.count()));
550 lastHeartbeatAt = elapsedSeconds;
551 }
552
553 QThread::sleep(pollInterval);
554 }
555
556 const bool interrupted = g_interrupted.load();
557
558 if (!completed) {
559 if (!interrupted) {
560 fprintf(stderr,
561 "harmonyostestrunner: TIMEOUT — %s did not complete within %lld seconds\n",
562 qPrintable(testLibName), static_cast<long long>(timeout.count()));
563 }
564 forceStopBundle(hdc, bundleName);
565 }
566
567 const bool outputComplete = outputForwarder.forwardRemaining(
568 []() {
569 return g_interrupted.load();
570 });
571
572#if QT_CONFIG(systemsemaphore)
573 runnerLock.release();
574#endif
575
576 if (!completed)
577 return interrupted ? EXIT_ERROR : EXIT_TIMEOUT;
578 if (testExitCode == 0 && !outputComplete)
579 return EXIT_ERROR;
580 return testExitCode;
581}
Definition hdc.h:17
static constexpr int EXIT_NOEXITCODE
Definition main.cpp:45
static constexpr int EXIT_ERROR
Definition main.cpp:43
static constexpr auto quietBeforeDialogCheck
Definition main.cpp:53
static QString shellSingleQuote(const QString &value)
Definition main.cpp:46
static constexpr int EXIT_CRASH
Definition main.cpp:43
static q23::expected< void, QString > startAbility(const Hdc &hdc, const QStringList &aaStartCommand, const QString &bundleName, const QString &shellExitCodePath, std::chrono::seconds timeout=30s)
Definition main.cpp:169
static std::atomic< bool > g_interrupted
Definition main.cpp:111
static constexpr auto quietBeforeDialogCheckWhileStarting
Definition main.cpp:54
static void sigHandler(int sig)
Definition main.cpp:113
static constexpr auto dialogsExpectedWhileStarting
Definition main.cpp:55
static bool runAaStart(const Hdc &hdc, const QStringList &aaStartCommand)
Definition main.cpp:157
static bool waitForStdoutFile(const Hdc &hdc, const QString &shellStdoutPath, std::chrono::seconds timeout=10s)
Definition main.cpp:210
static void removeFilesByName(const Hdc &hdc, const QString &directory, const QStringList &namePatterns)
Definition main.cpp:143
static void waitForProcessDeath(const Hdc &hdc, const QString &bundleName, std::chrono::seconds timeout=15s)
Definition main.cpp:127
static constexpr int EXIT_TIMEOUT
Definition main.cpp:44
static void answerBlockingDialogsIfStalled(BlockingTestDialogs &blockingTestDialogs, const QElapsedTimer &elapsed, std::chrono::nanoseconds lastOutputAt)
Definition main.cpp:226
ProcessState
DeviceFileState
BundleState
int main(int argc, char *argv[])
[ctor_close]