cmCTest.h 11 KB

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