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"
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

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() override;
Andy Cedilnik's avatar
Andy Cedilnik committed
40

41
  /**
luz.paz's avatar
luz.paz committed
42
   * When both -R and -I are used should the resulting test list be the
43
44
45
   * 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) 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() 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
    std::chrono::duration<double> Timeout;
127
    bool ExplicitTimeout;
128
    std::chrono::duration<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
    std::chrono::duration<double> ExecutionTime;
150
151
    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
193
194
  void WriteTestResultHeader(cmXMLWriter& xml,
                             cmCTestTestResult const& result);
  void WriteTestResultFooter(cmXMLWriter& xml,
                             cmCTestTestResult const& result);
195
  // Write attached test files into the xml
196
  void AttachFiles(cmXMLWriter& xml, cmCTestTestResult& result);
197

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

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

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

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

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

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

237
  void PrintLabelOrSubprojectSummary(bool isSubProject);
238

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

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

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

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

262
263
  void UpdateMaxTestNameWidth();

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

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

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

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

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

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

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

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

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

#endif