cmCTestTestHandler.h 9.07 KB
Newer Older
1
2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
Ken Martin's avatar
Ken Martin committed
3
4
5
#ifndef cmCTestTestHandler_h
#define cmCTestTestHandler_h

6
#include "cmConfigure.h" // IWYU pragma: keep
7

8
#include "cmCTestGenericHandler.h"
Brad King's avatar
Brad King committed
9

10
#include "cmsys/RegularExpression.hxx"
11
12
13
14
15
16
17
#include <iosfwd>
#include <map>
#include <set>
#include <stddef.h>
#include <string>
#include <utility>
#include <vector>
Ken Martin's avatar
Ken Martin committed
18

19
class cmCTest;
Ken Martin's avatar
Ken Martin committed
20
class cmMakefile;
21
class cmXMLWriter;
Ken Martin's avatar
Ken Martin committed
22
23
24
25
26

/** \class cmCTestTestHandler
 * \brief A class that handles ctest -S invocations
 *
 */
27
class cmCTestTestHandler : public cmCTestGenericHandler
Ken Martin's avatar
Ken Martin committed
28
{
29
  friend class cmCTestRunTest;
30
  friend class cmCTestMultiProcessHandler;
31
  friend class cmCTestBatchTestHandler;
32

Ken Martin's avatar
Ken Martin committed
33
public:
34
  typedef cmCTestGenericHandler Superclass;
Ken Martin's avatar
Ken Martin committed
35

36
  /**
Ken Martin's avatar
Ken Martin committed
37
38
   * The main entry point for this class
   */
39
  int ProcessHandler() CM_OVERRIDE;
Andy Cedilnik's avatar
Andy Cedilnik committed
40

41
  /**
42
43
44
45
   * When both -R and -I are used should te resulting test list be the
   * intersection or the union of the lists. By default it is the
   * intersection.
   */
Andy Cedilnik's avatar
Andy Cedilnik committed
46
  void SetUseUnion(bool val) { this->UseUnion = val; }
47

48
49
50
51
52
53
  /**
   * Set whether or not CTest should only execute the tests that failed
   * on the previous run.  By default this is false.
   */
  void SetRerunFailed(bool val) { this->RerunFailed = val; }

54
55
56
  /**
   * This method is called when reading CTest custom file
   */
57
  void PopulateCustomVectors(cmMakefile* mf) CM_OVERRIDE;
Andy Cedilnik's avatar
Andy Cedilnik committed
58

Ken Martin's avatar
Ken Martin committed
59
  ///! Control the use of the regular expresisons, call these methods to turn
60
  /// them on
Ken Martin's avatar
Ken Martin committed
61
62
  void UseIncludeRegExp();
  void UseExcludeRegExp();
63
64
  void SetIncludeRegExp(const char*);
  void SetExcludeRegExp(const char*);
Andy Cedilnik's avatar
Andy Cedilnik committed
65

66
67
  void SetMaxIndex(int n) { this->MaxIndex = n; }
  int GetMaxIndex() { return this->MaxIndex; }
Ken Martin's avatar
Ken Martin committed
68

69
  void SetTestOutputSizePassed(int n)
70
71
72
  {
    this->CustomMaximumPassedTestOutputSize = n;
  }
73
  void SetTestOutputSizeFailed(int n)
74
75
76
  {
    this->CustomMaximumFailedTestOutputSize = n;
  }
77

Ken Martin's avatar
Ken Martin committed
78
79
80
  ///! pass the -I argument down
  void SetTestsToRunInformation(const char*);

81
  cmCTestTestHandler();
Ken Martin's avatar
Ken Martin committed
82

83
84
85
  /*
   * Add the test to the list of tests to be executed
   */
86
  bool AddTest(const std::vector<std::string>& args);
87

88
89
90
91
92
  /*
   * Set tests properties
   */
  bool SetTestsProperties(const std::vector<std::string>& args);

93
94
95
96
97
  /**
   * Set directory properties
   */
  bool SetDirectoryProperties(const std::vector<std::string>& args);

98
  void Initialize() CM_OVERRIDE;
99

Bill Hoffman's avatar
Bill Hoffman committed
100
101
102
103
  // NOTE: This struct is Saved/Restored
  // in cmCTestTestHandler, if you add to this class
  // then you must add the new members to that code or
  // ctest -j N will break for that feature
Andy Cedilnik's avatar
Andy Cedilnik committed
104
105
  struct cmCTestTestProperties
  {
106
107
    std::string Name;
    std::string Directory;
Andy Cedilnik's avatar
Andy Cedilnik committed
108
    std::vector<std::string> Args;
109
    std::vector<std::string> RequiredFiles;
110
    std::vector<std::string> Depends;
111
    std::vector<std::string> AttachedFiles;
112
    std::vector<std::string> AttachOnFail;
113
    std::vector<std::pair<cmsys::RegularExpression, std::string>>
114
      ErrorRegularExpressions;
115
    std::vector<std::pair<cmsys::RegularExpression, std::string>>
116
      RequiredRegularExpressions;
117
    std::vector<std::pair<cmsys::RegularExpression, std::string>>
118
      TimeoutRegularExpressions;
119
    std::map<std::string, std::string> Measurements;
Andy Cedilnik's avatar
Andy Cedilnik committed
120
121
    bool IsInBasedOnREOptions;
    bool WillFail;
Betsy McPhail's avatar
Betsy McPhail committed
122
    bool Disabled;
123
    float Cost;
124
    int PreviousRuns;
125
    bool RunSerial;
126
    double Timeout;
127
    bool ExplicitTimeout;
128
    double AlternateTimeout;
129
    int Index;
130
    // Requested number of process slots
131
    int Processors;
132
133
    // return code of test which will mark test as "not run"
    int SkipReturnCode;
134
    std::vector<std::string> Environment;
135
    std::vector<std::string> Labels;
Zach's avatar
Zach committed
136
    std::set<std::string> LockedResources;
137
138
139
140
    std::set<std::string> FixturesSetup;
    std::set<std::string> FixturesCleanup;
    std::set<std::string> FixturesRequired;
    std::set<std::string> RequireSuccessDepends;
Andy Cedilnik's avatar
Andy Cedilnik committed
141
142
  };

143
144
145
146
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
147
    std::string Reason;
148
    std::string FullCommandLine;
149
150
151
    double ExecutionTime;
    int ReturnValue;
    int Status;
152
    std::string ExceptionStatus;
153
    bool CompressOutput;
154
155
    std::string CompletionStatus;
    std::string Output;
156
    std::string DartString;
157
    int TestCount;
158
159
160
    cmCTestTestProperties* Properties;
  };

