summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-11-30 10:38:29 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2021-12-06 19:06:30 +0100
commitbe63c3011b2a841a2e84b70751ca5a76dbb03f3a (patch)
tree2b6dd1caab93d2f55650c85eda4859e4bf589b21 /src/testlib/qtestcase.cpp
parent9e835fe5a4f8b266082869fc4c0b218c8eec75fd (diff)
Suppress test set-up and tear-down in callgrind parent process
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ø <tor.arne.vestbo@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index db7c4d4a3d..8d0d549f17 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;