From be63c3011b2a841a2e84b70751ca5a76dbb03f3a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 30 Nov 2021 10:38:29 +0100 Subject: [PATCH] Suppress test set-up and tear-down in callgrind parent process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running a test using -callgrind, we recurse into a child process, run under valgrind, to which we pass -callgrindchild; and we only want the output from the child process, since the parent won't actually be running any tests. We also won't be using the global data table for the test in the parent process. So bypass the set-up and tear-down of both logging and the global data table in the parent process. Prior to commit 3ee6d8d336db2d9d15818b234ce16531ea0cdd48, these parts of the set-up and tear-down were skipped in the callgrind parent process, but that refactoring split qExec() up into qInit(), qRun() and qCleanup() to enable QtQuick to recombine them to implement an equivalent of qExec(), calling qRun() once for each built-in style. It needs these pieces of set-up to happen in qInit(), and of tear-down in qCleanup(), to avoid repeating them for each style. Leave a comment in qExec() that might help future readers to understand why it's done the way it is. Change-Id: Ieaca9a125c713b8fcf8dec8f9be0c024a798d504 Reviewed-by: Tor Arne Vestbø Reviewed-by: Mårten Nordheim --- src/testlib/qtestcase.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index db7c4d4a3dc..8d0d549f17f 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1877,6 +1877,10 @@ static void initEnvironment() int QTest::qExec(QObject *testObject, int argc, char **argv) { + // NB: QtQuick's testing recombines qInit(), qRun() and qCleanup() to + // provide a replacement for qExec() that calls qRun() once for each + // built-in style. So think twice about moving parts between these three + // functions, as doing so may mess up QtQuick's testing. qInit(testObject, argc, argv); int ret = qRun(); qCleanup(); @@ -1920,8 +1924,13 @@ void QTest::qInit(QObject *testObject, int argc, char **argv) qtest_qParseArgs(argc, argv, false); - QTestTable::globalTestTable(); - QTestLog::startLogging(); +#if QT_CONFIG(valgrind) + if (QBenchmarkGlobalData::current->mode() != QBenchmarkGlobalData::CallgrindParentProcess) +#endif + { + QTestTable::globalTestTable(); + QTestLog::startLogging(); + } } /*! \internal @@ -2005,8 +2014,13 @@ void QTest::qCleanup() { currentTestObject = nullptr; - QTestTable::clearGlobalTestTable(); - QTestLog::stopLogging(); +#if QT_CONFIG(valgrind) + if (QBenchmarkGlobalData::current->mode() != QBenchmarkGlobalData::CallgrindParentProcess) +#endif + { + QTestLog::stopLogging(); + QTestTable::clearGlobalTestTable(); + } delete QBenchmarkGlobalData::current; QBenchmarkGlobalData::current = nullptr;