summaryrefslogtreecommitdiffstats
path: root/src/testlib/qplaintestlogger.cpp
diff options
context:
space:
mode:
authorjasplin <qt-info@nokia.com>2009-12-17 06:43:05 (GMT)
committerjasplin <qt-info@nokia.com>2009-12-17 06:43:05 (GMT)
commita66af3b563a90e55015f7cfe7f04f8704ee7d402 (patch)
tree761229a1a920bac07f1ef4b55d238c79698bbc4a /src/testlib/qplaintestlogger.cpp
parent63c8293b60bb997d370a4ec343b7f04808969393 (diff)
downloadQt-a66af3b563a90e55015f7cfe7f04f8704ee7d402.zip
Qt-a66af3b563a90e55015f7cfe7f04f8704ee7d402.tar.gz
Qt-a66af3b563a90e55015f7cfe7f04f8704ee7d402.tar.bz2
Added QTest::setBenchmarkResult() to public API.
A benchmark result can now be registered explicitly using the QTest::setBenchmarkResult() function as an alternative to using a QBENCHMARK* macro. This gives benchmark writers the freedom to compute the benchmark result however they like and not be dependent on the automatic iteration/accumulation algorithm of a QBENCHMARK* macro. The function takes two arguments: a value and a metric. The value must be a non-negative real, while the metric is an enum type. WARNING: The set of available metrics include metrics for which a high value is considered better (i.e. faster) than a low value (one example is 'frames per second'). QTestLib currently does not distinguish between the two cases of "higher is better" and "lower is better", and leaves it to external tools (parsing the QTestLib output) to recognize them and do any necessary conversion. A tool that plots benchmark result history could e.g. convert all "higher is better" to "lower is better". For the 'frames per second' case, this would typically mean converting FPS to SPF (= 1/FPS). Reviewed-by: MortenS
Diffstat (limited to 'src/testlib/qplaintestlogger.cpp')
-rw-r--r--src/testlib/qplaintestlogger.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp
index 61c3728..2830556 100644
--- a/src/testlib/qplaintestlogger.cpp
+++ b/src/testlib/qplaintestlogger.cpp
@@ -44,6 +44,7 @@
#include "QtTest/private/qtestlog_p.h"
#include "QtTest/private/qplaintestlogger_p.h"
#include "QtTest/private/qbenchmark_p.h"
+#include "QtTest/private/qbenchmarkmetric_p.h"
#include <stdarg.h>
#include <stdio.h>
@@ -324,7 +325,6 @@ namespace QTest {
QTestResult::currentTestObjectName(),
result.context.slotName.toAscii().data());
-
char bufTag[1024];
bufTag[0] = 0;
QByteArray tag = result.context.tag.toAscii();
@@ -340,32 +340,42 @@ namespace QTest {
char fill[1024];
QTest::qt_snprintf(fill, sizeof(fill), fillFormat, "");
-
- QByteArray unitText = QBenchmarkGlobalData::current->measurer->unitText().toAscii();
+ const char * unitText = QTest::benchmarkMetricUnit(result.metric);
qreal valuePerIteration = qreal(result.value) / qreal(result.iterations);
char resultBuffer[100] = "";
formatResult(resultBuffer, 100, valuePerIteration, countSignificantDigits(result.value));
- QByteArray iterationText = "per iteration";
-
char buf2[1024];
- Q_ASSERT(result.iterations > 0);
QTest::qt_snprintf(
- buf2, sizeof(buf2), "%s %s %s",
+ buf2, sizeof(buf2), "%s %s",
resultBuffer,
- unitText.data(),
+ unitText);
+
+ char buf2_[1024];
+ QByteArray iterationText = " per iteration";
+ Q_ASSERT(result.iterations > 0);
+ QTest::qt_snprintf(
+ buf2_,
+ sizeof(buf2_), "%s",
iterationText.data());
char buf3[1024];
Q_ASSERT(result.iterations > 0);
QTest::qt_snprintf(
- buf3, sizeof(buf3), " (total: %s, iterations: %d)\n",
+ buf3, sizeof(buf3), " (total: %s, iterations: %d)",
QByteArray::number(result.value).constData(), // no 64-bit qt_snprintf support
result.iterations);
char buf[1024];
- QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s%s", buf1, bufTag, fill, buf2, buf3);
+
+ if (result.setByMacro) {
+ QTest::qt_snprintf(
+ buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3);
+ } else {
+ QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2);
+ }
+
memcpy(buf, bmtag, strlen(bmtag));
outputMessage(buf);
}