summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-04-28 10:55:37 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-04-28 10:55:37 (GMT)
commit13adf589a053186e9f678c9f09b02213246e4cbe (patch)
tree1a1525c910f736950727a4349786093decf0dd47 /tests
parent4d520cd01007f0133ca197c07d9d8eb0ad2c5d82 (diff)
downloadQt-13adf589a053186e9f678c9f09b02213246e4cbe.zip
Qt-13adf589a053186e9f678c9f09b02213246e4cbe.tar.gz
Qt-13adf589a053186e9f678c9f09b02213246e4cbe.tar.bz2
tst_selftest: parse benchlib results in XML format too
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/selftests/tst_selftests.cpp68
1 files changed, 67 insertions, 1 deletions
diff --git a/tests/auto/selftests/tst_selftests.cpp b/tests/auto/selftests/tst_selftests.cpp
index b824fd3..0be4e22 100644
--- a/tests/auto/selftests/tst_selftests.cpp
+++ b/tests/auto/selftests/tst_selftests.cpp
@@ -428,7 +428,7 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QString const& logger, Q
Are we expecting this line to be a benchmark result?
If so, don't do a literal comparison, since results have some natural variance.
*/
- if (benchmark) {
+ if (benchmark || line.startsWith("<BenchmarkResult")) {
QString error;
BenchmarkResult actualResult = BenchmarkResult::parse(output, &error);
@@ -458,6 +458,22 @@ void tst_Selftests::runSubTest()
doRunSubTest(subdir, logger, arguments);
}
+// attribute must contain ="
+QString extractXmlAttribute(const QString &line, const char *attribute)
+{
+ int index = line.indexOf(attribute);
+ if (index == -1)
+ return QString();
+ int end = line.indexOf('"', index + strlen(attribute));
+ if (end == -1)
+ return QString();
+
+ QString result = line.mid(index + strlen(attribute), end - index - strlen(attribute));
+ if (result.isEmpty())
+ return ""; // ensure empty but not null
+ return result;
+}
+
/* Parse line into the BenchmarkResult it represents. */
BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error)
{
@@ -471,6 +487,56 @@ BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error)
return out;
}
+ if (line.startsWith("<BenchmarkResult ")) {
+ // XML result
+ // format:
+ // <BenchmarkResult metric="$unit" tag="$tag" value="$total" iterations="$iterations" />
+ if (!line.endsWith("/>")) {
+ if (error) *error = "unterminated XML";
+ return out;
+ }
+
+ QString unit = extractXmlAttribute(line, " metric=\"");
+ QString sTotal = extractXmlAttribute(line, " value=\"");
+ QString sIterations = extractXmlAttribute(line, " iterations=\"");
+ if (unit.isNull() || sTotal.isNull() || sIterations.isNull()) {
+ if (error) *error = "XML snippet did not contain all required values";
+ return out;
+ }
+
+ bool ok;
+#if QT_VERSION >= 0x040700
+ // Qt 4.7 uses floating point
+ double total = sTotal.toDouble(&ok);
+ if (!ok) {
+ if (error) *error = sTotal + " is not a valid number";
+ return out;
+ }
+ double iterations = sIterations.toDouble(&ok);
+ if (!ok) {
+ if (error) *error = sIterations + " is not a valid number";
+ return out;
+ }
+#else
+ qlonglong total = sTotal.toLongLong(&ok);
+ if (!ok) {
+ if (error) *error = sTotal + " is not a valid integer";
+ return out;
+ }
+ qlonglong iterations = sIterations.toLongLong(&ok);
+ if (!ok) {
+ if (error) *error = sIterations + " is not a valid integer";
+ return out;
+ }
+#endif
+
+ out.unit = unit;
+ out.total = total;
+ out.iterations = iterations;
+ return out;
+ }
+ // Text result
+
/* This code avoids using a QRegExp because QRegExp might be broken. */
/* Sample format: 4,000 msec per iteration (total: 4000, iterations: 1) */