cmCTestTestHandler.h 7.6 KB

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