cmCTest.h 11 KB

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