cmCTest.h 6.1 KB

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