summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@theqtcompany.com>2015-01-13 11:20:51 +0100
committerTim Jenssen <tim.jenssen@theqtcompany.com>2015-01-14 10:39:37 +0200
commit042b1d61d0153f61fad3da0199835c302e3243b4 (patch)
tree2d39705ee201e605759382301b0e1d2c71496e05
parent2287ba501fe30bc954d761a0afb2600d19f5dfae (diff)
downloadqt-creator-042b1d61d0153f61fad3da0199835c302e3243b4.tar.gz
merge performTestRun and performExec
This is a preparation for later refactoring. Also moved the get settings values outside from the threaded code. Change-Id: I0acceece4bc55a453880f4235e02a5712443b32d Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
-rw-r--r--plugins/autotest/testrunner.cpp111
1 files changed, 52 insertions, 59 deletions
diff --git a/plugins/autotest/testrunner.cpp b/plugins/autotest/testrunner.cpp
index ed7d4a0e5c..607e02b618 100644
--- a/plugins/autotest/testrunner.cpp
+++ b/plugins/autotest/testrunner.cpp
@@ -336,60 +336,8 @@ static QString which(const QString &path, const QString &cmd)
}
return QString();
}
-bool performExec(const QString &command, const QStringList &argumentList, const QString &workingDirectory,
- const Utils::Environment &environment, int timeout)
-{
- QString runCmd;
- if (!QDir::toNativeSeparators(command).contains(QDir::separator())) {
- if (environment.hasKey(QLatin1String("PATH")))
- runCmd = which(environment.value(QLatin1String("PATH")), command);
- } else if (QFileInfo(command).exists()) {
- runCmd = command;
- }
-
- if (runCmd.isEmpty()) {
- emitTestResultCreated(FaultyTestResult(Result::MESSAGE_FATAL,
- QObject::tr("*** Could not find command '%1' ***").arg(command)));
- return false;
- }
-
- m_runner->setWorkingDirectory(workingDirectory);
- m_runner->setProcessEnvironment(environment.toProcessEnvironment());
- QTime executionTimer;
-
- if (argumentList.count()) {
- m_runner->start(runCmd, argumentList);
- } else {
- m_runner->start(runCmd);
- }
-
- bool ok = m_runner->waitForStarted();
- executionTimer.start();
- if (ok) {
- while (m_runner->state() == QProcess::Running && executionTimer.elapsed() < timeout) {
- if (m_currentFuture->isCanceled()) {
- m_runner->kill();
- m_runner->waitForFinished();
- emitTestResultCreated(FaultyTestResult(Result::MESSAGE_FATAL,
- QObject::tr("*** Test Run canceled by user ***")));
- }
- qApp->processEvents();
- }
- }
- if (ok && executionTimer.elapsed() < timeout) {
- return m_runner->exitCode() == 0;
- } else {
- if (m_runner->state() != QProcess::NotRunning) {
- m_runner->kill();
- m_runner->waitForFinished();
- emitTestResultCreated(FaultyTestResult(Result::MESSAGE_FATAL,
- QObject::tr("*** Test Case canceled due to timeout ***\nMaybe raise the timeout?")));
- }
- return false;
- }
-}
-void performTestRun(QFutureInterface<void> &future, const QList<TestConfiguration *> selectedTests)
+void performTestRun(QFutureInterface<void> &future, const QList<TestConfiguration *> selectedTests, const int timeout, const QString metricsOption)
{
int testCaseCount = 0;
foreach (const TestConfiguration *config, selectedTests)
@@ -405,10 +353,6 @@ void performTestRun(QFutureInterface<void> &future, const QList<TestConfiguratio
future.setProgressRange(0, testCaseCount);
future.setProgressValue(0);
- const QSharedPointer<TestSettings> settings = AutotestPlugin::instance()->settings();
- const int timeout = settings->timeout;
- const QString metricsOption = TestSettings::metricsTypeToOption(settings->metrics);
-
foreach (const TestConfiguration *tc, selectedTests) {
if (future.isCanceled())
break;
@@ -422,8 +366,52 @@ void performTestRun(QFutureInterface<void> &future, const QList<TestConfiguratio
argumentList << metricsOption;
if (tc->testCases().count())
argumentList << tc->testCases();
+ QString runCmd;
+ if (!QDir::toNativeSeparators(command).contains(QDir::separator())) {
+ if (environment.hasKey(QLatin1String("PATH")))
+ runCmd = which(environment.value(QLatin1String("PATH")), command);
+ } else if (QFileInfo(command).exists()) {
+ runCmd = command;
+ }
+
+ if (runCmd.isEmpty()) {
+ emitTestResultCreated(FaultyTestResult(Result::MESSAGE_FATAL,
+ QObject::tr("*** Could not find command '%1' ***").arg(command)));
+ continue;
+ }
+
+ m_runner->setWorkingDirectory(workingDirectory);
+ m_runner->setProcessEnvironment(environment.toProcessEnvironment());
+ QTime executionTimer;
- performExec(command, argumentList, workingDirectory, environment, timeout);
+ if (argumentList.count()) {
+ m_runner->start(runCmd, argumentList);
+ } else {
+ m_runner->start(runCmd);
+ }
+
+ bool ok = m_runner->waitForStarted();
+ executionTimer.start();
+ if (ok) {
+ while (m_runner->state() == QProcess::Running && executionTimer.elapsed() < timeout) {
+ if (m_currentFuture->isCanceled()) {
+ m_runner->kill();
+ m_runner->waitForFinished();
+ emitTestResultCreated(FaultyTestResult(Result::MESSAGE_FATAL,
+ QObject::tr("*** Test Run canceled by user ***")));
+ }
+ qApp->processEvents();
+ }
+ }
+
+ if (executionTimer.elapsed() >= timeout) {
+ if (m_runner->state() != QProcess::NotRunning) {
+ m_runner->kill();
+ m_runner->waitForFinished();
+ emitTestResultCreated(FaultyTestResult(Result::MESSAGE_FATAL, QObject::tr(
+ "*** Test Case canceled due to timeout ***\nMaybe raise the timeout?")));
+ }
+ }
}
future.setProgressValue(testCaseCount);
@@ -492,8 +480,13 @@ void TestRunner::runTests()
TestResultsPane::instance(), &TestResultsPane::addTestResult,
Qt::QueuedConnection);
+ const QSharedPointer<TestSettings> settings = AutotestPlugin::instance()->settings();
+ const int timeout = settings->timeout;
+ const QString metricsOption = TestSettings::metricsTypeToOption(settings->metrics);
+
emit testRunStarted();
- QFuture<void> future = QtConcurrent::run(&performTestRun , m_selectedTests);
+
+ QFuture<void> future = QtConcurrent::run(&performTestRun, m_selectedTests, timeout, metricsOption);
Core::FutureProgress *progress = Core::ProgressManager::addTask(future, tr("Running Tests"),
Autotest::Constants::TASK_INDEX);
connect(progress, &Core::FutureProgress::finished,