1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCTest.h,v $
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 =========================================================================*/
21 #include "cmStandardIncludes.h"
22 #include "cmListFileCache.h"
27 class cmCTestGenericHandler
;
28 class cmGeneratedFileStream
;
31 #define cmCTestLog(ctSelf, logType, msg) \
33 cmOStringStream cmCTestLog_msg; \
34 cmCTestLog_msg << msg; \
35 (ctSelf)->Log(cmCTest::logType, __FILE__, __LINE__,\
36 cmCTestLog_msg.str().c_str());\
42 #define cerr no_cerr_use_cmCTestLog
47 #define cout no_cout_use_cmCTestLog
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);
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);
67 * Process the tests. This is the main routine. The execution of the
68 * tests should look like this:
72 * // Set some things on foo
79 * A utility function that returns the nightly time
81 struct tm
* GetNightlyTime(std::string str
,
85 * Is the tomorrow tag set?
87 bool GetTomorrowTag() { return this->TomorrowTag
; };
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
; }
100 * Check if CTest file exists
102 bool CTestFileExists(const std::string
& filename
);
103 bool AddIfExists(SetOfStrings
& files
, const char* file
);
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
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
,
137 ///! Get the current time as string
138 std::string
CurrentTime();
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?
160 * Run a single executable command and put the stdout and stderr
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
,
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(); }
217 // provide some more detailed info on the return code for ctest
219 UPDATE_ERRORS
= 0x01,
220 CONFIGURE_ERRORS
= 0x02,
223 MEMORY_ERRORS
= 0x10,
224 COVERAGE_ERRORS
= 0x20,
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
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
287 HANDLER_VERBOSE_OUTPUT
,
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();
314 std::string ConfigType
;
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
;
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
;
358 std::string SpecificTrack
;
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
;
410 bool ShowLineNumbers
;
415 std::set
<cmStdString
> SubmitFiles
;
416 std::vector
<cmStdString
> InitialCommandLineArguments
;
420 cmGeneratedFileStream
* OutputLogFile
;
421 int OutputLogFileLastTag
;
424 class cmCTestLogWrite
427 cmCTestLogWrite(const char* data
, size_t length
)
428 : Data(data
), Length(length
) {}
434 inline std::ostream
& operator<< (std::ostream
& os
, const cmCTestLogWrite
& c
)
440 os
.write(c
.Data
, c
.Length
);