cmCTest.h 11 KB

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