Commit 32a6849f authored by Christian Stenger's avatar Christian Stenger
Browse files

Add support for minimal benchmarks

parent d2784769
......@@ -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>
......
......@@ -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:
......
......@@ -33,6 +33,7 @@ enum ResultType {
SKIP,
BLACKLISTED_PASS,
BLACKLISTED_FAIL,
BENCHMARK,
MESSAGE_DEBUG,
MESSAGE_WARN,
MESSAGE_FATAL,
......
......@@ -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);
......
......@@ -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();
}
......
......@@ -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"));
......
......@@ -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())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment