From e85b4ed77a6b77e4a5aa9b858e41ff4bbcea04b0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 21 Feb 2014 19:02:45 -0800 Subject: [PATCH] QtTest: Don't crash when -callgrind is used on QTEST_APPLESS_MAIN If there's no qApp, then QCoreApplication::arguments() returns an empty list (after printing a warning). That means the callgrind runner can't get the arguments it needs in order to rerun the benchmark. The crash happens because it always uses .at(0) to try and get the executable's path. Even if we get the path from somewhere else, we still need the arguments. Change-Id: I5c74af4d96fc5824b2b7fd7a89648d78393016e2 Reviewed-by: Sergio Ahumada --- src/testlib/qtestcase.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index f0520330afb..10bf200f4f9 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2442,6 +2442,9 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) #ifdef QTESTLIB_USE_VALGRIND if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) { + if (!qApp) + qFatal("QtTest: -callgrind option is not available with QTEST_APPLESS_MAIN"); + const QStringList origAppArgs(QCoreApplication::arguments()); if (!QBenchmarkValgrindUtils::rerunThroughCallgrind(origAppArgs, callgrindChildExitCode)) return -1;