cmCTestTestHandler.h 9.16 KB
Newer Older
1
2
3
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc.
Ken Martin's avatar
Ken Martin committed
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
Ken Martin's avatar
Ken Martin committed
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
Ken Martin's avatar
Ken Martin committed
12
13
14
15

#ifndef cmCTestTestHandler_h
#define cmCTestTestHandler_h

16
17
#include <cmConfigure.h>

18
#include "cmCTestGenericHandler.h"
19
#include "cmTypeMacro.h"
Brad King's avatar
Brad King committed
20

21
#include <cmsys/RegularExpression.hxx>
22
23
24
25
26
27
28
#include <iosfwd>
#include <map>
#include <set>
#include <stddef.h>
#include <string>
#include <utility>
#include <vector>
Ken Martin's avatar
Ken Martin committed
29

30
class cmCTest;
Ken Martin's avatar
Ken Martin committed
31
class cmMakefile;
32
class cmXMLWriter;
Ken Martin's avatar
Ken Martin committed
33
34
35
36
37

/** \class cmCTestTestHandler
 * \brief A class that handles ctest -S invocations
 *
 */
38
class cmCTestTestHandler : public cmCTestGenericHandler
Ken Martin's avatar
Ken Martin committed
39
{
40
  friend class cmCTestRunTest;
41
  friend class cmCTestMultiProcessHandler;
42
  friend class cmCTestBatchTestHandler;
43

Ken Martin's avatar
Ken Martin committed
44
public:
45
  cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
Ken Martin's avatar
Ken Martin committed
46

47
  /**
Ken Martin's avatar
Ken Martin committed
48
49
   * The main entry point for this class
   */
50
  int ProcessHandler() CM_OVERRIDE;
Andy Cedilnik's avatar
Andy Cedilnik committed
51

52
  /**
53
54
55
56
   * 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
57
  void SetUseUnion(bool val) { this->UseUnion = val; }
58

59
60
61
62
63
64
  /**
   * 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; }

65
66
67
  /**
   * This method is called when reading CTest custom file
   */
68
  void PopulateCustomVectors(cmMakefile* mf) CM_OVERRIDE;
Andy Cedilnik's avatar
Andy Cedilnik committed
69

Ken Martin's avatar
Ken Martin committed
70
  ///! Control the use of the regular expresisons, call these methods to turn
71
  /// them on
Ken Martin's avatar
Ken Martin committed
72
73
  void UseIncludeRegExp();
  void UseExcludeRegExp();
74
75
  void SetIncludeRegExp(const char*);
  void SetExcludeRegExp(const char*);
Andy Cedilnik's avatar
Andy Cedilnik committed
76

77
78
  void SetMaxIndex(int n) { this->MaxIndex = n; }
  int GetMaxIndex() { return this->MaxIndex; }
Ken Martin's avatar
Ken Martin committed
79

80
  void SetTestOutputSizePassed(int n)
81
82
83
  {
    this->CustomMaximumPassedTestOutputSize = n;
  }
84
  void SetTestOutputSizeFailed(int n)
85
86
87
  {
    this->CustomMaximumFailedTestOutputSize = n;
  }
88

Ken Martin's avatar
Ken Martin committed
89
90
91
  ///! pass the -I argument down
  void SetTestsToRunInformation(const char*);

92
  cmCTestTestHandler();
Ken Martin's avatar
Ken Martin committed
93

94
95
96
  /*
   * Add the test to the list of tests to be executed
   */
97
  bool AddTest(const std::vector<std::string>& args);
98

99
100
101
102
103
  /*
   * Set tests properties
   */
  bool SetTestsProperties(const std::vector<std::string>& args);

104
  void Initialize() CM_OVERRIDE;
105

Bill Hoffman's avatar
Bill Hoffman committed
106
107
108
109
  // 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
110
111
  struct cmCTestTestProperties
  {
112
113
    std::string Name;
    std::string Directory;
Andy Cedilnik's avatar
Andy Cedilnik committed
114
    std::vector<std::string> Args;
115
    std::vector<std::string> RequiredFiles;
116
    std::vector<std::string> Depends;
117
    std::vector<std::string> AttachedFiles;
118
    std::vector<std::string> AttachOnFail;
119
120
121
122
123
124
    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;
125
    std::map<std::string, std::string> Measurements;
Andy Cedilnik's avatar
Andy Cedilnik committed
126
127
    bool IsInBasedOnREOptions;
    bool WillFail;
128
    float Cost;
129
    int PreviousRuns;
130
    bool RunSerial;
131
    double Timeout;
132
    bool ExplicitTimeout;
133
    double AlternateTimeout;
134
    int Index;
135
    // Requested number of process slots
136
    int Processors;
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;
Andy Cedilnik's avatar
Andy Cedilnik committed
146
147
  };

148
149
150
151
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
152
    std::string Reason;
153
    std::string FullCommandLine;
154
155
156
157
    double ExecutionTime;
    int ReturnValue;
    int Status;
    bool CompressOutput;
158
159
    std::string CompletionStatus;
    std::string Output;
160
    std::string DartString;
161
    int TestCount;
162
163
164
    cmCTestTestProperties* Properties;
  };

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

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

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

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

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

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

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

203
  double ElapsedTestingTime;
204

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

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

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

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

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

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

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

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

263
264
  void UpdateMaxTestNameWidth();

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

  const char* GetTestStatus(int status);
Bill Hoffman's avatar
Bill Hoffman committed
276
  void ExpandTestsToRunInformation(size_t numPossibleTests);
277
  void ExpandTestsToRunInformationForRerunFailed();
Ken Martin's avatar
Ken Martin committed
278

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

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

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

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

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

Andy Cedilnik's avatar
Andy Cedilnik committed
310
  std::ostream* LogFile;
311
312

  bool RerunFailed;
Ken Martin's avatar
Ken Martin committed
313
314
315
};

#endif