cmake/Source/CTest/cmCTestTestHandler.h

372 lines
11 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>
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>
2020-02-01 23:06:01 +01:00
#include <stddef.h>
#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"
#include "cmCTestResourceSpec.h"
#include "cmDuration.h"
#include "cmListFileCache.h"
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
{
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();
2016-07-09 11:21:54 +02:00
void SetIncludeRegExp(const char*);
void SetExcludeRegExp(const char*);
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
2019-11-11 23:01:05 +01:00
//! pass the -I argument down
void SetTestsToRunInformation(const char*);
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;
};
2009-10-04 10:30:41 +03:00
// NOTE: This struct is Saved/Restored
// in cmCTestTestHandler, if you add to this class
// then you must add the new members to that code or
// ctest -j N will break for that feature
struct cmCTestTestProperties
{
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;
bool IsInBasedOnREOptions;
bool WillFail;
2017-07-20 19:35:53 +02:00
bool Disabled;
2009-10-04 10:30:41 +03:00
float Cost;
2010-06-23 01:18:35 +03:00
int PreviousRuns;
2009-10-04 10:30:41 +03:00
bool RunSerial;
2018-04-23 21:13:27 +02:00
cmDuration Timeout;
2011-01-16 11:35:12 +01:00
bool ExplicitTimeout;
2018-04-23 21:13:27 +02:00
cmDuration AlternateTimeout;
2009-10-04 10:30:41 +03:00
int Index;
2016-07-09 11:21:54 +02:00
// Requested number of process slots
2009-10-04 10:30:41 +03:00
int Processors;
2018-08-09 18:06:22 +02:00
bool WantAffinity;
std::vector<size_t> Affinity;
2014-08-03 19:52:23 +02:00
// return code of test which will mark test as "not run"
int SkipReturnCode;
2009-10-04 10:30:41 +03:00
std::vector<std::string> Environment;
std::vector<std::string> Labels;
2010-06-23 01:18:35 +03:00
std::set<std::string> LockedResources;
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;
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;
2018-04-23 21:13:27 +02:00
cmDuration ExecutionTime;
2019-11-11 23:01:05 +01:00
std::int64_t ReturnValue;
2016-07-09 11:21:54 +02:00
int Status;
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;
2015-08-17 11:37:30 +02:00
std::string DartString;
2016-07-09 11:21:54 +02:00
int TestCount;
cmCTestTestProperties* Properties;
};
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
//! Clean test output to specified length
2020-08-30 11:54:41 +02:00
void CleanTestOutput(std::string& output, size_t length);
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;
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:
/**
* Generate the Dart compatible output
*/
2015-08-17 11:37:30 +02:00
virtual void GenerateDartOutput(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
void ComputeTestListForRerunFailed();
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();
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;
2020-02-01 23:06:01 +01:00
bool UseResourceSpec;
cmCTestResourceSpec ResourceSpec;
2020-08-30 11:54:41 +02:00
std::string ResourceSpecFile;
2020-02-01 23:06:01 +01:00
2015-08-17 11:37:30 +02:00
void GenerateRegressionImages(cmXMLWriter& xml, const std::string& dart);
2009-10-04 10:30:41 +03:00
cmsys::RegularExpression DartStuff1;
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;
cmsys::RegularExpression DartStuff;
2021-09-14 00:13:48 +02:00
cmsys::RegularExpression CustomCompletionStatusRegex;
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;
};