summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-05-03 19:10:08 -0700
committerThiago Macieira <thiago.macieira@intel.com>2022-06-03 16:52:41 -0700
commit8b262335733a25a41a9625bfc5e29d41e7e25481 (patch)
treefec0b7ee86fa142eeb59bde35f59812384fabd16 /src/testlib/qtestcase.cpp
parent8cf168b8710296bf3e6a983f9bec0a27fe68d6b4 (diff)
qtestcase.cpp: create a common function to print the test runtime
The time was getting printed twice for the stack trace, but zero for the watch dog if the stack trace was disabled. Selftest appears to pass (though I thought it shouldn't). Change-Id: I5ff8e16fcdcb4ffd9ab6fffd16ebc4ec99e7fc5a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 7eeacccf39..644bc9116b 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -71,6 +71,7 @@
#endif
#ifdef Q_OS_WIN
+# include <iostream>
# if !defined(Q_CC_MINGW) || (defined(Q_CC_MINGW) && defined(__MINGW64_VERSION_MAJOR))
# include <crtdbg.h>
# endif
@@ -198,6 +199,17 @@ static struct iovec asyncSafeToString(int n, AsyncSafeIntBuffer &&result = Qt::U
r.iov_len = ptr - result.array.data();
return r;
};
+#elif defined(Q_OS_WIN)
+// Windows doesn't need to be async-safe
+template <typename... Args> static void writeToStderr(Args &&... args)
+{
+ (std::cerr << ... << args);
+}
+
+static std::string asyncSafeToString(int n)
+{
+ return std::to_string(n);
+}
#endif // Q_OS_UNIX
} // unnamed namespace
@@ -341,17 +353,21 @@ static void prepareStackTrace()
#endif // Q_OS_UNIX
}
-[[maybe_unused]] static void generateStackTrace()
+static void printTestRunTime()
+{
+ const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
+ const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
+ writeToStderr("\n Function time: ", asyncSafeToString(msecsFunctionTime),
+ "ms, total time: ", asyncSafeToString(msecsTotalTime), "ms\n");
+}
+
+static void generateStackTrace()
{
if (debugger == None || alreadyDebugging())
return;
#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM) && !defined(Q_OS_INTEGRITY)
- const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
- const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
- writeToStderr("\n=== Received signal at function time: ", asyncSafeToString(msecsFunctionTime),
- "ms, total time: ", asyncSafeToString(msecsTotalTime),
- "ms, dumping stack ===\n");
+ writeToStderr("\n=== Stack trace ===\n");
// execlp() requires null-termination, so call the default constructor
AsyncSafeIntBuffer pidbuffer;
@@ -385,6 +401,7 @@ static void prepareStackTrace()
int ret;
EINTR_LOOP(ret, waitpid(pid, nullptr, 0));
}
+
writeToStderr("=== End of stack trace ===\n");
#endif // Q_OS_UNIX && !Q_OS_WASM
}
@@ -1246,6 +1263,8 @@ public:
case TestFunctionStart:
case TestFunctionEnd:
if (Q_UNLIKELY(!waitFor(locker, e))) {
+ fflush(stderr);
+ printTestRunTime();
generateStackTrace();
qFatal("Test function timed out");
}
@@ -2036,8 +2055,9 @@ private:
static void actionHandler(int signum, siginfo_t * /* info */, void * /* ucontext */)
{
- const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
- const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
+ writeToStderr("Received signal ", asyncSafeToString(signum), "\n");
+ printTestRunTime();
+
if (signum != SIGINT) {
generateStackTrace();
if (pauseOnCrash) {
@@ -2047,10 +2067,6 @@ private:
}
}
- writeToStderr("Received signal ", asyncSafeToString(signum),
- "\n Function time: ", asyncSafeToString(msecsFunctionTime),
- "ms Total time: ", asyncSafeToString(msecsTotalTime), "ms\n");
-
bool isCrashingSignal =
std::find(crashingSignals.begin(), crashingSignals.end(), signum) != crashingSignals.end();