cmCTestTestHandler.h 9.5 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
121
    std::vector<std::pair<cmsys::RegularExpression, std::string>>
      SkipRegularExpressions;
122
    std::vector<std::pair<cmsys::RegularExpression, std::string>>
123
      TimeoutRegularExpressions;
124
    std::map<std::string, std::string> Measurements;
Andy Cedilnik's avatar
Andy Cedilnik committed
125
126
    bool IsInBasedOnREOptions;
    bool WillFail;
Betsy McPhail's avatar
Betsy McPhail committed
127
    bool Disabled;
128
    float Cost;
129
    int PreviousRuns;
130
    bool RunSerial;
Wouter Klouwen's avatar
Wouter Klouwen committed
131
    cmDuration Timeout;
132
    bool ExplicitTimeout;
Wouter Klouwen's avatar
Wouter Klouwen committed
133
    cmDuration AlternateTimeout;
134
    int Index;
135
    // Requested number of process slots
136
    int Processors;
137
138
    bool WantAffinity;
    std::vector<size_t> Affinity;
139
140
    // return code of test which will mark test as "not run"
    int SkipReturnCode;
141
    std::vector<std::string> Environment;
142
    std::vector<std::string> Labels;
Zach's avatar
Zach committed
143
    std::set<std::string> LockedResources;
144
145
146
147
    std::set<std::string> FixturesSetup;
    std::set<std::string> FixturesCleanup;
    std::set<std::string> FixturesRequired;
    std::set<std::string> RequireSuccessDepends;
148
149
    // Private test generator properties used to track backtraces
    cmListFileBacktrace Backtrace;
Andy Cedilnik's avatar
Andy Cedilnik committed
150
151
  };

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

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

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

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

191
  typedef std::vector<cmCTestTestProperties> ListOfTests;
192

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

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

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

Wouter Klouwen's avatar
Wouter Klouwen committed
210
  cmDuration ElapsedTestingTime;
211

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

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

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

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

246
  void PrintLabelOrSubprojectSummary(bool isSubProject);
247

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

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

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

266
267
268
269
270
  // 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;

271
272
  void UpdateMaxTestNameWidth();

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

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

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

290
  std::vector<int> TestsToRun;
Ken Martin's avatar
Ken Martin committed
291

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

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

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

Andy Cedilnik's avatar
Andy Cedilnik committed
321
  std::ostream* LogFile;
322
323

  bool RerunFailed;
Ken Martin's avatar
Ken Martin committed
324
325
326
};

#endif