diff options
| author | Mitch Curtis <mitch.curtis@qt.io> | 2024-03-04 17:24:21 +0800 |
|---|---|---|
| committer | Mitch Curtis <mitch.curtis@qt.io> | 2024-04-04 14:09:03 +0800 |
| commit | d72d7945d44d88d84dc1e9d4543a216641c7f01d (patch) | |
| tree | 2a4a857934fd93a1c59a6c842554f2654de029cd /src/testlib/qtestcase.cpp | |
| parent | c0014becca2cd376eadd5c8a0265e5cf47c9aa01 (diff) | |
QTest: expose API needed for Qt Quick Test to print crash backtraces
As discussed in QTQAINFRA-6146, there were two potential approaches to
enabling backtraces in Qt Quick tests:
- Either via a thorough refactoring of quicktest.cpp so that each
testcase is a Slot in a programmatically-created QObject-derived class,
which will be executed via QTest::qExec() similar to the documented
QTest way. This way the pre-existing code in QTest::qRun() will setup
the fatal signal handler.
- Or as a quick fix, modify quick_test_main_with_setup() to setup a
FatalSignalHandler class and invoke prepareStackTrace() like it's
already done in QTest::qRun(). This would require exporting these
symbols in the private header.
This patch enables the implementation of the latter, as it has a
fairly light footprint, is easily revertable (should we need to),
and allows us to immediately gain insight into crashes in CI.
Task-number: QTQAINFRA-6146
Change-Id: Iedffc968acb3e570214df34884ab0afcb6b30850
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
| -rw-r--r-- | src/testlib/qtestcase.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index afa96a7032a..42795fade78 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -432,11 +432,14 @@ static int eventDelay = -1; #if QT_CONFIG(thread) static int timeout = -1; #endif -static bool noCrashHandler = false; static int repetitions = 1; static bool repeatForever = false; static bool skipBlacklisted = false; +namespace Internal { +bool noCrashHandler = false; +} + static bool invokeTestMethodIfValid(QMetaMethod m, QObject *obj = QTest::currentTestObject) { if (!m.isValid()) @@ -843,7 +846,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool repeatForever = repetitions < 0; } } else if (strcmp(argv[i], "-nocrashhandler") == 0) { - QTest::noCrashHandler = true; + QTest::Internal::noCrashHandler = true; } else if (strcmp(argv[i], "-skipblacklisted") == 0) { QTest::skipBlacklisted = true; } else if (strcmp(argv[i], "-throwonfail") == 0) { @@ -1889,7 +1892,7 @@ int QTest::qRun() { std::optional<CrashHandler::FatalSignalHandler> handler; CrashHandler::prepareStackTrace(); - if (!noCrashHandler) + if (!Internal::noCrashHandler) handler.emplace(); bool seenBad = false; |
