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"
|
2017-09-09 16:46:43 +02:00
|
|
|
#include "testtreeitem.h"
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2017-09-13 14:27:20 +02:00
|
|
|
#include <coreplugin/icore.h>
|
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>
|
2017-09-13 14:27:20 +02:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
|
|
|
#include <projectexplorer/session.h>
|
2016-06-15 12:29:24 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2018-02-28 10:50:38 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2017-04-06 15:42:09 +02:00
|
|
|
#include <utils/outputformat.h>
|
2018-02-28 10:50:38 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2016-02-15 16:26:11 +01:00
|
|
|
#include <utils/runextensions.h>
|
2014-11-04 12:35:00 +01:00
|
|
|
|
2017-09-13 14:27:20 +02:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QFormLayout>
|
2014-11-04 12:35:00 +01:00
|
|
|
#include <QFuture>
|
|
|
|
#include <QFutureInterface>
|
2017-09-13 14:27:20 +02:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
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>
|
|
|
|
|
2017-09-13 14:27:20 +02:00
|
|
|
#include <utils/algorithm.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-09-09 16:46:43 +02:00
|
|
|
void TestRunner::runTest(TestRunMode mode, const TestTreeItem *item)
|
|
|
|
{
|
2018-02-16 17:57:37 +01:00
|
|
|
TestConfiguration *configuration = item->asConfiguration(mode);
|
2017-09-09 16:46:43 +02:00
|
|
|
|
|
|
|
if (configuration) {
|
|
|
|
setSelectedTests({configuration});
|
|
|
|
prepareToRunTests(mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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() + '"';
|
|
|
|
}
|
|
|
|
|
2017-09-01 14:59:39 +02:00
|
|
|
static QString constructOmittedDetailsString(const QStringList &omitted)
|
|
|
|
{
|
2018-05-16 11:11:34 +02:00
|
|
|
return TestRunner::tr("Omitted the following arguments specified on the run "
|
|
|
|
"configuration page for \"%1\":") + '\n' + omitted.join('\n');
|
2017-09-01 14:59:39 +02:00
|
|
|
}
|
|
|
|
|
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,
|
2018-05-17 08:34:03 +02:00
|
|
|
const TestSettings &settings, int testCaseCount)
|
2014-11-04 12:35:00 +01:00
|
|
|
{
|
2016-02-23 17:40:10 +01:00
|
|
|
const int timeout = settings.timeout;
|
2016-01-19 12:02:07 +01:00
|
|
|
QEventLoop eventLoop;
|
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) {
|
2017-12-14 06:46:26 +01:00
|
|
|
QString commandFilePath = testConfiguration->executableFilePath();
|
|
|
|
if (commandFilePath.isEmpty()) {
|
|
|
|
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
|
|
|
TestRunner::tr("Executable path is empty. (%1)")
|
|
|
|
.arg(testConfiguration->displayName()))));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
testProcess.setProgram(commandFilePath);
|
|
|
|
|
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;
|
|
|
|
|
2017-09-01 14:59:39 +02:00
|
|
|
QStringList omitted;
|
|
|
|
testProcess.setArguments(testConfiguration->argumentsForTestRunner(&omitted));
|
|
|
|
if (!omitted.isEmpty()) {
|
|
|
|
const QString &details = constructOmittedDetailsString(omitted);
|
|
|
|
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
|
|
|
|
details.arg(testConfiguration->displayName()))));
|
|
|
|
}
|
2015-01-16 11:53:33 +01:00
|
|
|
testProcess.setWorkingDirectory(testConfiguration->workingDirectory());
|
2017-12-14 06:46:26 +01:00
|
|
|
QProcessEnvironment environment = testConfiguration->environment().toProcessEnvironment();
|
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.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) {
|
2018-01-16 08:41:53 +01:00
|
|
|
outputReader->reportCrash();
|
2016-04-14 17:34:00 +02:00
|
|
|
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
2017-04-03 09:17:58 +02:00
|
|
|
TestRunner::tr("Test for project \"%1\" crashed.")
|
2017-09-20 11:20:25 +02:00
|
|
|
.arg(testConfiguration->displayName()) + processInformation(testProcess)
|
|
|
|
+ rcInfo(testConfiguration))));
|
|
|
|
} else if (!outputReader->hadValidOutput()) {
|
|
|
|
futureInterface.reportResult(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
|
|
|
|
TestRunner::tr("Test for project \"%1\" did not produce any expected output.")
|
2017-04-03 09:17:58 +02:00
|
|
|
.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
|
|
|
}
|
|
|
|
|
2017-09-05 13:57:22 +02:00
|
|
|
void TestRunner::prepareToRunTests(TestRunMode 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
|
|
|
|
2017-09-05 13:57:22 +02:00
|
|
|
if (!projectExplorerSettings.buildBeforeDeploy || mode == TestRunMode::DebugWithoutDeploy
|
|
|
|
|| mode == TestRunMode::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
|
|
|
}
|
|
|
|
|
2017-09-13 14:27:20 +02:00
|
|
|
static QString firstTestCaseTarget(const TestConfiguration *config)
|
|
|
|
{
|
2017-11-09 10:06:53 +01:00
|
|
|
for (const QString &internalTarget : config->internalTargets()) {
|
|
|
|
const QString buildTarget = internalTarget.split('|').first();
|
|
|
|
if (!buildTarget.isEmpty())
|
|
|
|
return buildTarget;
|
|
|
|
}
|
|
|
|
return QString();
|
2017-09-13 14:27:20 +02:00
|
|
|
}
|
|
|
|
|
2017-11-09 08:38:07 +01:00
|
|
|
static ProjectExplorer::RunConfiguration *getRunConfiguration(const QString &dialogDetail)
|
2017-09-13 14:27:20 +02:00
|
|
|
{
|
|
|
|
using namespace ProjectExplorer;
|
2017-11-09 08:38:07 +01:00
|
|
|
const Project *project = SessionManager::startupProject();
|
|
|
|
if (!project)
|
|
|
|
return nullptr;
|
|
|
|
const Target *target = project->activeTarget();
|
|
|
|
if (!target)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
RunConfiguration *runConfig = nullptr;
|
|
|
|
const QList<RunConfiguration *> runConfigurations
|
|
|
|
= Utils::filtered(target->runConfigurations(), [] (const RunConfiguration *rc) {
|
|
|
|
if (!rc->runnable().is<StandardRunnable>())
|
|
|
|
return false;
|
|
|
|
return !rc->runnable().as<StandardRunnable>().executable.isEmpty();
|
|
|
|
});
|
|
|
|
if (runConfigurations.size() == 1)
|
|
|
|
return runConfigurations.first();
|
|
|
|
|
|
|
|
RunConfigurationSelectionDialog dialog(dialogDetail, Core::ICore::dialogParent());
|
2017-09-13 14:27:20 +02:00
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
|
|
const QString dName = dialog.displayName();
|
|
|
|
if (dName.isEmpty())
|
2017-11-09 08:38:07 +01:00
|
|
|
return nullptr;
|
2017-09-13 14:27:20 +02:00
|
|
|
// run configuration has been selected - fill config based on this one..
|
|
|
|
const QString exe = dialog.executable();
|
2017-11-09 08:38:07 +01:00
|
|
|
runConfig = Utils::findOr(runConfigurations, nullptr, [&dName, &exe] (const RunConfiguration *rc) {
|
|
|
|
if (rc->displayName() != dName)
|
|
|
|
return false;
|
|
|
|
return rc->runnable().as<StandardRunnable>().executable == exe;
|
|
|
|
});
|
2017-09-13 14:27:20 +02:00
|
|
|
}
|
2017-11-09 08:38:07 +01:00
|
|
|
return runConfig;
|
2017-09-13 14:27:20 +02:00
|
|
|
}
|
|
|
|
|
2018-05-17 08:34:03 +02:00
|
|
|
int TestRunner::precheckTestConfigurations()
|
|
|
|
{
|
|
|
|
const bool omitWarnings = AutotestPlugin::settings()->omitRunConfigWarn;
|
|
|
|
int testCaseCount = 0;
|
|
|
|
for (TestConfiguration *config : m_selectedTests) {
|
|
|
|
config->completeTestInformation(TestRunMode::Run);
|
|
|
|
if (config->project()) {
|
|
|
|
testCaseCount += config->testCaseCount();
|
|
|
|
if (!omitWarnings && config->isGuessed()) {
|
|
|
|
QString message = 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());
|
|
|
|
emit testResultReady(
|
|
|
|
TestResultPtr(new FaultyTestResult(Result::MessageWarn, message)));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
|
|
|
|
tr("Project is null for \"%1\". Removing from test run.\n"
|
|
|
|
"Check the test environment.").arg(config->displayName()))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return testCaseCount;
|
|
|
|
}
|
|
|
|
|
2015-06-29 09:22:58 +02:00
|
|
|
void TestRunner::runTests()
|
|
|
|
{
|
2017-09-28 13:46:22 +02:00
|
|
|
QList<TestConfiguration *> toBeRemoved;
|
2017-09-13 14:27:20 +02:00
|
|
|
for (TestConfiguration *config : m_selectedTests) {
|
|
|
|
config->completeTestInformation(TestRunMode::Run);
|
2017-11-09 08:38:07 +01:00
|
|
|
if (!config->hasExecutable()) {
|
|
|
|
if (auto rc = getRunConfiguration(firstTestCaseTarget(config)))
|
|
|
|
config->setOriginalRunConfiguration(rc);
|
|
|
|
else
|
2017-09-28 13:46:22 +02:00
|
|
|
toBeRemoved.append(config);
|
2017-11-09 08:38:07 +01:00
|
|
|
}
|
2017-09-13 14:27:20 +02:00
|
|
|
}
|
2017-09-28 13:46:22 +02:00
|
|
|
for (TestConfiguration *config : toBeRemoved)
|
|
|
|
m_selectedTests.removeOne(config);
|
|
|
|
qDeleteAll(toBeRemoved);
|
|
|
|
toBeRemoved.clear();
|
|
|
|
if (m_selectedTests.isEmpty()) {
|
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
|
|
|
|
tr("No test cases left for execution. Canceling test run."))));
|
|
|
|
onFinished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-17 08:34:03 +02:00
|
|
|
int testCaseCount = precheckTestConfigurations();
|
|
|
|
|
2016-02-25 13:02:31 +01:00
|
|
|
QFuture<TestResultPtr> future = Utils::runAsync(&performTestRun, m_selectedTests,
|
2018-05-17 08:34:03 +02:00
|
|
|
*AutotestPlugin::settings(), testCaseCount);
|
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'))
|
2017-09-09 23:33:02 +02:00
|
|
|
outputreader->processOutput(line.toUtf8());
|
2016-07-21 16:02:42 +02:00
|
|
|
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();
|
2017-09-05 13:57:22 +02:00
|
|
|
config->completeTestInformation(TestRunMode::Debug);
|
2017-09-13 14:27:20 +02:00
|
|
|
if (!config->hasExecutable()) {
|
2017-11-09 08:38:07 +01:00
|
|
|
if (auto *rc = getRunConfiguration(firstTestCaseTarget(config)))
|
|
|
|
config->completeTestInformation(rc, TestRunMode::Debug);
|
2017-09-13 14:27:20 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 12:29:24 +02:00
|
|
|
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-09-01 14:59:39 +02:00
|
|
|
QStringList omitted;
|
|
|
|
ProjectExplorer::StandardRunnable inferior = config->runnable();
|
2017-08-24 16:04:25 +02:00
|
|
|
inferior.executable = commandFilePath;
|
2018-02-28 10:50:38 +01:00
|
|
|
|
|
|
|
const QStringList args = config->argumentsForTestRunner(&omitted);
|
|
|
|
inferior.commandLineArguments = Utils::QtcProcess::joinArgs(args);
|
2017-09-01 14:59:39 +02:00
|
|
|
if (!omitted.isEmpty()) {
|
|
|
|
const QString &details = constructOmittedDetailsString(omitted);
|
|
|
|
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageWarn,
|
|
|
|
details.arg(config->displayName()))));
|
|
|
|
}
|
2017-08-24 16:04:25 +02:00
|
|
|
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);
|
2018-05-14 14:32:59 +02:00
|
|
|
outputreader->setId(inferior.executable);
|
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) {
|
2017-09-05 13:57:22 +02:00
|
|
|
case TestRunMode::Run:
|
|
|
|
case TestRunMode::RunWithoutDeploy:
|
2016-06-15 12:29:24 +02:00
|
|
|
runTests();
|
|
|
|
break;
|
2017-09-05 13:57:22 +02:00
|
|
|
case TestRunMode::Debug:
|
|
|
|
case TestRunMode::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();
|
|
|
|
}
|
|
|
|
|
2017-09-13 14:27:20 +02:00
|
|
|
/*************************************************************************************************/
|
|
|
|
|
|
|
|
RunConfigurationSelectionDialog::RunConfigurationSelectionDialog(const QString &testsInfo,
|
|
|
|
QWidget *parent)
|
|
|
|
: QDialog(parent)
|
|
|
|
{
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
setWindowTitle(tr("Select Run Configuration"));
|
|
|
|
|
2017-11-09 10:06:53 +01:00
|
|
|
QString details = tr("Could not determine which run configuration to choose for running tests");
|
|
|
|
if (!testsInfo.isEmpty())
|
|
|
|
details.append(QString(" (%1)").arg(testsInfo));
|
|
|
|
m_details = new QLabel(details, this);
|
2017-09-13 14:27:20 +02:00
|
|
|
m_rcCombo = new QComboBox(this);
|
|
|
|
m_executable = new QLabel(this);
|
|
|
|
m_arguments = new QLabel(this);
|
|
|
|
m_workingDir = new QLabel(this);
|
|
|
|
m_buttonBox = new QDialogButtonBox(this);
|
|
|
|
m_buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
|
|
|
m_buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
|
|
|
|
|
|
|
auto line = new QFrame(this);
|
|
|
|
line->setFrameShape(QFrame::HLine);
|
|
|
|
line->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
|
|
|
auto formLayout = new QFormLayout;
|
|
|
|
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
|
|
|
formLayout->addRow(m_details);
|
|
|
|
formLayout->addRow(tr("Run Configuration:"), m_rcCombo);
|
|
|
|
formLayout->addRow(line);
|
|
|
|
formLayout->addRow(tr("Executable:"), m_executable);
|
|
|
|
formLayout->addRow(tr("Arguments:"), m_arguments);
|
|
|
|
formLayout->addRow(tr("Working Directory:"), m_workingDir);
|
|
|
|
// TODO Device support
|
|
|
|
auto vboxLayout = new QVBoxLayout(this);
|
|
|
|
vboxLayout->addLayout(formLayout);
|
|
|
|
vboxLayout->addStretch();
|
|
|
|
vboxLayout->addWidget(line);
|
|
|
|
vboxLayout->addWidget(m_buttonBox);
|
|
|
|
|
|
|
|
connect(m_rcCombo, &QComboBox::currentTextChanged,
|
|
|
|
this, &RunConfigurationSelectionDialog::updateLabels);
|
|
|
|
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
|
|
|
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
|
|
|
|
populate();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RunConfigurationSelectionDialog::displayName() const
|
|
|
|
{
|
|
|
|
return m_rcCombo ? m_rcCombo->currentText() : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RunConfigurationSelectionDialog::executable() const
|
|
|
|
{
|
|
|
|
return m_executable ? m_executable->text() : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunConfigurationSelectionDialog::populate()
|
|
|
|
{
|
|
|
|
m_rcCombo->addItem(QString(), QStringList({QString(), QString(), QString()})); // empty default
|
|
|
|
|
|
|
|
if (auto project = ProjectExplorer::SessionManager::startupProject()) {
|
|
|
|
if (auto target = project->activeTarget()) {
|
|
|
|
for (ProjectExplorer::RunConfiguration *rc : target->runConfigurations()) {
|
|
|
|
if (rc->runnable().is<ProjectExplorer::StandardRunnable>()) {
|
|
|
|
auto runnable = rc->runnable().as<ProjectExplorer::StandardRunnable>();
|
|
|
|
const QStringList rcDetails = { runnable.executable,
|
|
|
|
runnable.commandLineArguments,
|
|
|
|
runnable.workingDirectory };
|
|
|
|
m_rcCombo->addItem(rc->displayName(), rcDetails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunConfigurationSelectionDialog::updateLabels()
|
|
|
|
{
|
|
|
|
int i = m_rcCombo->currentIndex();
|
|
|
|
const QStringList values = m_rcCombo->itemData(i).toStringList();
|
|
|
|
QTC_ASSERT(values.size() == 3, return);
|
|
|
|
m_executable->setText(values.at(0));
|
|
|
|
m_arguments->setText(values.at(1));
|
|
|
|
m_workingDir->setText(values.at(2));
|
|
|
|
}
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
} // namespace Internal
|
|
|
|
} // namespace Autotest
|