cmCTestTestHandler.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc.
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmCTestTestHandler_h
  11. #define cmCTestTestHandler_h
  12. #include "cmCTestGenericHandler.h"
  13. #include <cmsys/RegularExpression.hxx>
  14. class cmMakefile;
  15. class cmXMLWriter;
  16. /** \class cmCTestTestHandler
  17. * \brief A class that handles ctest -S invocations
  18. *
  19. */
  20. class cmCTestTestHandler : public cmCTestGenericHandler
  21. {
  22. friend class cmCTestRunTest;
  23. friend class cmCTestMultiProcessHandler;
  24. friend class cmCTestBatchTestHandler;
  25. public:
  26. cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
  27. /**
  28. * The main entry point for this class
  29. */
  30. int ProcessHandler() CM_OVERRIDE;
  31. /**
  32. * When both -R and -I are used should te resulting test list be the
  33. * intersection or the union of the lists. By default it is the
  34. * intersection.
  35. */
  36. void SetUseUnion(bool val) { this->UseUnion = val; }
  37. /**
  38. * Set whether or not CTest should only execute the tests that failed
  39. * on the previous run. By default this is false.
  40. */
  41. void SetRerunFailed(bool val) { this->RerunFailed = val; }
  42. /**
  43. * This method is called when reading CTest custom file
  44. */
  45. void PopulateCustomVectors(cmMakefile* mf) CM_OVERRIDE;
  46. ///! Control the use of the regular expresisons, call these methods to turn
  47. /// them on
  48. void UseIncludeRegExp();
  49. void UseExcludeRegExp();
  50. void SetIncludeRegExp(const char*);
  51. void SetExcludeRegExp(const char*);
  52. void SetMaxIndex(int n) { this->MaxIndex = n; }
  53. int GetMaxIndex() { return this->MaxIndex; }
  54. void SetTestOutputSizePassed(int n)
  55. {
  56. this->CustomMaximumPassedTestOutputSize = n;
  57. }
  58. void SetTestOutputSizeFailed(int n)
  59. {
  60. this->CustomMaximumFailedTestOutputSize = n;
  61. }
  62. ///! pass the -I argument down
  63. void SetTestsToRunInformation(const char*);
  64. cmCTestTestHandler();
  65. /*
  66. * Add the test to the list of tests to be executed
  67. */
  68. bool AddTest(const std::vector<std::string>& args);
  69. /*
  70. * Set tests properties
  71. */
  72. bool SetTestsProperties(const std::vector<std::string>& args);
  73. void Initialize() CM_OVERRIDE;
  74. // NOTE: This struct is Saved/Restored
  75. // in cmCTestTestHandler, if you add to this class
  76. // then you must add the new members to that code or
  77. // ctest -j N will break for that feature
  78. struct cmCTestTestProperties
  79. {
  80. std::string Name;
  81. std::string Directory;
  82. std::vector<std::string> Args;
  83. std::vector<std::string> RequiredFiles;
  84. std::vector<std::string> Depends;
  85. std::vector<std::string> AttachedFiles;
  86. std::vector<std::string> AttachOnFail;
  87. std::vector<std::pair<cmsys::RegularExpression, std::string> >
  88. ErrorRegularExpressions;
  89. std::vector<std::pair<cmsys::RegularExpression, std::string> >
  90. RequiredRegularExpressions;
  91. std::vector<std::pair<cmsys::RegularExpression, std::string> >
  92. TimeoutRegularExpressions;
  93. std::map<std::string, std::string> Measurements;
  94. bool IsInBasedOnREOptions;
  95. bool WillFail;
  96. float Cost;
  97. int PreviousRuns;
  98. bool RunSerial;
  99. double Timeout;
  100. bool ExplicitTimeout;
  101. double AlternateTimeout;
  102. int Index;
  103. // Requested number of process slots
  104. int Processors;
  105. // return code of test which will mark test as "not run"
  106. int SkipReturnCode;
  107. std::vector<std::string> Environment;
  108. std::vector<std::string> Labels;
  109. std::set<std::string> LockedResources;
  110. };
  111. struct cmCTestTestResult
  112. {
  113. std::string Name;
  114. std::string Path;
  115. std::string Reason;
  116. std::string FullCommandLine;
  117. double ExecutionTime;
  118. int ReturnValue;
  119. int Status;
  120. bool CompressOutput;
  121. std::string CompletionStatus;
  122. std::string Output;
  123. std::string DartString;
  124. int TestCount;
  125. cmCTestTestProperties* Properties;
  126. };
  127. struct cmCTestTestResultLess
  128. {
  129. bool operator()(const cmCTestTestResult& lhs,
  130. const cmCTestTestResult& rhs) const
  131. {
  132. return lhs.TestCount < rhs.TestCount;
  133. }
  134. };
  135. // add configurations to a search path for an executable
  136. static void AddConfigurations(cmCTest* ctest,
  137. std::vector<std::string>& attempted,
  138. std::vector<std::string>& attemptedConfigs,
  139. std::string filepath, std::string& filename);
  140. // full signature static method to find an executable
  141. static std::string FindExecutable(cmCTest* ctest, const char* testCommand,
  142. std::string& resultingConfig,
  143. std::vector<std::string>& extraPaths,
  144. std::vector<std::string>& failed);
  145. typedef std::vector<cmCTestTestProperties> ListOfTests;
  146. protected:
  147. // compute a final test list
  148. virtual int PreProcessHandler();
  149. virtual int PostProcessHandler();
  150. virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
  151. int ExecuteCommands(std::vector<std::string>& vec);
  152. void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result);
  153. void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result);
  154. // Write attached test files into the xml
  155. void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result);
  156. //! Clean test output to specified length
  157. bool CleanTestOutput(std::string& output, size_t length);
  158. double ElapsedTestingTime;
  159. typedef std::vector<cmCTestTestResult> TestResultsVector;
  160. TestResultsVector TestResults;
  161. std::vector<std::string> CustomTestsIgnore;
  162. std::string StartTest;
  163. std::string EndTest;
  164. unsigned int StartTestTime;
  165. unsigned int EndTestTime;
  166. bool MemCheck;
  167. int CustomMaximumPassedTestOutputSize;
  168. int CustomMaximumFailedTestOutputSize;
  169. int MaxIndex;
  170. public:
  171. enum
  172. { // Program statuses
  173. NOT_RUN = 0,
  174. TIMEOUT,
  175. SEGFAULT,
  176. ILLEGAL,
  177. INTERRUPT,
  178. NUMERICAL,
  179. OTHER_FAULT,
  180. FAILED,
  181. BAD_COMMAND,
  182. COMPLETED
  183. };
  184. private:
  185. /**
  186. * Generate the Dart compatible output
  187. */
  188. virtual void GenerateDartOutput(cmXMLWriter& xml);
  189. void PrintLabelSummary();
  190. /**
  191. * Run the tests for a directory and any subdirectories
  192. */
  193. void ProcessDirectory(std::vector<std::string>& passed,
  194. std::vector<std::string>& failed);
  195. /**
  196. * Get the list of tests in directory and subdirectories.
  197. */
  198. void GetListOfTests();
  199. // compute the lists of tests that will actually run
  200. // based on union regex and -I stuff
  201. void ComputeTestList();
  202. // compute the lists of tests that will actually run
  203. // based on LastTestFailed.log
  204. void ComputeTestListForRerunFailed();
  205. void UpdateMaxTestNameWidth();
  206. bool GetValue(const char* tag, std::string& value, std::istream& fin);
  207. bool GetValue(const char* tag, int& value, std::istream& fin);
  208. bool GetValue(const char* tag, size_t& value, std::istream& fin);
  209. bool GetValue(const char* tag, bool& value, std::istream& fin);
  210. bool GetValue(const char* tag, double& value, std::istream& fin);
  211. /**
  212. * Find the executable for a test
  213. */
  214. std::string FindTheExecutable(const char* exe);
  215. const char* GetTestStatus(int status);
  216. void ExpandTestsToRunInformation(size_t numPossibleTests);
  217. void ExpandTestsToRunInformationForRerunFailed();
  218. std::vector<std::string> CustomPreTest;
  219. std::vector<std::string> CustomPostTest;
  220. std::vector<int> TestsToRun;
  221. bool UseIncludeLabelRegExpFlag;
  222. bool UseExcludeLabelRegExpFlag;
  223. bool UseIncludeRegExpFlag;
  224. bool UseExcludeRegExpFlag;
  225. bool UseExcludeRegExpFirst;
  226. std::string IncludeLabelRegExp;
  227. std::string ExcludeLabelRegExp;
  228. std::string IncludeRegExp;
  229. std::string ExcludeRegExp;
  230. cmsys::RegularExpression IncludeLabelRegularExpression;
  231. cmsys::RegularExpression ExcludeLabelRegularExpression;
  232. cmsys::RegularExpression IncludeTestsRegularExpression;
  233. cmsys::RegularExpression ExcludeTestsRegularExpression;
  234. void GenerateRegressionImages(cmXMLWriter& xml, const std::string& dart);
  235. cmsys::RegularExpression DartStuff1;
  236. void CheckLabelFilter(cmCTestTestProperties& it);
  237. void CheckLabelFilterExclude(cmCTestTestProperties& it);
  238. void CheckLabelFilterInclude(cmCTestTestProperties& it);
  239. std::string TestsToRunString;
  240. bool UseUnion;
  241. ListOfTests TestList;
  242. size_t TotalNumberOfTests;
  243. cmsys::RegularExpression DartStuff;
  244. std::ostream* LogFile;
  245. bool RerunFailed;
  246. };
  247. #endif