diff options
author | Christian Stenger <christian.stenger@theqtcompany.com> | 2014-12-01 16:12:05 +0100 |
---|---|---|
committer | Christian Stenger <christian.stenger@theqtcompany.com> | 2014-12-04 13:52:16 +0100 |
commit | 32a6849fae4cfa35a8c5f395701cdbb15c31ef03 (patch) | |
tree | 52e436c83ab18ef869f25a103e3c625c01e2e6af | |
parent | d2784769567a96221ac036e90b1f3f207257cf27 (diff) | |
download | qt-creator-32a6849fae4cfa35a8c5f395701cdbb15c31ef03.tar.gz |
Add support for minimal benchmarks
-rw-r--r-- | plugins/autotest/autotest.qrc | 1 | ||||
-rw-r--r-- | plugins/autotest/images/benchmark.png | bin | 0 -> 374 bytes | |||
-rw-r--r-- | plugins/autotest/testresult.cpp | 4 | ||||
-rw-r--r-- | plugins/autotest/testresult.h | 1 | ||||
-rw-r--r-- | plugins/autotest/testresultdelegate.cpp | 38 | ||||
-rw-r--r-- | plugins/autotest/testresultmodel.cpp | 6 | ||||
-rw-r--r-- | plugins/autotest/testresultspane.cpp | 1 | ||||
-rw-r--r-- | plugins/autotest/testrunner.cpp | 37 |
8 files changed, 78 insertions, 10 deletions
diff --git a/plugins/autotest/autotest.qrc b/plugins/autotest/autotest.qrc index e76830ba04..7b98beaab9 100644 --- a/plugins/autotest/autotest.qrc +++ b/plugins/autotest/autotest.qrc @@ -16,6 +16,7 @@ <file>images/xpass.png</file> <file>images/blacklisted_fail.png</file> <file>images/blacklisted_pass.png</file> + <file>images/benchmark.png</file> <file>images/run.png</file> <file>images/runselected.png</file> <file>images/stop.png</file> diff --git a/plugins/autotest/images/benchmark.png b/plugins/autotest/images/benchmark.png Binary files differnew file mode 100644 index 0000000000..c9d3c5b2b5 --- /dev/null +++ b/plugins/autotest/images/benchmark.png diff --git a/plugins/autotest/testresult.cpp b/plugins/autotest/testresult.cpp index 0373b72010..175644d570 100644 --- a/plugins/autotest/testresult.cpp +++ b/plugins/autotest/testresult.cpp @@ -76,6 +76,8 @@ ResultType TestResult::toResultType(int rt) return BLACKLISTED_PASS; case BLACKLISTED_FAIL: return BLACKLISTED_FAIL; + case BENCHMARK: + return BENCHMARK; case MESSAGE_DEBUG: return MESSAGE_DEBUG; case MESSAGE_WARN: @@ -102,6 +104,8 @@ QString TestResult::resultToString(const ResultType type) return QLatin1String("XPASS"); case SKIP: return QLatin1String("SKIP"); + case BENCHMARK: + return QLatin1String("BENCH"); case MESSAGE_DEBUG: return QLatin1String("DEBUG"); case MESSAGE_WARN: diff --git a/plugins/autotest/testresult.h b/plugins/autotest/testresult.h index f1f246ef49..6ebcff9a6f 100644 --- a/plugins/autotest/testresult.h +++ b/plugins/autotest/testresult.h @@ -33,6 +33,7 @@ enum ResultType { SKIP, BLACKLISTED_PASS, BLACKLISTED_FAIL, + BENCHMARK, MESSAGE_DEBUG, MESSAGE_WARN, MESSAGE_FATAL, diff --git a/plugins/autotest/testresultdelegate.cpp b/plugins/autotest/testresultdelegate.cpp index b3b210f11d..21a595fa6f 100644 --- a/plugins/autotest/testresultdelegate.cpp +++ b/plugins/autotest/testresultdelegate.cpp @@ -85,6 +85,7 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op painter->setPen(tmp); } + const QString desc = testResult.description(); QString output; switch (type) { case ResultType::PASS: @@ -96,13 +97,23 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op output = testResult.className() + QLatin1String("::") + testResult.testCase(); if (!testResult.dataTag().isEmpty()) output.append(QString::fromLatin1(" (%1)").arg(testResult.dataTag())); - if (selected && !testResult.description().isEmpty()) { - output.append(QLatin1Char('\n')); - output.append(testResult.description()); + if (selected && !desc.isEmpty()) { + output.append(QLatin1Char('\n')).append(desc); + } + break; + case ResultType::BENCHMARK: + output = testResult.className() + QLatin1String("::") + testResult.testCase(); + if (!testResult.dataTag().isEmpty()) + output.append(QString::fromLatin1(" (%1)").arg(testResult.dataTag())); + if (!desc.isEmpty()) { + int breakPos = desc.indexOf(QLatin1Char('(')); + output.append(QLatin1String(" - ")).append(desc.left(breakPos)); + if (selected) + output.append(QLatin1Char('\n')).append(desc.mid(breakPos)); } break; default: - output = testResult.description(); + output = desc; if (!selected) output = output.split(QLatin1Char('\n')).first(); } @@ -188,6 +199,7 @@ QSize TestResultDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo if (selected) { TestResult testResult = resultModel->testResult(resultFilterModel->mapToSource(index)); + QString desc = testResult.description(); QString output; switch (testResult.result()) { case ResultType::PASS: @@ -199,13 +211,23 @@ QSize TestResultDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo output = testResult.className() + QLatin1String("::") + testResult.testCase(); if (!testResult.dataTag().isEmpty()) output.append(QString::fromLatin1(" (%1)").arg(testResult.dataTag())); - if (!testResult.description().isEmpty()) { - output.append(QLatin1Char('\n')); - output.append(testResult.description()); + if (!desc.isEmpty()) { + output.append(QLatin1Char('\n')).append(desc); + } + break; + case ResultType::BENCHMARK: + output = testResult.className() + QLatin1String("::") + testResult.testCase(); + if (!testResult.dataTag().isEmpty()) + output.append(QString::fromLatin1(" (%1)").arg(testResult.dataTag())); + if (!desc.isEmpty()) { + int breakPos = desc.indexOf(QLatin1Char('(')); + output.append(QLatin1String(" - ")).append(desc.left(breakPos)); + if (selected) + output.append(QLatin1Char('\n')).append(desc.mid(breakPos)); } break; default: - output = testResult.description(); + output = desc; } output.replace(QLatin1Char('\n'), QChar::LineSeparator); diff --git a/plugins/autotest/testresultmodel.cpp b/plugins/autotest/testresultmodel.cpp index ab303364c4..8a5e8aca64 100644 --- a/plugins/autotest/testresultmodel.cpp +++ b/plugins/autotest/testresultmodel.cpp @@ -64,7 +64,7 @@ int TestResultModel::columnCount(const QModelIndex &parent) const } static QIcon testResultIcon(ResultType result) { - static QIcon icons[10] = { + static QIcon icons[11] = { QIcon(QLatin1String(":/images/pass.png")), QIcon(QLatin1String(":/images/fail.png")), QIcon(QLatin1String(":/images/xfail.png")), @@ -72,6 +72,7 @@ static QIcon testResultIcon(ResultType result) { QIcon(QLatin1String(":/images/skip.png")), QIcon(QLatin1String(":/images/blacklisted_pass.png")), QIcon(QLatin1String(":/images/blacklisted_fail.png")), + QIcon(QLatin1String(":/images/benchmark.png")), QIcon(QLatin1String(":/images/debug.png")), QIcon(QLatin1String(":/images/warn.png")), QIcon(QLatin1String(":/images/fatal.png")), @@ -97,6 +98,7 @@ QVariant TestResultModel::data(const QModelIndex &index, int role) const case ResultType::SKIP: case ResultType::BLACKLISTED_PASS: case ResultType::BLACKLISTED_FAIL: + case ResultType::BENCHMARK: return QString::fromLatin1("%1::%2 (%3) - %4").arg(tr.className(), tr.testCase(), tr.dataTag(), tr.fileName()); default: @@ -209,7 +211,7 @@ void TestResultFilterModel::enableAllResultTypes() << ResultType::UNEXPECTED_PASS << ResultType::SKIP << ResultType::MESSAGE_DEBUG << ResultType::MESSAGE_WARN << ResultType::MESSAGE_INTERNAL << ResultType::MESSAGE_FATAL << ResultType::UNKNOWN << ResultType::BLACKLISTED_PASS - << ResultType::BLACKLISTED_FAIL; + << ResultType::BLACKLISTED_FAIL << ResultType::BENCHMARK; invalidateFilter(); } diff --git a/plugins/autotest/testresultspane.cpp b/plugins/autotest/testresultspane.cpp index 45c8d4085b..998e80f57f 100644 --- a/plugins/autotest/testresultspane.cpp +++ b/plugins/autotest/testresultspane.cpp @@ -277,6 +277,7 @@ void TestResultsPane::initializeFilterMenu() textAndType.insert(ResultType::EXPECTED_FAIL, tr("Expected Fail")); textAndType.insert(ResultType::UNEXPECTED_PASS, tr("Unexpected Pass")); textAndType.insert(ResultType::SKIP, tr("Skip")); + textAndType.insert(ResultType::BENCHMARK, tr("Benchmarks")); textAndType.insert(ResultType::MESSAGE_DEBUG, tr("Debug Messages")); textAndType.insert(ResultType::MESSAGE_WARN, tr("Warning Messages")); textAndType.insert(ResultType::MESSAGE_INTERNAL, tr("Internal Messages")); diff --git a/plugins/autotest/testrunner.cpp b/plugins/autotest/testrunner.cpp index c7b582aab1..b3abaf7194 100644 --- a/plugins/autotest/testrunner.cpp +++ b/plugins/autotest/testrunner.cpp @@ -112,6 +112,37 @@ static bool xmlExtractTypeFileLine(const QString &code, const QString &tagStart, return false; } +static bool xmlExtractBenchmarkInformation(const QString &code, const QString &tagStart, + QString &description) +{ + if (code.startsWith(tagStart)) { + int start = code.indexOf(QLatin1String(" metric=\"")) + 9; + const QString metric = code.mid(start, code.indexOf(QLatin1Char('"'), start) - start); + start = code.indexOf(QLatin1String(" value=\"")) + 8; + const double value = code.mid(start, code.indexOf(QLatin1Char('"'), start) - start).toDouble(); + start = code.indexOf(QLatin1String(" iterations=\"")) + 13; + const int iterations = code.mid(start, code.indexOf(QLatin1Char('"'), start) - start).toInt(); + QString metricsTxt; + if (metric == QLatin1String("WalltimeMilliseconds")) // default + metricsTxt = QLatin1String("msecs"); + else if (metric == QLatin1String("CPUTicks")) // -tickcounter + metricsTxt = QLatin1String("CPU ticks"); + else if (metric == QLatin1String("Events")) // -eventcounter + metricsTxt = QLatin1String("events"); + else if (metric == QLatin1String("InstructionReads")) // -callgrind + metricsTxt = QLatin1String("instruction reads"); + else if (metric == QLatin1String("CPUCycles")) // -perf + metricsTxt = QLatin1String("CPU cycles"); + description = QObject::tr("%1 %2 per iteration (total: %3, iterations: %4)") + .arg(QString::number(value, 'f', 6)) + .arg(metricsTxt) + .arg(QString::number(value * (double)iterations, 'g', 3)) + .arg(iterations); + return true; + } + return false; +} + /****************** XML line parser helper end ******************/ void processOutput() @@ -129,6 +160,7 @@ void processOutput() static bool readingDescription = false; static QString qtVersion; static QString qtestVersion; + static QString bmDescription; while (m_runner->canReadLine()) { // TODO Qt5 uses UTF-8 - while Qt4 uses ISO-8859-1 - could this be a problem? @@ -172,6 +204,11 @@ void processOutput() } continue; } + if (xmlExtractBenchmarkInformation(line, QLatin1String("<BenchmarkResult"), bmDescription)) { + TestResult testResult(className, testCase, dataTag, ResultType::BENCHMARK, bmDescription); + TestResultsPane::instance()->addTestResult(testResult); + continue; + } if (line == QLatin1String("</Message>") || line == QLatin1String("</Incident>")) { TestResult testResult(className, testCase, dataTag, result, description); if (!file.isEmpty()) |