cmCTestTestHandler.h 9.22 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
#include <chrono>
12
13
14
15
16
17
18
#include <iosfwd>
#include <map>
#include <set>
#include <stddef.h>
#include <string>
#include <utility>
#include <vector>
Ken Martin's avatar
Ken Martin committed
19

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

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

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

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

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

49
50
51
52
53
54
  /**
   * 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; }

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

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

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

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

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

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

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

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

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

99
  void Initialize() override;
100

Bill Hoffman's avatar
Bill Hoffman committed
101
102
103
104
  // 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
105
106
  struct cmCTestTestProperties
  {
107
108
    std::string Name;
    std::string Directory;
Andy Cedilnik's avatar
Andy Cedilnik committed
109
    std::vector<std::string> Args;
110
    std::vector<std::string> RequiredFiles;
111
    std::vector<std::string> Depends;
112
    std::vector<std::string> AttachedFiles;
113
    std::vector<std::string> AttachOnFail;
114
    std::vector<std::pair<cmsys::RegularExpression, std::string>>
115
      ErrorRegularExpressions;
116
    std::vector<std::pair<cmsys::RegularExpression, std::string>>
117
      RequiredRegularExpressions;
118
    std::vector<std::pair<cmsys::RegularExpression, std::string>>
119
      TimeoutRegularExpressions;
120
    std::map<std::string, std::string> Measurements;
Andy Cedilnik's avatar
Andy Cedilnik committed
121
122
    bool IsInBasedOnREOptions;
    bool WillFail;
Betsy McPhail's avatar
Betsy McPhail committed
123
    bool Disabled;
124
    float Cost;
125
    int PreviousRuns;
126
    bool RunSerial;
127
    double Timeout;
128
    bool ExplicitTimeout;
129
    double AlternateTimeout;
130
    int Index;
131
    // Requested number of process slots
132
    int Processors;
133
134
    // return code of test which will mark test as "not run"
    int SkipReturnCode;
135
    std::vector<std::string> Environment;
136
    std::vector<std::string> Labels;
Zach's avatar
Zach committed
137
    std::set<std::string> LockedResources;
138
139
140
141
    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
142
143
  };

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

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

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

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

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

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

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

199
200
201
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

202
  std::chrono::duration<double> ElapsedTestingTime;
203

Andy Cedilnik's avatar
Andy Cedilnik committed
204
  typedef std::vector<cmCTestTestResult> TestResultsVector;
205
  TestResultsVector TestResults;
Ken Martin's avatar
Ken Martin committed
206

207
  std::vector<std::string> CustomTestsIgnore;
208
209
  std::string StartTest;
  std::string EndTest;
210
211
  std::chrono::system_clock::time_point StartTestTime;
  std::chrono::system_clock::time_point EndTestTime;
Andy Cedilnik's avatar
Andy Cedilnik committed
212
  bool MemCheck;
213
214
  int CustomMaximumPassedTestOutputSize;
  int CustomMaximumFailedTestOutputSize;
215
  int MaxIndex;
216

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

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

238
  void PrintLabelOrSubprojectSummary(bool isSubProject);
239

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

Ken Martin's avatar
Ken Martin committed
246
247
248
  /**
   * Get the list of tests in directory and subdirectories.
   */
249
  void GetListOfTests();
250
251
252
  // 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
253

254
255
256
257
  // compute the lists of tests that will actually run
  // based on LastTestFailed.log
  void ComputeTestListForRerunFailed();

258
259
260
261
262
  // 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;

263
264
  void UpdateMaxTestNameWidth();

265
266
267
268
269
  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
270
271
272
  /**
   * Find the executable for a test
   */
273
  std::string FindTheExecutable(const char* exe);
Ken Martin's avatar
Ken Martin committed
274

275
  const char* GetTestStatus(cmCTestTestResult const&);
Bill Hoffman's avatar
Bill Hoffman committed
276
  void ExpandTestsToRunInformation(size_t numPossibleTests);
277
  void ExpandTestsToRunInformationForRerunFailed();
Ken Martin's avatar
Ken Martin committed
278

279
280
  std::vector<std::string> CustomPreTest;
  std::vector<std::string> CustomPostTest;
Ken Martin's avatar
Ken Martin committed
281

282
  std::vector<int> TestsToRun;
Ken Martin's avatar
Ken Martin committed
283

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

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

  std::string TestsToRunString;
Andy Cedilnik's avatar
Andy Cedilnik committed
308
309
  bool UseUnion;
  ListOfTests TestList;
310
  size_t TotalNumberOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
311
  cmsys::RegularExpression DartStuff;
Andy Cedilnik's avatar
Andy Cedilnik committed
312

Andy Cedilnik's avatar
Andy Cedilnik committed
313
  std::ostream* LogFile;
314
315

  bool RerunFailed;
Ken Martin's avatar
Ken Martin committed
316
317
318
};

#endif