cmCTest.h 8.0 KB

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