Files
qt-creator/src/plugins/autotest/testconfiguration.h
Jarek Kobus 4f70aa7052 TestRunner: Reuse TaskTree
Get rid of QFutureInterface argument from
ITestConfiguration::createOutputReader() and from
TestOutputReader c'tor.

The fine-grained progress reporting was broken anyway:

1. The assumption was that testCaseCount was meant to be
   the total number of test functions executed. It didn't
   include the initTestCase() and cleanupTestCase(),
   while those were reported on runtime apparently
   (and exceeding the max progress by 2).
2. In case of tst_qtcprocess, when the whole test was run,
   the testCaseCount reported 41, while the real
   number of functions was 26 (+2 = 28 for init/cleanup).
3. While the max progress was set to testCaseCount initially,
   the corresponding FutureProgress rendered the progress
   always in 0-100 range, what didn't match the reality.

Instead, rely on TaskTree progress, which resolution
is per test as a whole. So, when executing a series
of tests this should scale fine. In addition, the
progress advances fluently according to the expected
run time - with 10 seconds hardcoded.

The original code locations, where progress was bumped,
are left with a TODO comment for any possible future tweaks.
Like in case of result reporting, fine-grained progress
reporting may be implemented by providing additional signal,
so there is no need for QFutureInterface inside
TestOutputReader.

Change-Id: Idc11d55e3a49dac8d1788948b9a82f68199203c6
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2023-02-03 08:15:58 +00:00

133 lines
4.9 KiB
C++

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "autotestconstants.h"
#include <projectexplorer/project.h>
#include <projectexplorer/runcontrol.h>
#include <utils/environment.h>
#include <QPointer>
#include <QStringList>
namespace Utils { class QtcProcess; }
namespace Autotest {
namespace Internal {
class TestRunConfiguration;
} // namespace Internal
class ITestBase;
class ITestFramework;
class TestOutputReader;
class TestResult;
enum class TestRunMode;
class ITestConfiguration
{
public:
explicit ITestConfiguration(ITestBase *testBase);
virtual ~ITestConfiguration() = default;
void setEnvironment(const Utils::Environment &env) { m_runnable.environment = env; }
Utils::Environment environment() const { return m_runnable.environment; }
void setWorkingDirectory(const Utils::FilePath &workingDirectory);
Utils::FilePath workingDirectory() const;
bool hasExecutable() const;
Utils::FilePath executableFilePath() const;
virtual Utils::FilePath testExecutable() const { return executableFilePath(); };
virtual TestOutputReader *createOutputReader(Utils::QtcProcess *app) const = 0;
virtual Utils::Environment filteredEnvironment(const Utils::Environment &original) const;
ITestBase *testBase() const { return m_testBase; }
void setProject(ProjectExplorer::Project *project) { m_project = project; }
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
QString displayName() const { return m_displayName; }
void setTestCaseCount(int count) { m_testCaseCount = count; }
int testCaseCount() const { return m_testCaseCount; }
ProjectExplorer::Project *project() const { return m_project.data(); }
ProjectExplorer::Runnable runnable() const { return m_runnable; }
protected:
ProjectExplorer::Runnable m_runnable;
private:
ITestBase *m_testBase = nullptr;
QPointer<ProjectExplorer::Project> m_project;
QString m_displayName;
int m_testCaseCount = 0;
};
class TestConfiguration : public ITestConfiguration
{
public:
explicit TestConfiguration(ITestFramework *framework);
~TestConfiguration() override;
void completeTestInformation(TestRunMode runMode);
void completeTestInformation(ProjectExplorer::RunConfiguration *rc, TestRunMode runMode);
void setTestCases(const QStringList &testCases);
void setProjectFile(const Utils::FilePath &projectFile);
void setBuildDirectory(const Utils::FilePath &buildDirectory);
void setInternalTarget(const QString &target);
void setInternalTargets(const QSet<QString> &targets);
void setOriginalRunConfiguration(ProjectExplorer::RunConfiguration *runConfig);
ITestFramework *framework() const;
QStringList testCases() const { return m_testCases; }
Utils::FilePath buildDirectory() const { return m_buildDir; }
Utils::FilePath projectFile() const { return m_projectFile; }
QSet<QString> internalTargets() const { return m_buildTargets; }
ProjectExplorer::RunConfiguration *originalRunConfiguration() const { return m_origRunConfig; }
Internal::TestRunConfiguration *runConfiguration() const { return m_runConfig; }
bool isDeduced() const { return m_deducedConfiguration; }
QString runConfigDisplayName() const { return m_deducedConfiguration ? m_deducedFrom
: displayName(); }
virtual QStringList argumentsForTestRunner(QStringList *omitted = nullptr) const = 0;
private:
QStringList m_testCases;
Utils::FilePath m_projectFile;
Utils::FilePath m_buildDir;
QString m_deducedFrom;
bool m_deducedConfiguration = false;
Internal::TestRunConfiguration *m_runConfig = nullptr;
QSet<QString> m_buildTargets;
ProjectExplorer::RunConfiguration *m_origRunConfig = nullptr;
};
class DebuggableTestConfiguration : public TestConfiguration
{
public:
explicit DebuggableTestConfiguration(ITestFramework *framework, TestRunMode runMode = TestRunMode::Run)
: TestConfiguration(framework), m_runMode(runMode) {}
void setRunMode(TestRunMode mode) { m_runMode = mode; }
TestRunMode runMode() const { return m_runMode; }
bool isDebugRunMode() const;
void setMixedDebugging(bool enable) { m_mixedDebugging = enable; }
bool mixedDebugging() const { return m_mixedDebugging; }
private:
TestRunMode m_runMode;
bool m_mixedDebugging = false;
};
class TestToolConfiguration : public ITestConfiguration
{
public:
explicit TestToolConfiguration(ITestBase *testBase) : ITestConfiguration(testBase) {}
Utils::CommandLine commandLine() const { return m_commandLine; }
void setCommandLine(const Utils::CommandLine &cmdline) { m_commandLine = cmdline; }
virtual Utils::FilePath testExecutable() const override { return m_commandLine.executable(); };
private:
Utils::CommandLine m_commandLine;
};
} // namespace Autotest