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>
This commit is contained in:
parent
8cf168b871
commit
8b26233573
@ -71,6 +71,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
# include <iostream>
|
||||||
# if !defined(Q_CC_MINGW) || (defined(Q_CC_MINGW) && defined(__MINGW64_VERSION_MAJOR))
|
# if !defined(Q_CC_MINGW) || (defined(Q_CC_MINGW) && defined(__MINGW64_VERSION_MAJOR))
|
||||||
# include <crtdbg.h>
|
# include <crtdbg.h>
|
||||||
# endif
|
# endif
|
||||||
@ -198,6 +199,17 @@ static struct iovec asyncSafeToString(int n, AsyncSafeIntBuffer &&result = Qt::U
|
|||||||
r.iov_len = ptr - result.array.data();
|
r.iov_len = ptr - result.array.data();
|
||||||
return r;
|
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
|
#endif // Q_OS_UNIX
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
@ -341,17 +353,21 @@ static void prepareStackTrace()
|
|||||||
#endif // Q_OS_UNIX
|
#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())
|
if (debugger == None || alreadyDebugging())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM) && !defined(Q_OS_INTEGRITY)
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM) && !defined(Q_OS_INTEGRITY)
|
||||||
const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
|
writeToStderr("\n=== Stack trace ===\n");
|
||||||
const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
|
|
||||||
writeToStderr("\n=== Received signal at function time: ", asyncSafeToString(msecsFunctionTime),
|
|
||||||
"ms, total time: ", asyncSafeToString(msecsTotalTime),
|
|
||||||
"ms, dumping stack ===\n");
|
|
||||||
|
|
||||||
// execlp() requires null-termination, so call the default constructor
|
// execlp() requires null-termination, so call the default constructor
|
||||||
AsyncSafeIntBuffer pidbuffer;
|
AsyncSafeIntBuffer pidbuffer;
|
||||||
@ -385,6 +401,7 @@ static void prepareStackTrace()
|
|||||||
int ret;
|
int ret;
|
||||||
EINTR_LOOP(ret, waitpid(pid, nullptr, 0));
|
EINTR_LOOP(ret, waitpid(pid, nullptr, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
writeToStderr("=== End of stack trace ===\n");
|
writeToStderr("=== End of stack trace ===\n");
|
||||||
#endif // Q_OS_UNIX && !Q_OS_WASM
|
#endif // Q_OS_UNIX && !Q_OS_WASM
|
||||||
}
|
}
|
||||||
@ -1246,6 +1263,8 @@ public:
|
|||||||
case TestFunctionStart:
|
case TestFunctionStart:
|
||||||
case TestFunctionEnd:
|
case TestFunctionEnd:
|
||||||
if (Q_UNLIKELY(!waitFor(locker, e))) {
|
if (Q_UNLIKELY(!waitFor(locker, e))) {
|
||||||
|
fflush(stderr);
|
||||||
|
printTestRunTime();
|
||||||
generateStackTrace();
|
generateStackTrace();
|
||||||
qFatal("Test function timed out");
|
qFatal("Test function timed out");
|
||||||
}
|
}
|
||||||
@ -2036,8 +2055,9 @@ private:
|
|||||||
|
|
||||||
static void actionHandler(int signum, siginfo_t * /* info */, void * /* ucontext */)
|
static void actionHandler(int signum, siginfo_t * /* info */, void * /* ucontext */)
|
||||||
{
|
{
|
||||||
const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
|
writeToStderr("Received signal ", asyncSafeToString(signum), "\n");
|
||||||
const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
|
printTestRunTime();
|
||||||
|
|
||||||
if (signum != SIGINT) {
|
if (signum != SIGINT) {
|
||||||
generateStackTrace();
|
generateStackTrace();
|
||||||
if (pauseOnCrash) {
|
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 =
|
bool isCrashingSignal =
|
||||||
std::find(crashingSignals.begin(), crashingSignals.end(), signum) != crashingSignals.end();
|
std::find(crashingSignals.begin(), crashingSignals.end(), signum) != crashingSignals.end();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user