summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qbenchmark.cpp51
-rw-r--r--src/testlib/qbenchmark.h10
-rw-r--r--src/testlib/qbenchmark_p.h26
-rw-r--r--src/testlib/qbenchmarkevent.cpp10
-rw-r--r--src/testlib/qbenchmarkevent_p.h3
-rw-r--r--src/testlib/qbenchmarkmeasurement.cpp20
-rw-r--r--src/testlib/qbenchmarkmeasurement_p.h10
-rw-r--r--src/testlib/qbenchmarkmetric.cpp87
-rw-r--r--src/testlib/qbenchmarkmetric.h71
-rw-r--r--src/testlib/qbenchmarkmetric_p.h63
-rw-r--r--src/testlib/qbenchmarkvalgrind.cpp9
-rw-r--r--src/testlib/qbenchmarkvalgrind_p.h4
-rw-r--r--src/testlib/qplaintestlogger.cpp30
-rw-r--r--src/testlib/qtestcoreelement.h5
-rw-r--r--src/testlib/qtestlogger.cpp4
-rw-r--r--src/testlib/qxmltestlogger.cpp3
-rw-r--r--src/testlib/testlib.pro1
17 files changed, 323 insertions, 84 deletions
diff --git a/src/testlib/qbenchmark.cpp b/src/testlib/qbenchmark.cpp
index 3bd9054..b2f388e 100644
--- a/src/testlib/qbenchmark.cpp
+++ b/src/testlib/qbenchmark.cpp
@@ -41,6 +41,7 @@
#include "QtTest/qbenchmark.h"
#include "QtTest/private/qbenchmark_p.h"
+#include "QtTest/private/qbenchmarkmetric_p.h"
#ifdef QT_GUI_LIB
#include <QtGui/qapplication.h>
@@ -138,7 +139,7 @@ void QBenchmarkTestMethodData::endDataRun()
int QBenchmarkTestMethodData::adjustIterationCount(int suggestion)
{
- // Let the -iteration-count option override the measurer.
+ // Let the -iterations option override the measurer.
if (QBenchmarkGlobalData::current->iterationCount != -1) {
iterationCount = QBenchmarkGlobalData::current->iterationCount;
} else {
@@ -148,12 +149,13 @@ int QBenchmarkTestMethodData::adjustIterationCount(int suggestion)
return iterationCount;
}
-void QBenchmarkTestMethodData::setResult(qint64 value)
+void QBenchmarkTestMethodData::setResult(
+ qreal value, QTest::QBenchmarkMetric metric, bool setByMacro)
{
bool accepted = false;
// Always accept the result if the iteration count has been
- // specified on the command line with -iteartion-count.
+ // specified on the command line with -iterations.
if (QBenchmarkGlobalData::current->iterationCount != -1)
accepted = true;
@@ -161,7 +163,7 @@ void QBenchmarkTestMethodData::setResult(qint64 value)
iterationCount = 1;
accepted = true;
}
-
+
// Test the result directly without calling the measurer if the minimum time
// has been specifed on the command line with -minimumvalue.
else if (QBenchmarkGlobalData::current->walltimeMinimum != -1)
@@ -175,8 +177,8 @@ void QBenchmarkTestMethodData::setResult(qint64 value)
else
iterationCount *= 2;
- this->result =
- QBenchmarkResult(QBenchmarkGlobalData::current->context, value, iterationCount);
+ this->result = QBenchmarkResult(
+ QBenchmarkGlobalData::current->context, value, iterationCount, metric, setByMacro);
}
/*!
@@ -208,7 +210,8 @@ QTest::QBenchmarkIterationController::QBenchmarkIterationController()
*/
QTest::QBenchmarkIterationController::~QBenchmarkIterationController()
{
- QBenchmarkTestMethodData::current->setResult(QTest::endBenchmarkMeasurement());
+ const qreal result = QTest::endBenchmarkMeasurement();
+ QBenchmarkTestMethodData::current->setResult(result, QBenchmarkGlobalData::current->measurer->metricType());
}
/*! \internal
@@ -259,28 +262,30 @@ void QTest::beginBenchmarkMeasurement()
/*! \internal
*/
-qint64 QTest::endBenchmarkMeasurement()
+quint64 QTest::endBenchmarkMeasurement()
{
// the clock is ticking before the line below, don't add code here.
return QBenchmarkGlobalData::current->measurer->stop();
}
-/*! \internal
-*/
-void QTest::setResult(qint64 result)
-{
- QBenchmarkTestMethodData::current->setResult(result);
-}
-
-/*! \internal
+/*!
+ Sets the benchmark result for this test function to \a result.
+
+ Use this function if you want to report benchmark results without
+ using the QBENCHMARK macro. Use \a metric to specify how QTestLib
+ should interpret the results.
+
+ The context for the result will be the test function name and any
+ data tag from the _data function. This function can only be called
+ once in each test function, subsequent calls will replace the
+ earlier reported results.
+
+ Note that the -iterations command line argument has no effect
+ on test functions without the QBENCHMARK macro.
*/
-void QTest::setResult(const QString &tag, qint64 result)
+void QTest::setBenchmarkResult(qreal result, QTest::QBenchmarkMetric metric)
{
- QBenchmarkContext context = QBenchmarkGlobalData::current->context;
- context.tag = tag;
- QBenchmarkTestMethodData::current->result =
- QBenchmarkResult( context, result,
- QBenchmarkTestMethodData::current->iterationCount);
+ QBenchmarkTestMethodData::current->setResult(result, metric, false);
}
template <typename T>
@@ -298,6 +303,4 @@ Q_TYPENAME T::value_type qAverage(const T &container)
return acc / count;
}
-
QT_END_NAMESPACE
-
diff --git a/src/testlib/qbenchmark.h b/src/testlib/qbenchmark.h
index 3fb1336..16263fe 100644
--- a/src/testlib/qbenchmark.h
+++ b/src/testlib/qbenchmark.h
@@ -43,6 +43,7 @@
#define QBENCHMARK_H
#include <QtTest/qtest_global.h>
+#include <QtTest/private/qbenchmarkmetric_p.h>
QT_BEGIN_HEADER
@@ -75,6 +76,8 @@ public:
}
+// --- BEGIN public API ---
+
#define QBENCHMARK \
for (QTest::QBenchmarkIterationController __iteration_controller; \
__iteration_controller.isDone() == false; __iteration_controller.next())
@@ -83,6 +86,13 @@ public:
for (QTest::QBenchmarkIterationController __iteration_controller(QTest::QBenchmarkIterationController::RunOnce); \
__iteration_controller.isDone() == false; __iteration_controller.next())
+namespace QTest
+{
+ void Q_TESTLIB_EXPORT setBenchmarkResult(qreal result, QBenchmarkMetric metric);
+}
+
+// --- END public API ---
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/testlib/qbenchmark_p.h b/src/testlib/qbenchmark_p.h
index 2f0900b..e294d69 100644
--- a/src/testlib/qbenchmark_p.h
+++ b/src/testlib/qbenchmark_p.h
@@ -42,6 +42,8 @@
#ifndef QBENCHMARK_P_H
#define QBENCHMARK_P_H
+#include <stdlib.h>
+
//
// W A R N I N G
// -------------
@@ -68,6 +70,7 @@
#include "QtTest/private/qbenchmarkvalgrind_p.h"
#endif
#include "QtTest/private/qbenchmarkevent_p.h"
+#include "QtTest/private/qbenchmarkmetric_p.h"
QT_BEGIN_NAMESPACE
@@ -92,23 +95,29 @@ class QBenchmarkResult
{
public:
QBenchmarkContext context;
- qint64 value;
+ qreal value;
int iterations;
+ QTest::QBenchmarkMetric metric;
+ bool setByMacro;
bool valid;
QBenchmarkResult()
: value(-1)
, iterations(-1)
+ , setByMacro(true)
, valid(false)
- { }
+ { }
- QBenchmarkResult(const QBenchmarkContext &context, const qint64 value, const int iterations)
+ QBenchmarkResult(
+ const QBenchmarkContext &context, const qreal value, const int iterations,
+ QTest::QBenchmarkMetric metric, bool setByMacro)
: context(context)
, value(value)
, iterations(iterations)
+ , metric(metric)
+ , setByMacro(setByMacro)
, valid(true)
- {
- }
+ { }
bool operator<(const QBenchmarkResult &other) const
{
@@ -167,7 +176,7 @@ public:
bool isBenchmark() const { return result.valid; }
bool resultsAccepted() const { return resultAccepted; }
int adjustIterationCount(int suggestion);
- void setResult(qint64 value);
+ void setResult(qreal value, QTest::QBenchmarkMetric metric, bool setByMacro = true);
QBenchmarkResult result;
bool resultAccepted;
@@ -183,10 +192,7 @@ namespace QTest
void setIterationCount(int count);
Q_TESTLIB_EXPORT void beginBenchmarkMeasurement();
- Q_TESTLIB_EXPORT qint64 endBenchmarkMeasurement();
-
- void setResult(qint64 result);
- void setResult(const QString &tag, qint64 result);
+ Q_TESTLIB_EXPORT quint64 endBenchmarkMeasurement();
}
QT_END_NAMESPACE
diff --git a/src/testlib/qbenchmarkevent.cpp b/src/testlib/qbenchmarkevent.cpp
index 60cd302..4f4e203 100644
--- a/src/testlib/qbenchmarkevent.cpp
+++ b/src/testlib/qbenchmarkevent.cpp
@@ -41,6 +41,7 @@
#include "QtTest/private/qbenchmarkevent_p.h"
#include "QtTest/private/qbenchmark_p.h"
+#include "QtTest/private/qbenchmarkmetric_p.h"
#include <qdebug.h>
QT_BEGIN_NAMESPACE
@@ -91,14 +92,9 @@ int QBenchmarkEvent::adjustMedianCount(int suggestion)
return 1;
}
-QString QBenchmarkEvent::unitText()
+QTest::QBenchmarkMetric QBenchmarkEvent::metricType()
{
- return QLatin1String("events");
-}
-
-QString QBenchmarkEvent::metricText()
-{
- return QLatin1String("events");
+ return QTest::Events;
}
// This could be done in a much better way, this is just the beginning.
diff --git a/src/testlib/qbenchmarkevent_p.h b/src/testlib/qbenchmarkevent_p.h
index f191a0d..2d625eb 100644
--- a/src/testlib/qbenchmarkevent_p.h
+++ b/src/testlib/qbenchmarkevent_p.h
@@ -70,8 +70,7 @@ public:
int adjustIterationCount(int suggestion);
int adjustMedianCount(int suggestion);
bool repeatCount() { return 1; }
- QString unitText();
- QString metricText();
+ QTest::QBenchmarkMetric metricType();
static bool eventCountingMechanism(void *message);
static qint64 eventCounter;
};
diff --git a/src/testlib/qbenchmarkmeasurement.cpp b/src/testlib/qbenchmarkmeasurement.cpp
index f860454..6107b98 100644
--- a/src/testlib/qbenchmarkmeasurement.cpp
+++ b/src/testlib/qbenchmarkmeasurement.cpp
@@ -41,6 +41,8 @@
#include "QtTest/private/qbenchmarkmeasurement_p.h"
#include "QtTest/private/qbenchmark_p.h"
+#include "QtTest/private/qbenchmarkmetric_p.h"
+#include "qbenchmark.h"
#include <qdebug.h>
QT_BEGIN_NAMESPACE
@@ -77,14 +79,9 @@ int QBenchmarkTimeMeasurer::adjustMedianCount(int)
return 1;
}
-QString QBenchmarkTimeMeasurer::unitText()
+QTest::QBenchmarkMetric QBenchmarkTimeMeasurer::metricType()
{
- return QLatin1String("msec");
-}
-
-QString QBenchmarkTimeMeasurer::metricText()
-{
- return QLatin1String("walltime");
+ return QTest::WalltimeMilliseconds;
}
#ifdef HAVE_TICK_COUNTER // defined in 3rdparty/cycle_p.h
@@ -126,14 +123,9 @@ bool QBenchmarkTickMeasurer::needsWarmupIteration()
return true;
}
-QString QBenchmarkTickMeasurer::unitText()
-{
- return QLatin1String("ticks");
-}
-
-QString QBenchmarkTickMeasurer::metricText()
+QTest::QBenchmarkMetric QBenchmarkTickMeasurer::metricType()
{
- return QLatin1String("cputicks");
+ return QTest::CPUTicks;
}
#endif
diff --git a/src/testlib/qbenchmarkmeasurement_p.h b/src/testlib/qbenchmarkmeasurement_p.h
index f237034..fc4b0fe 100644
--- a/src/testlib/qbenchmarkmeasurement_p.h
+++ b/src/testlib/qbenchmarkmeasurement_p.h
@@ -55,6 +55,7 @@
#include <QtCore/qdatetime.h>
#include "3rdparty/cycle_p.h"
+#include "qbenchmark.h"
QT_BEGIN_NAMESPACE
@@ -71,8 +72,7 @@ public:
virtual int adjustMedianCount(int suggestion) = 0;
virtual bool repeatCount() { return 1; }
virtual bool needsWarmupIteration() { return false; }
- virtual QString unitText() = 0;
- virtual QString metricText() = 0;
+ virtual QTest::QBenchmarkMetric metricType() = 0;
};
class QBenchmarkTimeMeasurer : public QBenchmarkMeasurerBase
@@ -84,8 +84,7 @@ public:
bool isMeasurementAccepted(qint64 measurement);
int adjustIterationCount(int sugestion);
int adjustMedianCount(int suggestion);
- QString unitText();
- QString metricText();
+ QTest::QBenchmarkMetric metricType();
private:
QTime time;
};
@@ -102,8 +101,7 @@ public:
int adjustIterationCount(int);
int adjustMedianCount(int suggestion);
bool needsWarmupIteration();
- QString unitText();
- QString metricText();
+ QTest::QBenchmarkMetric metricType();
private:
CycleCounterTicks startTicks;
};
diff --git a/src/testlib/qbenchmarkmetric.cpp b/src/testlib/qbenchmarkmetric.cpp
new file mode 100644
index 0000000..614357c
--- /dev/null
+++ b/src/testlib/qbenchmarkmetric.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ ** All rights reserved.
+ ** Contact: Nokia Corporation (qt-info@nokia.com)
+ **
+ ** This file is part of the QtTest module of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:LGPL$
+ ** No Commercial Usage
+ ** This file contains pre-release code and may not be distributed.
+ ** You may use this file in accordance with the terms and conditions
+ ** contained in the Technology Preview License Agreement accompanying
+ ** this package.
+ **
+ ** GNU Lesser General Public License Usage
+ ** Alternatively, this file may be used under the terms of the GNU Lesser
+ ** General Public License version 2.1 as published by the Free Software
+ ** Foundation and appearing in the file LICENSE.LGPL included in the
+ ** packaging of this file. Please review the following information to
+ ** ensure the GNU Lesser General Public License version 2.1 requirements
+ ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ **
+ ** In addition, as a special exception, Nokia gives you certain additional
+ ** rights. These rights are described in the Nokia Qt LGPL Exception
+ ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+ **
+ ** If you have questions regarding the use of this file, please contact
+ ** Nokia at qt-info@nokia.com.
+ **
+ **
+ **
+ **
+ **
+ **
+ **
+ **
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+#include <QtTest/private/qbenchmarkmetric_p.h>
+
+const char * QTest::benchmarkMetricName(QBenchmarkMetric metric)
+{
+ switch (metric) {
+ case FramesPerSecond:
+ return "FramesPerSecond";
+ case BitsPerSecond:
+ return "BitsPerSecond";
+ case BytesPerSecond:
+ return "BytesPerSecond";
+ case WalltimeMilliseconds:
+ return "WalltimeMilliseconds";
+ case CPUTicks:
+ return "CPUTicks";
+ case InstructionReads:
+ return "InstructionReads";
+ case Events:
+ return "Events";
+ default:
+ return "";
+ }
+};
+
+const char * QTest::benchmarkMetricUnit(QBenchmarkMetric metric)
+{
+ switch (metric) {
+ case FramesPerSecond:
+ return "fps";
+ case BitsPerSecond:
+ return "bits/s";
+ case BytesPerSecond:
+ return "bytes/s";
+ case WalltimeMilliseconds:
+ return "msecs";
+ case CPUTicks:
+ return "CPU ticks";
+ case InstructionReads:
+ return "instruction reads";
+ case Events:
+ return "events";
+ default:
+ return "";
+ }
+}
+
diff --git a/src/testlib/qbenchmarkmetric.h b/src/testlib/qbenchmarkmetric.h
new file mode 100644
index 0000000..302c1aa
--- /dev/null
+++ b/src/testlib/qbenchmarkmetric.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtTest module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QBENCHMARKMETRIC_H
+#define QBENCHMARKMETRIC_H
+
+#include <QtTest/qtest_global.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Test)
+
+namespace QTest {
+
+enum QBenchmarkMetric {
+ FramesPerSecond,
+ BitsPerSecond,
+ BytesPerSecond,
+ WalltimeMilliseconds,
+ CPUTicks,
+ InstructionReads,
+ Events
+};
+
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QBENCHMARK_H
diff --git a/src/testlib/qbenchmarkmetric_p.h b/src/testlib/qbenchmarkmetric_p.h
new file mode 100644
index 0000000..c919d2e
--- /dev/null
+++ b/src/testlib/qbenchmarkmetric_p.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtTest module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QBENCHMARKMETRIC_P_H
+#define QBENCHMARKMETRIC_P_H
+
+#include <QtTest/qtest_global.h>
+#include <QtTest/qbenchmarkmetric.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Test)
+
+namespace QTest {
+ const char * benchmarkMetricName(QBenchmarkMetric metric);
+ const char * benchmarkMetricUnit(QBenchmarkMetric metric);
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QBENCHMARK_H
diff --git a/src/testlib/qbenchmarkvalgrind.cpp b/src/testlib/qbenchmarkvalgrind.cpp
index 88cb37f..55cd901 100644
--- a/src/testlib/qbenchmarkvalgrind.cpp
+++ b/src/testlib/qbenchmarkvalgrind.cpp
@@ -263,14 +263,9 @@ bool QBenchmarkCallgrindMeasurer::needsWarmupIteration()
return true;
}
-QString QBenchmarkCallgrindMeasurer::unitText()
+QTest::QBenchmarkMetric QBenchmarkCallgrindMeasurer::metricType()
{
- return QLatin1String("instr. loads");
-}
-
-QString QBenchmarkCallgrindMeasurer::metricText()
-{
- return QLatin1String("callgrind");
+ return QTest::InstructionReads;
}
QT_END_NAMESPACE
diff --git a/src/testlib/qbenchmarkvalgrind_p.h b/src/testlib/qbenchmarkvalgrind_p.h
index 14bb5a0..bdb3a5c 100644
--- a/src/testlib/qbenchmarkvalgrind_p.h
+++ b/src/testlib/qbenchmarkvalgrind_p.h
@@ -54,6 +54,7 @@
//
#include "QtTest/private/qbenchmarkmeasurement_p.h"
+#include "QtTest/private/qbenchmarkmetric_p.h"
#include <QtCore/qmap.h>
#include <QtCore/qstring.h>
@@ -84,8 +85,7 @@ public:
int adjustIterationCount(int);
int adjustMedianCount(int);
bool needsWarmupIteration();
- QString unitText();
- QString metricText();
+ QTest::QBenchmarkMetric metricType();
};
QT_END_NAMESPACE
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);
}
diff --git a/src/testlib/qtestcoreelement.h b/src/testlib/qtestcoreelement.h
index b5e5d0f..ceeba52 100644
--- a/src/testlib/qtestcoreelement.h
+++ b/src/testlib/qtestcoreelement.h
@@ -45,6 +45,8 @@
#include <QtTest/qtestcorelist.h>
#include <QtTest/qtestelementattribute.h>
+#include <cstdlib>
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -93,6 +95,9 @@ void QTestCoreElement<ElementType>::addAttribute(const QTest::AttributeIndex att
if (attribute(attributeIndex))
return;
+ // if (attributeIndex == QTest::AI_Metric)
+ // abort();
+
QTestElementAttribute *testAttribute = new QTestElementAttribute;
testAttribute->setPair(attributeIndex, value);
testAttribute->addToList(&listOfAttributes);
diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp
index 3e89ff7..c5b8e7f 100644
--- a/src/testlib/qtestlogger.cpp
+++ b/src/testlib/qtestlogger.cpp
@@ -267,7 +267,9 @@ void QTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark);
// printf("element %i", benchmarkElement->elementType());
- benchmarkElement->addAttribute(QTest::AI_Metric, QBenchmarkGlobalData::current->measurer->metricText().toAscii().data());
+ benchmarkElement->addAttribute(
+ QTest::AI_Metric,
+ QTest::benchmarkMetricName(QBenchmarkTestMethodData::current->result.metric));
benchmarkElement->addAttribute(QTest::AI_Tag, result.context.tag.toAscii().data());
benchmarkElement->addAttribute(QTest::AI_Value, QByteArray::number(result.value).constData());
diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp
index fac3663..a4750ac 100644
--- a/src/testlib/qxmltestlogger.cpp
+++ b/src/testlib/qxmltestlogger.cpp
@@ -46,6 +46,7 @@
#include "QtTest/private/qxmltestlogger_p.h"
#include "QtTest/private/qtestresult_p.h"
#include "QtTest/private/qbenchmark_p.h"
+#include "QtTest/private/qbenchmarkmetric_p.h"
#include "QtTest/qtestcase.h"
QT_BEGIN_NAMESPACE
@@ -243,7 +244,7 @@ void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
QTestCharBuffer quotedTag;
xmlQuote(&quotedMetric,
- QBenchmarkGlobalData::current->measurer->metricText().toAscii().constData());
+ benchmarkMetricUnit(result.metric));
xmlQuote(&quotedTag, result.context.tag.toAscii().constData());
QTest::qt_asprintf(
diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro
index f68ff35..a8186d8 100644
--- a/src/testlib/testlib.pro
+++ b/src/testlib/testlib.pro
@@ -47,6 +47,7 @@ SOURCES = qtestcase.cpp \
qbenchmarkmeasurement.cpp \
qbenchmarkvalgrind.cpp \
qbenchmarkevent.cpp \
+ qbenchmarkmetric.cpp \
qtestelement.cpp \
qtestelementattribute.cpp \
qtestbasicstreamer.cpp \