2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
2016-01-21 02:33:50 +00:00
|
|
|
** Copyright (C) 2016 Intel Corporation.
|
2016-01-15 12:36:27 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-01-10 00:28:42 +00:00
|
|
|
#include <QtCore/QCoreApplication>
|
2018-01-19 09:46:49 +00:00
|
|
|
|
|
|
|
#if QT_CONFIG(temporaryfile) && QT_CONFIG(process)
|
|
|
|
# define USE_DIFF
|
|
|
|
#endif
|
2011-08-11 13:17:40 +00:00
|
|
|
#include <QtCore/QXmlStreamReader>
|
2011-12-13 16:08:45 +00:00
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
#include <QtCore/QDir>
|
2012-05-29 00:58:41 +00:00
|
|
|
#include <QtCore/QTemporaryDir>
|
2018-01-19 09:46:49 +00:00
|
|
|
#ifdef USE_DIFF
|
|
|
|
# include <QtCore/QTemporaryFile>
|
|
|
|
# include <QtCore/QStandardPaths>
|
|
|
|
#endif
|
2011-12-13 16:08:45 +00:00
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <private/cycle_p.h>
|
|
|
|
|
2017-03-21 10:11:26 +00:00
|
|
|
#include "emulationdetector.h"
|
|
|
|
|
2012-05-29 00:58:41 +00:00
|
|
|
struct LoggerSet;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class tst_Selftests: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2012-05-29 00:58:41 +00:00
|
|
|
public:
|
|
|
|
tst_Selftests();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
private slots:
|
2011-12-13 16:08:45 +00:00
|
|
|
void initTestCase();
|
2011-04-27 10:05:43 +00:00
|
|
|
void runSubTest_data();
|
|
|
|
void runSubTest();
|
2011-09-16 05:03:44 +00:00
|
|
|
void cleanup();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
2013-11-18 21:43:19 +00:00
|
|
|
void doRunSubTest(QString const& subdir, QStringList const& loggers, QStringList const& arguments, bool crashes);
|
2018-02-07 08:04:35 +00:00
|
|
|
bool compareOutput(const QString &logger, const QString &subdir,
|
|
|
|
const QByteArray &rawOutput, const QByteArrayList &actual,
|
|
|
|
const QByteArrayList &expected,
|
|
|
|
QString *errorMessage) const;
|
|
|
|
bool compareLine(const QString &logger, const QString &subdir, bool benchmark,
|
|
|
|
const QString &actualLine, const QString &expLine,
|
|
|
|
QString *errorMessage) const;
|
|
|
|
bool checkXml(const QString &logger, QByteArray rawOutput,
|
|
|
|
QString *errorMessage) const;
|
|
|
|
|
2012-05-29 00:58:41 +00:00
|
|
|
QString logName(const QString &logger) const;
|
|
|
|
QList<LoggerSet> allLoggerSets() const;
|
|
|
|
|
|
|
|
QTemporaryDir tempDir;
|
2013-10-24 18:10:37 +00:00
|
|
|
QRegularExpression durationRegExp;
|
2018-02-07 08:04:35 +00:00
|
|
|
QRegularExpression teamcityLocRegExp;
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BenchmarkResult
|
|
|
|
{
|
|
|
|
qint64 total;
|
|
|
|
qint64 iterations;
|
|
|
|
QString unit;
|
|
|
|
|
|
|
|
inline QString toString() const
|
|
|
|
{ return QString("total:%1, unit:%2, iterations:%3").arg(total).arg(unit).arg(iterations); }
|
|
|
|
|
|
|
|
static BenchmarkResult parse(QString const&, QString*);
|
|
|
|
};
|
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
static QString msgMismatch(const QString &actual, const QString &expected)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2018-02-07 08:04:35 +00:00
|
|
|
return QLatin1String("Mismatch:\n'") + actual + QLatin1String("'\n !=\n'")
|
|
|
|
+ expected + QLatin1Char('\'');
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool compareBenchmarkResult(BenchmarkResult const &r1, BenchmarkResult const &r2,
|
|
|
|
QString *errorMessage)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
// First make sure the iterations and unit match.
|
|
|
|
if (r1.iterations != r2.iterations || r1.unit != r2.unit) {
|
2011-09-16 04:42:51 +00:00
|
|
|
// Nope - compare whole string for best failure message
|
2018-02-07 08:04:35 +00:00
|
|
|
*errorMessage = msgMismatch(r1.toString(), r2.toString());
|
|
|
|
return false;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// Now check the value. Some variance is allowed, and how much depends on
|
|
|
|
// the measured unit.
|
2011-04-27 10:05:43 +00:00
|
|
|
qreal variance = 0.;
|
2018-02-07 08:04:35 +00:00
|
|
|
if (r1.unit == QLatin1String("msecs") || r1.unit == QLatin1String("WalltimeMilliseconds"))
|
2011-04-27 10:05:43 +00:00
|
|
|
variance = 0.1;
|
2018-02-07 08:04:35 +00:00
|
|
|
else if (r1.unit == QLatin1String("instruction reads"))
|
2011-04-27 10:05:43 +00:00
|
|
|
variance = 0.001;
|
2018-02-07 08:04:35 +00:00
|
|
|
else if (r1.unit == QLatin1String("CPU ticks") || r1.unit == QLatin1String("CPUTicks"))
|
2011-04-27 10:05:43 +00:00
|
|
|
variance = 0.001;
|
2018-02-07 08:04:35 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
if (variance == 0.) {
|
2011-09-16 04:42:51 +00:00
|
|
|
// No variance allowed - compare whole string
|
2018-02-07 08:04:35 +00:00
|
|
|
const QString r1S = r1.toString();
|
|
|
|
const QString r2S = r2.toString();
|
|
|
|
if (r1S != r2S) {
|
|
|
|
*errorMessage = msgMismatch(r1S, r2S);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
if (qAbs(qreal(r1.total) - qreal(r2.total)) > qreal(r1.total) * variance) {
|
|
|
|
// Whoops, didn't match. Compare the whole string for the most useful failure message.
|
|
|
|
*errorMessage = msgMismatch(r1.toString(), r2.toString());
|
|
|
|
return false;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2018-02-07 08:04:35 +00:00
|
|
|
return true;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// Split the passed block of text into an array of lines, replacing any
|
|
|
|
// filenames and line numbers with generic markers to avoid failing the test
|
|
|
|
// due to compiler-specific behaviour.
|
2011-04-27 10:05:43 +00:00
|
|
|
static QList<QByteArray> splitLines(QByteArray ba)
|
|
|
|
{
|
|
|
|
ba.replace('\r', "");
|
|
|
|
QList<QByteArray> out = ba.split('\n');
|
|
|
|
|
|
|
|
// Replace any ` file="..."' or ` line="..."' in XML with a generic location.
|
|
|
|
static const char *markers[][2] = {
|
|
|
|
{ " file=\"", " file=\"__FILE__\"" },
|
|
|
|
{ " line=\"", " line=\"__LINE__\"" }
|
|
|
|
};
|
|
|
|
static const int markerCount = sizeof markers / sizeof markers[0];
|
|
|
|
|
|
|
|
for (int i = 0; i < out.size(); ++i) {
|
|
|
|
QByteArray& line = out[i];
|
|
|
|
for (int j = 0; j < markerCount; ++j) {
|
|
|
|
int index = line.indexOf(markers[j][0]);
|
|
|
|
if (index == -1) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-04-02 12:22:04 +00:00
|
|
|
const int end = line.indexOf('"', index + int(strlen(markers[j][0])));
|
2011-04-27 10:05:43 +00:00
|
|
|
if (end == -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
line.replace(index, end-index + 1, markers[j][1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-09-21 01:39:07 +00:00
|
|
|
// Return the log format, e.g. for both "stdout txt" and "txt", return "txt'.
|
|
|
|
static inline QString logFormat(const QString &logger)
|
|
|
|
{
|
|
|
|
return (logger.startsWith("stdout") ? logger.mid(7) : logger);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the log file name, or an empty string if the log goes to stdout.
|
2012-05-29 00:58:41 +00:00
|
|
|
QString tst_Selftests::logName(const QString &logger) const
|
2011-09-21 01:39:07 +00:00
|
|
|
{
|
2012-05-29 00:58:41 +00:00
|
|
|
return (logger.startsWith("stdout") ? "" : QString(tempDir.path() + "/test_output." + logger));
|
2011-09-21 01:39:07 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 13:49:02 +00:00
|
|
|
static QString expectedFileNameFromTest(const QString &subdir, const QString &logger)
|
|
|
|
{
|
|
|
|
return QStringLiteral("expected_") + subdir + QLatin1Char('.') + logFormat(logger);
|
|
|
|
}
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// Load the expected test output for the nominated test (subdir) and logger
|
|
|
|
// as an array of lines. If there is no expected output file, return an
|
|
|
|
// empty array.
|
2014-02-14 13:49:02 +00:00
|
|
|
static QList<QByteArray> expectedResult(const QString &fileName)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2014-02-14 13:49:02 +00:00
|
|
|
QFile file(QStringLiteral(":/") + fileName);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
return QList<QByteArray>();
|
|
|
|
return splitLines(file.readAll());
|
|
|
|
}
|
|
|
|
|
2018-01-19 09:46:49 +00:00
|
|
|
// Helpers for running the 'diff' tool in case comparison fails
|
|
|
|
#ifdef USE_DIFF
|
|
|
|
static inline void writeLines(QIODevice &d, const QByteArrayList &lines)
|
|
|
|
{
|
|
|
|
for (const QByteArray &l : lines) {
|
|
|
|
d.write(l);
|
|
|
|
d.write("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // USE_DIFF
|
|
|
|
|
|
|
|
static QByteArray runDiff(const QByteArrayList &expected, const QByteArrayList &actual)
|
|
|
|
{
|
|
|
|
QByteArray result;
|
|
|
|
#ifdef USE_DIFF
|
|
|
|
# ifndef Q_OS_WIN
|
|
|
|
const QString diff = QStandardPaths::findExecutable("diff");
|
|
|
|
# else
|
|
|
|
const QString diff = QStandardPaths::findExecutable("diff.exe");
|
|
|
|
# endif
|
|
|
|
if (diff.isEmpty())
|
|
|
|
return result;
|
|
|
|
QTemporaryFile expectedFile;
|
|
|
|
if (!expectedFile.open())
|
|
|
|
return result;
|
|
|
|
writeLines(expectedFile, expected);
|
|
|
|
expectedFile.close();
|
|
|
|
QTemporaryFile actualFile;
|
|
|
|
if (!actualFile.open())
|
|
|
|
return result;
|
|
|
|
writeLines(actualFile, actual);
|
|
|
|
actualFile.close();
|
|
|
|
QProcess diffProcess;
|
|
|
|
diffProcess.start(diff, {QLatin1String("-u"), expectedFile.fileName(), actualFile.fileName()});
|
|
|
|
if (!diffProcess.waitForStarted())
|
|
|
|
return result;
|
|
|
|
if (diffProcess.waitForFinished())
|
|
|
|
result = diffProcess.readAllStandardOutput();
|
|
|
|
else
|
|
|
|
diffProcess.kill();
|
|
|
|
#endif // USE_DIFF
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-21 01:39:07 +00:00
|
|
|
// Each test is run with a set of one or more test output loggers.
|
|
|
|
// This struct holds information about one such test.
|
|
|
|
struct LoggerSet
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-09-21 01:39:07 +00:00
|
|
|
LoggerSet(QString const& _name, QStringList const& _loggers, QStringList const& _arguments)
|
|
|
|
: name(_name), loggers(_loggers), arguments(_arguments)
|
|
|
|
{ }
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QString name;
|
2011-09-21 01:39:07 +00:00
|
|
|
QStringList loggers;
|
2011-04-27 10:05:43 +00:00
|
|
|
QStringList arguments;
|
|
|
|
};
|
|
|
|
|
2011-09-21 01:39:07 +00:00
|
|
|
// This function returns a list of all sets of loggers to be used for
|
|
|
|
// running each subtest.
|
2012-05-29 00:58:41 +00:00
|
|
|
QList<LoggerSet> tst_Selftests::allLoggerSets() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
// Note that in order to test XML output to standard output, the subtests
|
|
|
|
// must not send output directly to stdout, bypassing Qt's output mechanisms
|
|
|
|
// (e.g. via printf), otherwise the output may not be well-formed XML.
|
2011-09-21 01:39:07 +00:00
|
|
|
return QList<LoggerSet>()
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
// Test with old-style options for a single logger
|
|
|
|
<< LoggerSet("old stdout txt",
|
2011-09-21 01:39:07 +00:00
|
|
|
QStringList() << "stdout txt",
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
QStringList()
|
|
|
|
)
|
|
|
|
<< LoggerSet("old txt",
|
2011-09-21 01:39:07 +00:00
|
|
|
QStringList() << "txt",
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
QStringList() << "-o" << logName("txt")
|
|
|
|
)
|
|
|
|
<< LoggerSet("old stdout xml",
|
|
|
|
QStringList() << "stdout xml",
|
|
|
|
QStringList() << "-xml"
|
|
|
|
)
|
|
|
|
<< LoggerSet("old xml",
|
2011-09-21 01:39:07 +00:00
|
|
|
QStringList() << "xml",
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
QStringList() << "-xml" << "-o" << logName("xml")
|
|
|
|
)
|
|
|
|
<< LoggerSet("old stdout xunitxml",
|
|
|
|
QStringList() << "stdout xunitxml",
|
|
|
|
QStringList() << "-xunitxml"
|
|
|
|
)
|
|
|
|
<< LoggerSet("old xunitxml",
|
2011-09-21 01:39:07 +00:00
|
|
|
QStringList() << "xunitxml",
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
QStringList() << "-xunitxml" << "-o" << logName("xunitxml")
|
|
|
|
)
|
|
|
|
<< LoggerSet("old stdout lightxml",
|
|
|
|
QStringList() << "stdout lightxml",
|
|
|
|
QStringList() << "-lightxml"
|
|
|
|
)
|
|
|
|
<< LoggerSet("old lightxml",
|
2011-09-21 01:39:07 +00:00
|
|
|
QStringList() << "lightxml",
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
QStringList() << "-lightxml" << "-o" << logName("lightxml")
|
|
|
|
)
|
2013-12-20 19:14:04 +00:00
|
|
|
<< LoggerSet("old stdout csv", // benchmarks only
|
|
|
|
QStringList() << "stdout csv",
|
|
|
|
QStringList() << "-csv")
|
|
|
|
<< LoggerSet("old csv", // benchmarks only
|
|
|
|
QStringList() << "csv",
|
|
|
|
QStringList() << "-csv" << "-o" << logName("csv"))
|
2016-01-06 17:20:29 +00:00
|
|
|
<< LoggerSet("old stdout teamcity",
|
|
|
|
QStringList() << "stdout teamcity",
|
|
|
|
QStringList() << "-teamcity"
|
|
|
|
)
|
|
|
|
<< LoggerSet("old teamcity",
|
|
|
|
QStringList() << "teamcity",
|
|
|
|
QStringList() << "-teamcity" << "-o" << logName("teamcity")
|
|
|
|
)
|
2018-03-01 16:06:23 +00:00
|
|
|
<< LoggerSet("old stdout tap",
|
|
|
|
QStringList() << "stdout tap",
|
|
|
|
QStringList() << "-tap"
|
|
|
|
)
|
|
|
|
<< LoggerSet("old tap",
|
|
|
|
QStringList() << "tap",
|
|
|
|
QStringList() << "-tap" << "-o" << logName("tap")
|
|
|
|
)
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
// Test with new-style options for a single logger
|
|
|
|
<< LoggerSet("new stdout txt",
|
|
|
|
QStringList() << "stdout txt",
|
|
|
|
QStringList() << "-o" << "-,txt"
|
|
|
|
)
|
|
|
|
<< LoggerSet("new txt",
|
|
|
|
QStringList() << "txt",
|
|
|
|
QStringList() << "-o" << logName("txt")+",txt"
|
|
|
|
)
|
|
|
|
<< LoggerSet("new stdout xml",
|
|
|
|
QStringList() << "stdout xml",
|
|
|
|
QStringList() << "-o" << "-,xml"
|
|
|
|
)
|
|
|
|
<< LoggerSet("new xml",
|
|
|
|
QStringList() << "xml",
|
|
|
|
QStringList() << "-o" << logName("xml")+",xml"
|
|
|
|
)
|
|
|
|
<< LoggerSet("new stdout xunitxml",
|
|
|
|
QStringList() << "stdout xunitxml",
|
|
|
|
QStringList() << "-o" << "-,xunitxml"
|
|
|
|
)
|
|
|
|
<< LoggerSet("new xunitxml",
|
|
|
|
QStringList() << "xunitxml",
|
|
|
|
QStringList() << "-o" << logName("xunitxml")+",xunitxml"
|
|
|
|
)
|
|
|
|
<< LoggerSet("new stdout lightxml",
|
|
|
|
QStringList() << "stdout lightxml",
|
|
|
|
QStringList() << "-o" << "-,lightxml"
|
|
|
|
)
|
|
|
|
<< LoggerSet("new lightxml",
|
|
|
|
QStringList() << "lightxml",
|
|
|
|
QStringList() << "-o" << logName("lightxml")+",lightxml"
|
|
|
|
)
|
2013-12-20 19:14:04 +00:00
|
|
|
<< LoggerSet("new stdout csv", // benchmarks only
|
|
|
|
QStringList() << "stdout csv",
|
|
|
|
QStringList() << "-o" << "-,csv")
|
|
|
|
<< LoggerSet("new csv", // benchmarks only
|
|
|
|
QStringList() << "csv",
|
|
|
|
QStringList() << "-o" << logName("csv")+",csv")
|
2016-01-06 17:20:29 +00:00
|
|
|
<< LoggerSet("new stdout teamcity",
|
|
|
|
QStringList() << "stdout teamcity",
|
|
|
|
QStringList() << "-o" << "-,teamcity"
|
|
|
|
)
|
|
|
|
<< LoggerSet("new teamcity",
|
|
|
|
QStringList() << "teamcity",
|
|
|
|
QStringList() << "-o" << logName("teamcity")+",teamcity"
|
|
|
|
)
|
2018-03-01 16:06:23 +00:00
|
|
|
<< LoggerSet("new stdout tap",
|
|
|
|
QStringList() << "stdout tap",
|
|
|
|
QStringList() << "-o" << "-,tap"
|
|
|
|
)
|
|
|
|
<< LoggerSet("new tap",
|
|
|
|
QStringList() << "tap",
|
|
|
|
QStringList() << "-o" << logName("tap")+",tap"
|
|
|
|
)
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
// Test with two loggers (don't test all 32 combinations, just a sample)
|
|
|
|
<< LoggerSet("stdout txt + txt",
|
|
|
|
QStringList() << "stdout txt" << "txt",
|
|
|
|
QStringList() << "-o" << "-,txt"
|
|
|
|
<< "-o" << logName("txt")+",txt"
|
|
|
|
)
|
|
|
|
<< LoggerSet("xml + stdout txt",
|
|
|
|
QStringList() << "xml" << "stdout txt",
|
|
|
|
QStringList() << "-o" << logName("xml")+",xml"
|
|
|
|
<< "-o" << "-,txt"
|
|
|
|
)
|
|
|
|
<< LoggerSet("txt + xunitxml",
|
|
|
|
QStringList() << "txt" << "xunitxml",
|
|
|
|
QStringList() << "-o" << logName("txt")+",txt"
|
|
|
|
<< "-o" << logName("xunitxml")+",xunitxml"
|
|
|
|
)
|
|
|
|
<< LoggerSet("lightxml + stdout xunitxml",
|
|
|
|
QStringList() << "lightxml" << "stdout xunitxml",
|
|
|
|
QStringList() << "-o" << logName("lightxml")+",lightxml"
|
|
|
|
<< "-o" << "-,xunitxml"
|
|
|
|
)
|
2013-12-20 19:14:04 +00:00
|
|
|
// All loggers at the same time (except csv)
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
<< LoggerSet("all loggers",
|
2018-03-01 16:06:23 +00:00
|
|
|
QStringList() << "txt" << "xml" << "lightxml" << "stdout txt" << "xunitxml" << "tap",
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
QStringList() << "-o" << logName("txt")+",txt"
|
|
|
|
<< "-o" << logName("xml")+",xml"
|
|
|
|
<< "-o" << logName("lightxml")+",lightxml"
|
|
|
|
<< "-o" << "-,txt"
|
|
|
|
<< "-o" << logName("xunitxml")+",xunitxml"
|
2016-01-06 17:20:29 +00:00
|
|
|
<< "-o" << logName("teamcity")+",teamcity"
|
2018-03-01 16:06:23 +00:00
|
|
|
<< "-o" << logName("tap")+",tap"
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
)
|
2011-04-27 10:05:43 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2012-05-29 00:58:41 +00:00
|
|
|
tst_Selftests::tst_Selftests()
|
|
|
|
: tempDir(QDir::tempPath() + "/tst_selftests.XXXXXX")
|
2013-10-24 18:10:37 +00:00
|
|
|
, durationRegExp("<Duration msecs=\"[\\d\\.]+\"/>")
|
2018-02-07 08:04:35 +00:00
|
|
|
, teamcityLocRegExp("\\|\\[Loc: .*\\(\\d*\\)\\|\\]")
|
2012-05-29 00:58:41 +00:00
|
|
|
{}
|
|
|
|
|
2011-12-13 16:08:45 +00:00
|
|
|
void tst_Selftests::initTestCase()
|
|
|
|
{
|
2015-09-24 13:56:57 +00:00
|
|
|
QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString()));
|
2012-01-04 02:28:20 +00:00
|
|
|
//Detect the location of the sub programs
|
|
|
|
QString subProgram = QLatin1String("float/float");
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
subProgram = QLatin1String("float/float.exe");
|
|
|
|
#endif
|
|
|
|
QString testdataDir = QFINDTESTDATA(subProgram);
|
|
|
|
if (testdataDir.lastIndexOf(subProgram) > 0)
|
|
|
|
testdataDir = testdataDir.left(testdataDir.lastIndexOf(subProgram));
|
|
|
|
else
|
|
|
|
testdataDir = QCoreApplication::applicationDirPath();
|
2011-12-13 16:08:45 +00:00
|
|
|
// chdir to our testdata path and execute helper apps relative to that.
|
|
|
|
QVERIFY2(QDir::setCurrent(testdataDir), qPrintable("Could not chdir to " + testdataDir));
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_Selftests::runSubTest_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("subdir");
|
2011-09-21 01:39:07 +00:00
|
|
|
QTest::addColumn<QStringList>("loggers");
|
2011-04-27 10:05:43 +00:00
|
|
|
QTest::addColumn<QStringList>("arguments");
|
2013-11-18 21:43:19 +00:00
|
|
|
QTest::addColumn<bool>("crashes");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QStringList tests = QStringList()
|
|
|
|
#if !defined(Q_OS_WIN)
|
2011-09-23 01:41:16 +00:00
|
|
|
// On windows, assert does nothing in release mode and blocks execution
|
|
|
|
// with a popup window in debug mode.
|
2011-04-27 10:05:43 +00:00
|
|
|
<< "assert"
|
|
|
|
#endif
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "badxml"
|
2011-04-27 10:05:43 +00:00
|
|
|
#if defined(__GNUC__) && defined(__i386) && defined(Q_OS_LINUX)
|
2011-09-23 01:41:16 +00:00
|
|
|
// Only run on platforms where callgrind is available.
|
2011-04-27 10:05:43 +00:00
|
|
|
<< "benchlibcallgrind"
|
|
|
|
#endif
|
2012-02-17 03:39:30 +00:00
|
|
|
<< "benchlibcounting"
|
2011-04-27 10:05:43 +00:00
|
|
|
<< "benchlibeventcounter"
|
|
|
|
<< "benchliboptions"
|
2015-04-28 11:40:26 +00:00
|
|
|
<< "blacklisted"
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "cmptest"
|
|
|
|
<< "commandlinedata"
|
2012-01-31 04:07:58 +00:00
|
|
|
<< "counting"
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "crashes"
|
|
|
|
<< "datatable"
|
|
|
|
<< "datetime"
|
|
|
|
<< "differentexec"
|
2011-12-22 14:01:40 +00:00
|
|
|
#if !defined(QT_NO_EXCEPTIONS) && !defined(Q_CC_INTEL) && !defined(Q_OS_WIN)
|
2011-09-23 01:41:16 +00:00
|
|
|
// Disable this test on Windows and for intel compiler, as the run-times
|
|
|
|
// will popup dialogs with warnings that uncaught exceptions were thrown
|
|
|
|
<< "exceptionthrow"
|
|
|
|
#endif
|
|
|
|
<< "expectfail"
|
2012-02-03 00:22:13 +00:00
|
|
|
<< "failcleanup"
|
2018-10-11 15:26:57 +00:00
|
|
|
#ifndef Q_OS_WIN // these assert, by design; so same problem as "assert"
|
|
|
|
<< "faildatatype"
|
|
|
|
<< "failfetchtype"
|
|
|
|
#endif
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "failinit"
|
|
|
|
<< "failinitdata"
|
2018-10-11 15:26:57 +00:00
|
|
|
#ifndef Q_OS_WIN // asserts, by design; so same problem as "assert"
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "fetchbogus"
|
2011-12-22 14:01:40 +00:00
|
|
|
#endif
|
2012-03-01 01:01:49 +00:00
|
|
|
<< "findtestdata"
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "float"
|
|
|
|
<< "globaldata"
|
2018-05-04 08:40:38 +00:00
|
|
|
<< "keyboard"
|
2011-04-27 10:05:43 +00:00
|
|
|
<< "longstring"
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "maxwarnings"
|
|
|
|
<< "multiexec"
|
2017-03-28 06:56:24 +00:00
|
|
|
<< "pairdiagnostics"
|
2011-11-01 11:19:39 +00:00
|
|
|
<< "printdatatags"
|
|
|
|
<< "printdatatagswithglobaltags"
|
2011-12-09 15:16:46 +00:00
|
|
|
<< "qexecstringlist"
|
2019-02-26 15:09:59 +00:00
|
|
|
<< "signaldumper"
|
2012-02-27 06:31:03 +00:00
|
|
|
<< "silent"
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "singleskip"
|
|
|
|
<< "skip"
|
2012-02-03 00:22:13 +00:00
|
|
|
<< "skipcleanup"
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "skipinit"
|
|
|
|
<< "skipinitdata"
|
|
|
|
<< "sleep"
|
|
|
|
<< "strcmp"
|
|
|
|
<< "subtest"
|
2018-10-16 17:07:14 +00:00
|
|
|
<< "testlib"
|
2017-12-07 08:46:30 +00:00
|
|
|
<< "tuplediagnostics"
|
2012-03-01 01:01:49 +00:00
|
|
|
<< "verbose1"
|
|
|
|
<< "verbose2"
|
2013-10-11 10:05:01 +00:00
|
|
|
#ifndef QT_NO_EXCEPTIONS
|
|
|
|
// this test will test nothing if the exceptions are disabled
|
|
|
|
<< "verifyexceptionthrown"
|
|
|
|
#endif //!QT_NO_EXCEPTIONS
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "warnings"
|
2018-10-15 15:47:42 +00:00
|
|
|
<< "watchdog"
|
2011-09-23 01:41:16 +00:00
|
|
|
<< "xunit"
|
2011-04-27 10:05:43 +00:00
|
|
|
;
|
|
|
|
|
2011-10-28 08:19:05 +00:00
|
|
|
// These tests are affected by timing and whether the CPU tick counter
|
|
|
|
// is monotonically increasing. They won't work on some machines so
|
|
|
|
// leave them off by default. Feel free to enable them for your own
|
|
|
|
// testing by setting the QTEST_ENABLE_EXTRA_SELFTESTS environment
|
|
|
|
// variable to something non-empty.
|
|
|
|
if (!qgetenv("QTEST_ENABLE_EXTRA_SELFTESTS").isEmpty())
|
|
|
|
tests << "benchlibtickcounter"
|
|
|
|
<< "benchlibwalltime"
|
|
|
|
;
|
|
|
|
|
2011-09-21 01:39:07 +00:00
|
|
|
foreach (LoggerSet const& loggerSet, allLoggerSets()) {
|
|
|
|
QStringList loggers = loggerSet.loggers;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
foreach (QString const& subtest, tests) {
|
2011-09-21 01:39:07 +00:00
|
|
|
QStringList arguments = loggerSet.arguments;
|
2018-10-15 17:48:13 +00:00
|
|
|
// Keep in sync with generateTestData()'s extraArgs in generate_expected_output.py:
|
2011-04-27 10:05:43 +00:00
|
|
|
if (subtest == "commandlinedata") {
|
|
|
|
arguments << QString("fiveTablePasses fiveTablePasses:fiveTablePasses_data1 -v2").split(' ');
|
|
|
|
}
|
|
|
|
else if (subtest == "benchlibcallgrind") {
|
|
|
|
arguments << "-callgrind";
|
|
|
|
}
|
|
|
|
else if (subtest == "benchlibeventcounter") {
|
|
|
|
arguments << "-eventcounter";
|
|
|
|
}
|
|
|
|
else if (subtest == "benchliboptions") {
|
|
|
|
arguments << "-eventcounter";
|
|
|
|
}
|
|
|
|
else if (subtest == "benchlibtickcounter") {
|
|
|
|
arguments << "-tickcounter";
|
|
|
|
}
|
|
|
|
else if (subtest == "badxml") {
|
|
|
|
arguments << "-eventcounter";
|
|
|
|
}
|
2012-02-17 03:39:30 +00:00
|
|
|
else if (subtest == "benchlibcounting") {
|
|
|
|
arguments << "-eventcounter";
|
|
|
|
}
|
2011-11-01 11:19:39 +00:00
|
|
|
else if (subtest == "printdatatags") {
|
|
|
|
arguments << "-datatags";
|
|
|
|
}
|
|
|
|
else if (subtest == "printdatatagswithglobaltags") {
|
|
|
|
arguments << "-datatags";
|
|
|
|
}
|
2019-02-26 15:09:59 +00:00
|
|
|
else if (subtest == "signaldumper") {
|
|
|
|
arguments << "-vs";
|
|
|
|
}
|
2012-02-27 06:31:03 +00:00
|
|
|
else if (subtest == "silent") {
|
|
|
|
arguments << "-silent";
|
|
|
|
}
|
2012-03-01 01:01:49 +00:00
|
|
|
else if (subtest == "verbose1") {
|
|
|
|
arguments << "-v1";
|
|
|
|
}
|
|
|
|
else if (subtest == "verbose2") {
|
|
|
|
arguments << "-v2";
|
|
|
|
}
|
2011-11-01 11:19:39 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-21 00:38:09 +00:00
|
|
|
// These tests don't work right unless logging plain text to
|
|
|
|
// standard output, either because they execute multiple test
|
|
|
|
// objects or because they internally supply arguments to
|
|
|
|
// themselves.
|
Allow tests to log to multiple destinations
Each destination and the format of output to write there is specified by
adding "-o filename,format" to the command-line. The special filename
"-" indicates that the log output is written to the standard output
stream, though standard output can be used as a destination at most
once.
The old-style testlib output options are still supported, but can only
be used to specify one logging destination, as before.
If no logging options are given on the command-line, a plain text log
will go to the console, as before.
To log to the console in plain text and to the file "test_output" in
xunit format, one would invoke a test in the following way:
tst_foo -o test_output,xunitxml -o -,txt
This commit also enhances the selftests to test with multiple loggers,
but negative tests (e.g. bad combinations of command-line options) are
left for future task QTBUG-21567.
Task-number: QTBUG-20615
Change-Id: If91e752bc7001657e15e427aba9d25ab0a29a0b0
Reviewed-on: http://codereview.qt-project.org/4125
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2011-09-02 09:08:21 +00:00
|
|
|
if (loggerSet.name != "old stdout txt" && loggerSet.name != "new stdout txt") {
|
2011-04-27 10:05:43 +00:00
|
|
|
if (subtest == "differentexec") {
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-21 00:38:09 +00:00
|
|
|
if (subtest == "multiexec") {
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-09 15:16:46 +00:00
|
|
|
if (subtest == "qexecstringlist") {
|
|
|
|
continue;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
if (subtest == "benchliboptions") {
|
|
|
|
continue;
|
|
|
|
}
|
2015-04-28 11:40:26 +00:00
|
|
|
if (subtest == "blacklisted") {
|
|
|
|
continue;
|
|
|
|
}
|
2011-11-01 11:19:39 +00:00
|
|
|
if (subtest == "printdatatags") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (subtest == "printdatatagswithglobaltags") {
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-27 06:31:03 +00:00
|
|
|
if (subtest == "silent") {
|
|
|
|
continue;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
// `crashes' will not output valid XML on platforms without a crash handler
|
|
|
|
if (subtest == "crashes") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// this test prints out some floats in the testlog and the formatting is
|
|
|
|
// platform-specific and hard to predict.
|
2011-09-20 01:56:31 +00:00
|
|
|
if (subtest == "float") {
|
2011-10-17 04:11:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// these tests are quite slow, and running them for all the loggers significantly
|
|
|
|
// increases the overall test time. They do not really relate to logging, so it
|
|
|
|
// should be safe to run them just for the stdout loggers.
|
|
|
|
if (subtest == "benchlibcallgrind" || subtest == "sleep") {
|
2011-04-27 10:05:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-01-16 12:45:37 +00:00
|
|
|
if (subtest == "badxml" && (loggerSet.name == "all loggers" || loggerSet.name.contains("txt")))
|
|
|
|
continue; // XML only, do not mix txt and XML for encoding test.
|
2013-12-20 19:14:04 +00:00
|
|
|
|
|
|
|
if (loggerSet.name.contains("csv") && !subtest.startsWith("benchlib"))
|
|
|
|
continue;
|
|
|
|
|
2016-01-06 17:20:29 +00:00
|
|
|
if (loggerSet.name.contains("teamcity") && subtest.startsWith("benchlib"))
|
|
|
|
continue; // Skip benchmark for TeamCity logger
|
|
|
|
|
2018-10-15 17:48:13 +00:00
|
|
|
// Keep in sync with generateTestData()'s crashers in generate_expected_output.py:
|
2013-11-18 21:43:19 +00:00
|
|
|
const bool crashes = subtest == QLatin1String("assert") || subtest == QLatin1String("exceptionthrow")
|
|
|
|
|| subtest == QLatin1String("fetchbogus") || subtest == QLatin1String("crashedterminate")
|
2018-10-11 15:26:57 +00:00
|
|
|
|| subtest == QLatin1String("faildatatype") || subtest == QLatin1String("failfetchtype")
|
2015-04-28 11:40:26 +00:00
|
|
|
|| subtest == QLatin1String("crashes") || subtest == QLatin1String("silent")
|
2018-10-15 15:47:42 +00:00
|
|
|
|| subtest == QLatin1String("blacklisted") || subtest == QLatin1String("watchdog");
|
2011-09-21 01:39:07 +00:00
|
|
|
QTest::newRow(qPrintable(QString("%1 %2").arg(subtest).arg(loggerSet.name)))
|
2011-04-27 10:05:43 +00:00
|
|
|
<< subtest
|
2011-09-21 01:39:07 +00:00
|
|
|
<< loggers
|
2011-04-27 10:05:43 +00:00
|
|
|
<< arguments
|
2013-11-18 21:43:19 +00:00
|
|
|
<< crashes
|
2011-04-27 10:05:43 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 11:25:17 +00:00
|
|
|
#if QT_CONFIG(process)
|
2013-09-02 18:00:14 +00:00
|
|
|
|
2013-11-18 21:43:19 +00:00
|
|
|
static QProcessEnvironment processEnvironment()
|
2011-12-07 15:45:14 +00:00
|
|
|
{
|
2013-11-18 21:43:19 +00:00
|
|
|
static QProcessEnvironment result;
|
|
|
|
if (result.isEmpty()) {
|
|
|
|
const QProcessEnvironment systemEnvironment = QProcessEnvironment::systemEnvironment();
|
2016-02-10 18:02:40 +00:00
|
|
|
const bool preserveLibPath = qEnvironmentVariableIsSet("QT_PRESERVE_TESTLIB_PATH");
|
2013-11-18 21:43:19 +00:00
|
|
|
foreach (const QString &key, systemEnvironment.keys()) {
|
|
|
|
const bool useVariable = key == QLatin1String("PATH") || key == QLatin1String("QT_QPA_PLATFORM")
|
2014-05-15 13:57:01 +00:00
|
|
|
#if defined(Q_OS_QNX)
|
|
|
|
|| key == QLatin1String("GRAPHICS_ROOT") || key == QLatin1String("TZ")
|
|
|
|
#elif defined(Q_OS_UNIX)
|
2013-11-18 21:43:19 +00:00
|
|
|
|| key == QLatin1String("HOME") || key == QLatin1String("USER") // Required for X11 on openSUSE
|
2017-03-21 10:11:26 +00:00
|
|
|
|| key == QLatin1String("QEMU_SET_ENV") || key == QLatin1String("QEMU_LD_PREFIX") // Required for QEMU
|
2014-05-15 13:57:01 +00:00
|
|
|
# if !defined(Q_OS_MAC)
|
2013-11-18 21:43:19 +00:00
|
|
|
|| key == QLatin1String("DISPLAY") || key == QLatin1String("XAUTHLOCALHOSTNAME")
|
|
|
|
|| key.startsWith(QLatin1String("XDG_"))
|
|
|
|
# endif // !Q_OS_MAC
|
|
|
|
#endif // Q_OS_UNIX
|
2012-02-02 09:12:21 +00:00
|
|
|
#ifdef __COVERAGESCANNER__
|
2013-11-18 21:43:19 +00:00
|
|
|
|| key == QLatin1String("QT_TESTCOCOON_ACTIVE")
|
2011-12-19 10:33:07 +00:00
|
|
|
#endif
|
2016-02-10 18:02:40 +00:00
|
|
|
|| ( preserveLibPath && (key == QLatin1String("QT_PLUGIN_PATH")
|
|
|
|
|| key == QLatin1String("LD_LIBRARY_PATH")))
|
2013-11-18 21:43:19 +00:00
|
|
|
;
|
|
|
|
if (useVariable)
|
|
|
|
result.insert(key, systemEnvironment.value(key));
|
|
|
|
}
|
2017-10-10 11:43:15 +00:00
|
|
|
// Avoid interference from any qtlogging.ini files, e.g. in /etc/xdg/QtProject/:
|
|
|
|
result.insert(QStringLiteral("QT_LOGGING_RULES"),
|
|
|
|
// Must match generate_expected_output.py's main()'s value:
|
2018-03-09 11:03:01 +00:00
|
|
|
QStringLiteral("*.debug=true;qt.*=false"));
|
2013-11-18 21:43:19 +00:00
|
|
|
}
|
2011-12-07 15:45:14 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-11-18 21:43:19 +00:00
|
|
|
static inline QByteArray msgProcessError(const QString &binary, const QStringList &args,
|
|
|
|
const QProcessEnvironment &e, const QString &what)
|
|
|
|
{
|
|
|
|
QString result;
|
|
|
|
QTextStream(&result) <<"Error running " << binary << ' ' << args.join(' ')
|
|
|
|
<< " with environment " << e.toStringList().join(' ') << ": " << what;
|
|
|
|
return result.toLocal8Bit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& loggers, QStringList const& arguments, bool crashes)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-01-10 03:46:12 +00:00
|
|
|
#if defined(__GNUC__) && defined(__i386) && defined(Q_OS_LINUX)
|
|
|
|
if (arguments.contains("-callgrind")) {
|
|
|
|
QProcess checkProcess;
|
|
|
|
QStringList args;
|
|
|
|
args << QLatin1String("--version");
|
|
|
|
checkProcess.start(QLatin1String("valgrind"), args);
|
|
|
|
if (!checkProcess.waitForFinished(-1))
|
|
|
|
QSKIP(QString("Valgrind broken or not available. Not running %1 test!").arg(subdir).toLocal8Bit());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QProcess proc;
|
2015-04-17 09:11:58 +00:00
|
|
|
QProcessEnvironment environment = processEnvironment();
|
2018-10-15 17:48:13 +00:00
|
|
|
// Keep in sync with generateTestData()'s extraEnv in generate_expected_output.py:
|
2016-12-08 13:07:25 +00:00
|
|
|
if (crashes) {
|
|
|
|
environment.insert("QTEST_DISABLE_CORE_DUMP", "1");
|
2015-04-17 09:11:58 +00:00
|
|
|
environment.insert("QTEST_DISABLE_STACK_DUMP", "1");
|
2018-10-15 15:47:42 +00:00
|
|
|
if (subdir == QLatin1String("watchdog"))
|
|
|
|
environment.insert("QTEST_FUNCTION_TIMEOUT", "100");
|
2016-12-08 13:07:25 +00:00
|
|
|
}
|
2011-12-07 15:45:14 +00:00
|
|
|
proc.setProcessEnvironment(environment);
|
2011-12-13 16:08:45 +00:00
|
|
|
const QString path = subdir + QLatin1Char('/') + subdir;
|
|
|
|
proc.start(path, arguments);
|
2013-11-18 21:43:19 +00:00
|
|
|
QVERIFY2(proc.waitForStarted(), msgProcessError(path, arguments, environment, QStringLiteral("Cannot start: ") + proc.errorString()));
|
|
|
|
QVERIFY2(proc.waitForFinished(), msgProcessError(path, arguments, environment, QStringLiteral("Timed out: ") + proc.errorString()));
|
|
|
|
if (!crashes) {
|
|
|
|
QVERIFY2(proc.exitStatus() == QProcess::NormalExit,
|
|
|
|
msgProcessError(path, arguments, environment,
|
|
|
|
QStringLiteral("Crashed: ") + proc.errorString()
|
|
|
|
+ QStringLiteral(": ") + QString::fromLocal8Bit(proc.readAllStandardError())));
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-21 01:39:07 +00:00
|
|
|
QList<QByteArray> actualOutputs;
|
|
|
|
for (int i = 0; i < loggers.count(); ++i) {
|
|
|
|
QString logFile = logName(loggers[i]);
|
|
|
|
QByteArray out;
|
|
|
|
if (logFile.isEmpty()) {
|
|
|
|
out = proc.readAllStandardOutput();
|
|
|
|
} else {
|
|
|
|
QFile file(logFile);
|
|
|
|
if (file.open(QIODevice::ReadOnly))
|
|
|
|
out = file.readAll();
|
|
|
|
}
|
|
|
|
actualOutputs << out;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const QByteArray err(proc.readAllStandardError());
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// Some tests may output unpredictable strings to stderr, which we'll ignore.
|
|
|
|
//
|
|
|
|
// For instance, uncaught exceptions on Windows might say (depending on Windows
|
|
|
|
// version and JIT debugger settings):
|
|
|
|
// "This application has requested the Runtime to terminate it in an unusual way.
|
|
|
|
// Please contact the application's support team for more information."
|
|
|
|
//
|
|
|
|
// Also, tests which use valgrind may generate warnings if the toolchain is
|
|
|
|
// newer than the valgrind version, such that valgrind can't understand the
|
|
|
|
// debug information on the binary.
|
2011-04-27 10:05:43 +00:00
|
|
|
if (subdir != QLatin1String("exceptionthrow")
|
2011-12-19 10:33:07 +00:00
|
|
|
&& subdir != QLatin1String("cmptest") // QImage comparison requires QGuiApplication
|
2011-04-27 10:05:43 +00:00
|
|
|
&& subdir != QLatin1String("fetchbogus")
|
2018-10-15 15:47:42 +00:00
|
|
|
&& subdir != QLatin1String("watchdog")
|
2011-04-27 10:05:43 +00:00
|
|
|
&& subdir != QLatin1String("xunit")
|
2013-01-22 11:20:45 +00:00
|
|
|
#ifdef Q_CC_MINGW
|
2015-04-28 11:40:26 +00:00
|
|
|
&& subdir != QLatin1String("blacklisted") // calls qFatal()
|
2013-01-22 11:20:45 +00:00
|
|
|
&& subdir != QLatin1String("silent") // calls qFatal()
|
2017-03-21 10:11:26 +00:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
// QEMU outputs to stderr about uncaught signals
|
2018-10-11 15:26:57 +00:00
|
|
|
&& !(EmulationDetector::isRunningArmOnX86() &&
|
|
|
|
(subdir == QLatin1String("assert")
|
|
|
|
|| subdir == QLatin1String("blacklisted")
|
|
|
|
|| subdir == QLatin1String("crashes")
|
|
|
|
|| subdir == QLatin1String("faildatatype")
|
|
|
|
|| subdir == QLatin1String("failfetchtype")
|
|
|
|
|| subdir == QLatin1String("silent")
|
2017-03-21 10:11:26 +00:00
|
|
|
)
|
|
|
|
)
|
2013-01-22 11:20:45 +00:00
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
&& subdir != QLatin1String("benchlibcallgrind"))
|
|
|
|
QVERIFY2(err.isEmpty(), err.constData());
|
|
|
|
|
2011-09-21 01:39:07 +00:00
|
|
|
for (int n = 0; n < loggers.count(); ++n) {
|
|
|
|
QString logger = loggers[n];
|
2015-09-25 13:55:31 +00:00
|
|
|
if (n == 0 && subdir == QLatin1String("crashes")) {
|
|
|
|
QByteArray &actual = actualOutputs[0];
|
|
|
|
#ifndef Q_OS_WIN
|
|
|
|
// Remove digits of times to match the expected file.
|
|
|
|
const QLatin1String timePattern("Function time:");
|
|
|
|
int timePos = actual.indexOf(timePattern);
|
|
|
|
if (timePos >= 0) {
|
|
|
|
timePos += timePattern.size();
|
|
|
|
const int nextLinePos = actual.indexOf('\n', timePos);
|
|
|
|
for (int c = (nextLinePos != -1 ? nextLinePos : actual.size()) - 1; c >= timePos; --c) {
|
|
|
|
if (actual.at(c) >= '0' && actual.at(c) <= '9')
|
|
|
|
actual.remove(c, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else // !Q_OS_WIN
|
|
|
|
// Remove stack trace which is output to stdout.
|
|
|
|
const int exceptionLogStart = actual.indexOf("A crash occurred in ");
|
2015-09-02 14:26:41 +00:00
|
|
|
if (exceptionLogStart >= 0)
|
2015-09-25 13:55:31 +00:00
|
|
|
actual.truncate(exceptionLogStart);
|
2015-09-02 14:26:41 +00:00
|
|
|
#endif // Q_OS_WIN
|
2015-09-25 13:55:31 +00:00
|
|
|
}
|
|
|
|
|
2011-09-21 01:39:07 +00:00
|
|
|
QList<QByteArray> res = splitLines(actualOutputs[n]);
|
2018-02-07 08:04:35 +00:00
|
|
|
QString errorMessage;
|
|
|
|
QString expectedFileName = expectedFileNameFromTest(subdir, logger);
|
2018-03-10 10:38:59 +00:00
|
|
|
QByteArrayList exp = expectedResult(expectedFileName);
|
|
|
|
if (!exp.isEmpty()) {
|
2018-02-07 08:04:35 +00:00
|
|
|
if (!compareOutput(logger, subdir, actualOutputs[n], res, exp, &errorMessage)) {
|
|
|
|
errorMessage.prepend(QLatin1Char('"') + logger + QLatin1String("\", ")
|
|
|
|
+ expectedFileName + QLatin1Char(' '));
|
|
|
|
errorMessage += QLatin1String("\nActual:\n") + QLatin1String(actualOutputs[n]);
|
|
|
|
const QByteArray diff = runDiff(exp, res);
|
|
|
|
if (!diff.isEmpty())
|
|
|
|
errorMessage += QLatin1String("\nDiff:\n") + QLatin1String(diff);
|
|
|
|
QFAIL(qPrintable(errorMessage));
|
2012-03-07 06:17:46 +00:00
|
|
|
}
|
2011-09-21 01:39:07 +00:00
|
|
|
} else {
|
2018-02-07 08:04:35 +00:00
|
|
|
// For the "crashes" and other tests, there are multiple versions of the
|
|
|
|
// expected output. Loop until a matching one is found.
|
|
|
|
bool ok = false;
|
|
|
|
for (int i = 1; !ok; ++i) {
|
|
|
|
expectedFileName = expectedFileNameFromTest(subdir + QLatin1Char('_') + QString::number(i), logger);
|
|
|
|
const QByteArrayList exp = expectedResult(expectedFileName);
|
|
|
|
if (exp.isEmpty())
|
|
|
|
break;
|
|
|
|
QString errorMessage2;
|
|
|
|
ok = compareOutput(logger, subdir, actualOutputs[n], res, exp, &errorMessage2);
|
|
|
|
if (!ok)
|
|
|
|
errorMessage += QLatin1Char('\n') + expectedFileName + QLatin1String(": ") + errorMessage2;
|
|
|
|
}
|
|
|
|
if (!ok) { // Use QDebug's quote mechanism to report potentially garbled output.
|
|
|
|
errorMessage.prepend(QLatin1String("Cannot find a matching file for ") + subdir);
|
|
|
|
errorMessage += QLatin1String("\nActual:\n");
|
|
|
|
QDebug(&errorMessage) << actualOutputs[n];
|
|
|
|
QFAIL(qPrintable(errorMessage));
|
2014-01-02 13:53:36 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2018-02-07 08:04:35 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
static QString teamCityLocation() { return QStringLiteral("|[Loc: _FILE_(_LINE_)|]"); }
|
|
|
|
static QString qtVersionPlaceHolder() { return QStringLiteral("@INSERT_QT_VERSION_HERE@"); }
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
bool tst_Selftests::compareOutput(const QString &logger, const QString &subdir,
|
|
|
|
const QByteArray &rawOutput, const QByteArrayList &actual,
|
|
|
|
const QByteArrayList &expected,
|
|
|
|
QString *errorMessage) const
|
|
|
|
{
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
if (actual.size() != expected.size()) {
|
|
|
|
*errorMessage = QString::fromLatin1("Mismatch in line count: %1 != %2.")
|
|
|
|
.arg(actual.size()).arg(expected.size());
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
// For xml output formats, verify that the log is valid XML.
|
|
|
|
if (logger.endsWith(QLatin1String("xml")) && !checkXml(logger, rawOutput, errorMessage))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Verify that the actual output is an acceptable match for the
|
|
|
|
// expected output.
|
|
|
|
|
|
|
|
const QString qtVersion = QLatin1String(QT_VERSION_STR);
|
|
|
|
bool benchmark = false;
|
|
|
|
for (int i = 0, size = actual.size(); i < size; ++i) {
|
|
|
|
const QByteArray &actualLineBA = actual.at(i);
|
|
|
|
// the __FILE__ __LINE__ output is compiler dependent, skip it
|
|
|
|
if (actualLineBA.startsWith(" Loc: [") && actualLineBA.endsWith(")]"))
|
|
|
|
continue;
|
|
|
|
if (actualLineBA.endsWith(" : failure location"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (actualLineBA.startsWith("Config: Using QtTest library") // Text build string
|
|
|
|
|| actualLineBA.startsWith(" <QtBuild") // XML, Light XML build string
|
|
|
|
|| (actualLineBA.startsWith(" <property value=") && actualLineBA.endsWith("name=\"QtBuild\"/>"))) { // XUNIT-XML build string
|
|
|
|
continue;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
QString actualLine = QString::fromLatin1(actualLineBA);
|
|
|
|
QString expectedLine = QString::fromLatin1(expected.at(i));
|
|
|
|
expectedLine.replace(qtVersionPlaceHolder(), qtVersion);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
// Special handling for ignoring _FILE_ and _LINE_ if logger is teamcity
|
|
|
|
if (logger.endsWith(QLatin1String("teamcity"))) {
|
|
|
|
actualLine.replace(teamcityLocRegExp, teamCityLocation());
|
|
|
|
expectedLine.replace(teamcityLocRegExp, teamCityLocation());
|
|
|
|
}
|
Use new QLibraryInfo::build() in testlib to log build information.
This produces:
********* Start testing of tst_QtJson *********
Config: Using QtTest library 5.3.0, Qt 5.3.0 (Feb 13 2014, GCC 4.6.3, 64 bit, debug build)
PASS : tst_QtJson::initTestCase()
<?xml version="1.0" encoding="UTF-8"?>
<TestCase name="tst_QtJson">
<Environment>
<QtVersion>5.3.0</QtVersion>
<QtBuild>Qt 5.3.0 (Feb 13 2014, GCC 4.6.3, 64 bit, debug build)</QtBuild>
<QTestVersion>5.3.0</QTestVersion>
</Environment>
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite errors="1" failures="1" tests="42" name="tst_QtJson">
<properties>
<property value="5.3.0" name="QTestVersion"/>
<property value="5.3.0" name="QtVersion"/>
<property value="Qt 5.3.0 (Feb 13 2014, GCC 4.6.3, 64 bit, debug build)" name="QtBuild"/>
</properties>
<Environment>
<QtVersion>5.3.0</QtVersion>
<QtBuild>Qt 5.3.0 (Feb 13 2014, GCC 4.6.3, 64 bit, debug build)</QtBuild>
<QTestVersion>5.3.0</QTestVersion>
</Environment>
[ChangeLog][QtTest] Tests now output build information.
Change-Id: I0ab473371575f2b807db725256805b8bffea3454
Reviewed-by: Sergio Ahumada <sahumada@blackberry.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
2014-02-26 16:12:45 +00:00
|
|
|
|
2018-03-01 16:06:23 +00:00
|
|
|
if (logger.endsWith(QLatin1String("tap"))) {
|
2018-03-27 14:53:32 +00:00
|
|
|
if (expectedLine.contains(QLatin1String("at:"))
|
|
|
|
|| expectedLine.contains(QLatin1String("file:"))
|
|
|
|
|| expectedLine.contains(QLatin1String("line:")))
|
2018-03-01 16:06:23 +00:00
|
|
|
actualLine = expectedLine;
|
|
|
|
}
|
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
if (!compareLine(logger, subdir, benchmark, actualLine,
|
|
|
|
expectedLine, errorMessage)) {
|
|
|
|
errorMessage->prepend(QLatin1String("Line ") + QString::number(i + 1)
|
|
|
|
+ QLatin1String(": "));
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-06 17:20:29 +00:00
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
benchmark = actualLineBA.startsWith("RESULT : ");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-06 17:20:29 +00:00
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
bool tst_Selftests::compareLine(const QString &logger, const QString &subdir,
|
|
|
|
bool benchmark,
|
|
|
|
const QString &actualLine, const QString &expectedLine,
|
|
|
|
QString *errorMessage) const
|
|
|
|
{
|
2018-10-17 17:32:54 +00:00
|
|
|
if (actualLine == expectedLine)
|
|
|
|
return true;
|
|
|
|
|
2018-10-11 15:26:57 +00:00
|
|
|
if ((subdir == QLatin1String("assert")
|
|
|
|
|| subdir == QLatin1String("faildatatype") || subdir == QLatin1String("failfetchtype"))
|
2018-10-17 17:32:54 +00:00
|
|
|
&& actualLine.contains(QLatin1String("ASSERT: "))
|
|
|
|
&& expectedLine.contains(QLatin1String("ASSERT: "))) {
|
2018-02-07 08:04:35 +00:00
|
|
|
// Q_ASSERT uses __FILE__, the exact contents of which are
|
|
|
|
// undefined. If have we something that looks like a Q_ASSERT and we
|
|
|
|
// were expecting to see a Q_ASSERT, we'll skip the line.
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-21 01:39:07 +00:00
|
|
|
|
2018-10-17 17:32:54 +00:00
|
|
|
if (expectedLine.startsWith(QLatin1String("FAIL! : tst_Exception::throwException() Caught unhandled exce"))) {
|
2018-02-07 08:04:35 +00:00
|
|
|
// On some platforms we compile without RTTI, and as a result we never throw an exception
|
|
|
|
if (actualLine.simplified() != QLatin1String("tst_Exception::throwException()")) {
|
|
|
|
*errorMessage = QString::fromLatin1("'%1' != 'tst_Exception::throwException()'").arg(actualLine);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
if (benchmark || actualLine.startsWith(QLatin1String("<BenchmarkResult"))
|
|
|
|
|| (logger == QLatin1String("csv") && actualLine.startsWith(QLatin1Char('"')))) {
|
|
|
|
// Don't do a literal comparison for benchmark results, since
|
|
|
|
// results have some natural variance.
|
|
|
|
QString error;
|
|
|
|
BenchmarkResult actualResult = BenchmarkResult::parse(actualLine, &error);
|
|
|
|
if (!error.isEmpty()) {
|
|
|
|
*errorMessage = QString::fromLatin1("Actual line didn't parse as benchmark result: %1\nLine: %2").arg(error, actualLine);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
BenchmarkResult expectedResult = BenchmarkResult::parse(expectedLine, &error);
|
|
|
|
if (!error.isEmpty()) {
|
|
|
|
*errorMessage = QString::fromLatin1("Expected line didn't parse as benchmark result: %1\nLine: %2").arg(error, expectedLine);
|
|
|
|
return false;
|
2011-09-21 01:39:07 +00:00
|
|
|
}
|
2018-02-07 08:04:35 +00:00
|
|
|
return compareBenchmarkResult(actualResult, expectedResult, errorMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actualLine.startsWith(QLatin1String(" <Duration msecs="))
|
|
|
|
|| actualLine.startsWith(QLatin1String("<Duration msecs="))) {
|
|
|
|
QRegularExpressionMatch match = durationRegExp.match(actualLine);
|
|
|
|
if (match.hasMatch())
|
|
|
|
return true;
|
|
|
|
*errorMessage = QString::fromLatin1("Invalid Duration tag: '%1'").arg(actualLine);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actualLine.startsWith(QLatin1String("Totals:")) && expectedLine.startsWith(QLatin1String("Totals:")))
|
|
|
|
return true;
|
|
|
|
|
2019-02-26 15:09:59 +00:00
|
|
|
const QLatin1String pointerPlaceholder("_POINTER_");
|
|
|
|
if (expectedLine.contains(pointerPlaceholder)
|
|
|
|
&& (expectedLine.contains(QLatin1String("Signal: "))
|
|
|
|
|| expectedLine.contains(QLatin1String("Slot: ")))) {
|
|
|
|
QString actual = actualLine;
|
|
|
|
// We don't care about the pointer of the object to whom the signal belongs, so we
|
|
|
|
// replace it with _POINTER_, e.g.:
|
|
|
|
// Signal: SignalSlotClass(7ffd72245410) signalWithoutParameters ()
|
|
|
|
// Signal: QThread(7ffd72245410) started ()
|
|
|
|
// After this instance pointer we may have further pointers and
|
|
|
|
// references (with an @ prefix) as parameters of the signal or
|
|
|
|
// slot being invoked.
|
|
|
|
// Signal: SignalSlotClass(_POINTER_) qStringRefSignal ((QString&)@55f5fbb8dd40)
|
|
|
|
actual.replace(QRegularExpression("\\b[a-f0-9]{8,}\\b"), pointerPlaceholder);
|
|
|
|
// Also change QEventDispatcher{Glib,Win32,etc.} to QEventDispatcherPlatform
|
|
|
|
actual.replace(QRegularExpression("\\b(QEventDispatcher)\\w+\\b"), QLatin1String("\\1Platform"));
|
|
|
|
if (actual != expectedLine) {
|
|
|
|
*errorMessage = msgMismatch(actual, expectedLine);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-07 08:04:35 +00:00
|
|
|
*errorMessage = msgMismatch(actualLine, expectedLine);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tst_Selftests::checkXml(const QString &logger, QByteArray xml,
|
|
|
|
QString *errorMessage) const
|
|
|
|
{
|
|
|
|
// lightxml intentionally skips the root element, which technically makes it
|
|
|
|
// not valid XML.
|
|
|
|
// We'll add that ourselves for the purpose of validation.
|
|
|
|
if (logger.endsWith(QLatin1String("lightxml"))) {
|
|
|
|
xml.prepend("<root>");
|
|
|
|
xml.append("</root>");
|
|
|
|
}
|
|
|
|
|
|
|
|
QXmlStreamReader reader(xml);
|
|
|
|
while (!reader.atEnd())
|
|
|
|
reader.readNext();
|
|
|
|
|
|
|
|
if (reader.hasError()) {
|
|
|
|
const int lineNumber = int(reader.lineNumber());
|
|
|
|
const QByteArray line = xml.split('\n').value(lineNumber - 1);
|
|
|
|
*errorMessage = QString::fromLatin1("line %1, col %2 '%3': %4")
|
|
|
|
.arg(lineNumber).arg(reader.columnNumber())
|
|
|
|
.arg(QString::fromLatin1(line), reader.errorString());
|
|
|
|
return false;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2018-02-07 08:04:35 +00:00
|
|
|
return true;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 11:25:17 +00:00
|
|
|
#endif // QT_CONFIG(process)
|
2013-09-02 18:00:14 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_Selftests::runSubTest()
|
|
|
|
{
|
2016-11-23 11:25:17 +00:00
|
|
|
#if !QT_CONFIG(process)
|
2013-09-02 18:00:14 +00:00
|
|
|
QSKIP("This test requires QProcess support");
|
|
|
|
#else
|
2011-04-27 10:05:43 +00:00
|
|
|
QFETCH(QString, subdir);
|
2011-09-21 01:39:07 +00:00
|
|
|
QFETCH(QStringList, loggers);
|
2011-04-27 10:05:43 +00:00
|
|
|
QFETCH(QStringList, arguments);
|
2013-11-18 21:43:19 +00:00
|
|
|
QFETCH(bool, crashes);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-11-18 21:43:19 +00:00
|
|
|
doRunSubTest(subdir, loggers, arguments, crashes);
|
2016-11-23 11:25:17 +00:00
|
|
|
#endif // QT_CONFIG(process)
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// attribute must contain ="
|
|
|
|
QString extractXmlAttribute(const QString &line, const char *attribute)
|
|
|
|
{
|
|
|
|
int index = line.indexOf(attribute);
|
|
|
|
if (index == -1)
|
|
|
|
return QString();
|
2012-04-02 12:22:04 +00:00
|
|
|
const int attributeLength = int(strlen(attribute));
|
|
|
|
const int end = line.indexOf('"', index + attributeLength);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (end == -1)
|
|
|
|
return QString();
|
|
|
|
|
2012-04-02 12:22:04 +00:00
|
|
|
const QString result = line.mid(index + attributeLength, end - index - attributeLength);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (result.isEmpty())
|
|
|
|
return ""; // ensure empty but not null
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// Parse line into the BenchmarkResult it represents.
|
2011-04-27 10:05:43 +00:00
|
|
|
BenchmarkResult BenchmarkResult::parse(QString const& line, QString* error)
|
|
|
|
{
|
|
|
|
if (error) *error = QString();
|
|
|
|
BenchmarkResult out;
|
|
|
|
|
|
|
|
QString remaining = line.trimmed();
|
|
|
|
|
|
|
|
if (remaining.isEmpty()) {
|
|
|
|
if (error) *error = "Line is empty";
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.unit = unit;
|
|
|
|
out.total = total;
|
|
|
|
out.iterations = iterations;
|
|
|
|
return out;
|
|
|
|
}
|
2013-12-20 19:14:04 +00:00
|
|
|
|
|
|
|
if (line.startsWith('"')) {
|
|
|
|
// CSV result
|
|
|
|
// format:
|
|
|
|
// "function","[globaltag:]tag","metric",value_per_iteration,total,iterations
|
|
|
|
QStringList split = line.split(',');
|
|
|
|
if (split.count() != 6) {
|
|
|
|
if (error) *error = QString("Wrong number of columns (%1)").arg(split.count());
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
double total = split.at(4).toDouble(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
if (error) *error = split.at(4) + " is not a valid number";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
double iterations = split.at(5).toDouble(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
if (error) *error = split.at(5) + " is not a valid number";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.unit = split.at(2);
|
|
|
|
out.total = total;
|
|
|
|
out.iterations = iterations;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// Text result
|
2011-09-16 04:42:51 +00:00
|
|
|
// This code avoids using a QRegExp because QRegExp might be broken.
|
|
|
|
// Sample format: 4,000 msec per iteration (total: 4,000, iterations: 1)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QString sFirstNumber;
|
|
|
|
while (!remaining.isEmpty() && !remaining.at(0).isSpace()) {
|
|
|
|
sFirstNumber += remaining.at(0);
|
|
|
|
remaining.remove(0,1);
|
|
|
|
}
|
|
|
|
remaining = remaining.trimmed();
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// 4,000 -> 4000
|
2011-04-27 10:05:43 +00:00
|
|
|
sFirstNumber.remove(',');
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// Should now be parseable as floating point
|
2011-04-27 10:05:43 +00:00
|
|
|
bool ok;
|
|
|
|
double firstNumber = sFirstNumber.toDouble(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
if (error) *error = sFirstNumber + " (at beginning of line) is not a valid number";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// Remaining: msec per iteration (total: 4000, iterations: 1)
|
2011-04-27 10:05:43 +00:00
|
|
|
static const char periterbit[] = " per iteration (total: ";
|
|
|
|
QString unit;
|
|
|
|
while (!remaining.startsWith(periterbit) && !remaining.isEmpty()) {
|
|
|
|
unit += remaining.at(0);
|
|
|
|
remaining.remove(0,1);
|
|
|
|
}
|
|
|
|
if (remaining.isEmpty()) {
|
|
|
|
if (error) *error = "Could not find pattern: '<unit> per iteration (total: '";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
remaining = remaining.mid(sizeof(periterbit)-1);
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// Remaining: 4,000, iterations: 1)
|
2011-04-27 10:05:43 +00:00
|
|
|
static const char itersbit[] = ", iterations: ";
|
|
|
|
QString sTotal;
|
|
|
|
while (!remaining.startsWith(itersbit) && !remaining.isEmpty()) {
|
|
|
|
sTotal += remaining.at(0);
|
|
|
|
remaining.remove(0,1);
|
|
|
|
}
|
|
|
|
if (remaining.isEmpty()) {
|
|
|
|
if (error) *error = "Could not find pattern: '<number>, iterations: '";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
remaining = remaining.mid(sizeof(itersbit)-1);
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// 4,000 -> 4000
|
2011-04-27 10:05:43 +00:00
|
|
|
sTotal.remove(',');
|
|
|
|
|
|
|
|
double total = sTotal.toDouble(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
if (error) *error = sTotal + " (total) is not a valid number";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-09-16 04:42:51 +00:00
|
|
|
// Remaining: 1)
|
2011-04-27 10:05:43 +00:00
|
|
|
QString sIters;
|
|
|
|
while (remaining != QLatin1String(")") && !remaining.isEmpty()) {
|
|
|
|
sIters += remaining.at(0);
|
|
|
|
remaining.remove(0,1);
|
|
|
|
}
|
|
|
|
if (remaining.isEmpty()) {
|
|
|
|
if (error) *error = "Could not find pattern: '<num>)'";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
qint64 iters = sIters.toLongLong(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
if (error) *error = sIters + " (iterations) is not a valid integer";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
double calcFirstNumber = double(total)/double(iters);
|
|
|
|
if (!qFuzzyCompare(firstNumber, calcFirstNumber)) {
|
|
|
|
if (error) *error = QString("total/iters is %1, but benchlib output result as %2").arg(calcFirstNumber).arg(firstNumber);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.total = total;
|
|
|
|
out.unit = unit;
|
|
|
|
out.iterations = iters;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2011-09-16 05:03:44 +00:00
|
|
|
void tst_Selftests::cleanup()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-09-21 01:39:07 +00:00
|
|
|
QFETCH(QStringList, loggers);
|
|
|
|
|
|
|
|
// Remove the test output files
|
|
|
|
for (int i = 0; i < loggers.count(); ++i) {
|
2011-12-19 10:33:07 +00:00
|
|
|
QString logFileName = logName(loggers[i]);
|
|
|
|
if (!logFileName.isEmpty()) {
|
|
|
|
QFile logFile(logFileName);
|
|
|
|
if (logFile.exists())
|
|
|
|
QVERIFY2(logFile.remove(), qPrintable(QString::fromLatin1("Cannot remove file '%1': %2: ").arg(logFileName, logFile.errorString())));
|
|
|
|
}
|
2011-09-21 01:39:07 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_Selftests)
|
|
|
|
|
|
|
|
#include "tst_selftests.moc"
|