cmCTestTestHandler.h 9.41 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
#include <cstdint>
15
16
17
18
19
20
21
#include <iosfwd>
#include <map>
#include <set>
#include <stddef.h>
#include <string>
#include <utility>
#include <vector>
Ken Martin's avatar
Ken Martin committed
22

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

101
  void Initialize() override;
102

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

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

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

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

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

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

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

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

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

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

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

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

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

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

244
  void PrintLabelOrSubprojectSummary(bool isSubProject);
245

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

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

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

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

269
270
  void UpdateMaxTestNameWidth();

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

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

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

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

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

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

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

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

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

#endif