CodeCoverage: Save coverage data in QTestLog::stopLogging()

Currently when tests are crashing, aborting or hanging, their status are
reported with a status "Unknown" because SaveCoverageTool is never called
for them. The status of the test given by the coverage tool should be the
same as the one reported in the log output when the test is run. This change
will allow more accuracy in the status reported.

Add QTestResult::setCurrentAppname and QTestResult::currentAppname.
To retrieve the name of the current application running.

Task-number: QTQAINFRA-460

Change-Id: Icc476dc2d6cb28185e5447f1e79da6a8a31cad54
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
This commit is contained in:
Caroline Chao 2012-01-23 12:55:21 +01:00 committed by Qt by Nokia
parent 6a75785f49
commit 36f5cc848d
4 changed files with 37 additions and 20 deletions

View File

@ -947,22 +947,6 @@ static void installCoverageTool(const char * appname, const char * testname)
#endif
}
static void saveCoverageTool(const char * appname, bool testfailed)
{
#ifdef __COVERAGESCANNER__
// install again to make sure the filename is correct.
// without this, a plugin or similar may have changed the filename.
__coveragescanner_install(appname);
__coveragescanner_teststate(testfailed ? "FAILED" : "PASSED");
__coveragescanner_save();
__coveragescanner_testname("");
__coveragescanner_clear();
#else
Q_UNUSED(appname);
Q_UNUSED(testfailed);
#endif
}
namespace QTest
{
static QObject *currentTestObject = 0;
@ -1970,10 +1954,13 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
const QMetaObject *metaObject = testObject->metaObject();
QTEST_ASSERT(metaObject);
QTestResult::setCurrentTestObject(metaObject->className());
QTestResult::setCurrentAppname(argv[0]);
qtest_qParseArgs(argc, argv, false);
installCoverageTool(argv[0], metaObject->className());
QTestResult::setCurrentTestObject(metaObject->className());
qtest_qParseArgs(argc, argv, false);
#ifdef QTESTLIB_USE_VALGRIND
if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) {
const QStringList origAppArgs(QCoreApplication::arguments());
@ -2025,8 +2012,6 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
}
#endif
saveCoverageTool(argv[0], QTestLog::failCount());
#ifdef QTESTLIB_USE_VALGRIND
if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess)
return callgrindChildExitCode;

View File

@ -56,6 +56,22 @@
QT_BEGIN_NAMESPACE
static void saveCoverageTool(const char * appname, bool testfailed)
{
#ifdef __COVERAGESCANNER__
// install again to make sure the filename is correct.
// without this, a plugin or similar may have changed the filename.
__coveragescanner_install(appname);
__coveragescanner_teststate(testfailed ? "FAILED" : "PASSED");
__coveragescanner_save();
__coveragescanner_testname("");
__coveragescanner_clear();
#else
Q_UNUSED(appname);
Q_UNUSED(testfailed);
#endif
}
namespace QTest {
int fails = 0;
@ -368,6 +384,7 @@ void QTestLog::stopLogging()
QTest::TestLoggers::stopLogging();
QTest::TestLoggers::destroyLoggers();
QTest::loggerUsingStdout = false;
saveCoverageTool(QTestResult::currentAppname(), failCount() != 0);
}
void QTestLog::addLogger(LogMode mode, const char *filename)

View File

@ -64,6 +64,8 @@ namespace QTest
static const char *expectFailComment = 0;
static int expectFailMode = 0;
static const char *currentAppname = 0;
}
void QTestResult::reset()
@ -313,4 +315,14 @@ bool QTestResult::skipCurrentTest()
return QTest::skipCurrentTest;
}
void QTestResult::setCurrentAppname(const char *appname)
{
QTest::currentAppname = appname;
}
const char *QTestResult::currentAppname()
{
return QTest::currentAppname;
}
QT_END_NAMESPACE

View File

@ -95,6 +95,9 @@ public:
static void setSkipCurrentTest(bool value);
static bool skipCurrentTest();
static void setCurrentAppname(const char *appname);
static const char *currentAppname();
private:
Q_DISABLE_COPY(QTestResult)
};