cmCTest.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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();
  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. std::string m_ConfigType;
  90. bool m_Verbose;
  91. bool m_DartMode;
  92. bool m_ForceNewCTestProcess;
  93. bool m_RunConfigurationScript;
  94. enum {
  95. EXPERIMENTAL,
  96. NIGHTLY,
  97. CONTINUOUS
  98. };
  99. // provide some more detailed info on the return code for ctest
  100. enum {
  101. UPDATE_ERRORS = 0x01,
  102. CONFIGURE_ERRORS = 0x02,
  103. BUILD_ERRORS = 0x04,
  104. TEST_ERRORS = 0x08,
  105. MEMORY_ERRORS = 0x10,
  106. COVERAGE_ERRORS = 0x20
  107. };
  108. int GenerateNotesFile(const char* files);
  109. bool OpenOutputFile(const std::string& path,
  110. const std::string& name,
  111. cmGeneratedFileStream& stream,
  112. bool compress = false);
  113. static std::string MakeXMLSafe(const std::string&);
  114. static std::string MakeURLSafe(const std::string&);
  115. /*
  116. * return the current tag
  117. */
  118. std::string GetCurrentTag();
  119. ///! Get the current time as string
  120. std::string CurrentTime();
  121. ///! Should we only show what we would do?
  122. bool GetShowOnly();
  123. ///! Are we producing XML
  124. bool GetProduceXML();
  125. //! Start CTest XML output file
  126. void StartXML(std::ostream& ostr);
  127. //! End CTest XML output file
  128. void EndXML(std::ostream& ostr);
  129. //! Run command specialized for make and configure. Returns process status
  130. // and retVal is return value or exception.
  131. int RunMakeCommand(const char* command, std::string* output,
  132. int* retVal, const char* dir, bool verbose, int timeout,
  133. std::ofstream& ofs);
  134. static void PopulateCustomVector(cmMakefile* mf, const char* definition,
  135. tm_VectorOfStrings& vec);
  136. static void PopulateCustomInteger(cmMakefile* mf, const char* def, int& val);
  137. std::string GetToplevelPath();
  138. //! Run command specialized for tests. Returns process status and retVal is
  139. // return value or exception.
  140. int RunTest(std::vector<const char*> args, std::string* output, int *retVal,
  141. std::ostream* logfile);
  142. //! Get the path to CTest
  143. const char* GetCTestExecutable() { return m_CTestSelf.c_str(); }
  144. //! Get the short path to the file. This means if the file is in binary or
  145. //source directory, it will become /.../relative/path/to/file
  146. std::string GetShortPathToFile(const char* fname);
  147. private:
  148. // these are helper classes
  149. typedef std::map<cmStdString,cmCTestGenericHandler*> t_TestingHandlers;
  150. t_TestingHandlers m_TestingHandlers;
  151. bool m_ShowOnly;
  152. enum {
  153. FIRST_TEST = 0,
  154. UPDATE_TEST = 1,
  155. START_TEST = 2,
  156. CONFIGURE_TEST = 3,
  157. BUILD_TEST = 4,
  158. TEST_TEST = 5,
  159. COVERAGE_TEST = 6,
  160. MEMCHECK_TEST = 7,
  161. SUBMIT_TEST = 8,
  162. NOTES_TEST = 9,
  163. ALL_TEST = 10,
  164. LAST_TEST = 11
  165. };
  166. //! Map of configuration properties
  167. typedef std::map<cmStdString, cmStdString> tm_DartConfigurationMap;
  168. std::string m_ToplevelPath;
  169. tm_DartConfigurationMap m_DartConfiguration;
  170. int m_Tests[LAST_TEST];
  171. std::string m_CurrentTag;
  172. bool m_TomorrowTag;
  173. int m_TestModel;
  174. double m_TimeOut;
  175. int m_CompatibilityMode;
  176. // information for the --build-and-test options
  177. std::string m_ExecutableDirectory;
  178. std::string m_CMakeSelf;
  179. std::string m_CTestSelf;
  180. std::string m_SourceDir;
  181. std::string m_BinaryDir;
  182. std::string m_BuildRunDir;
  183. std::string m_BuildGenerator;
  184. std::string m_BuildMakeProgram;
  185. std::string m_BuildProject;
  186. std::string m_BuildTarget;
  187. std::vector<std::string> m_BuildOptions;
  188. std::string m_TestCommand;
  189. std::vector<std::string> m_TestCommandArgs;
  190. bool m_BuildTwoConfig;
  191. bool m_BuildNoClean;
  192. bool m_BuildNoCMake;
  193. std::string m_NotesFiles;
  194. int ReadCustomConfigurationFileTree(const char* dir);
  195. bool m_InteractiveDebugMode;
  196. bool m_ShortDateFormat;
  197. bool m_CompressXMLFiles;
  198. void BlockTestErrorDiagnostics();
  199. //! Reread the configuration file
  200. void UpdateCTestConfiguration();
  201. //! Create not from files.
  202. int GenerateDartNotesOutput(std::ostream& os, const tm_VectorOfStrings& files);
  203. ///! Run CMake and build a test and then run it as a single test.
  204. int RunCMakeAndTest(std::string* output);
  205. ///! Find the running cmake
  206. void FindRunningCMake(const char* arg0);
  207. };
  208. #endif