From a5754b484ce559f4aedb04b02b91fa2805293068 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 11 Aug 2022 11:59:16 +0200 Subject: [PATCH] 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. Conflict resolved: dev has changed some uses of printf(...) to fprintf(stderr, ...), so apply to the printf() calls the same transformation as the fprintf() ones got on dev. Change-Id: Icab0ccd1fe434827ee92459ab0c97f9dc034754e Reviewed-by: Jason McDonald (cherry picked from commit f9b58b5c14518e5fcad634a3dae91b47f3068190) --- src/testlib/qtestcase.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 242246d279c..494a96cd641 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -358,7 +358,9 @@ static void printTestRunTime() { const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime()); 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"); } @@ -1869,12 +1871,14 @@ private: const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime()); const int msecsTotalTime = qRound(QTestLog::msecsTotalTime()); const void *exceptionAddress = exInfo->ExceptionRecord->ExceptionAddress; - printf("A crash occurred in %s.\n" - "Function time: %dms Total time: %dms\n\n" + printf("A crash occurred in %s.\n", appName); + if (const char *name = QTest::currentTestFunction()) + printf("While testing %s\n", name); + printf("Function time: %dms Total time: %dms\n\n" "Exception address: 0x%p\n" "Exception code : 0x%lx\n", - appName, msecsFunctionTime, msecsTotalTime, - exceptionAddress, exInfo->ExceptionRecord->ExceptionCode); + msecsFunctionTime, msecsTotalTime, exceptionAddress, + exInfo->ExceptionRecord->ExceptionCode); DebugSymbolResolver resolver(GetCurrentProcess()); if (resolver.isValid()) {