CVS resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmCTest.h
blob6ede366a8b467becb81f552b10944612f2df6856
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTest.h,v $
5 Language: C++
6 Date: $Date: 2008/02/03 13:57:41 $
7 Version: $Revision: 1.100 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. 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 cmCTest_h
19 #define cmCTest_h
21 #include "cmStandardIncludes.h"
22 #include "cmListFileCache.h"
23 #include <time.h>
25 class cmake;
26 class cmMakefile;
27 class cmCTestGenericHandler;
28 class cmGeneratedFileStream;
29 class cmCTestCommand;
31 #define cmCTestLog(ctSelf, logType, msg) \
32 do { \
33 cmOStringStream cmCTestLog_msg; \
34 cmCTestLog_msg << msg; \
35 (ctSelf)->Log(cmCTest::logType, __FILE__, __LINE__,\
36 cmCTestLog_msg.str().c_str());\
37 } while ( 0 )
39 #ifdef cerr
40 # undef cerr
41 #endif
42 #define cerr no_cerr_use_cmCTestLog
44 #ifdef cout
45 # undef cout
46 #endif
47 #define cout no_cout_use_cmCTestLog
49 class cmCTest
51 public:
52 typedef std::vector<cmStdString> VectorOfStrings;
53 typedef std::set<cmStdString> SetOfStrings;
55 ///! Process Command line arguments
56 int Run(std::vector<std::string> &, std::string* output = 0);
58 /**
59 * Initialize and finalize testing
61 int Initialize(const char* binary_dir, bool new_tag = false,
62 bool verbose_tag = true);
63 bool InitializeFromCommand(cmCTestCommand* command, bool first = false);
64 void Finalize();
66 /**
67 * Process the tests. This is the main routine. The execution of the
68 * tests should look like this:
70 * ctest foo;
71 * foo.Initialize();
72 * // Set some things on foo
73 * foo.ProcessTests();
74 * foo.Finalize();
76 int ProcessTests();
79 * A utility function that returns the nightly time
81 struct tm* GetNightlyTime(std::string str,
82 bool tomorrowtag);
85 * Is the tomorrow tag set?
87 bool GetTomorrowTag() { return this->TomorrowTag; };
89 /**
90 * Try to run tests of the project
92 int TestDirectory(bool memcheck);
94 ///! what is the configuraiton type, e.g. Debug, Release etc.
95 std::string const& GetConfigType();
96 double GetTimeOut() { return this->TimeOut; }
97 void SetTimeOut(double t) { this->TimeOut = t; }
99 /**
100 * Check if CTest file exists
102 bool CTestFileExists(const std::string& filename);
103 bool AddIfExists(SetOfStrings& files, const char* file);
106 * Set the cmake test
108 bool SetTest(const char*, bool report = true);
111 * Set the cmake test mode (experimental, nightly, continuous).
113 void SetTestModel(int mode);
114 int GetTestModel() { return this->TestModel; };
116 std::string GetTestModelString();
117 static int GetTestModelFromString(const char* str);
118 static std::string CleanString(const std::string& str);
119 std::string GetCTestConfiguration(const char *name);
120 void SetCTestConfiguration(const char *name, const char* value);
121 void EmptyCTestConfiguration();
124 * constructor and destructor
126 cmCTest();
127 ~cmCTest();
129 //! Set the notes files to be created.
130 void SetNotesFiles(const char* notes);
132 void PopulateCustomVector(cmMakefile* mf, const char* definition,
133 VectorOfStrings& vec);
134 void PopulateCustomInteger(cmMakefile* mf, const char* def,
135 int& val);
137 ///! Get the current time as string
138 std::string CurrentTime();
140 /**
141 * Return the time remaianing that the script is allowed to run in
142 * seconds if the user has set the variable CTEST_TIME_LIMIT. If that has
143 * not been set it returns 1e7 seconds
145 double GetRemainingTimeAllowed();
147 ///! Open file in the output directory and set the stream
148 bool OpenOutputFile(const std::string& path,
149 const std::string& name,
150 cmGeneratedFileStream& stream,
151 bool compress = false);
153 ///! Convert string to something that is XML safe
154 static std::string MakeXMLSafe(const std::string&);
156 ///! Should we only show what we would do?
157 bool GetShowOnly();
160 * Run a single executable command and put the stdout and stderr
161 * in output.
163 * If verbose is false, no user-viewable output from the program
164 * being run will be generated.
166 * If timeout is specified, the command will be terminated after
167 * timeout expires. Timeout is specified in seconds.
169 * Argument retVal should be a pointer to the location where the
170 * exit code will be stored. If the retVal is not specified and
171 * the program exits with a code other than 0, then the this
172 * function will return false.
174 * If the command has spaces in the path the caller MUST call
175 * cmSystemTools::ConvertToRunCommandPath on the command before passing
176 * it into this function or it will not work. The command must be correctly
177 * escaped for this to with spaces.
179 bool RunCommand(const char* command,
180 std::string* stdOut, std::string* stdErr,
181 int* retVal = 0, const char* dir = 0, double timeout = 0.0);
183 //! Start CTest XML output file
184 void StartXML(std::ostream& ostr);
186 //! End CTest XML output file
187 void EndXML(std::ostream& ostr);
189 //! Run command specialized for make and configure. Returns process status
190 // and retVal is return value or exception.
191 int RunMakeCommand(const char* command, std::string* output,
192 int* retVal, const char* dir, int timeout,
193 std::ofstream& ofs);
196 * return the current tag
198 std::string GetCurrentTag();
200 //! Get the path to the build tree
201 std::string GetBinaryDir();
203 //! Get the short path to the file. This means if the file is in binary or
204 //source directory, it will become /.../relative/path/to/file
205 std::string GetShortPathToFile(const char* fname);
207 //! Get the path to CTest
208 const char* GetCTestExecutable() { return this->CTestSelf.c_str(); }
209 const char* GetCMakeExecutable() { return this->CMakeSelf.c_str(); }
211 enum {
212 EXPERIMENTAL,
213 NIGHTLY,
214 CONTINUOUS
217 // provide some more detailed info on the return code for ctest
218 enum {
219 UPDATE_ERRORS = 0x01,
220 CONFIGURE_ERRORS = 0x02,
221 BUILD_ERRORS = 0x04,
222 TEST_ERRORS = 0x08,
223 MEMORY_ERRORS = 0x10,
224 COVERAGE_ERRORS = 0x20,
225 SUBMIT_ERRORS = 0x40
228 ///! Are we producing XML
229 bool GetProduceXML();
230 void SetProduceXML(bool v);
232 //! Run command specialized for tests. Returns process status and retVal is
233 // return value or exception.
234 int RunTest(std::vector<const char*> args, std::string* output, int *retVal,
235 std::ostream* logfile, double testTimeOut);
238 * Execute handler and return its result. If the handler fails, it returns
239 * negative value.
241 int ExecuteHandler(const char* handler);
244 * Get the handler object
246 cmCTestGenericHandler* GetHandler(const char* handler);
247 cmCTestGenericHandler* GetInitializedHandler(const char* handler);
250 * Set the CTest variable from CMake variable
252 bool SetCTestConfigurationFromCMakeVariable(cmMakefile* mf,
253 const char* dconfig, const char* cmake_var);
255 //! Make string safe to be send as an URL
256 static std::string MakeURLSafe(const std::string&);
258 //! Should ctect configuration be updated. When using new style ctest
259 // script, this should be true.
260 void SetSuppressUpdatingCTestConfiguration(bool val)
262 this->SuppressUpdatingCTestConfiguration = val;
265 //! Add overwrite to ctest configuration.
266 // The format is key=value
267 void AddCTestConfigurationOverwrite(const char* encstr);
269 //! Create XML file that contains all the notes specified
270 int GenerateNotesFile(const std::vector<cmStdString> &files);
272 //! Submit extra files to the server
273 bool SubmitExtraFiles(const char* files);
274 bool SubmitExtraFiles(const std::vector<cmStdString> &files);
276 //! Set the output log file name
277 void SetOutputLogFileName(const char* name);
279 //! Set the visual studio or Xcode config type
280 void SetConfigType(const char* ct);
282 //! Various log types
283 enum {
284 DEBUG = 0,
285 OUTPUT,
286 HANDLER_OUTPUT,
287 HANDLER_VERBOSE_OUTPUT,
288 WARNING,
289 ERROR_MESSAGE,
290 OTHER
293 //! Add log to the output
294 void Log(int logType, const char* file, int line, const char* msg);
296 //! Get the version of dart server
297 int GetDartVersion() { return this->DartVersion; }
299 //! Add file to be submitted
300 void AddSubmitFile(const char* name);
301 SetOfStrings* GetSubmitFiles() { return &this->SubmitFiles; }
303 //! Read the custom configuration files and apply them to the current ctest
304 int ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf);
306 std::vector<cmStdString> &GetInitialCommandLineArguments()
307 { return this->InitialCommandLineArguments; };
309 //! Set the track to submit to
310 void SetSpecificTrack(const char* track);
311 const char* GetSpecificTrack();
313 private:
314 std::string ConfigType;
315 bool Verbose;
316 bool ExtraVerbose;
317 bool ProduceXML;
319 bool ForceNewCTestProcess;
321 bool RunConfigurationScript;
323 int GenerateNotesFile(const char* files);
325 // these are helper classes
326 typedef std::map<cmStdString,cmCTestGenericHandler*> t_TestingHandlers;
327 t_TestingHandlers TestingHandlers;
329 bool ShowOnly;
331 enum {
332 FIRST_TEST = 0,
333 UPDATE_TEST = 1,
334 START_TEST = 2,
335 CONFIGURE_TEST = 3,
336 BUILD_TEST = 4,
337 TEST_TEST = 5,
338 COVERAGE_TEST = 6,
339 MEMCHECK_TEST = 7,
340 SUBMIT_TEST = 8,
341 NOTES_TEST = 9,
342 ALL_TEST = 10,
343 LAST_TEST = 11
346 //! Map of configuration properties
347 typedef std::map<cmStdString, cmStdString> CTestConfigurationMap;
349 std::string CTestConfigFile;
350 CTestConfigurationMap CTestConfiguration;
351 CTestConfigurationMap CTestConfigurationOverwrites;
352 int Tests[LAST_TEST];
354 std::string CurrentTag;
355 bool TomorrowTag;
357 int TestModel;
358 std::string SpecificTrack;
360 double TimeOut;
362 int CompatibilityMode;
364 // information for the --build-and-test options
365 std::string CMakeSelf;
366 std::string CTestSelf;
367 std::string BinaryDir;
369 std::string NotesFiles;
372 bool InteractiveDebugMode;
374 bool ShortDateFormat;
376 bool CompressXMLFiles;
378 void BlockTestErrorDiagnostics();
381 //! parse the option after -D and convert it into the appropriate steps
382 bool AddTestsForDashboardType(std::string &targ);
384 //! parse and process most common command line arguments
385 void HandleCommandLineArguments(size_t &i,
386 std::vector<std::string> &args);
388 //! hande the -S -SP and -SR arguments
389 void HandleScriptArguments(size_t &i,
390 std::vector<std::string> &args,
391 bool &SRArgumentSpecified);
393 //! Reread the configuration file
394 bool UpdateCTestConfiguration();
396 //! Create not from files.
397 int GenerateCTestNotesOutput(std::ostream& os,
398 const VectorOfStrings& files);
400 ///! Find the running cmake
401 void FindRunningCMake();
403 //! Check if the argument is the one specified
404 bool CheckArgument(const std::string& arg, const char* varg1,
405 const char* varg2 = 0);
407 bool SuppressUpdatingCTestConfiguration;
409 bool Debug;
410 bool ShowLineNumbers;
411 bool Quiet;
413 int DartVersion;
415 std::set<cmStdString> SubmitFiles;
416 std::vector<cmStdString> InitialCommandLineArguments;
418 int SubmitIndex;
420 cmGeneratedFileStream* OutputLogFile;
421 int OutputLogFileLastTag;
424 class cmCTestLogWrite
426 public:
427 cmCTestLogWrite(const char* data, size_t length)
428 : Data(data), Length(length) {}
430 const char* Data;
431 size_t Length;
434 inline std::ostream& operator<< (std::ostream& os, const cmCTestLogWrite& c)
436 if (!c.Length)
438 return os;
440 os.write(c.Data, c.Length);
441 os.flush();
442 return os;
445 #endif