cmCTest.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. enum {
  126. FIRST_TEST = 0,
  127. UPDATE_TEST = 1,
  128. START_TEST = 2,
  129. CONFIGURE_TEST = 3,
  130. BUILD_TEST = 4,
  131. TEST_TEST = 5,
  132. COVERAGE_TEST = 6,
  133. MEMCHECK_TEST = 7,
  134. SUBMIT_TEST = 8,
  135. NOTES_TEST = 9,
  136. ALL_TEST = 10,
  137. LAST_TEST = 11
  138. };
  139. enum { // Program statuses
  140. NOT_RUN = 0,
  141. TIMEOUT,
  142. SEGFAULT,
  143. ILLEGAL,
  144. INTERRUPT,
  145. NUMERICAL,
  146. OTHER_FAULT,
  147. FAILED,
  148. BAD_COMMAND,
  149. COMPLETED
  150. };
  151. enum { // Memory checkers
  152. UNKNOWN = 0,
  153. VALGRIND,
  154. PURIFY,
  155. BOUNDS_CHECKER
  156. };
  157. enum { // Memory faults
  158. ABR = 0,
  159. ABW,
  160. ABWL,
  161. COR,
  162. EXU,
  163. FFM,
  164. FIM,
  165. FMM,
  166. FMR,
  167. FMW,
  168. FUM,
  169. IPR,
  170. IPW,
  171. MAF,
  172. MLK,
  173. MPK,
  174. NPR,
  175. ODS,
  176. PAR,
  177. PLK,
  178. UMC,
  179. UMR,
  180. NO_MEMORY_FAULT
  181. };
  182. struct cmCTestTestResult
  183. {
  184. std::string m_Name;
  185. std::string m_Path;
  186. std::string m_FullCommandLine;
  187. double m_ExecutionTime;
  188. int m_ReturnValue;
  189. int m_Status;
  190. std::string m_CompletionStatus;
  191. std::string m_Output;
  192. std::string m_RegressionImages;
  193. int m_TestCount;
  194. };
  195. struct cmCTestBuildErrorWarning
  196. {
  197. bool m_Error;
  198. int m_LogLine;
  199. std::string m_Text;
  200. std::string m_SourceFile;
  201. std::string m_SourceFileTail;
  202. int m_LineNumber;
  203. std::string m_PreContext;
  204. std::string m_PostContext;
  205. };
  206. struct cmCTestTestProperties
  207. {
  208. cmStdString m_Name;
  209. cmStdString m_Directory;
  210. tm_VectorOfListFileArgs m_Args;
  211. };
  212. typedef std::vector<cmCTestTestProperties> tm_ListOfTests;
  213. // Some structures needed for cvs update
  214. struct StringPair :
  215. public std::pair<std::string, std::string>{};
  216. struct UpdateFiles : public std::vector<StringPair>{};
  217. struct AuthorsToUpdatesMap :
  218. public std::map<std::string, UpdateFiles>{};
  219. struct cmCTestCoverage
  220. {
  221. cmCTestCoverage()
  222. {
  223. m_AbsolutePath = "";
  224. m_FullPath = "";
  225. m_Covered = false;
  226. m_Tested = 0;
  227. m_UnTested = 0;
  228. m_Lines.clear();
  229. m_Show = false;
  230. }
  231. std::string m_AbsolutePath;
  232. std::string m_FullPath;
  233. bool m_Covered;
  234. int m_Tested;
  235. int m_UnTested;
  236. std::vector<int> m_Lines;
  237. bool m_Show;
  238. };
  239. typedef std::vector<cmCTestTestResult> tm_TestResultsVector;
  240. typedef std::map<std::string, std::string> tm_DartConfigurationMap;
  241. typedef std::map<std::string, cmCTestCoverage> tm_CoverageMap;
  242. tm_TestResultsVector m_TestResults;
  243. std::string m_ToplevelPath;
  244. tm_DartConfigurationMap m_DartConfiguration;
  245. int m_Tests[LAST_TEST];
  246. std::string m_CurrentTag;
  247. bool m_TomorrowTag;
  248. std::string m_StartBuild;
  249. std::string m_EndBuild;
  250. std::string m_StartTest;
  251. std::string m_EndTest;
  252. int m_TestModel;
  253. int m_TimeOut;
  254. std::string m_MemoryTester;
  255. std::string m_MemoryTesterOptions;
  256. int m_MemoryTesterStyle;
  257. std::string m_MemoryTesterOutputFile;
  258. tm_VectorOfStrings m_MemoryTesterOptionsParsed;
  259. int m_MemoryTesterGlobalResults[NO_MEMORY_FAULT];
  260. int m_CompatibilityMode;
  261. // information for the --build-and-test options
  262. std::string m_ExecutableDirectory;
  263. std::string m_CMakeSelf;
  264. std::string m_CTestSelf;
  265. std::string m_SourceDir;
  266. std::string m_BinaryDir;
  267. std::string m_BuildRunDir;
  268. std::string m_BuildGenerator;
  269. std::string m_BuildMakeProgram;
  270. std::string m_BuildProject;
  271. std::string m_BuildTarget;
  272. std::vector<std::string> m_BuildOptions;
  273. std::string m_TestCommand;
  274. std::vector<std::string> m_TestCommandArgs;
  275. bool m_BuildTwoConfig;
  276. bool m_BuildNoClean;
  277. bool m_BuildNoCMake;
  278. std::string m_NotesFiles;
  279. int ReadCustomConfigurationFileTree(const char* dir);
  280. void PopulateCustomVector(cmMakefile* mf, const char* definition, tm_VectorOfStrings& vec);
  281. tm_VectorOfStrings m_CustomErrorMatches;
  282. tm_VectorOfStrings m_CustomErrorExceptions;
  283. tm_VectorOfStrings m_CustomWarningMatches;
  284. tm_VectorOfStrings m_CustomWarningExceptions;
  285. tm_VectorOfStrings m_CustomTestsIgnore;
  286. tm_VectorOfStrings m_CustomMemCheckIgnore;
  287. tm_VectorOfStrings m_CustomPreTest;
  288. tm_VectorOfStrings m_CustomPostTest;
  289. tm_VectorOfStrings m_CustomPreMemCheck;
  290. tm_VectorOfStrings m_CustomPostMemCheck;
  291. int ExecuteCommands(tm_VectorOfStrings& vec);
  292. /**
  293. * Get the list of tests in directory and subdirectories.
  294. */
  295. void GetListOfTests(tm_ListOfTests* testlist, bool memcheck);
  296. //! Reread the configuration file
  297. void UpdateCTestConfiguration();
  298. /**
  299. * Generate the Dart compatible output
  300. */
  301. void GenerateDartTestOutput(std::ostream& os);
  302. void GenerateDartMemCheckOutput(std::ostream& os);
  303. void GenerateDartBuildOutput(std::ostream& os,
  304. std::vector<cmCTestBuildErrorWarning>);
  305. bool OpenOutputFile(const std::string& path,
  306. const std::string& name, std::ofstream& stream);
  307. std::string MakeXMLSafe(const std::string&);
  308. std::string MakeURLSafe(const std::string&);
  309. //! Run command specialized for make and configure. Returns process status
  310. // and retVal is return value or exception.
  311. int RunMakeCommand(const char* command, std::string* output,
  312. int* retVal, const char* dir, bool verbose, int timeout,
  313. std::ofstream& ofs);
  314. //! Run command specialized for tests. Returns process status and retVal is
  315. // return value or exception.
  316. int RunTest(std::vector<const char*> args, std::string* output, int *retVal,
  317. std::ostream* logfile);
  318. std::string GenerateRegressionImages(const std::string& xml);
  319. const char* GetTestStatus(int status);
  320. //! Start CTest XML output file
  321. void StartXML(std::ostream& ostr);
  322. //! End CTest XML output file
  323. void EndXML(std::ostream& ostr);
  324. //! Create not from files.
  325. int GenerateDartNotesOutput(std::ostream& os, const tm_VectorOfStrings& files);
  326. //! Parse Valgrind/Purify/Bounds Checker result out of the output string. After running,
  327. // log holds the output and results hold the different memmory errors.
  328. bool ProcessMemCheckOutput(const std::string& str, std::string& log, int* results);
  329. bool ProcessMemCheckValgrindOutput(const std::string& str, std::string& log, int* results);
  330. bool ProcessMemCheckPurifyOutput(const std::string& str, std::string& log, int* results);
  331. ///! Run CMake and build a test and then run it as a single test.
  332. int RunCMakeAndTest(std::string* output);
  333. ///! Initialize memory checking subsystem.
  334. bool InitializeMemoryChecking();
  335. ///! Find the running cmake
  336. void FindRunningCMake(const char* arg0);
  337. };
  338. #endif