AutoTest: Refactor output handling

Handle getting output from application's process inside base class
and just process output inside the sub classes.
Additionally this is a preparation for being able to process output
for debugging tests as well.

Change-Id: I8a2289dc7faab25afe08530b5021a0318f3ba6a6
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2016-07-21 10:08:11 +02:00
parent ce8bff4b31
commit bb643a3cdc
6 changed files with 240 additions and 245 deletions

View File

@@ -43,11 +43,8 @@ GTestOutputReader::GTestOutputReader(const QFutureInterface<TestResultPtr> &futu
{ {
} }
void GTestOutputReader::processOutput() void GTestOutputReader::processOutput(const QByteArray &outputLine)
{ {
if (!m_testApplication || m_testApplication->state() != QProcess::Running)
return;
static QRegExp newTestStarts(QStringLiteral("^\\[-{10}\\] \\d+ tests? from (.*)$")); static QRegExp newTestStarts(QStringLiteral("^\\[-{10}\\] \\d+ tests? from (.*)$"));
static QRegExp testEnds(QStringLiteral("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$")); static QRegExp testEnds(QStringLiteral("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$"));
static QRegExp newTestSetStarts(QStringLiteral("^\\[ RUN \\] (.*)$")); static QRegExp newTestSetStarts(QStringLiteral("^\\[ RUN \\] (.*)$"));
@@ -58,17 +55,14 @@ void GTestOutputReader::processOutput()
static QRegExp errorLocation(QStringLiteral("^(.*)\\((\\d+)\\): error:.*$")); static QRegExp errorLocation(QStringLiteral("^(.*)\\((\\d+)\\): error:.*$"));
static QRegExp iterations(QStringLiteral("^Repeating all tests \\(iteration (\\d+)\\) . . .$")); static QRegExp iterations(QStringLiteral("^Repeating all tests \\(iteration (\\d+)\\) . . .$"));
while (m_testApplication->canReadLine()) { QByteArray read = outputLine;
if (m_futureInterface.isCanceled())
return;
QByteArray read = m_testApplication->readLine();
if (!m_unprocessed.isEmpty()) { if (!m_unprocessed.isEmpty()) {
read = m_unprocessed + read; read = m_unprocessed + read;
m_unprocessed.clear(); m_unprocessed.clear();
} }
if (!read.endsWith('\n')) { if (!read.endsWith('\n')) {
m_unprocessed = read; m_unprocessed = read;
continue; return;
} }
read.chop(1); // remove the newline from the output read.chop(1); // remove the newline from the output
if (read.endsWith('\r')) if (read.endsWith('\r'))
@@ -76,7 +70,7 @@ void GTestOutputReader::processOutput()
const QString line = QString::fromLatin1(read); const QString line = QString::fromLatin1(read);
if (line.trimmed().isEmpty()) if (line.trimmed().isEmpty())
continue; return;
if (!line.startsWith(QLatin1Char('['))) { if (!line.startsWith(QLatin1Char('['))) {
m_description.append(line).append(QLatin1Char('\n')); m_description.append(line).append(QLatin1Char('\n'));
@@ -98,7 +92,7 @@ void GTestOutputReader::processOutput()
m_futureInterface.reportResult(testResult); m_futureInterface.reportResult(testResult);
m_description.clear(); m_description.clear();
} }
continue; return; //continue;
} }
if (testEnds.exactMatch(line)) { if (testEnds.exactMatch(line)) {
@@ -174,7 +168,6 @@ void GTestOutputReader::processOutput()
m_futureInterface.setProgressValue(m_futureInterface.progressValue() + 1); m_futureInterface.setProgressValue(m_futureInterface.progressValue() + 1);
} }
} }
}
} // namespace Internal } // namespace Internal
} // namespace Autotest } // namespace Autotest

View File

@@ -37,7 +37,7 @@ public:
QProcess *testApplication, const QString &buildDirectory); QProcess *testApplication, const QString &buildDirectory);
protected: protected:
void processOutput() override; void processOutput(const QByteArray &outputLine) override;
private: private:
QString m_currentTestName; QString m_currentTestName;

View File

@@ -133,10 +133,8 @@ QtTestOutputReader::QtTestOutputReader(const QFutureInterface<TestResultPtr> &fu
{ {
} }
void QtTestOutputReader::processOutput() void QtTestOutputReader::processOutput(const QByteArray &outputLine)
{ {
if (!m_testApplication || m_testApplication->state() != QProcess::Running)
return;
static QStringList validEndTags = { QStringLiteral("Incident"), static QStringList validEndTags = { QStringLiteral("Incident"),
QStringLiteral("Message"), QStringLiteral("Message"),
QStringLiteral("BenchmarkResult"), QStringLiteral("BenchmarkResult"),
@@ -144,8 +142,7 @@ void QtTestOutputReader::processOutput()
QStringLiteral("QtBuild"), QStringLiteral("QtBuild"),
QStringLiteral("QTestVersion") }; QStringLiteral("QTestVersion") };
while (m_testApplication->canReadLine()) { m_xmlReader.addData(outputLine);
m_xmlReader.addData(m_testApplication->readLine());
while (!m_xmlReader.atEnd()) { while (!m_xmlReader.atEnd()) {
if (m_futureInterface.isCanceled()) if (m_futureInterface.isCanceled())
return; return;
@@ -282,7 +279,6 @@ void QtTestOutputReader::processOutput()
} }
} }
} }
}
} // namespace Internal } // namespace Internal
} // namespace Autotest } // namespace Autotest

View File

@@ -39,7 +39,7 @@ public:
QProcess *testApplication, const QString &buildDirectory); QProcess *testApplication, const QString &buildDirectory);
protected: protected:
void processOutput() override; void processOutput(const QByteArray &outputLine) override;
private: private:
enum CDATAMode enum CDATAMode

View File

@@ -38,14 +38,20 @@ TestOutputReader::TestOutputReader(const QFutureInterface<TestResultPtr> &future
, m_testApplication(testApplication) , m_testApplication(testApplication)
, m_buildDir(buildDirectory) , m_buildDir(buildDirectory)
{ {
connect(m_testApplication, &QProcess::readyRead, this, &TestOutputReader::processOutput); connect(m_testApplication, &QProcess::readyRead,
this, [this] () {
while (m_testApplication->canReadLine())
processOutput(m_testApplication->readLine());
});
connect(m_testApplication, &QProcess::readyReadStandardError, connect(m_testApplication, &QProcess::readyReadStandardError,
this, &TestOutputReader::processStdError); this, [this] () {
processStdError(m_testApplication->readAllStandardError());
});
} }
void TestOutputReader::processStdError() void TestOutputReader::processStdError(const QByteArray &output)
{ {
qWarning() << "AutoTest.Run: Ignored plain output:" << m_testApplication->readAllStandardError(); qWarning() << "AutoTest.Run: Ignored plain output:" << output;
} }
} // namespace Internal } // namespace Internal

View File

@@ -43,8 +43,8 @@ public:
QProcess *testApplication, const QString &buildDirectory); QProcess *testApplication, const QString &buildDirectory);
protected: protected:
virtual void processOutput() = 0; virtual void processOutput(const QByteArray &outputLine) = 0;
virtual void processStdError(); virtual void processStdError(const QByteArray &output);
QFutureInterface<TestResultPtr> m_futureInterface; QFutureInterface<TestResultPtr> m_futureInterface;
QProcess *m_testApplication; // not owned QProcess *m_testApplication; // not owned
QString m_buildDir; QString m_buildDir;