diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2023-08-26 17:16:27 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2023-09-06 12:36:06 -0700 |
commit | b6462bbd5c1708d7743c99a56f2d90026a801e2f (patch) | |
tree | 18b46a1989759f081e0d9d91a4ede9e5f0526c6e /tests/auto/testlib | |
parent | 1c8402dd412e64216d42bfa6c15e8f3d58081a81 (diff) |
tst_selftests: split the qFatal() test away from tst_Silent
This allows us to control whether to run this particular test in ASan
mode or with specific loggers or not. Adding the expected log output for
tst_silent for other loggers is left as an exercise to the reader.
Change-Id: Ifa1111900d6945ea8e05fffd177f1548c8c8e714
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/testlib')
8 files changed, 63 insertions, 19 deletions
diff --git a/tests/auto/testlib/selftests/CMakeLists.txt b/tests/auto/testlib/selftests/CMakeLists.txt index 79aefb3a10..643647e6d6 100644 --- a/tests/auto/testlib/selftests/CMakeLists.txt +++ b/tests/auto/testlib/selftests/CMakeLists.txt @@ -91,6 +91,7 @@ set(subprograms printdatatagswithglobaltags qexecstringlist silent + silent_fatal signaldumper singleskip skip diff --git a/tests/auto/testlib/selftests/expected_silent.txt b/tests/auto/testlib/selftests/expected_silent.txt index 127e39a6c1..6c9b71a835 100644 --- a/tests/auto/testlib/selftests/expected_silent.txt +++ b/tests/auto/testlib/selftests/expected_silent.txt @@ -5,7 +5,4 @@ FAIL! : tst_Silent::fail() 'false' returned FALSE. (This test should fail) Loc: [qtbase/tests/auto/testlib/selftests/silent/tst_silent.cpp(0)] XPASS : tst_Silent::xpass() 'true' returned TRUE unexpectedly. (This test should XPASS) Loc: [qtbase/tests/auto/testlib/selftests/silent/tst_silent.cpp(0)] -QFATAL : tst_Silent::messages() This is a fatal error message that should still appear in silent test output -FAIL! : tst_Silent::messages() Received a fatal error. - Loc: [qtbase/tests/auto/testlib/selftests/silent/tst_silent.cpp(0)] -Totals: 3 passed, 3 failed, 1 skipped, 0 blacklisted, 0ms +Totals: 5 passed, 2 failed, 1 skipped, 0 blacklisted, 0ms diff --git a/tests/auto/testlib/selftests/expected_silent_fatal.txt b/tests/auto/testlib/selftests/expected_silent_fatal.txt new file mode 100644 index 0000000000..fb00066c13 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_silent_fatal.txt @@ -0,0 +1,5 @@ +Testing tst_SilentFatal +QFATAL : tst_SilentFatal::fatalmessages() This is a fatal error message that should still appear in silent test output +FAIL! : tst_SilentFatal::fatalmessages() Received a fatal error. + Loc: [qtbase/tests/auto/testlib/selftests/silent_fatal/tst_silent_fatal.cpp(0)] +Totals: 1 passed, 1 failed, 0 skipped, 0 blacklisted, 0ms diff --git a/tests/auto/testlib/selftests/generate_expected_output.py b/tests/auto/testlib/selftests/generate_expected_output.py index be3633db74..2a7a070640 100755 --- a/tests/auto/testlib/selftests/generate_expected_output.py +++ b/tests/auto/testlib/selftests/generate_expected_output.py @@ -37,7 +37,7 @@ TESTS = ['assert', 'badxml', 'benchlibcallgrind', 'benchlibcounting', 'fetchbogus', 'findtestdata', 'float', 'globaldata', 'longstring', 'maxwarnings', 'mouse', 'multiexec', 'pairdiagnostics', 'pass', 'printdatatags', 'printdatatagswithglobaltags', 'qexecstringlist', - 'signaldumper', 'silent', 'singleskip', 'skip', 'skipcleanup', + 'signaldumper', 'silent', 'silent_fatal', 'singleskip', 'skip', 'skipcleanup', 'skipcleanuptestcase', 'skipinit', 'skipinitdata', 'sleep', 'strcmp', 'subtest', 'testlib', 'tuplediagnostics', 'verbose1', 'verbose2', 'verifyexceptionthrown', 'warnings', 'watchdog', 'junit', 'keyboard'] @@ -254,7 +254,7 @@ def testEnv(testname, # Must match tst_Selftests::runSubTest_data(): crashers = ("assert", "crashes", "crashedterminate", "exceptionthrow", "faildatatype", "failfetchtype", - "fetchbogus", "silent", "watchdog")): + "fetchbogus", "silent_fatal", "watchdog")): """Determine the environment in which to run a test.""" data = baseEnv() if testname in crashers: @@ -281,6 +281,7 @@ def shouldIgnoreTest(testname, format): "printdatatags", "printdatatagswithglobaltags", "silent", + "silent_fatal", "crashes", "benchlibcallgrind", "float", diff --git a/tests/auto/testlib/selftests/silent/tst_silent.cpp b/tests/auto/testlib/selftests/silent/tst_silent.cpp index 3a3fbf2bf2..66cf68f098 100644 --- a/tests/auto/testlib/selftests/silent/tst_silent.cpp +++ b/tests/auto/testlib/selftests/silent/tst_silent.cpp @@ -15,8 +15,6 @@ private slots: void fail(); void xfail(); void xpass(); - - // This test function must be last, as it calls qFatal(). void messages(); }; @@ -55,7 +53,6 @@ void tst_Silent::messages() qCritical("This is a critical message that should not appear in silent test output"); qInfo("This is an info message that should not appear in silent test output"); QTestLog::info("This is an internal testlib info message that should not appear in silent test output", __FILE__, __LINE__); - qFatal("This is a fatal error message that should still appear in silent test output"); } QTEST_MAIN_WRAPPER(tst_Silent, diff --git a/tests/auto/testlib/selftests/silent_fatal/CMakeLists.txt b/tests/auto/testlib/selftests/silent_fatal/CMakeLists.txt new file mode 100644 index 0000000000..f19ffb4ff6 --- /dev/null +++ b/tests/auto/testlib/selftests/silent_fatal/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +qt_internal_add_executable(silent_fatal + NO_INSTALL + OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + SOURCES + tst_silent_fatal.cpp + LIBRARIES + Qt::TestPrivate +) + +# No coverage because this crashes, making data collection difficult, if not +# impossible. diff --git a/tests/auto/testlib/selftests/silent_fatal/tst_silent_fatal.cpp b/tests/auto/testlib/selftests/silent_fatal/tst_silent_fatal.cpp new file mode 100644 index 0000000000..fcb97ca4cd --- /dev/null +++ b/tests/auto/testlib/selftests/silent_fatal/tst_silent_fatal.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include <QtCore/QCoreApplication> +#include <QTest> +#include <private/qtestlog_p.h> + +class tst_SilentFatal : public QObject +{ + Q_OBJECT + +private slots: + void fatalmessages(); +}; +void tst_SilentFatal::fatalmessages() +{ + qFatal("This is a fatal error message that should still appear in silent test output"); +} + +QTEST_MAIN_WRAPPER(tst_SilentFatal, + std::vector<const char*> args(argv, argv + argc); + args.push_back("-silent"); + args.push_back("-nocrashhandler"); + argc = int(args.size()); + argv = const_cast<char**>(&args[0]); + QTEST_MAIN_SETUP()) + +#include "tst_silent_fatal.moc" diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 7ceeb12f75..adcc32da6b 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -699,7 +699,8 @@ bool TestLogger::shouldIgnoreTest(const QString &test) const || test == "benchliboptions" || test == "printdatatags" || test == "printdatatagswithglobaltags" - || test == "silent") + || test == "silent" + || test == "silent_fatal") return true; // These tests produce variable output (callgrind because of #if-ery, @@ -764,11 +765,6 @@ void checkErrorOutput(const QString &test, const QByteArray &errorOutput) || test == "benchlibcallgrind") return; -#ifdef Q_CC_MINGW - if (test == "silent") // calls qFatal() - return; -#endif - #ifdef Q_OS_WIN if (test == "crashes") return; // Complains about uncaught exception @@ -782,12 +778,17 @@ void checkErrorOutput(const QString &test, const QByteArray &errorOutput) return; // Outputs "Received signal 6 (SIGABRT)" #endif -#ifdef Q_OS_LINUX - if (test == "silent") { + if (test == "silent_fatal") { +#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) + // Under ASan, this test is not silent + return; +#elif defined(Q_CC_MINGW) + // Originally QTBUG-29014 (I can't reproduce this -Thiago) + return; +#endif if (QTestPrivate::isRunningArmOnX86()) return; // QEMU outputs to stderr about uncaught signals } -#endif INFO(errorOutput.toStdString()); REQUIRE(errorOutput.isEmpty()); @@ -974,7 +975,7 @@ TestProcessResult runTestProcess(const QString &test, const QStringList &argumen const bool expectedCrash = test == "assert" || test == "exceptionthrow" || test == "fetchbogus" || test == "crashedterminate" || test == "faildatatype" || test == "failfetchtype" - || test == "crashes" || test == "silent" || test == "watchdog"; + || test == "crashes" || test == "silent_fatal" || test == "watchdog"; if (expectedCrash) { environment.insert("QTEST_DISABLE_CORE_DUMP", "1"); |