161
162
  struct cmCTestTestResultLess
  {
163
164
    bool operator()(const cmCTestTestResult& lhs,
                    const cmCTestTestResult& rhs) const
165
    {
166
      return lhs.TestCount < rhs.TestCount;
167
168
169
170
    }
  };

  // add configurations to a search path for an executable
171
172
173
174
  static void AddConfigurations(cmCTest* ctest,
                                std::vector<std::string>& attempted,
                                std::vector<std::string>& attemptedConfigs,
                                std::string filepath, std::string& filename);
175
176

  // full signature static method to find an executable
177
178
179
180
  static std::string FindExecutable(cmCTest* ctest, const char* testCommand,
                                    std::string& resultingConfig,
                                    std::vector<std::string>& extraPaths,
                                    std::vector<std::string>& failed);
181

182
  typedef std::vector<cmCTestTestProperties> ListOfTests;
183

Andy Cedilnik's avatar
Andy Cedilnik committed
184
protected:
185
  // compute a final test list
186
187
  virtual int PreProcessHandler();
  virtual int PostProcessHandler();
188
  virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
189
  int ExecuteCommands(std::vector<std::string>& vec);
190

191
192
  void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result);
  void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result);
193
  // Write attached test files into the xml
194
  void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result);
195

196
197
198
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

199
  double ElapsedTestingTime;
200

Andy Cedilnik's avatar
Andy Cedilnik committed
201
  typedef std::vector<cmCTestTestResult> TestResultsVector;
202
  TestResultsVector TestResults;
Ken Martin's avatar
Ken Martin committed
203

204
  std::vector<std::string> CustomTestsIgnore;
205
206
207
208
  std::string StartTest;
  std::string EndTest;
  unsigned int StartTestTime;
  unsigned int EndTestTime;
Andy Cedilnik's avatar
Andy Cedilnik committed
209
  bool MemCheck;
210
211
  int CustomMaximumPassedTestOutputSize;
  int CustomMaximumFailedTestOutputSize;
212
  int MaxIndex;
213

214
public:
215
216
  enum
  { // Program statuses
217
218
219
220
221
222
223
224
225
226
227
    NOT_RUN = 0,
    TIMEOUT,
    SEGFAULT,
    ILLEGAL,
    INTERRUPT,
    NUMERICAL,
    OTHER_FAULT,
    FAILED,
    BAD_COMMAND,
    COMPLETED
  };
Ken Martin's avatar
Ken Martin committed
228

229
private:
Ken Martin's avatar
Ken Martin committed
230
231
232
  /**
   * Generate the Dart compatible output
   */
233
  virtual void GenerateDartOutput(cmXMLWriter& xml);
