Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / CTest / cmCTestTestHandler.h
blob08ae17e8d3a4daa09aff4bd8e62d1be76805c14e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTestTestHandler.h,v $
5 Language: C++
6 Date: $Date: 2009-02-24 22:23:51 $
7 Version: $Revision: 1.36 $
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 public:
34 cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
36 /**
37 * The main entry point for this class
39 int ProcessHandler();
41 /**
42 * When both -R and -I are used should te resulting test list be the
43 * intersection or the union of the lists. By default it is the
44 * intersection.
46 void SetUseUnion(bool val) { this->UseUnion = val; }
48 /**
49 * This method is called when reading CTest custom file
51 void PopulateCustomVectors(cmMakefile *mf);
53 ///! Control the use of the regular expresisons, call these methods to turn
54 ///them on
55 void UseIncludeRegExp();
56 void UseExcludeRegExp();
57 void SetIncludeRegExp(const char *);
58 void SetExcludeRegExp(const char *);
61 ///! pass the -I argument down
62 void SetTestsToRunInformation(const char*);
64 cmCTestTestHandler();
67 * Add the test to the list of tests to be executed
69 bool AddTest(const std::vector<std::string>& args);
72 * Set tests properties
74 bool SetTestsProperties(const std::vector<std::string>& args);
76 void Initialize();
78 // NOTE: This struct is Saved/Restored
79 // in cmCTestTestHandler, if you add to this class
80 // then you must add the new members to that code or
81 // ctest -j N will break for that feature
82 struct cmCTestTestProperties
84 cmStdString Name;
85 cmStdString Directory;
86 std::vector<std::string> Args;
87 std::vector<std::string> Depends;
88 std::vector<std::pair<cmsys::RegularExpression,
89 std::string> > ErrorRegularExpressions;
90 std::vector<std::pair<cmsys::RegularExpression,
91 std::string> > RequiredRegularExpressions;
92 std::map<cmStdString, cmStdString> Measurements;
93 bool IsInBasedOnREOptions;
94 bool WillFail;
95 double Timeout;
96 int Index;
97 std::vector<std::string> Environment;
98 std::vector<std::string> Labels;
101 struct cmCTestTestResult
103 std::string Name;
104 std::string Path;
105 std::string Reason;
106 std::string FullCommandLine;
107 double ExecutionTime;
108 int ReturnValue;
109 int Status;
110 std::string CompletionStatus;
111 std::string Output;
112 std::string RegressionImages;
113 int TestCount;
114 cmCTestTestProperties* Properties;
117 // add configuraitons to a search path for an executable
118 static void AddConfigurations(cmCTest *ctest,
119 std::vector<std::string> &attempted,
120 std::vector<std::string> &attemptedConfigs,
121 std::string filepath,
122 std::string &filename);
124 // full signature static method to find an executable
125 static std::string FindExecutable(cmCTest *ctest,
126 const char *testCommand,
127 std::string &resultingConfig,
128 std::vector<std::string> &extraPaths,
129 std::vector<std::string> &failed);
131 protected:
132 // comput a final test list
133 virtual int PreProcessHandler();
134 virtual int PostProcessHandler();
135 virtual void GenerateTestCommand(std::vector<const char*>& args);
136 int ExecuteCommands(std::vector<cmStdString>& vec);
138 void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
139 void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
141 //! Clean test output to specified length
142 bool CleanTestOutput(std::string& output, size_t length);
144 double ElapsedTestingTime;
146 typedef std::vector<cmCTestTestResult> TestResultsVector;
147 TestResultsVector TestResults;
149 std::vector<cmStdString> CustomTestsIgnore;
150 std::string StartTest;
151 std::string EndTest;
152 unsigned int StartTestTime;
153 unsigned int EndTestTime;
154 bool MemCheck;
155 int CustomMaximumPassedTestOutputSize;
156 int CustomMaximumFailedTestOutputSize;
157 protected:
159 * Run one test
161 virtual void ProcessOneTest(cmCTestTestProperties *props,
162 std::vector<cmStdString> &passed,
163 std::vector<cmStdString> &failed,
164 int count, int tmsize);
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);
189 * Run the tests for a directory and any subdirectories
191 void ProcessDirectory(std::vector<cmStdString> &passed,
192 std::vector<cmStdString> &failed);
194 typedef std::vector<cmCTestTestProperties> ListOfTests;
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 // Save the state of the test list and return the file
204 // name it was saved to
205 std::string SaveTestList();
206 void LoadTestList();
207 bool GetValue(const char* tag,
208 std::string& value,
209 std::ifstream& fin);
210 bool GetValue(const char* tag,
211 int& value,
212 std::ifstream& fin);
213 bool GetValue(const char* tag,
214 size_t& value,
215 std::ifstream& fin);
216 bool GetValue(const char* tag,
217 bool& value,
218 std::ifstream& fin);
219 bool GetValue(const char* tag,
220 double& value,
221 std::ifstream& fin);
222 // run in -j N mode
223 void ProcessParallel(std::vector<cmStdString> &passed,
224 std::vector<cmStdString> &failed);
226 * Find the executable for a test
228 std::string FindTheExecutable(const char *exe);
230 const char* GetTestStatus(int status);
231 void ExpandTestsToRunInformation(size_t numPossibleTests);
233 std::vector<cmStdString> CustomPreTest;
234 std::vector<cmStdString> CustomPostTest;
236 std::vector<int> TestsToRun;
238 bool UseIncludeLabelRegExpFlag;
239 bool UseExcludeLabelRegExpFlag;
240 bool UseIncludeRegExpFlag;
241 bool UseExcludeRegExpFlag;
242 bool UseExcludeRegExpFirst;
243 std::string IncludeLabelRegExp;
244 std::string ExcludeLabelRegExp;
245 std::string IncludeRegExp;
246 std::string ExcludeRegExp;
247 cmsys::RegularExpression IncludeLabelRegularExpression;
248 cmsys::RegularExpression ExcludeLabelRegularExpression;
249 cmsys::RegularExpression IncludeTestsRegularExpression;
250 cmsys::RegularExpression ExcludeTestsRegularExpression;
252 std::string GenerateRegressionImages(const std::string& xml);
253 cmsys::RegularExpression DartStuff1;
254 void CheckLabelFilter(cmCTestTestProperties& it);
255 void CheckLabelFilterExclude(cmCTestTestProperties& it);
256 void CheckLabelFilterInclude(cmCTestTestProperties& it);
258 std::string TestsToRunString;
259 bool UseUnion;
260 ListOfTests TestList;
261 size_t TotalNumberOfTests;
262 cmsys::RegularExpression DartStuff;
264 std::ostream* LogFile;
267 #endif