Updated formatting of documentation plus a little reorganization.
[cmake.git] / Source / CTest / cmCTestTestHandler.h
blob5413ffee76bf8019b43dce88db8a33d2c70f4930
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestTestHandler.h,v $
5 Language: C++
6 Date: $Date: 2009-09-10 15:16:08 $
7 Version: $Revision: 1.49 $
9 Copyright (c) 2002 Kitware, Inc. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #ifndef cmCTestTestHandler_h
19 #define cmCTestTestHandler_h
22 #include "cmCTestGenericHandler.h"
23 #include <cmsys/RegularExpression.hxx>
25 class cmMakefile;
27 /** \class cmCTestTestHandler
28 * \brief A class that handles ctest -S invocations
31 class cmCTestTestHandler : public cmCTestGenericHandler
33 friend class cmCTestRunTest;
34 friend class cmCTestMultiProcessHandler;
35 friend class cmCTestBatchTestHandler;
36 public:
37 cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
39 /**
40 * The main entry point for this class
42 int ProcessHandler();
44 /**
45 * When both -R and -I are used should te resulting test list be the
46 * intersection or the union of the lists. By default it is the
47 * intersection.
49 void SetUseUnion(bool val) { this->UseUnion = val; }
51 /**
52 * This method is called when reading CTest custom file
54 void PopulateCustomVectors(cmMakefile *mf);
56 ///! Control the use of the regular expresisons, call these methods to turn
57 ///them on
58 void UseIncludeRegExp();
59 void UseExcludeRegExp();
60 void SetIncludeRegExp(const char *);
61 void SetExcludeRegExp(const char *);
63 void SetMaxIndex(int n) {this->MaxIndex = n;}
64 int GetMaxIndex() {return this->MaxIndex;}
66 ///! pass the -I argument down
67 void SetTestsToRunInformation(const char*);
69 cmCTestTestHandler();
72 * Add the test to the list of tests to be executed
74 bool AddTest(const std::vector<std::string>& args);
77 * Set tests properties
79 bool SetTestsProperties(const std::vector<std::string>& args);
81 void Initialize();
83 // NOTE: This struct is Saved/Restored
84 // in cmCTestTestHandler, if you add to this class
85 // then you must add the new members to that code or
86 // ctest -j N will break for that feature
87 struct cmCTestTestProperties
89 cmStdString Name;
90 cmStdString Directory;
91 std::vector<std::string> Args;
92 std::vector<std::string> Depends;
93 std::vector<std::pair<cmsys::RegularExpression,
94 std::string> > ErrorRegularExpressions;
95 std::vector<std::pair<cmsys::RegularExpression,
96 std::string> > RequiredRegularExpressions;
97 std::map<cmStdString, cmStdString> Measurements;
98 bool IsInBasedOnREOptions;
99 bool WillFail;
100 float Cost;
101 bool RunSerial;
102 double Timeout;
103 int Index;
104 //Requested number of process slots
105 int Processors;
106 std::vector<std::string> Environment;
107 std::vector<std::string> Labels;
110 struct cmCTestTestResult
112 std::string Name;
113 std::string Path;
114 std::string Reason;
115 std::string FullCommandLine;
116 double ExecutionTime;
117 int ReturnValue;
118 int Status;
119 std::string CompletionStatus;
120 std::string Output;
121 std::string RegressionImages;
122 int TestCount;
123 cmCTestTestProperties* Properties;
126 // add configuraitons to a search path for an executable
127 static void AddConfigurations(cmCTest *ctest,
128 std::vector<std::string> &attempted,
129 std::vector<std::string> &attemptedConfigs,
130 std::string filepath,
131 std::string &filename);
133 // full signature static method to find an executable
134 static std::string FindExecutable(cmCTest *ctest,
135 const char *testCommand,
136 std::string &resultingConfig,
137 std::vector<std::string> &extraPaths,
138 std::vector<std::string> &failed);
140 typedef std::vector<cmCTestTestProperties> ListOfTests;
141 protected:
142 // comput a final test list
143 virtual int PreProcessHandler();
144 virtual int PostProcessHandler();
145 virtual void GenerateTestCommand(std::vector<std::string>& args);
146 int ExecuteCommands(std::vector<cmStdString>& vec);
148 void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
149 void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
151 //! Clean test output to specified length
152 bool CleanTestOutput(std::string& output, size_t length);
154 double ElapsedTestingTime;
156 typedef std::vector<cmCTestTestResult> TestResultsVector;
157 TestResultsVector TestResults;
159 std::vector<cmStdString> CustomTestsIgnore;
160 std::string StartTest;
161 std::string EndTest;
162 unsigned int StartTestTime;
163 unsigned int EndTestTime;
164 bool MemCheck;
165 int CustomMaximumPassedTestOutputSize;
166 int CustomMaximumFailedTestOutputSize;
167 int MaxIndex;
168 public:
169 enum { // Program statuses
170 NOT_RUN = 0,
171 TIMEOUT,
172 SEGFAULT,
173 ILLEGAL,
174 INTERRUPT,
175 NUMERICAL,
176 OTHER_FAULT,
177 FAILED,
178 BAD_COMMAND,
179 COMPLETED
182 private:
184 * Generate the Dart compatible output
186 virtual void GenerateDartOutput(std::ostream& os);
188 void PrintLabelSummary();
190 * Run the tests for a directory and any subdirectories
192 void ProcessDirectory(std::vector<cmStdString> &passed,
193 std::vector<cmStdString> &failed);
196 * Get the list of tests in directory and subdirectories.
198 void GetListOfTests();
199 // compute the lists of tests that will actually run
200 // based on union regex and -I stuff
201 void ComputeTestList();
203 bool GetValue(const char* tag,
204 std::string& value,
205 std::ifstream& fin);
206 bool GetValue(const char* tag,
207 int& value,
208 std::ifstream& fin);
209 bool GetValue(const char* tag,
210 size_t& value,
211 std::ifstream& fin);
212 bool GetValue(const char* tag,
213 bool& value,
214 std::ifstream& fin);
215 bool GetValue(const char* tag,
216 double& value,
217 std::ifstream& fin);
219 * Find the executable for a test
221 std::string FindTheExecutable(const char *exe);
223 const char* GetTestStatus(int status);
224 void ExpandTestsToRunInformation(size_t numPossibleTests);
226 std::vector<cmStdString> CustomPreTest;
227 std::vector<cmStdString> CustomPostTest;
229 std::vector<int> TestsToRun;
231 bool UseIncludeLabelRegExpFlag;
232 bool UseExcludeLabelRegExpFlag;
233 bool UseIncludeRegExpFlag;
234 bool UseExcludeRegExpFlag;
235 bool UseExcludeRegExpFirst;
236 std::string IncludeLabelRegExp;
237 std::string ExcludeLabelRegExp;
238 std::string IncludeRegExp;
239 std::string ExcludeRegExp;
240 cmsys::RegularExpression IncludeLabelRegularExpression;
241 cmsys::RegularExpression ExcludeLabelRegularExpression;
242 cmsys::RegularExpression IncludeTestsRegularExpression;
243 cmsys::RegularExpression ExcludeTestsRegularExpression;
245 std::string GenerateRegressionImages(const std::string& xml);
246 cmsys::RegularExpression DartStuff1;
247 void CheckLabelFilter(cmCTestTestProperties& it);
248 void CheckLabelFilterExclude(cmCTestTestProperties& it);
249 void CheckLabelFilterInclude(cmCTestTestProperties& it);
251 std::string TestsToRunString;
252 bool UseUnion;
253 ListOfTests TestList;
254 size_t TotalNumberOfTests;
255 cmsys::RegularExpression DartStuff;
257 std::ostream* LogFile;
260 #endif