cmCTestTestHandler.h 7.4 KB

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