cmCTest.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. private:
  112. enum {
  113. FIRST_TEST = 0,
  114. UPDATE_TEST = 1,
  115. START_TEST = 2,
  116. CONFIGURE_TEST = 3,
  117. BUILD_TEST = 4,
  118. TEST_TEST = 5,
  119. COVERAGE_TEST = 6,
  120. MEMCHECK_TEST = 7,
  121. SUBMIT_TEST = 8,
  122. ALL_TEST = 9,
  123. LAST_TEST = 10
  124. };
  125. enum { // Program statuses
  126. NOT_RUN = 0,
  127. TIMEOUT,
  128. SEGFAULT,
  129. ILLEGAL,
  130. INTERRUPT,
  131. NUMERICAL,
  132. OTHER_FAULT,
  133. FAILED,
  134. BAD_COMMAND,
  135. COMPLETED
  136. };
  137. enum { // Memory checkers
  138. UNKNOWN = 0,
  139. VALGRIND,
  140. PURIFY,
  141. BOUNDS_CHECKER
  142. };
  143. enum { // Memory faults
  144. ABR = 0,
  145. ABW,
  146. ABWL,
  147. COR,
  148. EXU,
  149. FFM,
  150. FIM,
  151. FMM,
  152. FMR,
  153. FMW,
  154. FUM,
  155. IPR,
  156. IPW,
  157. MAF,
  158. MLK,
  159. MPK,
  160. NPR,
  161. ODS,
  162. PAR,
  163. PLK,
  164. UMC,
  165. UMR,
  166. NO_MEMORY_FAULT
  167. };
  168. struct cmCTestTestResult
  169. {
  170. std::string m_Name;
  171. std::string m_Path;
  172. std::string m_FullCommandLine;
  173. double m_ExecutionTime;
  174. int m_ReturnValue;
  175. int m_Status;
  176. std::string m_CompletionStatus;
  177. std::string m_Output;
  178. std::string m_RegressionImages;
  179. };
  180. struct cmCTestBuildErrorWarning
  181. {
  182. bool m_Error;
  183. int m_LogLine;
  184. std::string m_Text;
  185. std::string m_SourceFile;
  186. std::string m_SourceFileTail;
  187. int m_LineNumber;
  188. std::string m_PreContext;
  189. std::string m_PostContext;
  190. };
  191. // Some structures needed for cvs update
  192. struct StringPair :
  193. public std::pair<std::string, std::string>{};
  194. struct UpdateFiles : public std::vector<StringPair>{};
  195. struct AuthorsToUpdatesMap :
  196. public std::map<std::string, UpdateFiles>{};
  197. struct cmCTestCoverage
  198. {
  199. cmCTestCoverage()
  200. {
  201. m_AbsolutePath = "";
  202. m_FullPath = "";
  203. m_Covered = false;
  204. m_Tested = 0;
  205. m_UnTested = 0;
  206. m_Lines.clear();
  207. m_Show = false;
  208. }
  209. std::string m_AbsolutePath;
  210. std::string m_FullPath;
  211. bool m_Covered;
  212. int m_Tested;
  213. int m_UnTested;
  214. std::vector<int> m_Lines;
  215. bool m_Show;
  216. };
  217. typedef std::vector<cmCTestTestResult> tm_TestResultsVector;
  218. typedef std::map<std::string, std::string> tm_DartConfigurationMap;
  219. typedef std::map<std::string, cmCTestCoverage> tm_CoverageMap;
  220. tm_TestResultsVector m_TestResults;
  221. std::string m_ToplevelPath;
  222. tm_DartConfigurationMap m_DartConfiguration;
  223. int m_Tests[LAST_TEST];
  224. std::string m_CurrentTag;
  225. std::string m_StartBuild;
  226. std::string m_EndBuild;
  227. std::string m_StartTest;
  228. std::string m_EndTest;
  229. int m_TestModel;
  230. int m_TimeOut;
  231. std::string m_MemoryTester;
  232. std::string m_MemoryTesterOptions;
  233. int m_MemoryTesterStyle;
  234. std::string m_MemoryTesterOutputFile;
  235. tm_VectorOfStrings m_MemoryTesterOptionsParsed;
  236. int m_MemoryTesterGlobalResults[NO_MEMORY_FAULT];
  237. int m_CompatibilityMode;
  238. /**
  239. * Generate the Dart compatible output
  240. */
  241. void GenerateDartTestOutput(std::ostream& os);
  242. void GenerateDartMemCheckOutput(std::ostream& os);
  243. void GenerateDartBuildOutput(std::ostream& os,
  244. std::vector<cmCTestBuildErrorWarning>);
  245. bool OpenOutputFile(const std::string& path,
  246. const std::string& name, std::ofstream& stream);
  247. std::string MakeXMLSafe(const std::string&);
  248. std::string MakeURLSafe(const std::string&);
  249. //! Run command specialized for make and configure. Returns process status
  250. // and retVal is return value or exception.
  251. int RunMakeCommand(const char* command, std::string* output,
  252. int* retVal, const char* dir, bool verbose, int timeout,
  253. std::ofstream& ofs);
  254. //! Run command specialized for tests. Returns process status and retVal is
  255. // return value or exception.
  256. int RunTest(std::vector<const char*> args, std::string* output, int *retVal);
  257. std::string GenerateRegressionImages(const std::string& xml);
  258. const char* GetTestStatus(int status);
  259. //! Start CTest XML output file
  260. void StartXML(std::ostream& ostr);
  261. //! End CTest XML output file
  262. void EndXML(std::ostream& ostr);
  263. //! Parse Valgrind/Purify/Bounds Checker result out of the output string. After running,
  264. // log holds the output and results hold the different memmory errors.
  265. bool ProcessMemCheckOutput(const std::string& str, std::string& log, int* results);
  266. bool ProcessMemCheckValgrindOutput(const std::string& str, std::string& log, int* results);
  267. bool ProcessMemCheckPurifyOutput(const std::string& str, std::string& log, int* results);
  268. //! Initialize memory checking subsystem.
  269. bool InitializeMemoryChecking();
  270. };
  271. #endif