summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-05-02 19:50:07 -0700
committerThiago Macieira <thiago.macieira@intel.com>2022-05-20 12:01:31 -0700
commit55a4d35dc3e7da9686727469fb6fbf2e516ddd4b (patch)
treee67a8dbc4e98ba9d9c38e7ae29b4a39f8a40dd25 /src/testlib/qtestcase.cpp
parentc8d9b7291a9d48d8b0e4043b3cf9664d4b261e77 (diff)
FatalSignalHandler: remove call to qEnvironmentXxx from handler code
The Qt environment handling functions lock a mutex. That's a big no-no in signal handlers. [ChangeLog][QtTest][Behavior Change] QtTest will now check the value of the environment variable QTEST_PAUSE_ON_CRASH in QTest::qRun(), so if a test wants to modify this variable, it must do so from the main() or initMain() functions, not in the test itself (including initTestCase()). Pick-to: 6.3 Change-Id: I5ff8e16fcdcb4ffd9ab6fffd16eb78867cd8f54e Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 43facebe58..904c007594 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -1782,6 +1782,7 @@ public:
SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX);
SetUnhandledExceptionFilter(windowsFaultHandler);
#elif defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
+ pauseOnCrash = qEnvironmentVariableIsSet("QTEST_PAUSE_ON_CRASH");
sigemptyset(&handledSignals);
const int fatalSignals[] = {
@@ -1940,7 +1941,7 @@ private:
const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
if (signum != SIGINT) {
generateStackTrace();
- if (qEnvironmentVariableIsSet("QTEST_PAUSE_ON_CRASH")) {
+ if (pauseOnCrash) {
writeToStderr("Pausing process ", asyncSafeToString(getpid()),
" for debugging\n");
raise(SIGSTOP);
@@ -1962,8 +1963,12 @@ private:
}
sigset_t handledSignals;
+ static bool pauseOnCrash;
#endif // defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
};
+#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
+bool FatalSignalHandler::pauseOnCrash = false;
+#endif // defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
} // namespace