2014-10-07 15:51:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-10-07 15:51:02 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-10-07 15:51:02 +02: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
|
2014-10-07 15:51:02 +02: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.
|
2014-10-07 15:51:02 +02: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.
|
2014-10-07 15:51:02 +02:00
|
|
|
**
|
|
|
|
****************************************************************************/
|
2016-01-22 10:37:55 +01:00
|
|
|
|
2015-01-16 13:44:24 +01:00
|
|
|
#include "testrunner.h"
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2014-11-04 12:35:00 +01:00
|
|
|
#include "autotestconstants.h"
|
2014-12-04 14:05:19 +01:00
|
|
|
#include "autotestplugin.h"
|
2014-10-07 15:51:02 +02:00
|
|
|
#include "testresultspane.h"
|
2016-06-15 12:29:24 +02:00
|
|
|
#include "testrunconfiguration.h"
|
2014-12-04 14:05:19 +01:00
|
|
|
#include "testsettings.h"
|
2015-12-09 09:46:33 +01:00
|
|
|
#include "testoutputreader.h"
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2014-11-04 12:35:00 +01:00
|
|
|
#include <coreplugin/progressmanager/futureprogress.h>
|
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
#include <projectexplorer/buildmanager.h>
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
#include <projectexplorer/projectexplorersettings.h>
|
2016-06-15 12:29:24 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2017-04-06 15:42:09 +02:00
|
|
|
#include <utils/outputformat.h>
|
2016-02-15 16:26:11 +01:00
|
|
|
#include <utils/runextensions.h>
|
2017-04-03 09:17:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2014-11-04 12:35:00 +01:00
|
|
|
|
|
|
|
#include <QFuture>
|
|
|
|
#include <QFutureInterface>
|
2014-10-07 15:51:02 +02:00
|
|
|
#include <QTime>
|
|
|
|
|
2016-07-21 16:02:42 +02:00
|
|
|
#include <debugger/debuggerkitinformation.h>
|
2016-06-15 12:29:24 +02:00
|
|
|
#include <debugger/debuggerruncontrol.h>
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
namespace Autotest {
|
|
|
|
namespace Internal {
|
|
|
|
|
2017-02-13 10:05:06 +01:00
|
|
|
static TestRunner *s_instance = nullptr;
|
2014-12-01 16:12:05 +01:00
|
|
|
|
2015-01-16 13:44:24 +01:00
|
|
|
TestRunner *TestRunner::instance()
|
|
|
|
{
|
2017-02-13 10:05:06 +01:00
|
|
|
if (!s_instance)
|
|
|
|
s_instance = new TestRunner;
|
|
|
|
return s_instance;
|
2015-01-16 13:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TestRunner::TestRunner(QObject *parent) :
|
|
|
|
QObject(parent),
|
|
|
|
m_executingTests(false)
|
|
|
|
{
|
2016-02-25 13:02:31 +01:00
|
|
|
connect(&m_futureWatcher, &QFutureWatcher<TestResultPtr>::resultReadyAt,
|
2016-01-19 14:24:09 +01:00
|
|
|
this, [this](int index) { emit testResultReady(m_futureWatcher.resultAt(index)); });
|
2016-02-25 13:02:31 +01:00
|
|
|
connect(&m_futureWatcher, &QFutureWatcher<TestResultPtr>::finished,
|
2016-01-19 14:24:09 +01:00
|
|
|
this, &TestRunner::onFinished);
|
|
|
|
connect(this, &TestRunner::requestStopTestRun,
|
2016-02-25 13:02:31 +01:00
|
|
|
&m_futureWatcher, &QFutureWatcher<TestResultPtr>::cancel);
|
|
|
|
connect(&m_futureWatcher, &QFutureWatcher<TestResultPtr>::canceled,
|
2016-11-04 09:47:15 +01:00
|
|
|
this, [this]() {
|
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(
|
|
|
|
Result::MessageFatal, tr("Test run canceled by user."))));
|
|
|
|
m_executingTests = false; // avoid being stuck if finished() signal won't get emitted
|
2016-01-19 14:24:09 +01:00
|
|
|
});
|
2015-01-16 13:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TestRunner::~TestRunner()
|
|
|
|
{
|
|
|
|
qDeleteAll(m_selectedTests);
|
|
|
|
m_selectedTests.clear();
|
2017-02-13 10:05:06 +01:00
|
|
|
s_instance = nullptr;
|
2015-01-16 13:44:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestRunner::setSelectedTests(const QList<TestConfiguration *> &selected)
|
|
|
|
{
|
|
|
|
qDeleteAll(m_selectedTests);
|
|
|
|
m_selectedTests.clear();
|
|
|
|
m_selectedTests = selected;
|
|
|
|
}
|
|
|
|
|
2017-04-03 09:17:58 +02:00
|
|
|
static QString processInformation(const QProcess &proc)
|
|
|
|
{
|
|
|
|
QString information("\nCommand line: " + proc.program() + ' ' + proc.arguments().join(' '));
|
|
|
|
QStringList important = { "PATH" };
|
|
|
|
if (Utils::HostOsInfo::isLinuxHost())
|
|
|
|
important.append("LD_LIBRARY_PATH");
|
|
|
|
else if (Utils::HostOsInfo::isMacHost())
|
|
|
|
important.append({ "DYLD_LIBRARY_PATH", "DYLD_FRAMEWORK_PATH" });
|
|
|
|
const QProcessEnvironment &environment = proc.processEnvironment();
|
|
|
|
for (const QString &var : important)
|
|
|
|
information.append('\n' + var + ": " + environment.value(var));
|
|
|
|
return information;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString rcInfo(const TestConfiguration * const config)
|
|
|
|
{
|
|
|
|
QString info = '\n' + TestRunner::tr("Run configuration:") + ' ';
|
|
|
|
if (config->isGuessed())
|
|
|
|
info += TestRunner::tr("guessed from");
|
|
|
|
return info + " \"" + config->runConfigDisplayName() + '"';
|
|
|
|
}
|
|
|
|
|
2016-02-25 13:02:31 +01:00
|
|
|
static void performTestRun(QFutureInterface<TestResultPtr> &futureInterface,
|
2016-02-23 17:40:10 +01:00
|
|
|
const QList<TestConfiguration *> selectedTests,
|
|
|
|
const TestSettings &settings)
|
2014-11-04 12:35:00 +01:00
|
|
|
{
|
2016-02-23 17:40:10 +01:00
|
|
|
const int timeout = settings.timeout;
|
2017-03-14 09:16:01 +01:00
|
|
|
const bool omitRunConfigWarnings = settings.omitRunConfigWarn;
|
2016-01-19 12:02:07 +01:00
|
|
|
QEventLoop eventLoop;
|
2014-11-04 12:35:00 +01:00
|
|
|
int testCaseCount = 0;
|
2017-02-13 10:05:06 +01:00
|
|
|
for (TestConfiguration *config : selectedTests) {
|
2016-06-15 12:29:24 +02:00
|
|
|
config->completeTestInformation(TestRunner::Run);
|
2015-04-27 16:11:28 +02:00
|
|
|
if (config->project()) {
|
|
|
|
testCaseCount += config->testCaseCount();
|
2017-04-03 09:17:58 +02:00
|
|
|
if (!omitRunConfigWarnings && config->isGuessed()) {
|
|
|
|
QString message = TestRunner::tr(
|
|
|
|
"Project's run configuration was guessed for \"%1\".\n"
|
|
|
|
"This might cause trouble during execution.\n"
|
|
|
|
"(guessed from \"%2\")");
|
|
|
|
message = message.arg(config->displayName()).arg(config->runConfigDisplayName());
|
|
|
|
futureInterface.reportResult(
|
|
|
|
TestResultPtr(new FaultyTestResult(Result::MessageWarn, message)));
|
2017-03-14 09:16:01 +01:00
|
|
|
}
|
2015-04-27 16:11:28 +02:00
|
|
|
} else {
|
2016-02-25 13:02:31 +01:00
|
|
|
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
|
2016-04-26 15:01:35 +09:00
|
|
|
TestRunner::tr("Project is null for \"%1\". Removing from test run.\n"
|
2016-02-25 13:02:31 +01:00
|
|
|
"Check the test environment.").arg(config->displayName()))));
|
2015-04-27 16:11:28 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-04 12:35:00 +01:00
|
|
|
|
2015-01-13 11:24:41 +01:00
|
|
|
QProcess testProcess;
|
|
|
|
testProcess.setReadChannel(QProcess::StandardOutput);
|
2014-11-04 12:35:00 +01:00
|
|
|
|
2015-01-16 13:44:24 +01:00
|
|
|
futureInterface.setProgressRange(0, testCaseCount);
|
|
|
|
futureInterface.setProgressValue(0);
|
2014-11-04 12:35:00 +01:00
|
|
|
|
2017-02-13 10:05:06 +01:00
|
|
|
for (const TestConfiguration *testConfiguration : selectedTests) {
|
2016-01-20 08:26:10 +01:00
|
|
|
QScopedPointer<TestOutputReader> outputReader;
|
2016-04-29 10:13:35 +02:00
|
|
|
outputReader.reset(testConfiguration->outputReader(futureInterface, &testProcess));
|
|
|
|
QTC_ASSERT(outputReader, continue);
|
2017-05-05 13:01:06 +02:00
|
|
|
TestRunner::connect(outputReader.data(), &TestOutputReader::newOutputAvailable,
|
|
|
|
TestResultsPane::instance(), &TestResultsPane::addOutput);
|
2015-01-16 13:44:24 +01:00
|
|
|
if (futureInterface.isCanceled())
|
2014-11-04 12:35:00 +01:00
|
|
|
break;
|
2015-01-13 11:20:51 +01:00
|
|
|
|
2015-04-27 16:11:28 +02:00
|
|
|
if (!testConfiguration->project())
|
|
|
|
continue;
|
|
|
|
|
2015-01-16 11:53:33 +01:00
|
|
|
QProcessEnvironment environment = testConfiguration->environment().toProcessEnvironment();
|
2016-08-05 15:02:37 +02:00
|
|
|
QString commandFilePath = testConfiguration->executableFilePath();
|
2015-01-16 11:53:33 +01:00
|
|
|
if (commandFilePath.isEmpty()) {
|
2016-02-25 13:02:31 +01:00
|
|
|
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
2017-03-29 09:29:20 +02:00
|
|
|
TestRunner::tr("Executable path is empty. (%1)")
|
2016-02-25 13:02:31 +01:00
|
|
|
.arg(testConfiguration->displayName()))));
|
2015-01-13 11:20:51 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-10-05 12:39:23 +02:00
|
|
|
testProcess.setArguments(testConfiguration->argumentsForTestRunner());
|
2015-01-16 11:53:33 +01:00
|
|
|
testProcess.setWorkingDirectory(testConfiguration->workingDirectory());
|
2015-01-27 13:29:53 +01:00
|
|
|
if (Utils::HostOsInfo::isWindowsHost())
|
2016-09-29 12:15:43 +02:00
|
|
|
environment.insert("QT_LOGGING_TO_CONSOLE", "1");
|
2015-01-16 11:53:33 +01:00
|
|
|
testProcess.setProcessEnvironment(environment);
|
|
|
|
testProcess.setProgram(commandFilePath);
|
|
|
|
testProcess.start();
|
2015-01-13 11:20:51 +01:00
|
|
|
|
2015-01-13 11:24:41 +01:00
|
|
|
bool ok = testProcess.waitForStarted();
|
2015-01-16 11:53:33 +01:00
|
|
|
QTime executionTimer;
|
2015-01-13 11:20:51 +01:00
|
|
|
executionTimer.start();
|
2016-01-19 13:31:55 +01:00
|
|
|
bool canceledByTimeout = false;
|
2015-01-13 11:20:51 +01:00
|
|
|
if (ok) {
|
2016-01-19 13:31:55 +01:00
|
|
|
while (testProcess.state() == QProcess::Running) {
|
|
|
|
if (executionTimer.elapsed() >= timeout) {
|
|
|
|
canceledByTimeout = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-16 13:44:24 +01:00
|
|
|
if (futureInterface.isCanceled()) {
|
2015-01-13 11:24:41 +01:00
|
|
|
testProcess.kill();
|
|
|
|
testProcess.waitForFinished();
|
2016-01-19 14:24:09 +01:00
|
|
|
return;
|
2015-01-13 11:20:51 +01:00
|
|
|
}
|
2016-01-19 12:02:07 +01:00
|
|
|
eventLoop.processEvents();
|
2015-01-13 11:20:51 +01:00
|
|
|
}
|
2016-06-17 12:56:57 +02:00
|
|
|
} else {
|
|
|
|
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
2017-04-03 09:17:58 +02:00
|
|
|
TestRunner::tr("Failed to start test for project \"%1\".")
|
|
|
|
.arg(testConfiguration->displayName()) + processInformation(testProcess)
|
|
|
|
+ rcInfo(testConfiguration))));
|
2015-01-13 11:20:51 +01:00
|
|
|
}
|
2016-04-14 17:34:00 +02:00
|
|
|
if (testProcess.exitStatus() == QProcess::CrashExit) {
|
|
|
|
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
2017-04-03 09:17:58 +02:00
|
|
|
TestRunner::tr("Test for project \"%1\" crashed.")
|
|
|
|
.arg(testConfiguration->displayName()) + processInformation(testProcess)
|
|
|
|
+ rcInfo(testConfiguration))));
|
2016-04-14 17:34:00 +02:00
|
|
|
}
|
2015-01-13 11:20:51 +01:00
|
|
|
|
2016-01-19 13:31:55 +01:00
|
|
|
if (canceledByTimeout) {
|
2015-01-13 11:24:41 +01:00
|
|
|
if (testProcess.state() != QProcess::NotRunning) {
|
|
|
|
testProcess.kill();
|
|
|
|
testProcess.waitForFinished();
|
2015-01-13 11:20:51 +01:00
|
|
|
}
|
2016-02-25 13:02:31 +01:00
|
|
|
futureInterface.reportResult(TestResultPtr(
|
2016-04-26 15:01:35 +09:00
|
|
|
new FaultyTestResult(Result::MessageFatal, TestRunner::tr(
|
2016-08-25 16:34:22 +02:00
|
|
|
"Test case canceled due to timeout.\nMaybe raise the timeout?"))));
|
2015-01-13 11:20:51 +01:00
|
|
|
}
|
2014-11-04 12:35:00 +01:00
|
|
|
}
|
2015-01-16 13:44:24 +01:00
|
|
|
futureInterface.setProgressValue(testCaseCount);
|
2014-11-04 12:35:00 +01:00
|
|
|
}
|
|
|
|
|
2016-06-15 12:29:24 +02:00
|
|
|
void TestRunner::prepareToRunTests(Mode mode)
|
2014-11-04 12:35:00 +01:00
|
|
|
{
|
2016-06-15 12:29:24 +02:00
|
|
|
m_runMode = mode;
|
2016-01-20 09:38:26 +01:00
|
|
|
ProjectExplorer::Internal::ProjectExplorerSettings projectExplorerSettings =
|
|
|
|
ProjectExplorer::ProjectExplorerPlugin::projectExplorerSettings();
|
|
|
|
if (projectExplorerSettings.buildBeforeDeploy && !projectExplorerSettings.saveBeforeBuild) {
|
|
|
|
if (!ProjectExplorer::ProjectExplorerPlugin::saveModifiedFiles())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-15 09:30:28 +02:00
|
|
|
m_executingTests = true;
|
|
|
|
emit testRunStarted();
|
|
|
|
|
2014-11-04 13:42:38 +01:00
|
|
|
// clear old log and output pane
|
|
|
|
TestResultsPane::instance()->clearContents();
|
|
|
|
|
2014-11-04 12:35:00 +01:00
|
|
|
if (m_selectedTests.empty()) {
|
2016-02-25 13:02:31 +01:00
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
|
|
|
|
tr("No tests selected. Canceling test run."))));
|
2015-04-15 09:30:28 +02:00
|
|
|
onFinished();
|
2014-11-04 12:35:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::Project *project = m_selectedTests.at(0)->project();
|
2014-11-13 12:31:58 +01:00
|
|
|
if (!project) {
|
2016-02-25 13:02:31 +01:00
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
|
2015-03-30 13:56:50 +02:00
|
|
|
tr("Project is null. Canceling test run.\n"
|
|
|
|
"Only desktop kits are supported. Make sure the "
|
2016-02-25 13:02:31 +01:00
|
|
|
"currently active kit is a desktop kit."))));
|
2015-04-15 09:30:28 +02:00
|
|
|
onFinished();
|
2014-11-04 12:35:00 +01:00
|
|
|
return;
|
2014-11-13 12:31:58 +01:00
|
|
|
}
|
2014-11-04 12:35:00 +01:00
|
|
|
|
2016-06-27 11:07:16 +02:00
|
|
|
if (!projectExplorerSettings.buildBeforeDeploy || mode == TestRunner::DebugWithoutDeploy
|
|
|
|
|| mode == TestRunner::RunWithoutDeploy) {
|
2016-06-15 12:29:24 +02:00
|
|
|
runOrDebugTests();
|
2016-11-04 09:47:15 +01:00
|
|
|
} else if (project->hasActiveBuildSettings()) {
|
|
|
|
buildProject(project);
|
2015-06-29 09:22:58 +02:00
|
|
|
} else {
|
2016-11-04 09:47:15 +01:00
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
|
|
|
tr("Project is not configured. Canceling test run."))));
|
|
|
|
onFinished();
|
2014-11-04 12:35:00 +01:00
|
|
|
}
|
2015-06-29 09:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestRunner::runTests()
|
|
|
|
{
|
2016-02-25 13:02:31 +01:00
|
|
|
QFuture<TestResultPtr> future = Utils::runAsync(&performTestRun, m_selectedTests,
|
|
|
|
*AutotestPlugin::instance()->settings());
|
2016-01-19 14:24:09 +01:00
|
|
|
m_futureWatcher.setFuture(future);
|
|
|
|
Core::ProgressManager::addTask(future, tr("Running Tests"), Autotest::Constants::TASK_INDEX);
|
2014-11-04 12:35:00 +01:00
|
|
|
}
|
|
|
|
|
2016-07-21 16:02:42 +02:00
|
|
|
static void processOutput(TestOutputReader *outputreader, const QString &msg,
|
2017-04-06 15:42:09 +02:00
|
|
|
Utils::OutputFormat format)
|
2016-07-21 16:02:42 +02:00
|
|
|
{
|
2017-04-06 15:42:09 +02:00
|
|
|
switch (format) {
|
|
|
|
case Utils::OutputFormat::StdOutFormatSameLine:
|
|
|
|
case Utils::OutputFormat::DebugFormat: {
|
2016-07-21 16:02:42 +02:00
|
|
|
static const QString gdbSpecialOut = "Qt: gdb: -nograb added to command-line options.\n"
|
|
|
|
"\t Use the -dograb option to enforce grabbing.";
|
|
|
|
int start = msg.startsWith(gdbSpecialOut) ? gdbSpecialOut.length() + 1 : 0;
|
|
|
|
if (start) {
|
|
|
|
int maxIndex = msg.length() - 1;
|
|
|
|
while (start < maxIndex && msg.at(start + 1) == '\n')
|
|
|
|
++start;
|
|
|
|
if (start >= msg.length()) // we cut out the whole message
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (const QString &line : msg.mid(start).split('\n'))
|
|
|
|
outputreader->processOutput(line.toUtf8() + '\n');
|
|
|
|
break;
|
|
|
|
}
|
2017-04-06 15:42:09 +02:00
|
|
|
case Utils::OutputFormat::StdErrFormatSameLine:
|
2016-07-21 16:02:42 +02:00
|
|
|
outputreader->processStdError(msg.toUtf8());
|
|
|
|
break;
|
|
|
|
default:
|
2017-04-06 15:42:09 +02:00
|
|
|
break; // channels we're not caring about
|
2016-07-21 16:02:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 12:29:24 +02:00
|
|
|
void TestRunner::debugTests()
|
|
|
|
{
|
|
|
|
// TODO improve to support more than one test configuration
|
|
|
|
QTC_ASSERT(m_selectedTests.size() == 1, onFinished();return);
|
|
|
|
|
|
|
|
TestConfiguration *config = m_selectedTests.first();
|
|
|
|
config->completeTestInformation(Debug);
|
|
|
|
if (!config->runConfiguration()) {
|
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
|
|
|
TestRunner::tr("Failed to get run configuration."))));
|
|
|
|
onFinished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-05 15:02:37 +02:00
|
|
|
const QString &commandFilePath = config->executableFilePath();
|
2016-06-15 12:29:24 +02:00
|
|
|
if (commandFilePath.isEmpty()) {
|
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
|
|
|
TestRunner::tr("Could not find command \"%1\". (%2)")
|
2017-02-21 14:53:58 +01:00
|
|
|
.arg(config->executableFilePath())
|
2016-06-15 12:29:24 +02:00
|
|
|
.arg(config->displayName()))));
|
|
|
|
onFinished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString errorMessage;
|
2017-04-27 09:53:07 +02:00
|
|
|
auto runControl = new ProjectExplorer::RunControl(config->runConfiguration(),
|
|
|
|
ProjectExplorer::Constants::DEBUG_RUN_MODE);
|
2016-06-15 12:29:24 +02:00
|
|
|
if (!runControl) {
|
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
|
|
|
TestRunner::tr("Failed to create run configuration.\n%1").arg(errorMessage))));
|
|
|
|
onFinished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:04:25 +02:00
|
|
|
ProjectExplorer::StandardRunnable inferior;
|
|
|
|
inferior.executable = commandFilePath;
|
|
|
|
inferior.commandLineArguments = config->argumentsForTestRunner().join(' ');
|
|
|
|
inferior.environment = config->environment();
|
|
|
|
inferior.workingDirectory = config->workingDirectory();
|
|
|
|
|
|
|
|
auto debugger = new Debugger::DebuggerRunTool(runControl);
|
|
|
|
debugger->setInferior(inferior);
|
|
|
|
debugger->setRunControlName(config->displayName());
|
2017-05-26 17:40:30 +02:00
|
|
|
|
2016-07-21 16:02:42 +02:00
|
|
|
bool useOutputProcessor = true;
|
|
|
|
if (ProjectExplorer::Target *targ = config->project()->activeTarget()) {
|
|
|
|
if (Debugger::DebuggerKitInformation::engineType(targ->kit()) == Debugger::CdbEngineType) {
|
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
|
|
|
|
TestRunner::tr("Unable to display test results when using CDB."))));
|
|
|
|
useOutputProcessor = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need a fake QFuture for the results. TODO: replace with QtConcurrent::run
|
|
|
|
QFutureInterface<TestResultPtr> *futureInterface
|
|
|
|
= new QFutureInterface<TestResultPtr>(QFutureInterfaceBase::Running);
|
|
|
|
QFuture<TestResultPtr> future(futureInterface);
|
|
|
|
m_futureWatcher.setFuture(future);
|
|
|
|
|
|
|
|
if (useOutputProcessor) {
|
|
|
|
TestOutputReader *outputreader = config->outputReader(*futureInterface, 0);
|
2017-05-05 13:01:06 +02:00
|
|
|
connect(outputreader, &TestOutputReader::newOutputAvailable,
|
|
|
|
TestResultsPane::instance(), &TestResultsPane::addOutput);
|
2017-04-27 09:53:07 +02:00
|
|
|
connect(runControl, &ProjectExplorer::RunControl::appendMessageRequested,
|
2017-09-07 17:05:47 +02:00
|
|
|
this, [outputreader]
|
2017-04-06 15:42:09 +02:00
|
|
|
(ProjectExplorer::RunControl *, const QString &msg, Utils::OutputFormat format) {
|
|
|
|
processOutput(outputreader, msg, format);
|
|
|
|
});
|
|
|
|
|
2017-07-11 17:25:33 +02:00
|
|
|
connect(runControl, &ProjectExplorer::RunControl::stopped,
|
2016-07-21 16:02:42 +02:00
|
|
|
outputreader, &QObject::deleteLater);
|
|
|
|
}
|
|
|
|
|
2017-06-26 18:40:11 +02:00
|
|
|
connect(this, &TestRunner::requestStopTestRun, runControl,
|
|
|
|
&ProjectExplorer::RunControl::initiateStop);
|
2017-07-11 17:25:33 +02:00
|
|
|
connect(runControl, &ProjectExplorer::RunControl::stopped, this, &TestRunner::onFinished);
|
2017-04-11 14:36:03 +02:00
|
|
|
ProjectExplorer::ProjectExplorerPlugin::startRunControl(runControl);
|
2016-06-15 12:29:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestRunner::runOrDebugTests()
|
|
|
|
{
|
|
|
|
switch (m_runMode) {
|
|
|
|
case Run:
|
2016-06-27 11:07:16 +02:00
|
|
|
case RunWithoutDeploy:
|
2016-06-15 12:29:24 +02:00
|
|
|
runTests();
|
|
|
|
break;
|
|
|
|
case Debug:
|
2016-06-27 11:07:16 +02:00
|
|
|
case DebugWithoutDeploy:
|
2016-06-15 12:29:24 +02:00
|
|
|
debugTests();
|
|
|
|
break;
|
|
|
|
default:
|
2016-11-04 09:47:15 +01:00
|
|
|
onFinished();
|
2016-06-15 12:29:24 +02:00
|
|
|
QTC_ASSERT(false, return); // unexpected run mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-04 12:35:00 +01:00
|
|
|
void TestRunner::buildProject(ProjectExplorer::Project *project)
|
|
|
|
{
|
2015-04-15 09:30:28 +02:00
|
|
|
ProjectExplorer::BuildManager *buildManager = ProjectExplorer::BuildManager::instance();
|
2015-06-29 09:22:58 +02:00
|
|
|
m_buildConnect = connect(this, &TestRunner::requestStopTestRun,
|
|
|
|
buildManager, &ProjectExplorer::BuildManager::cancel);
|
2015-01-13 11:26:13 +01:00
|
|
|
connect(buildManager, &ProjectExplorer::BuildManager::buildQueueFinished,
|
2014-11-04 12:35:00 +01:00
|
|
|
this, &TestRunner::buildFinished);
|
2015-01-08 12:52:17 +01:00
|
|
|
ProjectExplorer::ProjectExplorerPlugin::buildProject(project);
|
2016-11-04 09:47:15 +01:00
|
|
|
if (!buildManager->isBuilding())
|
|
|
|
buildFinished(false);
|
2014-11-04 12:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestRunner::buildFinished(bool success)
|
|
|
|
{
|
2015-06-29 09:22:58 +02:00
|
|
|
disconnect(m_buildConnect);
|
2015-04-15 09:30:28 +02:00
|
|
|
ProjectExplorer::BuildManager *buildManager = ProjectExplorer::BuildManager::instance();
|
2015-01-13 11:26:13 +01:00
|
|
|
disconnect(buildManager, &ProjectExplorer::BuildManager::buildQueueFinished,
|
2014-11-04 12:35:00 +01:00
|
|
|
this, &TestRunner::buildFinished);
|
2015-06-29 09:22:58 +02:00
|
|
|
|
|
|
|
if (success) {
|
2016-06-15 12:29:24 +02:00
|
|
|
runOrDebugTests();
|
2015-06-29 09:22:58 +02:00
|
|
|
} else {
|
2016-02-25 13:02:31 +01:00
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
|
|
|
tr("Build failed. Canceling test run."))));
|
2015-06-29 09:22:58 +02:00
|
|
|
onFinished();
|
|
|
|
}
|
2014-11-04 12:35:00 +01:00
|
|
|
}
|
|
|
|
|
2014-11-06 10:48:17 +01:00
|
|
|
void TestRunner::onFinished()
|
|
|
|
{
|
|
|
|
m_executingTests = false;
|
|
|
|
emit testRunFinished();
|
|
|
|
}
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
} // namespace Internal
|
|
|
|
} // namespace Autotest
|