cmCTest.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. /**
  20. * Initialize and finalize testing
  21. */
  22. void Initialize();
  23. void Finalize();
  24. /**
  25. * Process the tests. This is the main routine. The execution of the
  26. * tests should look like this:
  27. *
  28. * ctest foo;
  29. * foo.Initialize();
  30. * // Set some things on foo
  31. * foo.ProcessTests();
  32. * foo.Finalize();
  33. */
  34. int ProcessTests();
  35. /**
  36. * Try to build the project
  37. */
  38. int BuildDirectory();
  39. /**
  40. * Try to run tests of the project
  41. */
  42. int TestDirectory();
  43. /**
  44. * Try to get coverage of the project
  45. */
  46. int CoverageDirectory();
  47. /**
  48. * Do revision control update of directory
  49. */
  50. int UpdateDirectory();
  51. /**
  52. * Do configure the project
  53. */
  54. int ConfigureDirectory();
  55. /**
  56. * Do submit testing results
  57. */
  58. int SubmitResults();
  59. std::string GetSubmitResultsPrefix();
  60. /**
  61. * Check if CTest file exists
  62. */
  63. bool CTestFileExists(const std::string& filename);
  64. /**
  65. * Run the test for a directory and any subdirectories
  66. */
  67. void ProcessDirectory(std::vector<std::string> &passed,
  68. std::vector<std::string> &failed);
  69. /**
  70. * Find the executable for a test
  71. */
  72. std::string FindTheExecutable(const char *exe);
  73. /**
  74. * Set the cmake test
  75. */
  76. bool SetTest(const char*);
  77. /**
  78. * Set the cmake test mode (experimental, nightly, continuous).
  79. */
  80. void SetTestModel(int mode)
  81. {
  82. m_TestModel = mode;
  83. }
  84. std::string GetTestModelString();
  85. /**
  86. * constructor
  87. */
  88. cmCTest();
  89. bool m_UseIncludeRegExp;
  90. std::string m_IncludeRegExp;
  91. bool m_UseExcludeRegExp;
  92. bool m_UseExcludeRegExpFirst;
  93. std::string m_ExcludeRegExp;
  94. std::string m_ConfigType;
  95. bool m_Verbose;
  96. bool m_DartMode;
  97. bool m_ShowOnly;
  98. enum {
  99. EXPERIMENTAL,
  100. NIGHTLY,
  101. CONTINUOUS
  102. };
  103. private:
  104. enum {
  105. FIRST_TEST = 0,
  106. UPDATE_TEST = 1,
  107. START_TEST = 2,
  108. CONFIGURE_TEST = 3,
  109. BUILD_TEST = 4,
  110. TEST_TEST = 5,
  111. COVERAGE_TEST = 6,
  112. PURIFY_TEST = 7,
  113. SUBMIT_TEST = 8,
  114. ALL_TEST = 9,
  115. LAST_TEST = 10
  116. };
  117. enum { // Program statuses
  118. NOT_RUN = 0,
  119. TIMEOUT,
  120. SEGFAULT,
  121. ILLEGAL,
  122. INTERRUPT,
  123. NUMERICAL,
  124. OTHER_FAULT,
  125. FAILED,
  126. BAD_COMMAND,
  127. COMPLETED
  128. };
  129. struct cmCTestTestResult
  130. {
  131. std::string m_Name;
  132. std::string m_Path;
  133. std::string m_FullCommandLine;
  134. double m_ExecutionTime;
  135. int m_ReturnValue;
  136. int m_Status;
  137. std::string m_CompletionStatus;
  138. std::string m_Output;
  139. std::string m_RegressionImages;
  140. };
  141. struct cmCTestBuildErrorWarning
  142. {
  143. bool m_Error;
  144. int m_LogLine;
  145. std::string m_Text;
  146. std::string m_SourceFile;
  147. std::string m_SourceFileTail;
  148. int m_LineNumber;
  149. std::string m_PreContext;
  150. std::string m_PostContext;
  151. };
  152. // Some structures needed for cvs update
  153. struct StringPair :
  154. public std::pair<std::string, std::string>{};
  155. struct UpdateFiles : public std::vector<StringPair>{};
  156. struct AuthorsToUpdatesMap :
  157. public std::map<std::string, UpdateFiles>{};
  158. struct cmCTestCoverage
  159. {
  160. cmCTestCoverage()
  161. {
  162. m_AbsolutePath = "";
  163. m_FullPath = "";
  164. m_Covered = false;
  165. m_Tested = 0;
  166. m_UnTested = 0;
  167. m_Lines.clear();
  168. m_Show = false;
  169. }
  170. std::string m_AbsolutePath;
  171. std::string m_FullPath;
  172. bool m_Covered;
  173. int m_Tested;
  174. int m_UnTested;
  175. std::vector<int> m_Lines;
  176. bool m_Show;
  177. };
  178. typedef std::vector<cmCTestTestResult> tm_TestResultsVector;
  179. typedef std::map<std::string, std::string> tm_DartConfigurationMap;
  180. typedef std::map<std::string, cmCTestCoverage> tm_CoverageMap;
  181. tm_TestResultsVector m_TestResults;
  182. std::string m_ToplevelPath;
  183. tm_DartConfigurationMap m_DartConfiguration;
  184. int m_Tests[LAST_TEST];
  185. std::string m_CurrentTag;
  186. std::string m_StartBuild;
  187. std::string m_EndBuild;
  188. std::string m_StartTest;
  189. std::string m_EndTest;
  190. int m_TestModel;
  191. int m_TimeOut;
  192. /**
  193. * Generate the Dart compatible output
  194. */
  195. void GenerateDartTestOutput(std::ostream& os);
  196. void GenerateDartBuildOutput(std::ostream& os,
  197. std::vector<cmCTestBuildErrorWarning>);
  198. bool OpenOutputFile(const std::string& path,
  199. const std::string& name, std::ofstream& stream);
  200. std::string MakeXMLSafe(const std::string&);
  201. std::string MakeURLSafe(const std::string&);
  202. //! Run command specialized for make and configure. Returns process status
  203. // and retVal is return value or exception.
  204. int RunMakeCommand(const char* command, std::string* output,
  205. int* retVal, const char* dir, bool verbose, int timeout,
  206. std::ofstream& ofs);
  207. //! Run command specialized for tests. Returns process status and retVal is
  208. // return value or exception.
  209. int RunTest(std::vector<const char*> args, std::string* output, int *retVal);
  210. std::string GenerateRegressionImages(const std::string& xml);
  211. const char* GetTestStatus(int status);
  212. };
  213. #endif