cmCTestTestHandler.h 8.7 KB

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