Include current test name in crash reports

Previously a crashing test's output would end with the last completed
test's output followed by a crash report, leading readers
(understandably enough) to conclude that the last-named test is the
one that crashed. In fact the crashing test is typically the next one
in the class definition.

Include the current test function's name (when non-null) in the output
accompanying crash logs. This always goes to stderr so does not show
up in the expected output.

Pick-to: 6.4
Change-Id: Icab0ccd1fe434827ee92459ab0c97f9dc034754e
Reviewed-by: Jason McDonald <macadder1@gmail.com>
This commit is contained in:
Edward Welbourne 2022-08-11 11:59:16 +02:00
parent 013574a5fd
commit f9b58b5c14

View File

@ -358,7 +358,9 @@ static void printTestRunTime()
{ {
const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime()); const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
const int msecsTotalTime = qRound(QTestLog::msecsTotalTime()); const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
writeToStderr("\n Function time: ", asyncSafeToString(msecsFunctionTime), const char *const name = QTest::currentTestFunction();
writeToStderr("\n ", name ? name : "[Non-test]",
" function time: ", asyncSafeToString(msecsFunctionTime),
"ms, total time: ", asyncSafeToString(msecsTotalTime), "ms\n"); "ms, total time: ", asyncSafeToString(msecsTotalTime), "ms\n");
} }
@ -1878,12 +1880,14 @@ private:
const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime()); const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime());
const int msecsTotalTime = qRound(QTestLog::msecsTotalTime()); const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
const void *exceptionAddress = exInfo->ExceptionRecord->ExceptionAddress; const void *exceptionAddress = exInfo->ExceptionRecord->ExceptionAddress;
fprintf(stderr, "A crash occurred in %s.\n" fprintf(stderr, "A crash occurred in %s.\n", appName);
"Function time: %dms Total time: %dms\n\n" if (const char *name = QTest::currentTestFunction())
fprintf(stderr, "While testing %s\n", name);
fprintf(stderr, "Function time: %dms Total time: %dms\n\n"
"Exception address: 0x%p\n" "Exception address: 0x%p\n"
"Exception code : 0x%lx\n", "Exception code : 0x%lx\n",
appName, msecsFunctionTime, msecsTotalTime, msecsFunctionTime, msecsTotalTime, exceptionAddress,
exceptionAddress, exInfo->ExceptionRecord->ExceptionCode); exInfo->ExceptionRecord->ExceptionCode);
DebugSymbolResolver resolver(GetCurrentProcess()); DebugSymbolResolver resolver(GetCurrentProcess());
if (resolver.isValid()) { if (resolver.isValid()) {