cmCTestTestHandler.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. 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 cmCTestTestHandler_h
  14. #define cmCTestTestHandler_h
  15. #include "cmCTestGenericHandler.h"
  16. #include <cmsys/RegularExpression.hxx>
  17. class cmMakefile;
  18. /** \class cmCTestTestHandler
  19. * \brief A class that handles ctest -S invocations
  20. *
  21. */
  22. class cmCTestTestHandler : public cmCTestGenericHandler
  23. {
  24. public:
  25. cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
  26. /**
  27. * The main entry point for this class
  28. */
  29. int ProcessHandler();
  30. /**
  31. * When both -R and -I are used should te resulting test list be the
  32. * intersection or the union of the lists. By default it is the
  33. * intersection.
  34. */
  35. void SetUseUnion(bool val) { this->UseUnion = val; }
  36. /**
  37. * This method is called when reading CTest custom file
  38. */
  39. void PopulateCustomVectors(cmMakefile *mf);
  40. ///! Control the use of the regular expresisons, call these methods to turn
  41. ///them on
  42. void UseIncludeRegExp();
  43. void UseExcludeRegExp();
  44. void SetIncludeRegExp(const char *);
  45. void SetExcludeRegExp(const char *);
  46. ///! pass the -I argument down
  47. void SetTestsToRunInformation(const char*);
  48. cmCTestTestHandler();
  49. /*
  50. * Add the test to the list of tests to be executed
  51. */
  52. bool AddTest(const std::vector<std::string>& args);
  53. /*
  54. * Set tests properties
  55. */
  56. bool SetTestsProperties(const std::vector<std::string>& args);
  57. void Initialize();
  58. // NOTE: This struct is Saved/Restored
  59. // in cmCTestTestHandler, if you add to this class
  60. // then you must add the new members to that code or
  61. // ctest -j N will break for that feature
  62. struct cmCTestTestProperties
  63. {
  64. cmStdString Name;
  65. cmStdString Directory;
  66. std::vector<std::string> Args;
  67. std::vector<std::string> Depends;
  68. std::vector<std::pair<cmsys::RegularExpression,
  69. std::string> > ErrorRegularExpressions;
  70. std::vector<std::pair<cmsys::RegularExpression,
  71. std::string> > RequiredRegularExpressions;
  72. std::map<cmStdString, cmStdString> Measurements;
  73. bool IsInBasedOnREOptions;
  74. bool WillFail;
  75. double Timeout;
  76. int Index;
  77. std::vector<std::string> Environment;
  78. std::vector<std::string> Labels;
  79. };
  80. struct cmCTestTestResult
  81. {
  82. std::string Name;
  83. std::string Path;
  84. std::string FullCommandLine;
  85. double ExecutionTime;
  86. int ReturnValue;
  87. int Status;
  88. std::string CompletionStatus;
  89. std::string Output;
  90. std::string RegressionImages;
  91. int TestCount;
  92. cmCTestTestProperties* Properties;
  93. };
  94. // add configuraitons to a search path for an executable
  95. static void AddConfigurations(cmCTest *ctest,
  96. std::vector<std::string> &attempted,
  97. std::vector<std::string> &attemptedConfigs,
  98. std::string filepath,
  99. std::string &filename);
  100. // full signature static method to find an executable
  101. static std::string FindExecutable(cmCTest *ctest,
  102. const char *testCommand,
  103. std::string &resultingConfig,
  104. std::vector<std::string> &extraPaths,
  105. std::vector<std::string> &failed);
  106. protected:
  107. // comput a final test list
  108. virtual int PreProcessHandler();
  109. virtual int PostProcessHandler();
  110. virtual void GenerateTestCommand(std::vector<const char*>& args);
  111. int ExecuteCommands(std::vector<cmStdString>& vec);
  112. void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
  113. void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
  114. //! Clean test output to specified length
  115. bool CleanTestOutput(std::string& output, size_t length);
  116. double ElapsedTestingTime;
  117. typedef std::vector<cmCTestTestResult> TestResultsVector;
  118. TestResultsVector TestResults;
  119. std::vector<cmStdString> CustomTestsIgnore;
  120. std::string StartTest;
  121. std::string EndTest;
  122. unsigned int StartTestTime;
  123. unsigned int EndTestTime;
  124. bool MemCheck;
  125. int CustomMaximumPassedTestOutputSize;
  126. int CustomMaximumFailedTestOutputSize;
  127. protected:
  128. /**
  129. * Run one test
  130. */
  131. virtual void ProcessOneTest(cmCTestTestProperties *props,
  132. std::vector<cmStdString> &passed,
  133. std::vector<cmStdString> &failed,
  134. int count, int tmsize);
  135. public:
  136. enum { // Program statuses
  137. NOT_RUN = 0,
  138. TIMEOUT,
  139. SEGFAULT,
  140. ILLEGAL,
  141. INTERRUPT,
  142. NUMERICAL,
  143. OTHER_FAULT,
  144. FAILED,
  145. BAD_COMMAND,
  146. COMPLETED
  147. };
  148. private:
  149. /**
  150. * Generate the Dart compatible output
  151. */
  152. virtual void GenerateDartOutput(std::ostream& os);
  153. /**
  154. * Run the tests for a directory and any subdirectories
  155. */
  156. void ProcessDirectory(std::vector<cmStdString> &passed,
  157. std::vector<cmStdString> &failed);
  158. typedef std::vector<cmCTestTestProperties> ListOfTests;
  159. /**
  160. * Get the list of tests in directory and subdirectories.
  161. */
  162. void GetListOfTests();
  163. // compute the lists of tests that will actually run
  164. // based on union regex and -I stuff
  165. void ComputeTestList();
  166. // Save the state of the test list and return the file
  167. // name it was saved to
  168. std::string SaveTestList();
  169. void LoadTestList();
  170. bool GetValue(const char* tag,
  171. std::string& value,
  172. std::ifstream& fin);
  173. bool GetValue(const char* tag,
  174. int& value,
  175. std::ifstream& fin);
  176. bool GetValue(const char* tag,
  177. size_t& value,
  178. std::ifstream& fin);
  179. bool GetValue(const char* tag,
  180. bool& value,
  181. std::ifstream& fin);
  182. bool GetValue(const char* tag,
  183. double& value,
  184. std::ifstream& fin);
  185. // run in -j N mode
  186. void ProcessParallel(std::vector<cmStdString> &passed,
  187. std::vector<cmStdString> &failed);
  188. /**
  189. * Find the executable for a test
  190. */
  191. std::string FindTheExecutable(const char *exe);
  192. const char* GetTestStatus(int status);
  193. void ExpandTestsToRunInformation(size_t numPossibleTests);
  194. std::vector<cmStdString> CustomPreTest;
  195. std::vector<cmStdString> CustomPostTest;
  196. std::vector<int> TestsToRun;
  197. bool UseIncludeLabelRegExpFlag;
  198. bool UseExcludeLabelRegExpFlag;
  199. bool UseIncludeRegExpFlag;
  200. bool UseExcludeRegExpFlag;
  201. bool UseExcludeRegExpFirst;
  202. std::string IncludeLabelRegExp;
  203. std::string ExcludeLabelRegExp;
  204. std::string IncludeRegExp;
  205. std::string ExcludeRegExp;
  206. cmsys::RegularExpression IncludeLabelRegularExpression;
  207. cmsys::RegularExpression ExcludeLabelRegularExpression;
  208. cmsys::RegularExpression IncludeTestsRegularExpression;
  209. cmsys::RegularExpression ExcludeTestsRegularExpression;
  210. std::string GenerateRegressionImages(const std::string& xml);
  211. cmsys::RegularExpression DartStuff1;
  212. void CheckLabelFilter(cmCTestTestProperties& it);
  213. void CheckLabelFilterExclude(cmCTestTestProperties& it);
  214. void CheckLabelFilterInclude(cmCTestTestProperties& it);
  215. std::string TestsToRunString;
  216. bool UseUnion;
  217. ListOfTests TestList;
  218. size_t TotalNumberOfTests;
  219. cmsys::RegularExpression DartStuff;
  220. std::ostream* LogFile;
  221. };
  222. #endif