cmCTest.h 10 KB

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