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
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "testconfiguration.h"
|
2016-04-29 10:13:35 +02:00
|
|
|
#include "testoutputreader.h"
|
2016-06-15 12:29:24 +02:00
|
|
|
#include "testrunconfiguration.h"
|
|
|
|
|
#include "testrunner.h"
|
2014-10-07 15:51:02 +02:00
|
|
|
|
2015-04-27 16:11:28 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2016-01-13 12:14:43 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
2015-04-27 16:11:28 +02:00
|
|
|
|
2016-01-26 17:24:11 +01:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2015-04-27 16:11:28 +02:00
|
|
|
#include <projectexplorer/buildtargetinfo.h>
|
|
|
|
|
#include <projectexplorer/environmentaspect.h>
|
2016-01-25 15:00:20 +01:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/runnables.h>
|
2015-04-27 16:11:28 +02:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
2014-10-07 15:51:02 +02:00
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2016-04-29 10:13:35 +02:00
|
|
|
TestConfiguration::TestConfiguration()
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestConfiguration::~TestConfiguration()
|
|
|
|
|
{
|
|
|
|
|
m_testCases.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 15:00:20 +01:00
|
|
|
static bool isLocal(RunConfiguration *runConfiguration)
|
2015-04-27 16:11:28 +02:00
|
|
|
{
|
2016-01-25 15:00:20 +01:00
|
|
|
Target *target = runConfiguration ? runConfiguration->target() : 0;
|
|
|
|
|
Kit *kit = target ? target->kit() : 0;
|
|
|
|
|
return DeviceTypeKitInformation::deviceTypeId(kit) == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
|
2015-04-27 16:11:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-15 12:29:24 +02:00
|
|
|
void TestConfiguration::completeTestInformation(int runMode)
|
2015-04-27 16:11:28 +02:00
|
|
|
{
|
2017-02-21 14:53:58 +01:00
|
|
|
QTC_ASSERT(!m_projectFile.isEmpty(), return);
|
2015-04-27 16:11:28 +02:00
|
|
|
|
|
|
|
|
Project *project = SessionManager::startupProject();
|
|
|
|
|
if (!project)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Target *target = project->activeTarget();
|
|
|
|
|
if (!target)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-02-01 15:42:55 +01:00
|
|
|
const auto cppMM = CppTools::CppModelManager::instance();
|
|
|
|
|
const QVector<CppTools::ProjectPart::Ptr> projectParts = cppMM->projectInfo(project).projectParts();
|
|
|
|
|
const QVector<CppTools::ProjectPart::Ptr> relevantParts
|
|
|
|
|
= Utils::filtered(projectParts, [this] (const CppTools::ProjectPart::Ptr &part) {
|
|
|
|
|
return part->selectedForBuilding && part->projectFile == m_projectFile;
|
|
|
|
|
});
|
|
|
|
|
const QSet<QString> buildSystemTargets
|
|
|
|
|
= Utils::transform<QSet>(relevantParts, [] (const CppTools::ProjectPart::Ptr &part) {
|
|
|
|
|
return part->buildSystemTarget;
|
|
|
|
|
});
|
|
|
|
|
|
2017-03-29 10:13:09 +02:00
|
|
|
const Utils::FileName fn = Utils::FileName::fromString(m_projectFile);
|
2017-02-01 15:42:55 +01:00
|
|
|
const BuildTargetInfo targetInfo
|
2017-03-29 10:13:09 +02:00
|
|
|
= Utils::findOrDefault(target->applicationTargets().list,
|
|
|
|
|
[&buildSystemTargets, &fn] (const BuildTargetInfo &bti) {
|
|
|
|
|
return Utils::anyOf(buildSystemTargets, [&fn, &bti](const QString &b) {
|
|
|
|
|
return b == bti.targetName || (b.contains(bti.targetName) && bti.projectFilePath == fn);
|
|
|
|
|
});
|
2017-02-01 15:42:55 +01:00
|
|
|
});
|
|
|
|
|
const Utils::FileName executable = targetInfo.targetFilePath; // empty if BTI is default created
|
|
|
|
|
for (RunConfiguration *runConfig : target->runConfigurations()) {
|
|
|
|
|
if (!isLocal(runConfig)) // TODO add device support
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (buildSystemTargets.contains(runConfig->buildSystemTarget())) {
|
|
|
|
|
Runnable runnable = runConfig->runnable();
|
|
|
|
|
if (!runnable.is<StandardRunnable>())
|
|
|
|
|
continue;
|
2016-01-25 15:00:20 +01:00
|
|
|
StandardRunnable stdRunnable = runnable.as<StandardRunnable>();
|
2017-02-01 15:42:55 +01:00
|
|
|
// TODO this might pick up the wrong executable
|
|
|
|
|
m_executableFile = stdRunnable.executable;
|
|
|
|
|
m_displayName = runConfig->displayName();
|
|
|
|
|
m_workingDir = Utils::FileUtils::normalizePathName(stdRunnable.workingDirectory);
|
|
|
|
|
m_environment = stdRunnable.environment;
|
|
|
|
|
m_project = project;
|
|
|
|
|
if (runMode == TestRunner::Debug)
|
|
|
|
|
m_runConfig = new TestRunConfiguration(runConfig->target(), this);
|
|
|
|
|
break;
|
2015-04-27 16:11:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-02-01 15:42:55 +01:00
|
|
|
// RunConfiguration for this target could be explicitly removed or not created at all
|
|
|
|
|
if (m_displayName.isEmpty() && !executable.isEmpty()) {
|
|
|
|
|
// we failed to find a valid runconfiguration - but we've got the executable already
|
2016-01-25 15:00:20 +01:00
|
|
|
if (auto rc = target->activeRunConfiguration()) {
|
2017-02-01 15:42:55 +01:00
|
|
|
if (isLocal(rc)) { // FIXME for now only Desktop support
|
|
|
|
|
Runnable runnable = rc->runnable();
|
|
|
|
|
if (runnable.is<StandardRunnable>()) {
|
|
|
|
|
StandardRunnable stdRunnable = runnable.as<StandardRunnable>();
|
|
|
|
|
m_environment = stdRunnable.environment;
|
|
|
|
|
// when guessing we might have no extension
|
|
|
|
|
const QString &exeString = executable.toString();
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost() && !exeString.toLower().endsWith(".exe"))
|
|
|
|
|
m_executableFile = Utils::HostOsInfo::withExecutableSuffix(exeString);
|
|
|
|
|
else
|
|
|
|
|
m_executableFile = exeString;
|
|
|
|
|
m_project = project;
|
|
|
|
|
m_guessedConfiguration = true;
|
|
|
|
|
if (runMode == TestRunner::Debug)
|
|
|
|
|
m_runConfig = new TestRunConfiguration(rc->target(), this);
|
|
|
|
|
}
|
2016-01-25 15:00:20 +01:00
|
|
|
}
|
2015-04-27 16:11:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 15:42:55 +01:00
|
|
|
if (auto buildConfig = target->activeBuildConfiguration()) {
|
|
|
|
|
const QString buildBase = buildConfig->buildDirectory().toString();
|
|
|
|
|
const QString projBase = project->projectDirectory().toString();
|
|
|
|
|
if (m_projectFile.startsWith(projBase))
|
|
|
|
|
m_buildDir = QFileInfo(buildBase + m_projectFile.mid(projBase.length())).absolutePath();
|
2015-04-27 16:11:28 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-01 15:42:55 +01:00
|
|
|
if (m_displayName.isEmpty()) // happens e.g. when guessing the TestConfiguration or error
|
|
|
|
|
m_displayName = buildSystemTargets.isEmpty() ? "unknown" : *buildSystemTargets.begin();
|
|
|
|
|
}
|
2015-04-27 16:11:28 +02:00
|
|
|
|
2014-11-06 16:01:06 +01:00
|
|
|
/**
|
|
|
|
|
* @brief sets the test cases for this test configuration.
|
|
|
|
|
*
|
|
|
|
|
* Watch out for special handling of test configurations, because this method also
|
|
|
|
|
* updates the test case count to the current size of \a testCases.
|
|
|
|
|
*
|
|
|
|
|
* @param testCases list of names of the test functions / test cases
|
|
|
|
|
*/
|
|
|
|
|
void TestConfiguration::setTestCases(const QStringList &testCases)
|
|
|
|
|
{
|
|
|
|
|
m_testCases.clear();
|
|
|
|
|
m_testCases << testCases;
|
|
|
|
|
m_testCaseCount = m_testCases.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestConfiguration::setTestCaseCount(int count)
|
|
|
|
|
{
|
|
|
|
|
m_testCaseCount = count;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-21 14:53:58 +01:00
|
|
|
void TestConfiguration::setExecutableFile(const QString &executableFile)
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
2017-02-21 14:53:58 +01:00
|
|
|
m_executableFile = executableFile;
|
2014-10-07 15:51:02 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-21 14:53:58 +01:00
|
|
|
void TestConfiguration::setProjectFile(const QString &projectFile)
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
2017-02-21 14:53:58 +01:00
|
|
|
m_projectFile = projectFile;
|
2014-10-07 15:51:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestConfiguration::setWorkingDirectory(const QString &workingDirectory)
|
|
|
|
|
{
|
|
|
|
|
m_workingDir = workingDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-26 17:24:11 +01:00
|
|
|
void TestConfiguration::setBuildDirectory(const QString &buildDirectory)
|
|
|
|
|
{
|
|
|
|
|
m_buildDir = buildDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 12:31:58 +01:00
|
|
|
void TestConfiguration::setDisplayName(const QString &displayName)
|
|
|
|
|
{
|
|
|
|
|
m_displayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
void TestConfiguration::setEnvironment(const Utils::Environment &env)
|
|
|
|
|
{
|
|
|
|
|
m_environment = env;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-27 16:11:28 +02:00
|
|
|
void TestConfiguration::setProject(Project *project)
|
2014-10-07 15:51:02 +02:00
|
|
|
{
|
|
|
|
|
m_project = project;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 10:13:35 +02:00
|
|
|
void TestConfiguration::setGuessedConfiguration(bool guessed)
|
|
|
|
|
{
|
|
|
|
|
m_guessedConfiguration = guessed;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 15:02:37 +02:00
|
|
|
QString TestConfiguration::executableFilePath() const
|
|
|
|
|
{
|
2017-02-21 14:53:58 +01:00
|
|
|
if (m_executableFile.isEmpty())
|
2016-08-05 15:02:37 +02:00
|
|
|
return QString();
|
|
|
|
|
|
2017-02-21 14:53:58 +01:00
|
|
|
QFileInfo commandFileInfo(m_executableFile);
|
2016-08-05 15:02:37 +02:00
|
|
|
if (commandFileInfo.isExecutable() && commandFileInfo.path() != ".") {
|
|
|
|
|
return commandFileInfo.absoluteFilePath();
|
|
|
|
|
} else if (commandFileInfo.path() == "."){
|
2017-02-21 14:53:58 +01:00
|
|
|
QString fullCommandFileName = m_executableFile;
|
2016-08-05 15:02:37 +02:00
|
|
|
// TODO: check if we can use searchInPath() from Utils::Environment
|
2016-09-10 22:58:14 +03:00
|
|
|
const QStringList &pathList = m_environment.toProcessEnvironment().value("PATH").split(
|
|
|
|
|
Utils::HostOsInfo::pathListSeparator());
|
2016-08-05 15:02:37 +02:00
|
|
|
|
|
|
|
|
foreach (const QString &path, pathList) {
|
|
|
|
|
QString filePath(path + QDir::separator() + fullCommandFileName);
|
|
|
|
|
if (QFileInfo(filePath).isExecutable())
|
|
|
|
|
return commandFileInfo.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString TestConfiguration::workingDirectory() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_workingDir.isEmpty()) {
|
|
|
|
|
const QFileInfo info(m_workingDir);
|
|
|
|
|
if (info.isDir()) // ensure wanted working dir does exist
|
|
|
|
|
return info.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString executable = executableFilePath();
|
|
|
|
|
return executable.isEmpty() ? executable : QFileInfo(executable).absolutePath();
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|