2015-01-16 13:44:24 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-01-16 13:44:24 +01:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** This file is part of Qt Creator.
|
2015-01-16 13:44:24 +01:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2015-01-16 13:44:24 +01:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-22 10:37:55 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-01-16 13:44:24 +01:00
|
|
|
**
|
2016-01-22 10:37:55 +01: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.
|
2015-01-16 13:44:24 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2015-12-09 09:46:33 +01:00
|
|
|
#include "testoutputreader.h"
|
2020-10-09 13:07:55 +02:00
|
|
|
|
2015-01-16 13:44:24 +01:00
|
|
|
#include "testresult.h"
|
2017-05-05 13:01:06 +02:00
|
|
|
#include "testresultspane.h"
|
2020-07-27 17:52:59 +02:00
|
|
|
#include "testtreeitem.h"
|
2015-01-16 13:44:24 +01:00
|
|
|
|
2018-11-05 15:58:27 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2015-10-09 14:19:53 +02:00
|
|
|
#include <QDebug>
|
2020-07-28 07:35:20 +02:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
2015-01-16 13:44:24 +01:00
|
|
|
#include <QProcess>
|
|
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
|
2021-05-26 15:50:03 +02:00
|
|
|
Utils::FilePath TestOutputReader::constructSourceFilePath(const Utils::FilePath &path,
|
|
|
|
|
const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
if (!filePath.isEmpty() && filePath.at(0) != '.')
|
|
|
|
|
return Utils::FilePath::fromFileInfo(QFileInfo(filePath));
|
|
|
|
|
return (path / filePath).canonicalPath();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 13:02:31 +01:00
|
|
|
TestOutputReader::TestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
|
2021-05-26 15:50:03 +02:00
|
|
|
QProcess *testApplication, const Utils::FilePath &buildDirectory)
|
2016-01-20 08:26:10 +01:00
|
|
|
: m_futureInterface(futureInterface)
|
|
|
|
|
, m_testApplication(testApplication)
|
2016-01-26 17:24:11 +01:00
|
|
|
, m_buildDir(buildDirectory)
|
2018-05-09 10:48:23 +02:00
|
|
|
, m_id(testApplication ? testApplication->program() : QString())
|
2015-01-16 13:44:24 +01:00
|
|
|
{
|
2019-11-11 08:03:16 +01:00
|
|
|
auto chopLineBreak = [](QByteArray line) {
|
|
|
|
|
if (line.endsWith('\n'))
|
|
|
|
|
line.chop(1);
|
|
|
|
|
if (line.endsWith('\r'))
|
|
|
|
|
line.chop(1);
|
|
|
|
|
return line;
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-21 16:02:42 +02:00
|
|
|
if (m_testApplication) {
|
2020-04-28 10:15:45 +02:00
|
|
|
connect(m_testApplication, &QProcess::readyReadStandardOutput,
|
2019-11-11 08:03:16 +01:00
|
|
|
this, [chopLineBreak, this] () {
|
|
|
|
|
m_testApplication->setReadChannel(QProcess::StandardOutput);
|
|
|
|
|
while (m_testApplication->canReadLine())
|
|
|
|
|
processStdOutput(chopLineBreak(m_testApplication->readLine()));
|
2016-07-21 16:02:42 +02:00
|
|
|
});
|
|
|
|
|
connect(m_testApplication, &QProcess::readyReadStandardError,
|
2019-11-11 08:03:16 +01:00
|
|
|
this, [chopLineBreak, this] () {
|
|
|
|
|
m_testApplication->setReadChannel(QProcess::StandardError);
|
|
|
|
|
while (m_testApplication->canReadLine())
|
|
|
|
|
processStdError(chopLineBreak(m_testApplication->readLine()));
|
2016-07-21 16:02:42 +02:00
|
|
|
});
|
|
|
|
|
}
|
2016-04-18 10:24:54 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-27 17:52:59 +02:00
|
|
|
TestOutputReader::~TestOutputReader()
|
|
|
|
|
{
|
|
|
|
|
if (m_sanitizerResult)
|
|
|
|
|
sendAndResetSanitizerResult();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-11 08:03:16 +01:00
|
|
|
void TestOutputReader::processStdOutput(const QByteArray &outputLine)
|
2018-11-06 16:00:48 +01:00
|
|
|
{
|
2019-11-11 08:03:16 +01:00
|
|
|
processOutputLine(outputLine);
|
2019-11-06 14:25:16 +01:00
|
|
|
emit newOutputLineAvailable(outputLine, OutputChannel::StdOut);
|
2018-11-06 16:00:48 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-11 08:03:16 +01:00
|
|
|
void TestOutputReader::processStdError(const QByteArray &outputLine)
|
2016-04-18 10:24:54 +02:00
|
|
|
{
|
2020-07-27 17:52:59 +02:00
|
|
|
checkForSanitizerOutput(outputLine);
|
2019-11-06 14:25:16 +01:00
|
|
|
emit newOutputLineAvailable(outputLine, OutputChannel::StdErr);
|
2015-01-16 13:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-16 08:41:53 +01:00
|
|
|
void TestOutputReader::reportCrash()
|
|
|
|
|
{
|
|
|
|
|
TestResultPtr result = createDefaultResult();
|
|
|
|
|
result->setDescription(tr("Test executable crashed."));
|
2019-02-06 14:11:19 +01:00
|
|
|
result->setResult(ResultType::MessageFatal);
|
2018-01-16 08:41:53 +01:00
|
|
|
m_futureInterface.reportResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 14:11:19 +01:00
|
|
|
void TestOutputReader::createAndReportResult(const QString &message, ResultType type)
|
2018-04-16 09:45:01 +02:00
|
|
|
{
|
|
|
|
|
TestResultPtr result = createDefaultResult();
|
|
|
|
|
result->setDescription(message);
|
|
|
|
|
result->setResult(type);
|
|
|
|
|
reportResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 14:26:40 +01:00
|
|
|
void TestOutputReader::resetCommandlineColor()
|
|
|
|
|
{
|
|
|
|
|
emit newOutputLineAvailable("\u001B[m", OutputChannel::StdOut);
|
|
|
|
|
emit newOutputLineAvailable("\u001B[m", OutputChannel::StdErr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString TestOutputReader::removeCommandlineColors(const QString &original)
|
|
|
|
|
{
|
|
|
|
|
static const QRegularExpression pattern("\u001B\\[.*?m");
|
|
|
|
|
QString result = original;
|
|
|
|
|
while (!result.isEmpty()) {
|
|
|
|
|
QRegularExpressionMatch match = pattern.match(result);
|
|
|
|
|
if (match.hasMatch())
|
|
|
|
|
result.remove(match.capturedStart(), match.captured().length());
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-20 11:20:25 +02:00
|
|
|
void TestOutputReader::reportResult(const TestResultPtr &result)
|
|
|
|
|
{
|
2021-02-18 08:32:27 +01:00
|
|
|
if (m_sanitizerResult)
|
|
|
|
|
sendAndResetSanitizerResult();
|
2017-09-20 11:20:25 +02:00
|
|
|
m_futureInterface.reportResult(result);
|
|
|
|
|
m_hadValidOutput = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 17:52:59 +02:00
|
|
|
void TestOutputReader::checkForSanitizerOutput(const QByteArray &line)
|
|
|
|
|
{
|
|
|
|
|
const QString lineStr = removeCommandlineColors(QString::fromUtf8(line));
|
|
|
|
|
if (m_sanitizerOutputMode == SanitizerOutputMode::Asan) {
|
|
|
|
|
// append the new line and check for end
|
|
|
|
|
m_sanitizerLines.append(lineStr);
|
2020-07-28 07:35:20 +02:00
|
|
|
static const QRegularExpression regex("^==\\d+==\\s*ABORTING.*");
|
2020-07-27 17:52:59 +02:00
|
|
|
if (regex.match(lineStr).hasMatch())
|
|
|
|
|
sendAndResetSanitizerResult();
|
2020-07-28 07:35:20 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const QRegularExpression regex("^==\\d+==\\s*(ERROR|WARNING|Sanitizer CHECK failed):.*");
|
|
|
|
|
static const QRegularExpression ubsanRegex("^(.*):(\\d+):(\\d+): runtime error:.*");
|
|
|
|
|
QRegularExpressionMatch match = regex.match(lineStr);
|
|
|
|
|
SanitizerOutputMode mode = SanitizerOutputMode::None;
|
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
|
mode = SanitizerOutputMode::Asan;
|
2020-07-27 17:52:59 +02:00
|
|
|
} else {
|
2020-07-28 07:35:20 +02:00
|
|
|
match = ubsanRegex.match(lineStr);
|
|
|
|
|
if (m_sanitizerOutputMode == SanitizerOutputMode::Ubsan && !match.hasMatch()) {
|
2020-07-27 17:52:59 +02:00
|
|
|
m_sanitizerLines.append(lineStr);
|
2020-07-28 07:35:20 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (match.hasMatch())
|
|
|
|
|
mode = SanitizerOutputMode::Ubsan;
|
|
|
|
|
}
|
|
|
|
|
if (mode != SanitizerOutputMode::None) {
|
|
|
|
|
if (m_sanitizerResult) // we have a result that has not been reported yet
|
|
|
|
|
sendAndResetSanitizerResult();
|
|
|
|
|
|
|
|
|
|
m_sanitizerOutputMode = mode;
|
|
|
|
|
m_sanitizerResult = createDefaultResult();
|
|
|
|
|
m_sanitizerLines.append("Sanitizer Issue");
|
|
|
|
|
m_sanitizerLines.append(lineStr);
|
|
|
|
|
if (m_sanitizerOutputMode == SanitizerOutputMode::Ubsan) {
|
2021-05-26 15:50:03 +02:00
|
|
|
const Utils::FilePath path = constructSourceFilePath(m_buildDir, match.captured(1));
|
2020-07-28 07:35:20 +02:00
|
|
|
// path may be empty if not existing - so, provide at least what we have
|
2021-05-26 15:50:03 +02:00
|
|
|
m_sanitizerResult->setFileName(path.isEmpty()
|
|
|
|
|
? Utils::FilePath::fromString(match.captured(1))
|
|
|
|
|
: path);
|
2020-07-28 07:35:20 +02:00
|
|
|
m_sanitizerResult->setLine(match.captured(2).toInt());
|
2020-07-27 17:52:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestOutputReader::sendAndResetSanitizerResult()
|
|
|
|
|
{
|
2020-07-28 07:35:20 +02:00
|
|
|
QTC_ASSERT(m_sanitizerResult, return);
|
2020-07-27 17:52:59 +02:00
|
|
|
m_sanitizerResult->setDescription(m_sanitizerLines.join('\n'));
|
2020-07-28 07:35:20 +02:00
|
|
|
m_sanitizerResult->setResult(m_sanitizerOutputMode == SanitizerOutputMode::Ubsan
|
|
|
|
|
? ResultType::Fail : ResultType::MessageFatal);
|
2020-07-27 17:52:59 +02:00
|
|
|
|
|
|
|
|
if (m_sanitizerResult->fileName().isEmpty()) {
|
2020-12-11 10:58:37 +01:00
|
|
|
const ITestTreeItem *testItem = m_sanitizerResult->findTestTreeItem();
|
2020-07-27 17:52:59 +02:00
|
|
|
if (testItem && testItem->line()) {
|
|
|
|
|
m_sanitizerResult->setFileName(testItem->filePath());
|
|
|
|
|
m_sanitizerResult->setLine(testItem->line());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 08:32:27 +01:00
|
|
|
m_futureInterface.reportResult(m_sanitizerResult);
|
|
|
|
|
m_hadValidOutput = true;
|
2020-07-27 17:52:59 +02:00
|
|
|
m_sanitizerLines.clear();
|
|
|
|
|
m_sanitizerResult.reset();
|
|
|
|
|
m_sanitizerOutputMode = SanitizerOutputMode::None;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-16 13:44:24 +01:00
|
|
|
} // namespace Autotest
|