From 32a6849fae4cfa35a8c5f395701cdbb15c31ef03 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 1 Dec 2014 16:12:05 +0100 Subject: [PATCH] Add support for minimal benchmarks --- plugins/autotest/autotest.qrc | 1 + plugins/autotest/images/benchmark.png | Bin 0 -> 374 bytes plugins/autotest/testresult.cpp | 4 +++ plugins/autotest/testresult.h | 1 + plugins/autotest/testresultdelegate.cpp | 38 +++++++++++++++++++----- plugins/autotest/testresultmodel.cpp | 6 ++-- plugins/autotest/testresultspane.cpp | 1 + plugins/autotest/testrunner.cpp | 37 +++++++++++++++++++++++ 8 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 plugins/autotest/images/benchmark.png diff --git a/plugins/autotest/autotest.qrc b/plugins/autotest/autotest.qrc index e76830ba046..7b98beaab96 100644 --- a/plugins/autotest/autotest.qrc +++ b/plugins/autotest/autotest.qrc @@ -16,6 +16,7 @@ images/xpass.png images/blacklisted_fail.png images/blacklisted_pass.png + images/benchmark.png images/run.png images/runselected.png images/stop.png diff --git a/plugins/autotest/images/benchmark.png b/plugins/autotest/images/benchmark.png new file mode 100644 index 0000000000000000000000000000000000000000..c9d3c5b2b50546b0261e7889245436fbc6e0882d GIT binary patch literal 374 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4rT@h1`S>QUwy?Xun^&2;CJh*%J z+0&<=K7IQ7_3QWV-+zAp{_EGTKY#xG{rmUdzkmP#|DWQqxr~8qqe&~Mxc=n2~Zk%GP6|}o_A`;WyMU~m=M+*ycO84DcUaWB;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 ab303364c40..8a5e8aca64b 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 45c8d4085b2..998e80f57fe 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 c7b582aab1e..b3abaf71948 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("addTestResult(testResult); + continue; + } if (line == QLatin1String("") || line == QLatin1String("")) { TestResult testResult(className, testCase, dataTag, result, description); if (!file.isEmpty())