Ken Martin's avatar
Ken Martin committed
234

235
  void PrintLabelOrSubprojectSummary(bool isSubProject);
236

Ken Martin's avatar
Ken Martin committed
237
  /**
238
   * Run the tests for a directory and any subdirectories
Ken Martin's avatar
Ken Martin committed
239
   */
240
241
  void ProcessDirectory(std::vector<std::string>& passed,
                        std::vector<std::string>& failed);
Andy Cedilnik's avatar
Andy Cedilnik committed
242

Ken Martin's avatar
Ken Martin committed
243
244
245
  /**
   * Get the list of tests in directory and subdirectories.
   */
246
  void GetListOfTests();
247
248
249
  // compute the lists of tests that will actually run
  // based on union regex and -I stuff
  void ComputeTestList();
Brad King's avatar
Brad King committed
250

251
252
253
254
  // compute the lists of tests that will actually run
  // based on LastTestFailed.log
  void ComputeTestListForRerunFailed();

255
256
257
258
259
  // add required setup/cleanup tests not already in the
  // list of tests to be run and update dependencies between
  // tests to account for fixture setup/cleanup
  void UpdateForFixtures(ListOfTests& tests) const;

260
261
  void UpdateMaxTestNameWidth();

262
263
264
265
266
  bool GetValue(const char* tag, std::string& value, std::istream& fin);
  bool GetValue(const char* tag, int& value, std::istream& fin);
  bool GetValue(const char* tag, size_t& value, std::istream& fin);
  bool GetValue(const char* tag, bool& value, std::istream& fin);
  bool GetValue(const char* tag, double& value, std::istream& fin);
Ken Martin's avatar
Ken Martin committed
267
268
269
  /**
   * Find the executable for a test
   */
270
  std::string FindTheExecutable(const char* exe);
Ken Martin's avatar
Ken Martin committed
271

272
  const char* GetTestStatus(const cmCTestTestResult*);
Bill Hoffman's avatar
Bill Hoffman committed
273
  void ExpandTestsToRunInformation(size_t numPossibleTests);
274
  void ExpandTestsToRunInformationForRerunFailed();
Ken Martin's avatar
Ken Martin committed
275

276
277
  std::vector<std::string> CustomPreTest;
  std::vector<std::string> CustomPostTest;
Ken Martin's avatar
Ken Martin committed
278

279
  std::vector<int> TestsToRun;
Ken Martin's avatar
Ken Martin committed
280

281
282
  bool UseIncludeLabelRegExpFlag;
  bool UseExcludeLabelRegExpFlag;
Andy Cedilnik's avatar
Andy Cedilnik committed
283
284
285
  bool UseIncludeRegExpFlag;
  bool UseExcludeRegExpFlag;
  bool UseExcludeRegExpFirst;
286
287
  std::string IncludeLabelRegExp;
  std::string ExcludeLabelRegExp;
Andy Cedilnik's avatar
Andy Cedilnik committed
288
289
  std::string IncludeRegExp;
  std::string ExcludeRegExp;
290
291
292
  std::string ExcludeFixtureRegExp;
  std::string ExcludeFixtureSetupRegExp;
  std::string ExcludeFixtureCleanupRegExp;
293
294
  cmsys::RegularExpression IncludeLabelRegularExpression;
  cmsys::RegularExpression ExcludeLabelRegularExpression;
Andy Cedilnik's avatar
Andy Cedilnik committed
295
296
  cmsys::RegularExpression IncludeTestsRegularExpression;
  cmsys::RegularExpression ExcludeTestsRegularExpression;
Ken Martin's avatar
Ken Martin committed
297

298
  void GenerateRegressionImages(cmXMLWriter& xml, const std::string& dart);
Bill Hoffman's avatar
Bill Hoffman committed
299
  cmsys::RegularExpression DartStuff1;
300
301
302
  void CheckLabelFilter(cmCTestTestProperties& it);
  void CheckLabelFilterExclude(cmCTestTestProperties& it);
  void CheckLabelFilterInclude(cmCTestTestProperties& it);
Ken Martin's avatar
Ken Martin committed
303
304

  std::string TestsToRunString;
Andy Cedilnik's avatar
Andy Cedilnik committed
305
306
  bool UseUnion;
  ListOfTests TestList;
307
  size_t TotalNumberOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
308
  cmsys::RegularExpression DartStuff;
Andy Cedilnik's avatar
Andy Cedilnik committed
309

Andy Cedilnik's avatar
Andy Cedilnik committed
310
  std::ostream* LogFile;
311
312

  bool RerunFailed;
Ken Martin's avatar
Ken Martin committed
313
314
315
};

#endif