cmCTestTestHandler.h 8.75 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"
7

8
#include "cmCTestGenericHandler.h"
Brad King's avatar
Brad King committed
9

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

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

/** \class cmCTestTestHandler
 * \brief A class that handles ctest -S invocations
 *
 */
27
class cmCTestTestHandler : public cmCTestGenericHandler
Ken Martin's avatar
Ken Martin committed
28
{
29
  friend class cmCTestRunTest;
30
  friend class cmCTestMultiProcessHandler;
31
  friend class cmCTestBatchTestHandler;
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() CM_OVERRIDE;
Andy Cedilnik's avatar
Andy Cedilnik committed
40

41
  /**
42
43
44
45
   * When both -R and -I are used should te resulting test list be the
   * 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) CM_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
  void Initialize() CM_OVERRIDE;
94

Bill Hoffman's avatar
Bill Hoffman committed
95
96
97
98
  // 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
99
100
  struct cmCTestTestProperties
  {
101
102
    std::string Name;
    std::string Directory;
Andy Cedilnik's avatar
Andy Cedilnik committed
103
    std::vector<std::string> Args;
104
    std::vector<std::string> RequiredFiles;
105
    std::vector<std::string> Depends;
106
    std::vector<std::string> AttachedFiles;
107
    std::vector<std::string> AttachOnFail;
108
109
110
111
112
113
    std::vector<std::pair<cmsys::RegularExpression, std::string> >
      ErrorRegularExpressions;
    std::vector<std::pair<cmsys::RegularExpression, std::string> >
      RequiredRegularExpressions;
    std::vector<std::pair<cmsys::RegularExpression, std::string> >
      TimeoutRegularExpressions;
114
    std::map<std::string, std::string> Measurements;
Andy Cedilnik's avatar
Andy Cedilnik committed
115
116
    bool IsInBasedOnREOptions;
    bool WillFail;
Betsy McPhail's avatar
Betsy McPhail committed
117
    bool Disabled;
118
    float Cost;
119
    int PreviousRuns;
120
    bool RunSerial;
121
    double Timeout;
122
    bool ExplicitTimeout;
123
    double AlternateTimeout;
124
    int Index;
125
    // Requested number of process slots
126
    int Processors;
127
128
    // return code of test which will mark test as "not run"
    int SkipReturnCode;
129
    std::vector<std::string> Environment;
130
    std::vector<std::string> Labels;
Zach's avatar
Zach committed
131
    std::set<std::string> LockedResources;
132
133
134
135
    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
136
137
  };

138
139
140
141
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
142
    std::string Reason;
143
    std::string FullCommandLine;
144
145
146
147
    double ExecutionTime;
    int ReturnValue;
    int Status;
    bool CompressOutput;
148
149
    std::string CompletionStatus;
    std::string Output;
150
    std::string DartString;
151
    int TestCount;
152
153
154
    cmCTestTestProperties* Properties;
  };

155
156
  struct cmCTestTestResultLess
  {
157
158
    bool operator()(const cmCTestTestResult& lhs,
                    const cmCTestTestResult& rhs) const
159
    {
160
      return lhs.TestCount < rhs.TestCount;
161
162
163
164
    }
  };

  // add configurations to a search path for an executable
165
166
167
168
  static void AddConfigurations(cmCTest* ctest,
                                std::vector<std::string>& attempted,
                                std::vector<std::string>& attemptedConfigs,
                                std::string filepath, std::string& filename);
169
170

  // full signature static method to find an executable
171
172
173
174
  static std::string FindExecutable(cmCTest* ctest, const char* testCommand,
                                    std::string& resultingConfig,
                                    std::vector<std::string>& extraPaths,
                                    std::vector<std::string>& failed);
175

176
  typedef std::vector<cmCTestTestProperties> ListOfTests;
177

Andy Cedilnik's avatar
Andy Cedilnik committed
178
protected:
179
  // compute a final test list
180
181
  virtual int PreProcessHandler();
  virtual int PostProcessHandler();
182
  virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
183
  int ExecuteCommands(std::vector<std::string>& vec);
184

185
186
  void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result);
  void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result);
187
  // Write attached test files into the xml
188
  void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result);
189

190
191
192
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

193
  double ElapsedTestingTime;
194

Andy Cedilnik's avatar
Andy Cedilnik committed
195
  typedef std::vector<cmCTestTestResult> TestResultsVector;
196
  TestResultsVector TestResults;
Ken Martin's avatar
Ken Martin committed
197

198
  std::vector<std::string> CustomTestsIgnore;
199
200
201
202
  std::string StartTest;
  std::string EndTest;
  unsigned int StartTestTime;
  unsigned int EndTestTime;
Andy Cedilnik's avatar
Andy Cedilnik committed
203
  bool MemCheck;
204
205
  int CustomMaximumPassedTestOutputSize;
  int CustomMaximumFailedTestOutputSize;
206
  int MaxIndex;
207

208
public:
209
210
  enum
  { // Program statuses
211
212
213
214
215
216
217
218
219
220
221
    NOT_RUN = 0,
    TIMEOUT,
    SEGFAULT,
    ILLEGAL,
    INTERRUPT,
    NUMERICAL,
    OTHER_FAULT,
    FAILED,
    BAD_COMMAND,
    COMPLETED
  };
Ken Martin's avatar
Ken Martin committed
222

223
private:
Ken Martin's avatar
Ken Martin committed
224
225
226
  /**
   * Generate the Dart compatible output
   */
227
  virtual void GenerateDartOutput(cmXMLWriter& xml);
Ken Martin's avatar
Ken Martin committed
228

229
  void PrintLabelSummary();
Ken Martin's avatar
Ken Martin committed
230
  /**
231
   * Run the tests for a directory and any subdirectories
Ken Martin's avatar
Ken Martin committed
232
   */
233
234
  void ProcessDirectory(std::vector<std::string>& passed,
                        std::vector<std::string>& failed);
Andy Cedilnik's avatar
Andy Cedilnik committed
235

Ken Martin's avatar
Ken Martin committed
236
237
238
  /**
   * Get the list of tests in directory and subdirectories.
   */
239
  void GetListOfTests();
240
241
242
  // 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
243

244
245
246
247
  // compute the lists of tests that will actually run
  // based on LastTestFailed.log
  void ComputeTestListForRerunFailed();

248
249
250
251
252
  // 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;

253
254
  void UpdateMaxTestNameWidth();

255
256
257
258
259
  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
260
261
262
  /**
   * Find the executable for a test
   */
263
  std::string FindTheExecutable(const char* exe);
Ken Martin's avatar
Ken Martin committed
264
265

  const char* GetTestStatus(int status);
Bill Hoffman's avatar
Bill Hoffman committed
266
  void ExpandTestsToRunInformation(size_t numPossibleTests);
267
  void ExpandTestsToRunInformationForRerunFailed();
Ken Martin's avatar
Ken Martin committed
268

269
270
  std::vector<std::string> CustomPreTest;
  std::vector<std::string> CustomPostTest;
Ken Martin's avatar
Ken Martin committed
271

272
  std::vector<int> TestsToRun;
Ken Martin's avatar
Ken Martin committed
273

274
275
  bool UseIncludeLabelRegExpFlag;
  bool UseExcludeLabelRegExpFlag;
Andy Cedilnik's avatar
Andy Cedilnik committed
276
277
278
  bool UseIncludeRegExpFlag;
  bool UseExcludeRegExpFlag;
  bool UseExcludeRegExpFirst;
279
280
  std::string IncludeLabelRegExp;
  std::string ExcludeLabelRegExp;
Andy Cedilnik's avatar
Andy Cedilnik committed
281
282
  std::string IncludeRegExp;
  std::string ExcludeRegExp;
283
284
  cmsys::RegularExpression IncludeLabelRegularExpression;
  cmsys::RegularExpression ExcludeLabelRegularExpression;
Andy Cedilnik's avatar
Andy Cedilnik committed
285
286
  cmsys::RegularExpression IncludeTestsRegularExpression;
  cmsys::RegularExpression ExcludeTestsRegularExpression;
Ken Martin's avatar
Ken Martin committed
287

288
  void GenerateRegressionImages(cmXMLWriter& xml, const std::string& dart);
Bill Hoffman's avatar
Bill Hoffman committed
289
  cmsys::RegularExpression DartStuff1;
290
291
292
  void CheckLabelFilter(cmCTestTestProperties& it);
  void CheckLabelFilterExclude(cmCTestTestProperties& it);
  void CheckLabelFilterInclude(cmCTestTestProperties& it);
Ken Martin's avatar
Ken Martin committed
293
294

  std::string TestsToRunString;
Andy Cedilnik's avatar
Andy Cedilnik committed
295
296
  bool UseUnion;
  ListOfTests TestList;
297
  size_t TotalNumberOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
298
  cmsys::RegularExpression DartStuff;
Andy Cedilnik's avatar
Andy Cedilnik committed
299

Andy Cedilnik's avatar
Andy Cedilnik committed
300
  std::ostream* LogFile;
301
302

  bool RerunFailed;
Ken Martin's avatar
Ken Martin committed
303
304
305
};

#endif