cmCTest.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 cmCTestBuildHandler;
  20. class cmCTestConfigureHandler;
  21. class cmCTestCoverageHandler;
  22. class cmCTestScriptHandler;
  23. class cmCTestTestHandler;
  24. class cmCTestUpdateHandler;
  25. class cmCTest
  26. {
  27. public:
  28. typedef std::vector<cmStdString> tm_VectorOfStrings;
  29. ///! Process Command line arguments
  30. int Run(std::vector<std::string>const&, std::string* output = 0);
  31. /**
  32. * Initialize and finalize testing
  33. */
  34. int Initialize();
  35. void Finalize();
  36. /**
  37. * Process the tests. This is the main routine. The execution of the
  38. * tests should look like this:
  39. *
  40. * ctest foo;
  41. * foo.Initialize();
  42. * // Set some things on foo
  43. * foo.ProcessTests();
  44. * foo.Finalize();
  45. */
  46. int ProcessTests();
  47. /*
  48. * A utility function that returns the nightly time
  49. */
  50. static struct tm* GetNightlyTime(std::string str,
  51. bool verbose,
  52. bool tomorrowtag);
  53. /*
  54. * Is the tomorrow tag set?
  55. */
  56. bool GetTomorrowTag() { return m_TomorrowTag; };
  57. /**
  58. * Try to run tests of the project
  59. */
  60. int TestDirectory(bool memcheck);
  61. /**
  62. * Do submit testing results
  63. */
  64. int SubmitResults();
  65. std::string GetSubmitResultsPrefix();
  66. ///! what is the configuraiton type, e.g. Debug, Release etc.
  67. std::string GetConfigType();
  68. /**
  69. * Check if CTest file exists
  70. */
  71. bool CTestFileExists(const std::string& filename);
  72. /**
  73. * Set the cmake test
  74. */
  75. bool SetTest(const char*, bool report = true);
  76. /**
  77. * Set the cmake test mode (experimental, nightly, continuous).
  78. */
  79. void SetTestModel(int mode);
  80. int GetTestModel() { return m_TestModel; };
  81. std::string GetTestModelString();
  82. static int GetTestModelFromString(const char* str);
  83. static std::string CleanString(const std::string& str);
  84. std::string GetDartConfiguration(const char *name);
  85. /**
  86. * constructor and destructor
  87. */
  88. cmCTest();
  89. ~cmCTest();
  90. //! Set the notes files to be created.
  91. void SetNotesFiles(const char* notes);
  92. std::string m_ConfigType;
  93. bool m_Verbose;
  94. bool m_DartMode;
  95. bool m_ForceNewCTestProcess;
  96. bool m_RunConfigurationScript;
  97. enum {
  98. EXPERIMENTAL,
  99. NIGHTLY,
  100. CONTINUOUS
  101. };
  102. // provide some more detailed info on the return code for ctest
  103. enum {
  104. UPDATE_ERRORS = 0x01,
  105. CONFIGURE_ERRORS = 0x02,
  106. BUILD_ERRORS = 0x04,
  107. TEST_ERRORS = 0x08,
  108. MEMORY_ERRORS = 0x10
  109. };
  110. int GenerateNotesFile(const char* files);
  111. bool OpenOutputFile(const std::string& path,
  112. const std::string& name, std::ofstream& stream);
  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. std::string GetToplevelPath();
  137. //! Run command specialized for tests. Returns process status and retVal is
  138. // return value or exception.
  139. int RunTest(std::vector<const char*> args, std::string* output, int *retVal,
  140. std::ostream* logfile);
  141. private:
  142. // these are helper classes
  143. cmCTestBuildHandler *BuildHandler;
  144. cmCTestCoverageHandler *CoverageHandler;
  145. cmCTestScriptHandler *ScriptHandler;
  146. cmCTestTestHandler *TestHandler;
  147. cmCTestUpdateHandler *UpdateHandler;
  148. cmCTestConfigureHandler *ConfigureHandler;
  149. bool m_ShowOnly;
  150. enum {
  151. FIRST_TEST = 0,
  152. UPDATE_TEST = 1,
  153. START_TEST = 2,
  154. CONFIGURE_TEST = 3,
  155. BUILD_TEST = 4,
  156. TEST_TEST = 5,
  157. COVERAGE_TEST = 6,
  158. MEMCHECK_TEST = 7,
  159. SUBMIT_TEST = 8,
  160. NOTES_TEST = 9,
  161. ALL_TEST = 10,
  162. LAST_TEST = 11
  163. };
  164. //! Map of configuration properties
  165. typedef std::map<std::string, std::string> tm_DartConfigurationMap;
  166. std::string m_ToplevelPath;
  167. tm_DartConfigurationMap m_DartConfiguration;
  168. int m_Tests[LAST_TEST];
  169. std::string m_CurrentTag;
  170. bool m_TomorrowTag;
  171. int m_TestModel;
  172. double m_TimeOut;
  173. int m_CompatibilityMode;
  174. // information for the --build-and-test options
  175. std::string m_ExecutableDirectory;
  176. std::string m_CMakeSelf;
  177. std::string m_CTestSelf;
  178. std::string m_SourceDir;
  179. std::string m_BinaryDir;
  180. std::string m_BuildRunDir;
  181. std::string m_BuildGenerator;
  182. std::string m_BuildMakeProgram;
  183. std::string m_BuildProject;
  184. std::string m_BuildTarget;
  185. std::vector<std::string> m_BuildOptions;
  186. std::string m_TestCommand;
  187. std::vector<std::string> m_TestCommandArgs;
  188. bool m_BuildTwoConfig;
  189. bool m_BuildNoClean;
  190. bool m_BuildNoCMake;
  191. std::string m_NotesFiles;
  192. int ReadCustomConfigurationFileTree(const char* dir);
  193. bool m_InteractiveDebugMode;
  194. bool m_ShortDateFormat;
  195. void BlockTestErrorDiagnostics();
  196. //! Reread the configuration file
  197. void UpdateCTestConfiguration();
  198. //! Create not from files.
  199. int GenerateDartNotesOutput(std::ostream& os, const tm_VectorOfStrings& files);
  200. ///! Run CMake and build a test and then run it as a single test.
  201. int RunCMakeAndTest(std::string* output);
  202. ///! Find the running cmake
  203. void FindRunningCMake(const char* arg0);
  204. };
  205. #endif