cmCTest.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. class cmCTest
  17. {
  18. public:
  19. typedef std::vector<cmStdString> tm_VectorOfStrings;
  20. ///! Process Command line arguments
  21. int Run(std::vector<std::string>const&, std::string* output = 0);
  22. /**
  23. * Run a dashboard using a specified confiuration script
  24. */
  25. int RunConfigurationScript();
  26. /**
  27. * Initialize and finalize testing
  28. */
  29. void Initialize();
  30. void Finalize();
  31. /**
  32. * Process the tests. This is the main routine. The execution of the
  33. * tests should look like this:
  34. *
  35. * ctest foo;
  36. * foo.Initialize();
  37. * // Set some things on foo
  38. * foo.ProcessTests();
  39. * foo.Finalize();
  40. */
  41. int ProcessTests();
  42. /**
  43. * Try to build the project
  44. */
  45. int BuildDirectory();
  46. /**
  47. * Try to run tests of the project
  48. */
  49. int TestDirectory(bool memcheck);
  50. /**
  51. * Try to get coverage of the project
  52. */
  53. int CoverageDirectory();
  54. /**
  55. * Do revision control update of directory
  56. */
  57. int UpdateDirectory();
  58. /**
  59. * Do configure the project
  60. */
  61. int ConfigureDirectory();
  62. /**
  63. * Do submit testing results
  64. */
  65. int SubmitResults();
  66. std::string GetSubmitResultsPrefix();
  67. /**
  68. * Check if CTest file exists
  69. */
  70. bool CTestFileExists(const std::string& filename);
  71. /**
  72. * Run the test for a directory and any subdirectories
  73. */
  74. void ProcessDirectory(tm_VectorOfStrings &passed,
  75. tm_VectorOfStrings &failed,
  76. bool memcheck);
  77. /**
  78. * Find the executable for a test
  79. */
  80. std::string FindTheExecutable(const char *exe);
  81. /**
  82. * Set the cmake test
  83. */
  84. bool SetTest(const char*);
  85. /**
  86. * Set the cmake test mode (experimental, nightly, continuous).
  87. */
  88. void SetTestModel(int mode)
  89. {
  90. m_TestModel = mode;
  91. }
  92. std::string GetTestModelString();
  93. static int GetTestModelFromString(const char* str);
  94. /**
  95. * constructor
  96. */
  97. cmCTest();
  98. //! Set the notes files to be created.
  99. void SetNotesFiles(const char* notes);
  100. bool m_UseIncludeRegExp;
  101. std::string m_IncludeRegExp;
  102. bool m_UseExcludeRegExp;
  103. bool m_UseExcludeRegExpFirst;
  104. std::string m_ExcludeRegExp;
  105. std::string m_ConfigType;
  106. bool m_Verbose;
  107. bool m_DartMode;
  108. bool m_ShowOnly;
  109. bool m_RunConfigurationScript;
  110. std::string m_ConfigurationScript;
  111. enum {
  112. EXPERIMENTAL,
  113. NIGHTLY,
  114. CONTINUOUS
  115. };
  116. int GenerateNotesFile(const char* files);
  117. private:
  118. enum {
  119. FIRST_TEST = 0,
  120. UPDATE_TEST = 1,
  121. START_TEST = 2,
  122. CONFIGURE_TEST = 3,
  123. BUILD_TEST = 4,
  124. TEST_TEST = 5,
  125. COVERAGE_TEST = 6,
  126. MEMCHECK_TEST = 7,
  127. SUBMIT_TEST = 8,
  128. NOTES_TEST = 9,
  129. ALL_TEST = 10,
  130. LAST_TEST = 11
  131. };
  132. enum { // Program statuses
  133. NOT_RUN = 0,
  134. TIMEOUT,
  135. SEGFAULT,
  136. ILLEGAL,
  137. INTERRUPT,
  138. NUMERICAL,
  139. OTHER_FAULT,
  140. FAILED,
  141. BAD_COMMAND,
  142. COMPLETED
  143. };
  144. enum { // Memory checkers
  145. UNKNOWN = 0,
  146. VALGRIND,
  147. PURIFY,
  148. BOUNDS_CHECKER
  149. };
  150. enum { // Memory faults
  151. ABR = 0,
  152. ABW,
  153. ABWL,
  154. COR,
  155. EXU,
  156. FFM,
  157. FIM,
  158. FMM,
  159. FMR,
  160. FMW,
  161. FUM,
  162. IPR,
  163. IPW,
  164. MAF,
  165. MLK,
  166. MPK,
  167. NPR,
  168. ODS,
  169. PAR,
  170. PLK,
  171. UMC,
  172. UMR,
  173. NO_MEMORY_FAULT
  174. };
  175. struct cmCTestTestResult
  176. {
  177. std::string m_Name;
  178. std::string m_Path;
  179. std::string m_FullCommandLine;
  180. double m_ExecutionTime;
  181. int m_ReturnValue;
  182. int m_Status;
  183. std::string m_CompletionStatus;
  184. std::string m_Output;
  185. std::string m_RegressionImages;
  186. };
  187. struct cmCTestBuildErrorWarning
  188. {
  189. bool m_Error;
  190. int m_LogLine;
  191. std::string m_Text;
  192. std::string m_SourceFile;
  193. std::string m_SourceFileTail;
  194. int m_LineNumber;
  195. std::string m_PreContext;
  196. std::string m_PostContext;
  197. };
  198. // Some structures needed for cvs update
  199. struct StringPair :
  200. public std::pair<std::string, std::string>{};
  201. struct UpdateFiles : public std::vector<StringPair>{};
  202. struct AuthorsToUpdatesMap :
  203. public std::map<std::string, UpdateFiles>{};
  204. struct cmCTestCoverage
  205. {
  206. cmCTestCoverage()
  207. {
  208. m_AbsolutePath = "";
  209. m_FullPath = "";
  210. m_Covered = false;
  211. m_Tested = 0;
  212. m_UnTested = 0;
  213. m_Lines.clear();
  214. m_Show = false;
  215. }
  216. std::string m_AbsolutePath;
  217. std::string m_FullPath;
  218. bool m_Covered;
  219. int m_Tested;
  220. int m_UnTested;
  221. std::vector<int> m_Lines;
  222. bool m_Show;
  223. };
  224. typedef std::vector<cmCTestTestResult> tm_TestResultsVector;
  225. typedef std::map<std::string, std::string> tm_DartConfigurationMap;
  226. typedef std::map<std::string, cmCTestCoverage> tm_CoverageMap;
  227. tm_TestResultsVector m_TestResults;
  228. std::string m_ToplevelPath;
  229. tm_DartConfigurationMap m_DartConfiguration;
  230. int m_Tests[LAST_TEST];
  231. std::string m_CurrentTag;
  232. std::string m_StartBuild;
  233. std::string m_EndBuild;
  234. std::string m_StartTest;
  235. std::string m_EndTest;
  236. int m_TestModel;
  237. int m_TimeOut;
  238. std::string m_MemoryTester;
  239. std::string m_MemoryTesterOptions;
  240. int m_MemoryTesterStyle;
  241. std::string m_MemoryTesterOutputFile;
  242. tm_VectorOfStrings m_MemoryTesterOptionsParsed;
  243. int m_MemoryTesterGlobalResults[NO_MEMORY_FAULT];
  244. int m_CompatibilityMode;
  245. // information for the --build-and-test options
  246. std::string m_ExecutableDirectory;
  247. std::string m_CMakeSelf;
  248. std::string m_CTestSelf;
  249. std::string m_SourceDir;
  250. std::string m_BinaryDir;
  251. std::string m_BuildRunDir;
  252. std::string m_BuildGenerator;
  253. std::string m_BuildMakeProgram;
  254. std::string m_BuildProject;
  255. std::string m_BuildTarget;
  256. std::vector<std::string> m_BuildOptions;
  257. std::string m_TestCommand;
  258. std::vector<std::string> m_TestCommandArgs;
  259. bool m_BuildTwoConfig;
  260. bool m_BuildNoClean;
  261. bool m_BuildNoCMake;
  262. std::string m_NotesFiles;
  263. //! Reread the configuration file
  264. void UpdateCTestConfiguration();
  265. /**
  266. * Generate the Dart compatible output
  267. */
  268. void GenerateDartTestOutput(std::ostream& os);
  269. void GenerateDartMemCheckOutput(std::ostream& os);
  270. void GenerateDartBuildOutput(std::ostream& os,
  271. std::vector<cmCTestBuildErrorWarning>);
  272. bool OpenOutputFile(const std::string& path,
  273. const std::string& name, std::ofstream& stream);
  274. std::string MakeXMLSafe(const std::string&);
  275. std::string MakeURLSafe(const std::string&);
  276. //! Run command specialized for make and configure. Returns process status
  277. // and retVal is return value or exception.
  278. int RunMakeCommand(const char* command, std::string* output,
  279. int* retVal, const char* dir, bool verbose, int timeout,
  280. std::ofstream& ofs);
  281. //! Run command specialized for tests. Returns process status and retVal is
  282. // return value or exception.
  283. int RunTest(std::vector<const char*> args, std::string* output, int *retVal);
  284. std::string GenerateRegressionImages(const std::string& xml);
  285. const char* GetTestStatus(int status);
  286. //! Start CTest XML output file
  287. void StartXML(std::ostream& ostr);
  288. //! End CTest XML output file
  289. void EndXML(std::ostream& ostr);
  290. //! Create not from files.
  291. int GenerateDartNotesOutput(std::ostream& os, const tm_VectorOfStrings& files);
  292. //! Parse Valgrind/Purify/Bounds Checker result out of the output string. After running,
  293. // log holds the output and results hold the different memmory errors.
  294. bool ProcessMemCheckOutput(const std::string& str, std::string& log, int* results);
  295. bool ProcessMemCheckValgrindOutput(const std::string& str, std::string& log, int* results);
  296. bool ProcessMemCheckPurifyOutput(const std::string& str, std::string& log, int* results);
  297. ///! Run CMake and build a test and then run it as a single test.
  298. int RunCMakeAndTest(std::string* output);
  299. ///! Initialize memory checking subsystem.
  300. bool InitializeMemoryChecking();
  301. ///! Find the running cmake
  302. void FindRunningCMake(const char* arg0);
  303. };
  304. #endif