cmCTest.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. class cmCTest
  17. {
  18. public:
  19. typedef std::vector<cmStdString> tm_VectorOfStrings;
  20. /**
  21. * Run a dashboard using a specified confiuration script
  22. */
  23. int RunConfigurationScript();
  24. /**
  25. * Initialize and finalize testing
  26. */
  27. void Initialize();
  28. void Finalize();
  29. /**
  30. * Process the tests. This is the main routine. The execution of the
  31. * tests should look like this:
  32. *
  33. * ctest foo;
  34. * foo.Initialize();
  35. * // Set some things on foo
  36. * foo.ProcessTests();
  37. * foo.Finalize();
  38. */
  39. int ProcessTests();
  40. /**
  41. * Try to build the project
  42. */
  43. int BuildDirectory();
  44. /**
  45. * Try to run tests of the project
  46. */
  47. int TestDirectory(bool memcheck);
  48. /**
  49. * Try to get coverage of the project
  50. */
  51. int CoverageDirectory();
  52. /**
  53. * Do revision control update of directory
  54. */
  55. int UpdateDirectory();
  56. /**
  57. * Do configure the project
  58. */
  59. int ConfigureDirectory();
  60. /**
  61. * Do submit testing results
  62. */
  63. int SubmitResults();
  64. std::string GetSubmitResultsPrefix();
  65. /**
  66. * Check if CTest file exists
  67. */
  68. bool CTestFileExists(const std::string& filename);
  69. /**
  70. * Run the test for a directory and any subdirectories
  71. */
  72. void ProcessDirectory(tm_VectorOfStrings &passed,
  73. tm_VectorOfStrings &failed,
  74. bool memcheck);
  75. /**
  76. * Find the executable for a test
  77. */
  78. std::string FindTheExecutable(const char *exe);
  79. /**
  80. * Set the cmake test
  81. */
  82. bool SetTest(const char*);
  83. /**
  84. * Set the cmake test mode (experimental, nightly, continuous).
  85. */
  86. void SetTestModel(int mode)
  87. {
  88. m_TestModel = mode;
  89. }
  90. std::string GetTestModelString();
  91. /**
  92. * constructor
  93. */
  94. cmCTest();
  95. bool m_UseIncludeRegExp;
  96. std::string m_IncludeRegExp;
  97. bool m_UseExcludeRegExp;
  98. bool m_UseExcludeRegExpFirst;
  99. std::string m_ExcludeRegExp;
  100. std::string m_ConfigType;
  101. bool m_Verbose;
  102. bool m_DartMode;
  103. bool m_ShowOnly;
  104. bool m_RunConfigurationScript;
  105. std::string m_ConfigurationScript;
  106. enum {
  107. EXPERIMENTAL,
  108. NIGHTLY,
  109. CONTINUOUS
  110. };
  111. int GenerateNotesFile(const char* files);
  112. private:
  113. enum {
  114. FIRST_TEST = 0,
  115. UPDATE_TEST = 1,
  116. START_TEST = 2,
  117. CONFIGURE_TEST = 3,
  118. BUILD_TEST = 4,
  119. TEST_TEST = 5,
  120. COVERAGE_TEST = 6,
  121. MEMCHECK_TEST = 7,
  122. SUBMIT_TEST = 8,
  123. NOTES_TEST = 9,
  124. ALL_TEST = 10,
  125. LAST_TEST = 11
  126. };
  127. enum { // Program statuses
  128. NOT_RUN = 0,
  129. TIMEOUT,
  130. SEGFAULT,
  131. ILLEGAL,
  132. INTERRUPT,
  133. NUMERICAL,
  134. OTHER_FAULT,
  135. FAILED,
  136. BAD_COMMAND,
  137. COMPLETED
  138. };
  139. enum { // Memory checkers
  140. UNKNOWN = 0,
  141. VALGRIND,
  142. PURIFY,
  143. BOUNDS_CHECKER
  144. };
  145. enum { // Memory faults
  146. ABR = 0,
  147. ABW,
  148. ABWL,
  149. COR,
  150. EXU,
  151. FFM,
  152. FIM,
  153. FMM,
  154. FMR,
  155. FMW,
  156. FUM,
  157. IPR,
  158. IPW,
  159. MAF,
  160. MLK,
  161. MPK,
  162. NPR,
  163. ODS,
  164. PAR,
  165. PLK,
  166. UMC,
  167. UMR,
  168. NO_MEMORY_FAULT
  169. };
  170. struct cmCTestTestResult
  171. {
  172. std::string m_Name;
  173. std::string m_Path;
  174. std::string m_FullCommandLine;
  175. double m_ExecutionTime;
  176. int m_ReturnValue;
  177. int m_Status;
  178. std::string m_CompletionStatus;
  179. std::string m_Output;
  180. std::string m_RegressionImages;
  181. };
  182. struct cmCTestBuildErrorWarning
  183. {
  184. bool m_Error;
  185. int m_LogLine;
  186. std::string m_Text;
  187. std::string m_SourceFile;
  188. std::string m_SourceFileTail;
  189. int m_LineNumber;
  190. std::string m_PreContext;
  191. std::string m_PostContext;
  192. };
  193. // Some structures needed for cvs update
  194. struct StringPair :
  195. public std::pair<std::string, std::string>{};
  196. struct UpdateFiles : public std::vector<StringPair>{};
  197. struct AuthorsToUpdatesMap :
  198. public std::map<std::string, UpdateFiles>{};
  199. struct cmCTestCoverage
  200. {
  201. cmCTestCoverage()
  202. {
  203. m_AbsolutePath = "";
  204. m_FullPath = "";
  205. m_Covered = false;
  206. m_Tested = 0;
  207. m_UnTested = 0;
  208. m_Lines.clear();
  209. m_Show = false;
  210. }
  211. std::string m_AbsolutePath;
  212. std::string m_FullPath;
  213. bool m_Covered;
  214. int m_Tested;
  215. int m_UnTested;
  216. std::vector<int> m_Lines;
  217. bool m_Show;
  218. };
  219. typedef std::vector<cmCTestTestResult> tm_TestResultsVector;
  220. typedef std::map<std::string, std::string> tm_DartConfigurationMap;
  221. typedef std::map<std::string, cmCTestCoverage> tm_CoverageMap;
  222. tm_TestResultsVector m_TestResults;
  223. std::string m_ToplevelPath;
  224. tm_DartConfigurationMap m_DartConfiguration;
  225. int m_Tests[LAST_TEST];
  226. std::string m_CurrentTag;
  227. std::string m_StartBuild;
  228. std::string m_EndBuild;
  229. std::string m_StartTest;
  230. std::string m_EndTest;
  231. int m_TestModel;
  232. int m_TimeOut;
  233. std::string m_MemoryTester;
  234. std::string m_MemoryTesterOptions;
  235. int m_MemoryTesterStyle;
  236. std::string m_MemoryTesterOutputFile;
  237. tm_VectorOfStrings m_MemoryTesterOptionsParsed;
  238. int m_MemoryTesterGlobalResults[NO_MEMORY_FAULT];
  239. int m_CompatibilityMode;
  240. /**
  241. * Generate the Dart compatible output
  242. */
  243. void GenerateDartTestOutput(std::ostream& os);
  244. void GenerateDartMemCheckOutput(std::ostream& os);
  245. void GenerateDartBuildOutput(std::ostream& os,
  246. std::vector<cmCTestBuildErrorWarning>);
  247. bool OpenOutputFile(const std::string& path,
  248. const std::string& name, std::ofstream& stream);
  249. std::string MakeXMLSafe(const std::string&);
  250. std::string MakeURLSafe(const std::string&);
  251. //! Run command specialized for make and configure. Returns process status
  252. // and retVal is return value or exception.
  253. int RunMakeCommand(const char* command, std::string* output,
  254. int* retVal, const char* dir, bool verbose, int timeout,
  255. std::ofstream& ofs);
  256. //! Run command specialized for tests. Returns process status and retVal is
  257. // return value or exception.
  258. int RunTest(std::vector<const char*> args, std::string* output, int *retVal);
  259. std::string GenerateRegressionImages(const std::string& xml);
  260. const char* GetTestStatus(int status);
  261. //! Start CTest XML output file
  262. void StartXML(std::ostream& ostr);
  263. //! End CTest XML output file
  264. void EndXML(std::ostream& ostr);
  265. //! Create not from files.
  266. int GenerateDartNotesOutput(std::ostream& os, const tm_VectorOfStrings& files);
  267. //! Parse Valgrind/Purify/Bounds Checker result out of the output string. After running,
  268. // log holds the output and results hold the different memmory errors.
  269. bool ProcessMemCheckOutput(const std::string& str, std::string& log, int* results);
  270. bool ProcessMemCheckValgrindOutput(const std::string& str, std::string& log, int* results);
  271. bool ProcessMemCheckPurifyOutput(const std::string& str, std::string& log, int* results);
  272. //! Initialize memory checking subsystem.
  273. bool InitializeMemoryChecking();
  274. };
  275. #endif