cmake/Source/CTest/cmCTestTestHandler.h

321 lines
9.3 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. */
#ifndef cmCTestTestHandler_h
#define cmCTestTestHandler_h
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
#include "cmCTestGenericHandler.h"
2018-04-23 21:13:27 +02:00
#include "cmDuration.h"
2016-07-09 11:21:54 +02:00
2017-07-20 19:35:53 +02:00
#include "cmsys/RegularExpression.hxx"
2018-04-23 21:13:27 +02:00
#include <chrono>
2016-10-30 18:24:19 +01:00
#include <iosfwd>
#include <map>
#include <set>
#include <stddef.h>
#include <string>
#include <utility>
#include <vector>
class cmCTest;
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:
2017-04-14 19:02:05 +02:00
typedef cmCTestGenericHandler Superclass;
/**
* 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;
///! 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
///! 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;
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;
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;
};
struct cmCTestTestResult
{
std::string Name;
std::string Path;
2009-10-04 10:30:41 +03:00
std::string Reason;
std::string FullCommandLine;
2018-04-23 21:13:27 +02:00
cmDuration ExecutionTime;
2016-07-09 11:21:54 +02:00
int ReturnValue;
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;
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
2016-07-09 11:21:54 +02:00
static std::string FindExecutable(cmCTest* ctest, const char* testCommand,
std::string& resultingConfig,
std::vector<std::string>& extraPaths,
std::vector<std::string>& failed);
2009-10-04 10:30:41 +03:00
typedef std::vector<cmCTestTestProperties> ListOfTests;
2016-07-09 11:21:54 +02:00
protected:
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);
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);
2009-10-04 10:30:41 +03:00
//! Clean test output to specified length
bool CleanTestOutput(std::string& output, size_t length);
2018-04-23 21:13:27 +02:00
cmDuration ElapsedTestingTime;
typedef std::vector<cmCTestTestResult> TestResultsVector;
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);
2018-01-26 17:06:56 +01:00
void PrintLabelOrSubprojectSummary(bool isSubProject);
/**
* Run the tests for a directory and any subdirectories
*/
2016-07-09 11:21:54 +02:00
void ProcessDirectory(std::vector<std::string>& passed,
std::vector<std::string>& failed);
/**
* Get the list of tests in directory and subdirectories.
*/
void 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
void 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
*/
2016-07-09 11:21:54 +02:00
std::string FindTheExecutable(const char* exe);
2018-01-26 17:06:56 +01:00
const char* 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;
2009-10-04 10:30:41 +03:00
bool UseIncludeLabelRegExpFlag;
bool UseExcludeLabelRegExpFlag;
bool UseIncludeRegExpFlag;
bool UseExcludeRegExpFlag;
bool UseExcludeRegExpFirst;
2009-10-04 10:30:41 +03:00
std::string IncludeLabelRegExp;
std::string ExcludeLabelRegExp;
std::string IncludeRegExp;
std::string ExcludeRegExp;
2017-07-20 19:35:53 +02:00
std::string ExcludeFixtureRegExp;
std::string ExcludeFixtureSetupRegExp;
std::string ExcludeFixtureCleanupRegExp;
2009-10-04 10:30:41 +03:00
cmsys::RegularExpression IncludeLabelRegularExpression;
cmsys::RegularExpression ExcludeLabelRegularExpression;
cmsys::RegularExpression IncludeTestsRegularExpression;
cmsys::RegularExpression ExcludeTestsRegularExpression;
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;
std::ostream* LogFile;
2014-08-03 19:52:23 +02:00
bool RerunFailed;
};
#endif