From c486cacba8fc6f22f8479ae588a399ae402f3bd0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 2 Sep 2015 16:26:41 +0200 Subject: [PATCH] Testlib/Windows: Output crash information on stdout instead of stderr. Make it easier to capture information about crashing tests in log files, since it is not possible to do something like foo > log.txt 2> errlog.txt on Windows. Adapt selftest. [ChangeLog][QtTest][Important Behavior Changes] Crash/exception information is now logged to standard output on Windows. Task-number: QTBUG-47370 Change-Id: I3e6a2d25855ed0f20516418a031990b562f5f757 Reviewed-by: Simon Hausmann --- src/testlib/qtestcase.cpp | 19 ++++++++++--------- .../auto/testlib/selftests/tst_selftests.cpp | 7 +++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index f9ae6138ad9..7f199182f9b 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2796,33 +2796,34 @@ static LONG WINAPI windowsFaultHandler(struct _EXCEPTION_POINTERS *exInfo) appName[0] = 0; const void *exceptionAddress = exInfo->ExceptionRecord->ExceptionAddress; - fprintf(stderr, "A crash occurred in %s.\n\n" - "Exception address: 0x%p\n" - "Exception code : 0x%lx\n", - appName, exceptionAddress, exInfo->ExceptionRecord->ExceptionCode); + printf("A crash occurred in %s.\n\n" + "Exception address: 0x%p\n" + "Exception code : 0x%lx\n", + appName, exceptionAddress, exInfo->ExceptionRecord->ExceptionCode); DebugSymbolResolver resolver(GetCurrentProcess()); if (resolver.isValid()) { DebugSymbolResolver::Symbol exceptionSymbol = resolver.resolveSymbol(DWORD64(exceptionAddress)); if (exceptionSymbol.name) { - fprintf(stderr, "Nearby symbol : %s\n", exceptionSymbol.name); + printf("Nearby symbol : %s\n", exceptionSymbol.name); delete [] exceptionSymbol.name; } void *stack[maxStackFrames]; - fputs("\nStack:\n", stderr); + fputs("\nStack:\n", stdout); const unsigned frameCount = CaptureStackBackTrace(0, DWORD(maxStackFrames), stack, NULL); for (unsigned f = 0; f < frameCount; ++f) { DebugSymbolResolver::Symbol symbol = resolver.resolveSymbol(DWORD64(stack[f])); if (symbol.name) { - fprintf(stderr, "#%3u: %s() - 0x%p\n", f + 1, symbol.name, (const void *)symbol.address); + printf("#%3u: %s() - 0x%p\n", f + 1, symbol.name, (const void *)symbol.address); delete [] symbol.name; } else { - fprintf(stderr, "#%3u: Unable to obtain symbol\n", f + 1); + printf("#%3u: Unable to obtain symbol\n", f + 1); } } } - fputc('\n', stderr); + fputc('\n', stdout); + fflush(stdout); return EXCEPTION_EXECUTE_HANDLER; } diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 9b76bca28c7..42d929c4a1f 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -625,6 +625,13 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge for (int n = 0; n < loggers.count(); ++n) { QString logger = loggers[n]; +#if defined(Q_OS_WIN) + if (n == 0 && subdir == QLatin1String("crashes")) { // Remove stack trace which is output to stdout. + const int exceptionLogStart = actualOutputs.first().indexOf("A crash occurred in "); + if (exceptionLogStart >= 0) + actualOutputs[0].truncate(exceptionLogStart); + } +#endif // Q_OS_WIN QList res = splitLines(actualOutputs[n]); const QString expectedFileName = expectedFileNameFromTest(subdir, logger); QList exp = expectedResult(expectedFileName);