cmCTest.h 9.9 KB

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