From b5341a9a0394364fa2b167402bfc0e9fb6540287 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 17 Feb 2015 10:33:35 +0100 Subject: [PATCH] Try to guess run configuration if none is explicitly set Additionally provide a setting to not display warnings regarding using a guessed run configuration. Change-Id: Ia7647f55e5085ffc84044281c5107770cd30d504 Reviewed-by: Tobias Hunger --- plugins/autotest/testconfiguration.cpp | 8 +- plugins/autotest/testconfiguration.h | 4 +- plugins/autotest/testrunner.cpp | 17 +- plugins/autotest/testsettings.cpp | 8 +- plugins/autotest/testsettings.h | 1 + plugins/autotest/testsettingspage.cpp | 2 + plugins/autotest/testsettingspage.ui | 466 +++++++++++++------------ plugins/autotest/testtreemodel.cpp | 33 ++ 8 files changed, 309 insertions(+), 230 deletions(-) diff --git a/plugins/autotest/testconfiguration.cpp b/plugins/autotest/testconfiguration.cpp index 9589d68c027..a8ca3743349 100644 --- a/plugins/autotest/testconfiguration.cpp +++ b/plugins/autotest/testconfiguration.cpp @@ -30,7 +30,8 @@ TestConfiguration::TestConfiguration(const QString &testClass, const QStringList m_testCases(testCases), m_testCaseCount(testCaseCount), m_unnamedOnly(false), - m_project(0) + m_project(0), + m_guessedConfiguration(false) { if (testCases.size() != 0) { m_testCaseCount = testCases.size(); @@ -102,5 +103,10 @@ void TestConfiguration::setUnnamedOnly(bool unnamedOnly) m_unnamedOnly = unnamedOnly; } +void TestConfiguration::setGuessedConfiguration(bool guessed) +{ + m_guessedConfiguration = guessed; +} + } // namespace Internal } // namespace Autotest diff --git a/plugins/autotest/testconfiguration.h b/plugins/autotest/testconfiguration.h index 8d9235b512b..82fb874ca48 100644 --- a/plugins/autotest/testconfiguration.h +++ b/plugins/autotest/testconfiguration.h @@ -50,6 +50,7 @@ public: void setEnvironment(const Utils::Environment &env); void setProject(ProjectExplorer::Project *project); void setUnnamedOnly(bool unnamedOnly); + void setGuessedConfiguration(bool guessed); QString testClass() const { return m_testClass; } QStringList testCases() const { return m_testCases; } @@ -62,7 +63,7 @@ public: Utils::Environment environment() const { return m_environment; } ProjectExplorer::Project *project() const { return m_project; } bool unnamedOnly() const { return m_unnamedOnly; } - + bool guessedConfiguration() const { return m_guessedConfiguration; } signals: @@ -80,6 +81,7 @@ private: QString m_displayName; Utils::Environment m_environment; ProjectExplorer::Project *m_project; + bool m_guessedConfiguration; }; } // namespace Internal diff --git a/plugins/autotest/testrunner.cpp b/plugins/autotest/testrunner.cpp index 185803fb020..150e72750d4 100644 --- a/plugins/autotest/testrunner.cpp +++ b/plugins/autotest/testrunner.cpp @@ -185,12 +185,17 @@ void performTestRun(QFutureInterface &futureInterface, void TestRunner::runTests() { + const QSharedPointer settings = AutotestPlugin::instance()->settings(); + const int timeout = settings->timeout; + const QString metricsOption = TestSettings::metricsTypeToOption(settings->metrics); + const bool displayRunConfigWarnings = !settings->omitRunConfigWarn; + // clear old log and output pane TestResultsPane::instance()->clearContents(); // handle faulty test configurations QList toBeRemoved; - foreach (TestConfiguration *config, m_selectedTests) + foreach (TestConfiguration *config, m_selectedTests) { if (!config->project()) { toBeRemoved.append(config); TestResultsPane::instance()->addTestResult(FaultyTestResult(Result::MESSAGE_WARN, @@ -198,6 +203,12 @@ void TestRunner::runTests() "This might be the case for a faulty environment or similar." ).arg(config->displayName()))); } + if (displayRunConfigWarnings && config->guessedConfiguration()) { + TestResultsPane::instance()->addTestResult(FaultyTestResult(Result::MESSAGE_WARN, + tr("*** Project's run configuration was guessed for '%1' ***\n" + "This might cause trouble during execution.").arg(config->displayName()))); + } + } foreach (TestConfiguration *config, toBeRemoved) { m_selectedTests.removeOne(config); delete config; @@ -243,10 +254,6 @@ void TestRunner::runTests() TestResultsPane::instance(), &TestResultsPane::addTestResult, Qt::QueuedConnection); - const QSharedPointer settings = AutotestPlugin::instance()->settings(); - const int timeout = settings->timeout; - const QString metricsOption = TestSettings::metricsTypeToOption(settings->metrics); - emit testRunStarted(); QFuture future = QtConcurrent::run(&performTestRun, m_selectedTests, timeout, metricsOption, this); diff --git a/plugins/autotest/testsettings.cpp b/plugins/autotest/testsettings.cpp index 17a9f7c7aa5..ce4c00d08d2 100644 --- a/plugins/autotest/testsettings.cpp +++ b/plugins/autotest/testsettings.cpp @@ -27,10 +27,11 @@ static const char group[] = "Autotest"; static const char timeoutKey[] = "Timeout"; static const char metricsKey[] = "Metrics"; static const char omitInternalKey[] = "OmitInternal"; +static const char omitRunConfigWarnKey[] = "OmitRCWarnings"; static const int defaultTimeout = 60000; TestSettings::TestSettings() - : timeout(defaultTimeout), metrics(Walltime), omitInternalMssg(true) + : timeout(defaultTimeout), metrics(Walltime), omitInternalMssg(true), omitRunConfigWarn(false) { } @@ -40,6 +41,7 @@ void TestSettings::toSettings(QSettings *s) const s->setValue(QLatin1String(timeoutKey), timeout); s->setValue(QLatin1String(metricsKey), metrics); s->setValue(QLatin1String(omitInternalKey), omitInternalMssg); + s->setValue(QLatin1String(omitRunConfigWarnKey), omitRunConfigWarn); s->endGroup(); } @@ -67,12 +69,14 @@ void TestSettings::fromSettings(const QSettings *s) timeout = s->value(root + QLatin1String(timeoutKey), defaultTimeout).toInt(); metrics = intToMetrics(s->value(root + QLatin1String(metricsKey), Walltime).toInt()); omitInternalMssg = s->value(root + QLatin1String(omitInternalKey), true).toBool(); + omitRunConfigWarn = s->value(root + QLatin1String(omitRunConfigWarnKey), false).toBool(); } bool TestSettings::equals(const TestSettings &rhs) const { return timeout == rhs.timeout && metrics == rhs.metrics - && omitInternalMssg == rhs.omitInternalMssg; + && omitInternalMssg == rhs.omitInternalMssg + && omitRunConfigWarn == rhs.omitRunConfigWarn; } QString TestSettings::metricsTypeToOption(const MetricsType type) diff --git a/plugins/autotest/testsettings.h b/plugins/autotest/testsettings.h index dc82647d105..44ab410093f 100644 --- a/plugins/autotest/testsettings.h +++ b/plugins/autotest/testsettings.h @@ -47,6 +47,7 @@ struct TestSettings int timeout; MetricsType metrics; bool omitInternalMssg; + bool omitRunConfigWarn; }; inline bool operator==(const TestSettings &s1, const TestSettings &s2) { return s1.equals(s2); } diff --git a/plugins/autotest/testsettingspage.cpp b/plugins/autotest/testsettingspage.cpp index 64be40bb9be..a41c287823e 100644 --- a/plugins/autotest/testsettingspage.cpp +++ b/plugins/autotest/testsettingspage.cpp @@ -39,6 +39,7 @@ void TestSettingsWidget::setSettings(const TestSettings &settings) { m_ui.timeoutSpin->setValue(settings.timeout / 1000); // we store milliseconds m_ui.omitInternalMsgCB->setChecked(settings.omitInternalMssg); + m_ui.omitRunConfigWarnCB->setChecked(settings.omitRunConfigWarn); switch (settings.metrics) { case MetricsType::Walltime: @@ -66,6 +67,7 @@ TestSettings TestSettingsWidget::settings() const TestSettings result; result.timeout = m_ui.timeoutSpin->value() * 1000; // we display seconds result.omitInternalMssg = m_ui.omitInternalMsgCB->isChecked(); + result.omitRunConfigWarn = m_ui.omitRunConfigWarnCB->isChecked(); if (m_ui.walltimeRB->isChecked()) result.metrics = MetricsType::Walltime; diff --git a/plugins/autotest/testsettingspage.ui b/plugins/autotest/testsettingspage.ui index 1a68db4b21b..164f9f7f5c1 100644 --- a/plugins/autotest/testsettingspage.ui +++ b/plugins/autotest/testsettingspage.ui @@ -6,252 +6,276 @@ 0 0 - 462 - 292 + 463 + 338 Form - - - - - - - - - - - Timeout used when executing test cases. This will apply for each test case on its own, not the whole project. - - - Timeout: - - - - - - - Timeout used when executing test cases. This will apply for each test case on its own, not the whole project. - - - s - - - 5 - - - 36000 - - - 60 - - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - If checked Internal Messages won't be shown by default. (You can still enable them on the test results filter) - - - Omit Internal Messages - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - - - 0 - 0 - - - - Benchmark Metrics - - + + + + 9 + 10 + 435 + 307 + + + + + + + - + - - - - 0 - 0 - - + - Use Walltime metrics for executing benchmarks. (default) + Timeout used when executing test cases. This will apply for each test case on its own, not the whole project. - Walltime - - - true + Timeout: - - - - 0 - 0 - - + - Use tick counter for executing benchmarks. + Timeout used when executing test cases. This will apply for each test case on its own, not the whole project. - - Tickcounter + + s - - - - - - - 0 - 0 - + + 5 - - Use event counter when executing benchmarks. + + 36000 - - Eventcounter - - - - - - - false - - - - 0 - 0 - - - - Use callgrind when executing benchmark. (valgrind must be installed) - - - Callgrind - - - - - - - false - - - - 0 - 0 - - - - Use perf when executing benchmarks. (perf must be installed) - - - Perf + + 60 - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 40 + 20 + + + + + + + + + + If checked Internal Messages won't be shown by default. (You can still enable them on the test results filter) + + + Omit Internal Messages + + + true + + + + + + + If checked Warnings regarding a guessed Run Configuration won't be shown. + + + Omit Run Configuration Warnings + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + + + 0 + 0 + + + + Benchmark Metrics + + + + + + + + + 0 + 0 + + + + Use Walltime metrics for executing benchmarks. (default) + + + Walltime + + + true + + + + + + + + 0 + 0 + + + + Use tick counter for executing benchmarks. + + + Tickcounter + + + + + + + + 0 + 0 + + + + Use event counter when executing benchmarks. + + + Eventcounter + + + + + + + false + + + + 0 + 0 + + + + Use callgrind when executing benchmark. (valgrind must be installed) + + + Callgrind + + + + + + + false + + + + 0 + 0 + + + + Use perf when executing benchmarks. (perf must be installed) + + + Perf + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + diff --git a/plugins/autotest/testtreemodel.cpp b/plugins/autotest/testtreemodel.cpp index 66abadd96a0..ea2832451d6 100644 --- a/plugins/autotest/testtreemodel.cpp +++ b/plugins/autotest/testtreemodel.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -385,8 +386,10 @@ static void addProjectInformation(TestConfiguration *config, const QString &file QString workDir; QString proFile; QString displayName; + ProjectExplorer::Project *targetProject = 0; Utils::Environment env; bool hasDesktopTarget = false; + bool guessedRunConfiguration = false; CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance(); QList projParts = cppMM->projectInfo(project).projectParts(); @@ -396,6 +399,7 @@ static void addProjectInformation(TestConfiguration *config, const QString &file if (currentFile.path == filePath) { proFile = part->projectFile; displayName = part->displayName; + targetProject = part->project; break; } } @@ -429,6 +433,34 @@ static void addProjectInformation(TestConfiguration *config, const QString &file break; } } + + // if we could not figure out the run configuration + // try to use the run configuration of the parent project + if (!hasDesktopTarget && targetProject && !targetFile.isEmpty()) { + QList rcs = target->runConfigurations(); + foreach (ProjectExplorer::RunConfiguration *rc, rcs) { + ProjectExplorer::LocalApplicationRunConfiguration *localRunConfiguration + = qobject_cast(rc); + if (localRunConfiguration) { + if (ProjectExplorer::ProjectNode *localRootProjectNode = targetProject->rootProjectNode()) { + QList localFileNodes = localRootProjectNode->fileNodes(); + if (localFileNodes.size()) { + if (localFileNodes.at(0)->path() + == targetProject->projectFilePath()) { + hasDesktopTarget = true; + workDir = Utils::FileUtils::normalizePathName( + localRunConfiguration->workingDirectory()); + ProjectExplorer::EnvironmentAspect *environmentAspect + = localRunConfiguration->extraAspect(); + env = environmentAspect->environment(); + guessedRunConfiguration = true; + break; + } + } + } + } + } + } } } @@ -440,6 +472,7 @@ static void addProjectInformation(TestConfiguration *config, const QString &file config->setEnvironment(env); config->setProject(project); config->setDisplayName(displayName); + config->setGuessedConfiguration(guessedRunConfiguration); } else { config->setProFile(proFile); config->setDisplayName(displayName);