cmCTest.h 7.8 KB

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