cmCTest.h 11 KB

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