CMake/Source/CTest/cmCTestTestHandler.h

292 lines
8.6 KiB
C
Raw Normal View History

/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc.
2004-09-09 16:41:05 +04:00
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
2004-09-09 16:41:05 +04:00
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
2004-09-09 16:41:05 +04:00
#ifndef cmCTestTestHandler_h
#define cmCTestTestHandler_h
2005-01-27 19:43:22 +03:00
#include "cmCTestGenericHandler.h"
#include <cmsys/RegularExpression.hxx>
2004-09-09 16:41:05 +04:00
class cmMakefile;
class cmXMLWriter;
2004-09-09 16:41:05 +04:00
/** \class cmCTestTestHandler
* \brief A class that handles ctest -S invocations
*
*/
2005-01-27 19:43:22 +03:00
class cmCTestTestHandler : public cmCTestGenericHandler
2004-09-09 16:41:05 +04:00
{
friend class cmCTestRunTest;
friend class cmCTestMultiProcessHandler;
friend class cmCTestBatchTestHandler;
2004-09-09 16:41:05 +04:00
public:
cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
2004-09-09 16:41:05 +04:00
2005-01-27 23:54:47 +03:00
/**
2004-09-09 16:41:05 +04:00
* The main entry point for this class
*/
2005-01-27 23:54:47 +03:00
int ProcessHandler();
2006-03-09 19:17:10 +03:00
2005-01-27 23:54:47 +03:00
/**
* When both -R and -I are used should te resulting test list be the
* intersection or the union of the lists. By default it is the
* intersection.
*/
2006-03-10 23:03:09 +03:00
void SetUseUnion(bool val) { this->UseUnion = val; }
/**
* 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; }
2005-01-27 23:54:47 +03:00
/**
* This method is called when reading CTest custom file
*/
void PopulateCustomVectors(cmMakefile *mf);
2006-03-09 19:17:10 +03:00
2004-09-09 16:41:05 +04:00
///! Control the use of the regular expresisons, call these methods to turn
///them on
void UseIncludeRegExp();
void UseExcludeRegExp();
void SetIncludeRegExp(const char *);
void SetExcludeRegExp(const char *);
2006-03-09 19:17:10 +03:00
void SetMaxIndex(int n) {this->MaxIndex = n;}
int GetMaxIndex() {return this->MaxIndex;}
2004-09-09 16:41:05 +04:00
///! pass the -I argument down
void SetTestsToRunInformation(const char*);
2005-01-27 23:54:47 +03:00
cmCTestTestHandler();
2004-09-09 16:41:05 +04:00
/*
* 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);
void Initialize();
2008-12-19 05:59:25 +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
2005-01-28 00:49:10 +03:00
struct cmCTestTestProperties
{
std::string Name;
std::string Directory;
2006-03-10 23:03:09 +03:00
std::vector<std::string> Args;
std::vector<std::string> RequiredFiles;
2008-07-03 17:31:33 +04:00
std::vector<std::string> Depends;
std::vector<std::string> AttachedFiles;
std::vector<std::string> AttachOnFail;
2007-09-24 19:10:55 +04:00
std::vector<std::pair<cmsys::RegularExpression,
std::string> > ErrorRegularExpressions;
std::vector<std::pair<cmsys::RegularExpression,
std::string> > RequiredRegularExpressions;
std::map<std::string, std::string> Measurements;
2006-03-10 23:03:09 +03:00
bool IsInBasedOnREOptions;
bool WillFail;
float Cost;
int PreviousRuns;
bool RunSerial;
2007-01-25 19:16:16 +03:00
double Timeout;
bool ExplicitTimeout;
2008-07-03 17:31:33 +04:00
int Index;
//Requested number of process slots
int Processors;
// return code of test which will mark test as "not run"
int SkipReturnCode;
std::vector<std::string> Environment;
std::vector<std::string> Labels;
2010-03-02 23:34:37 +03:00
std::set<std::string> LockedResources;
2005-01-28 00:49:10 +03:00
};
struct cmCTestTestResult
{
std::string Name;
std::string Path;
std::string Reason;
std::string FullCommandLine;
double ExecutionTime;
int ReturnValue;
int Status;
bool CompressOutput;
std::string CompletionStatus;
std::string Output;
std::string DartString;
int TestCount;
cmCTestTestProperties* Properties;
};
struct cmCTestTestResultLess
{
bool operator() (const cmCTestTestResult &lhs,
const cmCTestTestResult &rhs) const
{
return lhs.TestCount < rhs.TestCount;
}
};
// add configurations to a search path for an executable
2011-03-11 16:04:58 +03: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
static std::string FindExecutable(cmCTest *ctest,
const char *testCommand,
std::string &resultingConfig,
std::vector<std::string> &extraPaths,
std::vector<std::string> &failed);
typedef std::vector<cmCTestTestProperties> ListOfTests;
2006-10-13 22:44:35 +04:00
protected:
// compute a final test list
2005-01-27 23:54:47 +03:00
virtual int PreProcessHandler();
virtual int PostProcessHandler();
virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
int ExecuteCommands(std::vector<std::string>& vec);
2005-01-27 23:54:47 +03:00
void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result);
void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result);
// Write attached test files into the xml
void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result);
//! Clean test output to specified length
bool CleanTestOutput(std::string& output, size_t length);
2006-03-10 23:03:09 +03:00
double ElapsedTestingTime;
2005-01-27 23:54:47 +03:00
2006-03-10 23:03:09 +03:00
typedef std::vector<cmCTestTestResult> TestResultsVector;
TestResultsVector TestResults;
2004-09-09 16:41:05 +04:00
std::vector<std::string> CustomTestsIgnore;
2006-03-10 23:03:09 +03:00
std::string StartTest;
std::string EndTest;
unsigned int StartTestTime;
unsigned int EndTestTime;
2006-03-10 23:03:09 +03:00
bool MemCheck;
int CustomMaximumPassedTestOutputSize;
int CustomMaximumFailedTestOutputSize;
int MaxIndex;
2008-07-03 17:31:33 +04:00
public:
2005-01-27 23:54:47 +03:00
enum { // Program statuses
NOT_RUN = 0,
TIMEOUT,
SEGFAULT,
ILLEGAL,
INTERRUPT,
NUMERICAL,
OTHER_FAULT,
FAILED,
BAD_COMMAND,
COMPLETED
};
2004-09-09 16:41:05 +04:00
2008-07-03 17:31:33 +04:00
private:
2004-09-09 16:41:05 +04:00
/**
* Generate the Dart compatible output
*/
virtual void GenerateDartOutput(cmXMLWriter& xml);
2004-09-09 16:41:05 +04:00
void PrintLabelSummary();
2004-09-09 16:41:05 +04:00
/**
2007-01-25 19:16:16 +03:00
* Run the tests for a directory and any subdirectories
2004-09-09 16:41:05 +04:00
*/
void ProcessDirectory(std::vector<std::string> &passed,
std::vector<std::string> &failed);
2006-03-09 19:17:10 +03:00
2004-09-09 16:41:05 +04:00
/**
* Get the list of tests in directory and subdirectories.
*/
void GetListOfTests();
2008-07-03 17:31:33 +04:00
// compute the lists of tests that will actually run
// based on union regex and -I stuff
void ComputeTestList();
2011-03-11 16:04:58 +03:00
// compute the lists of tests that will actually run
// based on LastTestFailed.log
void ComputeTestListForRerunFailed();
void UpdateMaxTestNameWidth();
2008-07-03 17:31:33 +04:00
bool GetValue(const char* tag,
std::string& value,
std::istream& fin);
2008-07-03 17:31:33 +04:00
bool GetValue(const char* tag,
int& value,
std::istream& fin);
2008-07-03 17:31:33 +04:00
bool GetValue(const char* tag,
size_t& value,
std::istream& fin);
2008-07-03 17:31:33 +04:00
bool GetValue(const char* tag,
bool& value,
std::istream& fin);
2008-07-03 17:31:33 +04:00
bool GetValue(const char* tag,
double& value,
std::istream& fin);
2004-09-09 16:41:05 +04:00
/**
* Find the executable for a test
*/
std::string FindTheExecutable(const char *exe);
const char* GetTestStatus(int status);
2008-07-07 03:58:38 +04:00
void ExpandTestsToRunInformation(size_t numPossibleTests);
void ExpandTestsToRunInformationForRerunFailed();
2004-09-09 16:41:05 +04:00
std::vector<std::string> CustomPreTest;
std::vector<std::string> CustomPostTest;
2004-09-09 16:41:05 +04:00
2006-03-10 23:03:09 +03:00
std::vector<int> TestsToRun;
2004-09-09 16:41:05 +04:00
bool UseIncludeLabelRegExpFlag;
bool UseExcludeLabelRegExpFlag;
2006-03-10 23:03:09 +03:00
bool UseIncludeRegExpFlag;
bool UseExcludeRegExpFlag;
bool UseExcludeRegExpFirst;
std::string IncludeLabelRegExp;
std::string ExcludeLabelRegExp;
2006-03-10 23:03:09 +03:00
std::string IncludeRegExp;
std::string ExcludeRegExp;
cmsys::RegularExpression IncludeLabelRegularExpression;
cmsys::RegularExpression ExcludeLabelRegularExpression;
2006-03-10 23:03:09 +03:00
cmsys::RegularExpression IncludeTestsRegularExpression;
cmsys::RegularExpression ExcludeTestsRegularExpression;
2004-09-09 16:41:05 +04:00
void GenerateRegressionImages(cmXMLWriter& xml, const std::string& dart);
2009-01-15 18:32:56 +03:00
cmsys::RegularExpression DartStuff1;
void CheckLabelFilter(cmCTestTestProperties& it);
void CheckLabelFilterExclude(cmCTestTestProperties& it);
void CheckLabelFilterInclude(cmCTestTestProperties& it);
2004-09-09 16:41:05 +04:00
std::string TestsToRunString;
2006-03-10 23:03:09 +03:00
bool UseUnion;
ListOfTests TestList;
2008-07-03 17:31:33 +04:00
size_t TotalNumberOfTests;
2006-03-10 23:03:09 +03:00
cmsys::RegularExpression DartStuff;
2005-08-18 21:50:16 +04:00
2006-03-10 23:03:09 +03:00
std::ostream* LogFile;
bool RerunFailed;
2004-09-09 16:41:05 +04:00
};
#endif