1
0

cmCTest.h 9.9 KB

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