cmCTestTestHandler.h 9.25 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"
Brad King's avatar
Brad King committed
10

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

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

/** \class cmCTestTestHandler
 * \brief A class that handles ctest -S invocations
 *
 */
29
class cmCTestTestHandler : public cmCTestGenericHandler
Ken Martin's avatar
Ken Martin committed
30
{
31
  friend class cmCTestRunTest;
32
  friend class cmCTestMultiProcessHandler;
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;
Wouter Klouwen's avatar
Wouter Klouwen committed
127
    cmDuration Timeout;
128
    bool ExplicitTimeout;
Wouter Klouwen's avatar
Wouter Klouwen committed
129
    cmDuration AlternateTimeout;
130
    int Index;
131
    // Requested number of process slots
132
    int Processors;
133
134
    bool WantAffinity;
    std::vector<size_t> Affinity;
135
136
    // return code of test which will mark test as "not run"
    int SkipReturnCode;
137
    std::vector<std::string> Environment;
138
    std::vector<std::string> Labels;
Zach's avatar
Zach committed
139
    std::set<std::string> LockedResources;
140
141
142
143
    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
144
145
  };

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

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

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

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

185
  typedef std::vector<cmCTestTestProperties> ListOfTests;
186

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

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

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

Wouter Klouwen's avatar
Wouter Klouwen committed
204
  cmDuration ElapsedTestingTime;
205

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

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

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

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

240
  void PrintLabelOrSubprojectSummary(bool isSubProject);
241

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

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

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

260
261
262
263
264
  // 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;

265
266
  void UpdateMaxTestNameWidth();

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

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

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

284
  std::vector<int> TestsToRun;
Ken Martin's avatar
Ken Martin committed
285

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

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

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

Andy Cedilnik's avatar
Andy Cedilnik committed
315
  std::ostream* LogFile;
316
317

  bool RerunFailed;
Ken Martin's avatar
Ken Martin committed
318
319
320
};

#endif