cmCTest.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmCTest_h
  14. #define cmCTest_h
  15. #include "cmStandardIncludes.h"
  16. #include "cmListFileCache.h"
  17. #include <time.h>
  18. class cmMakefile;
  19. class cmCTestGenericHandler;
  20. class cmGeneratedFileStream;
  21. class cmCTest
  22. {
  23. public:
  24. typedef std::vector<cmStdString> tm_VectorOfStrings;
  25. ///! Process Command line arguments
  26. int Run(std::vector<std::string>const&, std::string* output = 0);
  27. /**
  28. * Initialize and finalize testing
  29. */
  30. int Initialize(const char* binary_dir);
  31. void Finalize();
  32. /**
  33. * Process the tests. This is the main routine. The execution of the
  34. * tests should look like this:
  35. *
  36. * ctest foo;
  37. * foo.Initialize();
  38. * // Set some things on foo
  39. * foo.ProcessTests();
  40. * foo.Finalize();
  41. */
  42. int ProcessTests();
  43. /*
  44. * A utility function that returns the nightly time
  45. */
  46. static struct tm* GetNightlyTime(std::string str,
  47. bool verbose,
  48. bool tomorrowtag);
  49. /*
  50. * Is the tomorrow tag set?
  51. */
  52. bool GetTomorrowTag() { return m_TomorrowTag; };
  53. /**
  54. * Try to run tests of the project
  55. */
  56. int TestDirectory(bool memcheck);
  57. /**
  58. * Do submit testing results
  59. */
  60. int SubmitResults();
  61. std::string GetSubmitResultsPrefix();
  62. ///! what is the configuraiton type, e.g. Debug, Release etc.
  63. std::string GetConfigType();
  64. /**
  65. * Check if CTest file exists
  66. */
  67. bool CTestFileExists(const std::string& filename);
  68. bool AddIfExists(tm_VectorOfStrings& files, const char* file);
  69. /**
  70. * Set the cmake test
  71. */
  72. bool SetTest(const char*, bool report = true);
  73. /**
  74. * Set the cmake test mode (experimental, nightly, continuous).
  75. */
  76. void SetTestModel(int mode);
  77. int GetTestModel() { return m_TestModel; };
  78. std::string GetTestModelString();
  79. static int GetTestModelFromString(const char* str);
  80. static std::string CleanString(const std::string& str);
  81. std::string GetDartConfiguration(const char *name);
  82. /**
  83. * constructor and destructor
  84. */
  85. cmCTest();
  86. ~cmCTest();
  87. //! Set the notes files to be created.
  88. void SetNotesFiles(const char* notes);
  89. static void PopulateCustomVector(cmMakefile* mf, const char* definition,
  90. tm_VectorOfStrings& vec);
  91. static void PopulateCustomInteger(cmMakefile* mf, const char* def, int& val);
  92. ///! Get the current time as string
  93. std::string CurrentTime();
  94. ///! Open file in the output directory and set the stream
  95. bool OpenOutputFile(const std::string& path,
  96. const std::string& name,
  97. cmGeneratedFileStream& stream,
  98. bool compress = false);
  99. ///! Convert string to something that is XML safe
  100. static std::string MakeXMLSafe(const std::string&);
  101. ///! Should we only show what we would do?
  102. bool GetShowOnly();
  103. //! Start CTest XML output file
  104. void StartXML(std::ostream& ostr);
  105. //! End CTest XML output file
  106. void EndXML(std::ostream& ostr);
  107. //! Run command specialized for make and configure. Returns process status
  108. // and retVal is return value or exception.
  109. int RunMakeCommand(const char* command, std::string* output,
  110. int* retVal, const char* dir, bool verbose, int timeout,
  111. std::ofstream& ofs);
  112. /*
  113. * return the current tag
  114. */
  115. std::string GetCurrentTag();
  116. //! Get the path to the build tree
  117. std::string GetBinaryDir();
  118. //! Get the short path to the file. This means if the file is in binary or
  119. //source directory, it will become /.../relative/path/to/file
  120. std::string GetShortPathToFile(const char* fname);
  121. //! Get the path to CTest
  122. const char* GetCTestExecutable() { return m_CTestSelf.c_str(); }
  123. enum {
  124. EXPERIMENTAL,
  125. NIGHTLY,
  126. CONTINUOUS
  127. };
  128. // provide some more detailed info on the return code for ctest
  129. enum {
  130. UPDATE_ERRORS = 0x01,
  131. CONFIGURE_ERRORS = 0x02,
  132. BUILD_ERRORS = 0x04,
  133. TEST_ERRORS = 0x08,
  134. MEMORY_ERRORS = 0x10,
  135. COVERAGE_ERRORS = 0x20
  136. };
  137. ///! Are we producing XML
  138. bool GetProduceXML();
  139. void SetProduceXML(bool v);
  140. //! Run command specialized for tests. Returns process status and retVal is
  141. // return value or exception.
  142. int RunTest(std::vector<const char*> args, std::string* output, int *retVal,
  143. std::ostream* logfile);
  144. /**
  145. * Execute handler and return its result. If the handler fails, it returns negative value.
  146. */
  147. int ExecuteHandler(const char* handler);
  148. /*
  149. * Get the handler object
  150. */
  151. cmCTestGenericHandler* GetHandler(const char* handler);
  152. private:
  153. std::string m_ConfigType;
  154. bool m_Verbose;
  155. bool m_ProduceXML;
  156. bool m_ForceNewCTestProcess;
  157. bool m_RunConfigurationScript;
  158. int GenerateNotesFile(const char* files);
  159. static std::string MakeURLSafe(const std::string&);
  160. // these are helper classes
  161. typedef std::map<cmStdString,cmCTestGenericHandler*> t_TestingHandlers;
  162. t_TestingHandlers m_TestingHandlers;
  163. bool m_ShowOnly;
  164. enum {
  165. FIRST_TEST = 0,
  166. UPDATE_TEST = 1,
  167. START_TEST = 2,
  168. CONFIGURE_TEST = 3,
  169. BUILD_TEST = 4,
  170. TEST_TEST = 5,
  171. COVERAGE_TEST = 6,
  172. MEMCHECK_TEST = 7,
  173. SUBMIT_TEST = 8,
  174. NOTES_TEST = 9,
  175. ALL_TEST = 10,
  176. LAST_TEST = 11
  177. };
  178. //! Map of configuration properties
  179. typedef std::map<cmStdString, cmStdString> tm_DartConfigurationMap;
  180. tm_DartConfigurationMap m_DartConfiguration;
  181. int m_Tests[LAST_TEST];
  182. std::string m_CurrentTag;
  183. bool m_TomorrowTag;
  184. int m_TestModel;
  185. double m_TimeOut;
  186. int m_CompatibilityMode;
  187. // information for the --build-and-test options
  188. std::string m_ExecutableDirectory;
  189. std::string m_CMakeSelf;
  190. std::string m_CTestSelf;
  191. std::string m_SourceDir;
  192. std::string m_BinaryDir;
  193. std::string m_BuildRunDir;
  194. std::string m_BuildGenerator;
  195. std::string m_BuildMakeProgram;
  196. std::string m_BuildProject;
  197. std::string m_BuildTarget;
  198. std::vector<std::string> m_BuildOptions;
  199. std::string m_TestCommand;
  200. std::vector<std::string> m_TestCommandArgs;
  201. bool m_BuildTwoConfig;
  202. bool m_BuildNoClean;
  203. bool m_BuildNoCMake;
  204. std::string m_NotesFiles;
  205. int ReadCustomConfigurationFileTree(const char* dir);
  206. bool m_InteractiveDebugMode;
  207. bool m_ShortDateFormat;
  208. bool m_CompressXMLFiles;
  209. void BlockTestErrorDiagnostics();
  210. //! Reread the configuration file
  211. bool UpdateCTestConfiguration();
  212. //! Create not from files.
  213. int GenerateDartNotesOutput(std::ostream& os, const tm_VectorOfStrings& files);
  214. ///! Run CMake and build a test and then run it as a single test.
  215. int RunCMakeAndTest(std::string* output);
  216. ///! Find the running cmake
  217. void FindRunningCMake(const char* arg0);
  218. };
  219. #endif