cmake/Source/CTest/cmCTestTestHandler.h

393 lines
12 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
2018-04-23 21:13:27 +02:00
#include <chrono>
2022-03-29 21:10:50 +02:00
#include <cstddef>
2019-11-11 23:01:05 +01:00
#include <cstdint>
2016-10-30 18:24:19 +01:00
#include <iosfwd>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
2023-07-02 19:51:09 +02:00
#include <cm/optional>
#include <cm/string_view>
2020-02-01 23:06:01 +01:00
#include "cmsys/RegularExpression.hxx"
2020-08-30 11:54:41 +02:00
#include "cmCTest.h"
2020-02-01 23:06:01 +01:00
#include "cmCTestGenericHandler.h"
2023-12-07 09:12:54 +01:00
#include "cmCTestTypes.h" // IWYU pragma: keep
2020-02-01 23:06:01 +01:00
#include "cmDuration.h"
#include "cmListFileCache.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2020-02-01 23:06:01 +01:00
class cmMakefile;
2015-08-17 11:37:30 +02:00
class cmXMLWriter;
/** \class cmCTestTestHandler
* \brief A class that handles ctest -S invocations
*
*/
class cmCTestTestHandler : public cmCTestGenericHandler
{
2022-08-04 22:12:04 +02:00
friend class cmCTest;
2009-10-04 10:30:41 +03:00
friend class cmCTestRunTest;
friend class cmCTestMultiProcessHandler;
2016-07-09 11:21:54 +02:00
public:
2020-02-01 23:06:01 +01:00
using Superclass = cmCTestGenericHandler;
/**
* The main entry point for this class
*/
2018-01-26 17:06:56 +01:00
int ProcessHandler() override;
/**
2018-04-23 21:13:27 +02:00
* When both -R and -I are used should the resulting test list be the
* intersection or the union of the lists. By default it is the
* intersection.
*/
void SetUseUnion(bool val) { this->UseUnion = val; }
2014-08-03 19:52:23 +02:00
/**
* Set whether or not CTest should only execute the tests that failed
* on the previous run. By default this is false.
*/
void SetRerunFailed(bool val) { this->RerunFailed = val; }
/**
* This method is called when reading CTest custom file
*/
2018-01-26 17:06:56 +01:00
void PopulateCustomVectors(cmMakefile* mf) override;
2019-11-11 23:01:05 +01:00
//! Control the use of the regular expresisons, call these methods to turn
2016-07-09 11:21:54 +02:00
/// them on
void UseIncludeRegExp();
void UseExcludeRegExp();
2021-11-20 13:41:27 +01:00
void SetIncludeRegExp(const std::string&);
void SetExcludeRegExp(const std::string&);
2016-07-09 11:21:54 +02:00
void SetMaxIndex(int n) { this->MaxIndex = n; }
int GetMaxIndex() { return this->MaxIndex; }
2015-11-17 17:22:37 +01:00
void SetTestOutputSizePassed(int n)
2016-07-09 11:21:54 +02:00
{
this->CustomMaximumPassedTestOutputSize = n;
}
2015-11-17 17:22:37 +01:00
void SetTestOutputSizeFailed(int n)
2016-07-09 11:21:54 +02:00
{
this->CustomMaximumFailedTestOutputSize = n;
}
2015-11-17 17:22:37 +01:00
2022-08-04 22:12:04 +02:00
//! Set test output truncation mode. Return false if unknown mode.
bool SetTestOutputTruncation(const std::string& mode);
2019-11-11 23:01:05 +01:00
//! pass the -I argument down
2021-11-20 13:41:27 +01:00
void SetTestsToRunInformation(cmValue);
cmCTestTestHandler();
/*
* Add the test to the list of tests to be executed
*/
bool AddTest(const std::vector<std::string>& args);
/*
* Set tests properties
*/
bool SetTestsProperties(const std::vector<std::string>& args);
2018-01-26 17:06:56 +01:00
/**
* Set directory properties
*/
bool SetDirectoryProperties(const std::vector<std::string>& args);
void Initialize() override;
2020-02-01 23:06:01 +01:00
struct cmCTestTestResourceRequirement
{
std::string ResourceType;
int SlotsNeeded;
int UnitsNeeded;
bool operator==(const cmCTestTestResourceRequirement& other) const;
bool operator!=(const cmCTestTestResourceRequirement& other) const;
};
2023-07-02 19:51:09 +02:00
struct Signal
{
int Number = 0;
std::string Name;
};
struct cmCTestTestProperties
{
2023-07-02 19:51:09 +02:00
void AppendError(cm::string_view err);
cm::optional<std::string> Error;
2015-04-27 22:25:09 +02:00
std::string Name;
std::string Directory;
std::vector<std::string> Args;
2010-03-17 14:00:29 +02:00
std::vector<std::string> RequiredFiles;
2009-10-04 10:30:41 +03:00
std::vector<std::string> Depends;
2010-03-17 14:00:29 +02:00
std::vector<std::string> AttachedFiles;
std::vector<std::string> AttachOnFail;
2018-01-26 17:06:56 +01:00
std::vector<std::pair<cmsys::RegularExpression, std::string>>
2016-07-09 11:21:54 +02:00
ErrorRegularExpressions;
2018-01-26 17:06:56 +01:00
std::vector<std::pair<cmsys::RegularExpression, std::string>>
2016-07-09 11:21:54 +02:00
RequiredRegularExpressions;
2020-02-01 23:06:01 +01:00
std::vector<std::pair<cmsys::RegularExpression, std::string>>
SkipRegularExpressions;
2018-01-26 17:06:56 +01:00
std::vector<std::pair<cmsys::RegularExpression, std::string>>
2016-07-09 11:21:54 +02:00
TimeoutRegularExpressions;
2015-04-27 22:25:09 +02:00
std::map<std::string, std::string> Measurements;
2023-07-02 19:51:09 +02:00
bool IsInBasedOnREOptions = true;
bool WillFail = false;
bool Disabled = false;
float Cost = 0;
int PreviousRuns = 0;
bool RunSerial = false;
cm::optional<cmDuration> Timeout;
cm::optional<Signal> TimeoutSignal;
cm::optional<cmDuration> TimeoutGracePeriod;
2018-04-23 21:13:27 +02:00
cmDuration AlternateTimeout;
2023-07-02 19:51:09 +02:00
int Index = 0;
2016-07-09 11:21:54 +02:00
// Requested number of process slots
2023-07-02 19:51:09 +02:00
int Processors = 1;
bool WantAffinity = false;
2018-08-09 18:06:22 +02:00
std::vector<size_t> Affinity;
2014-08-03 19:52:23 +02:00
// return code of test which will mark test as "not run"
2023-07-02 19:51:09 +02:00
int SkipReturnCode = -1;
2009-10-04 10:30:41 +03:00
std::vector<std::string> Environment;
2021-11-20 13:41:27 +01:00
std::vector<std::string> EnvironmentModification;
2009-10-04 10:30:41 +03:00
std::vector<std::string> Labels;
2024-04-14 22:45:38 +02:00
std::set<std::string> ProjectResources; // RESOURCE_LOCK
2016-10-30 18:24:19 +01:00
std::set<std::string> FixturesSetup;
std::set<std::string> FixturesCleanup;
std::set<std::string> FixturesRequired;
std::set<std::string> RequireSuccessDepends;
2020-02-01 23:06:01 +01:00
std::vector<std::vector<cmCTestTestResourceRequirement>> ResourceGroups;
2023-12-07 09:12:54 +01:00
std::string GeneratedResourceSpecFile;
2019-11-11 23:01:05 +01:00
// Private test generator properties used to track backtraces
cmListFileBacktrace Backtrace;
};
struct cmCTestTestResult
{
std::string Name;
std::string Path;
2009-10-04 10:30:41 +03:00
std::string Reason;
std::string FullCommandLine;
2020-08-30 11:54:41 +02:00
std::string Environment;
2023-07-02 19:51:09 +02:00
cmDuration ExecutionTime = cmDuration::zero();
std::int64_t ReturnValue = 0;
int Status = NOT_RUN;
2018-01-26 17:06:56 +01:00
std::string ExceptionStatus;
2016-07-09 11:21:54 +02:00
bool CompressOutput;
std::string CompletionStatus;
2021-09-14 00:13:48 +02:00
std::string CustomCompletionStatus;
std::string Output;
2021-11-20 13:41:27 +01:00
std::string TestMeasurementsOutput;
2023-07-02 19:51:09 +02:00
int TestCount = 0;
cmCTestTestProperties* Properties = nullptr;
};
2012-02-18 12:40:36 +02:00
struct cmCTestTestResultLess
{
2016-07-09 11:21:54 +02:00
bool operator()(const cmCTestTestResult& lhs,
const cmCTestTestResult& rhs) const
2012-02-18 12:40:36 +02:00
{
2016-07-09 11:21:54 +02:00
return lhs.TestCount < rhs.TestCount;
2012-02-18 12:40:36 +02:00
}
};
// add configurations to a search path for an executable
2016-07-09 11:21:54 +02:00
static void AddConfigurations(cmCTest* ctest,
std::vector<std::string>& attempted,
std::vector<std::string>& attemptedConfigs,
std::string filepath, std::string& filename);
// full signature static method to find an executable
2021-09-14 00:13:48 +02:00
static std::string FindExecutable(cmCTest* ctest,
const std::string& testCommand,
2016-07-09 11:21:54 +02:00
std::string& resultingConfig,
std::vector<std::string>& extraPaths,
std::vector<std::string>& failed);
2020-02-01 23:06:01 +01:00
static bool ParseResourceGroupsProperty(
const std::string& val,
std::vector<std::vector<cmCTestTestResourceRequirement>>& resourceGroups);
using ListOfTests = std::vector<cmCTestTestProperties>;
2016-07-09 11:21:54 +02:00
2021-09-14 00:13:48 +02:00
// Support for writing test results in JUnit XML format.
void SetJUnitXMLFileName(const std::string& id);
protected:
2020-02-01 23:06:01 +01:00
using SetOfTests =
std::set<cmCTestTestHandler::cmCTestTestResult, cmCTestTestResultLess>;
2012-02-18 12:40:36 +02:00
// compute a final test list
virtual int PreProcessHandler();
virtual int PostProcessHandler();
2013-11-03 12:27:13 +02:00
virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
2015-04-27 22:25:09 +02:00
int ExecuteCommands(std::vector<std::string>& vec);
2020-02-01 23:06:01 +01:00
bool ProcessOptions();
void LogTestSummary(const std::vector<std::string>& passed,
const std::vector<std::string>& failed,
const cmDuration& durationInSecs);
void LogDisabledTests(const std::vector<cmCTestTestResult>& disabledTests);
void LogFailedTests(const std::vector<std::string>& failed,
const SetOfTests& resultsSet);
bool GenerateXML();
2018-01-26 17:06:56 +01:00
void WriteTestResultHeader(cmXMLWriter& xml,
cmCTestTestResult const& result);
void WriteTestResultFooter(cmXMLWriter& xml,
cmCTestTestResult const& result);
2010-03-17 14:00:29 +02:00
// Write attached test files into the xml
2018-01-26 17:06:56 +01:00
void AttachFiles(cmXMLWriter& xml, cmCTestTestResult& result);
2021-09-14 00:13:48 +02:00
void AttachFile(cmXMLWriter& xml, std::string const& file,
std::string const& name);
2009-10-04 10:30:41 +03:00
2022-08-04 22:12:04 +02:00
//! Clean test output to specified length and truncation mode
void CleanTestOutput(std::string& output, size_t length,
cmCTestTypes::TruncationMode truncate);
2018-04-23 21:13:27 +02:00
cmDuration ElapsedTestingTime;
2020-02-01 23:06:01 +01:00
using TestResultsVector = std::vector<cmCTestTestResult>;
2016-07-09 11:21:54 +02:00
TestResultsVector TestResults;
2015-04-27 22:25:09 +02:00
std::vector<std::string> CustomTestsIgnore;
2016-07-09 11:21:54 +02:00
std::string StartTest;
std::string EndTest;
2018-04-23 21:13:27 +02:00
std::chrono::system_clock::time_point StartTestTime;
std::chrono::system_clock::time_point EndTestTime;
bool MemCheck;
int CustomMaximumPassedTestOutputSize;
int CustomMaximumFailedTestOutputSize;
2022-08-04 22:12:04 +02:00
cmCTestTypes::TruncationMode TestOutputTruncation;
2009-10-04 10:30:41 +03:00
int MaxIndex;
2016-07-09 11:21:54 +02:00
2009-10-04 10:30:41 +03:00
public:
2016-07-09 11:21:54 +02:00
enum
{ // Program statuses
NOT_RUN = 0,
TIMEOUT,
SEGFAULT,
ILLEGAL,
INTERRUPT,
NUMERICAL,
OTHER_FAULT,
FAILED,
BAD_COMMAND,
COMPLETED
};
2009-10-04 10:30:41 +03:00
private:
/**
2021-11-20 13:41:27 +01:00
* Write test results in CTest's Test.xml format
*/
2021-11-20 13:41:27 +01:00
virtual void GenerateCTestXML(cmXMLWriter& xml);
2021-09-14 00:13:48 +02:00
/**
* Write test results in JUnit XML format
*/
bool WriteJUnitXML();
2018-01-26 17:06:56 +01:00
void PrintLabelOrSubprojectSummary(bool isSubProject);
/**
* Run the tests for a directory and any subdirectories
*/
2020-08-30 11:54:41 +02:00
bool ProcessDirectory(std::vector<std::string>& passed,
2016-07-09 11:21:54 +02:00
std::vector<std::string>& failed);
/**
* Get the list of tests in directory and subdirectories.
*/
2021-09-14 00:13:48 +02:00
bool GetListOfTests();
2009-10-04 10:30:41 +03:00
// compute the lists of tests that will actually run
// based on union regex and -I stuff
2021-09-14 00:13:48 +02:00
bool ComputeTestList();
2011-06-19 15:41:06 +03:00
2014-08-03 19:52:23 +02:00
// compute the lists of tests that will actually run
// based on LastTestFailed.log
2023-12-07 09:12:54 +01:00
bool ComputeTestListForRerunFailed();
2014-08-03 19:52:23 +02:00
2016-10-30 18:24:19 +01:00
// add required setup/cleanup tests not already in the
// list of tests to be run and update dependencies between
// tests to account for fixture setup/cleanup
void UpdateForFixtures(ListOfTests& tests) const;
2014-08-03 19:52:23 +02:00
void UpdateMaxTestNameWidth();
2016-07-09 11:21:54 +02:00
bool GetValue(const char* tag, std::string& value, std::istream& fin);
bool GetValue(const char* tag, int& value, std::istream& fin);
bool GetValue(const char* tag, size_t& value, std::istream& fin);
bool GetValue(const char* tag, bool& value, std::istream& fin);
bool GetValue(const char* tag, double& value, std::istream& fin);
/**
* Find the executable for a test
*/
2021-09-14 00:13:48 +02:00
std::string FindTheExecutable(const std::string& exe);
2019-11-11 23:01:05 +01:00
std::string GetTestStatus(cmCTestTestResult const&);
2009-10-04 10:30:41 +03:00
void ExpandTestsToRunInformation(size_t numPossibleTests);
2014-08-03 19:52:23 +02:00
void ExpandTestsToRunInformationForRerunFailed();
2024-04-14 22:45:38 +02:00
cm::optional<std::set<std::string>> ReadTestListFile(
std::string const& testListFileName) const;
2015-04-27 22:25:09 +02:00
std::vector<std::string> CustomPreTest;
std::vector<std::string> CustomPostTest;
2016-07-09 11:21:54 +02:00
std::vector<int> TestsToRun;
bool UseIncludeRegExpFlag;
bool UseExcludeRegExpFlag;
bool UseExcludeRegExpFirst;
std::string IncludeRegExp;
std::string ExcludeRegExp;
2017-07-20 19:35:53 +02:00
std::string ExcludeFixtureRegExp;
std::string ExcludeFixtureSetupRegExp;
std::string ExcludeFixtureCleanupRegExp;
2021-09-14 00:13:48 +02:00
std::vector<cmsys::RegularExpression> IncludeLabelRegularExpressions;
std::vector<cmsys::RegularExpression> ExcludeLabelRegularExpressions;
cmsys::RegularExpression IncludeTestsRegularExpression;
cmsys::RegularExpression ExcludeTestsRegularExpression;
2024-04-14 22:45:38 +02:00
std::string TestListFile;
std::string ExcludeTestListFile;
cm::optional<std::set<std::string>> TestsToRunByName;
cm::optional<std::set<std::string>> TestsToExcludeByName;
2020-08-30 11:54:41 +02:00
std::string ResourceSpecFile;
2020-02-01 23:06:01 +01:00
2021-11-20 13:41:27 +01:00
void RecordCustomTestMeasurements(cmXMLWriter& xml, std::string content);
2009-10-04 10:30:41 +03:00
void CheckLabelFilter(cmCTestTestProperties& it);
void CheckLabelFilterExclude(cmCTestTestProperties& it);
void CheckLabelFilterInclude(cmCTestTestProperties& it);
std::string TestsToRunString;
bool UseUnion;
ListOfTests TestList;
2009-10-04 10:30:41 +03:00
size_t TotalNumberOfTests;
2021-11-20 13:41:27 +01:00
cmsys::RegularExpression AllTestMeasurementsRegex;
cmsys::RegularExpression SingleTestMeasurementRegex;
2021-09-14 00:13:48 +02:00
cmsys::RegularExpression CustomCompletionStatusRegex;
2021-11-20 13:41:27 +01:00
cmsys::RegularExpression CustomLabelRegex;
std::ostream* LogFile;
2014-08-03 19:52:23 +02:00
2020-08-30 11:54:41 +02:00
cmCTest::Repeat RepeatMode = cmCTest::Repeat::Never;
int RepeatCount = 1;
2014-08-03 19:52:23 +02:00
bool RerunFailed;
2021-09-14 00:13:48 +02:00
std::string JUnitXMLFileName;
};