cmCTestTestHandler.h 9.38 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"
Wouter Klouwen's avatar
Wouter Klouwen committed
9
#include "cmDuration.h"
10
#include "cmListFileCache.h"
Brad King's avatar
Brad King committed
11

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

100
  void Initialize() override;
101

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

149
150
151
152
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
153
    std::string Reason;
154
    std::string FullCommandLine;
Wouter Klouwen's avatar
Wouter Klouwen committed
155
    cmDuration ExecutionTime;
156
157
    int ReturnValue;
    int Status;
158
    std::string ExceptionStatus;
159
    bool CompressOutput;
160
161
    std::string CompletionStatus;
    std::string Output;
162
    std::string DartString;
163
    int TestCount;
164
165
166
    cmCTestTestProperties* Properties;
  };

167
168
  struct cmCTestTestResultLess
  {
169
170
    bool operator()(const cmCTestTestResult& lhs,
                    const cmCTestTestResult& rhs) const
171
    {
172
      return lhs.TestCount < rhs.TestCount;
173
174
175
176
    }
  };

  // add configurations to a search path for an executable
177
178
179
180
  static void AddConfigurations(cmCTest* ctest,
                                std::vector<std::string>& attempted,
                                std::vector<std::string>& attemptedConfigs,
                                std::string filepath, std::string& filename);
181
182

  // full signature static method to find an executable
183
184
185
186
  static std::string FindExecutable(cmCTest* ctest, const char* testCommand,
                                    std::string& resultingConfig,
                                    std::vector<std::string>& extraPaths,
                                    std::vector<std::string>& failed);
187

188
  typedef std::vector<cmCTestTestProperties> ListOfTests;
189

Andy Cedilnik's avatar
Andy Cedilnik committed
190
protected:
191
  // compute a final test list
192
193
  virtual int PreProcessHandler();
  virtual int PostProcessHandler();
194
  virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
195
  int ExecuteCommands(std::vector<std::string>& vec);
196

197
198
199
200
  void WriteTestResultHeader(cmXMLWriter& xml,
                             cmCTestTestResult const& result);
  void WriteTestResultFooter(cmXMLWriter& xml,
                             cmCTestTestResult const& result);
201
  // Write attached test files into the xml
202
  void AttachFiles(cmXMLWriter& xml, cmCTestTestResult& result);
203

204
205
206
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

Wouter Klouwen's avatar
Wouter Klouwen committed
207
  cmDuration ElapsedTestingTime;
208

Andy Cedilnik's avatar
Andy Cedilnik committed
209
  typedef std::vector<cmCTestTestResult> TestResultsVector;
210
  TestResultsVector TestResults;
Ken Martin's avatar
Ken Martin committed
211

212
  std::vector<std::string> CustomTestsIgnore;
213
214
  std::string StartTest;
  std::string EndTest;
215
216
  std::chrono::system_clock::time_point StartTestTime;
  std::chrono::system_clock::time_point EndTestTime;
Andy Cedilnik's avatar
Andy Cedilnik committed
217
  bool MemCheck;
218
219
  int CustomMaximumPassedTestOutputSize;
  int CustomMaximumFailedTestOutputSize;
220
  int MaxIndex;
221

222
public:
223
224
  enum
  { // Program statuses
225
226
227
228
229
230
231
232
233
234
235
    NOT_RUN = 0,
    TIMEOUT,
    SEGFAULT,
    ILLEGAL,
    INTERRUPT,
    NUMERICAL,
    OTHER_FAULT,
    FAILED,
    BAD_COMMAND,
    COMPLETED
  };
Ken Martin's avatar
Ken Martin committed
236

237
private:
Ken Martin's avatar
Ken Martin committed
238
239
240
  /**
   * Generate the Dart compatible output
   */
241
  virtual void GenerateDartOutput(cmXMLWriter& xml);
Ken Martin's avatar
Ken Martin committed
242

243
  void PrintLabelOrSubprojectSummary(bool isSubProject);
244

Ken Martin's avatar
Ken Martin committed
245
  /**
246
   * Run the tests for a directory and any subdirectories
Ken Martin's avatar
Ken Martin committed
247
   */
248
249
  void ProcessDirectory(std::vector<std::string>& passed,
                        std::vector<std::string>& failed);
Andy Cedilnik's avatar
Andy Cedilnik committed
250

Ken Martin's avatar
Ken Martin committed
251
252
253
  /**
   * Get the list of tests in directory and subdirectories.
   */
254
  void GetListOfTests();
255
256
257
  // 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
258

259
260
261
262
  // compute the lists of tests that will actually run
  // based on LastTestFailed.log
  void ComputeTestListForRerunFailed();

263
264
265
266
267
  // 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;

268
269
  void UpdateMaxTestNameWidth();

270
271
272
273
274
  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
275
276
277
  /**
   * Find the executable for a test
   */
278
  std::string FindTheExecutable(const char* exe);
Ken Martin's avatar
Ken Martin committed
279

280
  std::string GetTestStatus(cmCTestTestResult const&);
Bill Hoffman's avatar
Bill Hoffman committed
281
  void ExpandTestsToRunInformation(size_t numPossibleTests);
282
  void ExpandTestsToRunInformationForRerunFailed();
Ken Martin's avatar
Ken Martin committed
283

284
285
  std::vector<std::string> CustomPreTest;
  std::vector<std::string> CustomPostTest;
Ken Martin's avatar
Ken Martin committed
286

287
  std::vector<int> TestsToRun;
Ken Martin's avatar
Ken Martin committed
288

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

306
  void GenerateRegressionImages(cmXMLWriter& xml, const std::string& dart);
Bill Hoffman's avatar
Bill Hoffman committed
307
  cmsys::RegularExpression DartStuff1;
308
309
310
  void CheckLabelFilter(cmCTestTestProperties& it);
  void CheckLabelFilterExclude(cmCTestTestProperties& it);
  void CheckLabelFilterInclude(cmCTestTestProperties& it);
Ken Martin's avatar
Ken Martin committed
311
312

  std::string TestsToRunString;
Andy Cedilnik's avatar
Andy Cedilnik committed
313
314
  bool UseUnion;
  ListOfTests TestList;
315
  size_t TotalNumberOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
316
  cmsys::RegularExpression DartStuff;
Andy Cedilnik's avatar
Andy Cedilnik committed
317

Andy Cedilnik's avatar
Andy Cedilnik committed
318
  std::ostream* LogFile;
319
320

  bool RerunFailed;
Ken Martin's avatar
Ken Martin committed
321
322
323
};

#endif