cmCTestTestHandler.h 8.59 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
#include "cmCTestGenericHandler.h"
Brad King's avatar
Brad King committed
17

18
#include <cmsys/RegularExpression.hxx>
Ken Martin's avatar
Ken Martin committed
19
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
  cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
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;
117
    float Cost;
118
    int PreviousRuns;
119
    bool RunSerial;
120
    double Timeout;
121
    bool ExplicitTimeout;
122
    double AlternateTimeout;
123
    int Index;
124
    // Requested number of process slots
125
    int Processors;
126
127
    // return code of test which will mark test as "not run"
    int SkipReturnCode;
128
    std::vector<std::string> Environment;
129
    std::vector<std::string> Labels;
Zach's avatar
Zach committed
130
    std::set<std::string> LockedResources;
Andy Cedilnik's avatar
Andy Cedilnik committed
131
132
  };

133
134
135
136
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
137
    std::string Reason;
138
    std::string FullCommandLine;
139
140
141
142
    double ExecutionTime;
    int ReturnValue;
    int Status;
    bool CompressOutput;
143
144
    std::string CompletionStatus;
    std::string Output;
145
    std::string DartString;
146
    int TestCount;
147
148
149
    cmCTestTestProperties* Properties;
  };

150
151
  struct cmCTestTestResultLess
  {
152
153
    bool operator()(const cmCTestTestResult& lhs,
                    const cmCTestTestResult& rhs) const
154
    {
155
      return lhs.TestCount < rhs.TestCount;
156
157
158
159
    }
  };

  // add configurations to a search path for an executable
160
161
162
163
  static void AddConfigurations(cmCTest* ctest,
                                std::vector<std::string>& attempted,
                                std::vector<std::string>& attemptedConfigs,
                                std::string filepath, std::string& filename);
164
165

  // full signature static method to find an executable
166
167
168
169
  static std::string FindExecutable(cmCTest* ctest, const char* testCommand,
                                    std::string& resultingConfig,
                                    std::vector<std::string>& extraPaths,
                                    std::vector<std::string>& failed);
170

171
  typedef std::vector<cmCTestTestProperties> ListOfTests;
172

Andy Cedilnik's avatar
Andy Cedilnik committed
173
protected:
174
  // compute a final test list
175
176
  virtual int PreProcessHandler();
  virtual int PostProcessHandler();
177
  virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
178
  int ExecuteCommands(std::vector<std::string>& vec);
179

180
181
  void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result);
  void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result);
182
  // Write attached test files into the xml
183
  void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result);
184

185
186
187
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

188
  double ElapsedTestingTime;
189

Andy Cedilnik's avatar
Andy Cedilnik committed
190
  typedef std::vector<cmCTestTestResult> TestResultsVector;
191
  TestResultsVector TestResults;
Ken Martin's avatar
Ken Martin committed
192

193
  std::vector<std::string> CustomTestsIgnore;
194
195
196
197
  std::string StartTest;
  std::string EndTest;
  unsigned int StartTestTime;
  unsigned int EndTestTime;
Andy Cedilnik's avatar
Andy Cedilnik committed
198
  bool MemCheck;
199
200
  int CustomMaximumPassedTestOutputSize;
  int CustomMaximumFailedTestOutputSize;
201
  int MaxIndex;
202

203
public:
204
205
  enum
  { // Program statuses
206
207
208
209
210
211
212
213
214
215
216
    NOT_RUN = 0,
    TIMEOUT,
    SEGFAULT,
    ILLEGAL,
    INTERRUPT,
    NUMERICAL,
    OTHER_FAULT,
    FAILED,
    BAD_COMMAND,
    COMPLETED
  };
Ken Martin's avatar
Ken Martin committed
217

218
private:
Ken Martin's avatar
Ken Martin committed
219
220
221
  /**
   * Generate the Dart compatible output
   */
222
  virtual void GenerateDartOutput(cmXMLWriter& xml);
Ken Martin's avatar
Ken Martin committed
223

224
  void PrintLabelSummary();
Ken Martin's avatar
Ken Martin committed
225
  /**
226
   * Run the tests for a directory and any subdirectories
Ken Martin's avatar
Ken Martin committed
227
   */
228
229
  void ProcessDirectory(std::vector<std::string>& passed,
                        std::vector<std::string>& failed);
Andy Cedilnik's avatar
Andy Cedilnik committed
230

Ken Martin's avatar
Ken Martin committed
231
232
233
  /**
   * Get the list of tests in directory and subdirectories.
   */
234
  void GetListOfTests();
235
236
237
  // 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
238

239
240
241
242
243
244
  // compute the lists of tests that will actually run
  // based on LastTestFailed.log
  void ComputeTestListForRerunFailed();

  void UpdateMaxTestNameWidth();

245
246
247
248
249
  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
250
251
252
  /**
   * Find the executable for a test
   */
253
  std::string FindTheExecutable(const char* exe);
Ken Martin's avatar
Ken Martin committed
254
255

  const char* GetTestStatus(int status);
Bill Hoffman's avatar
Bill Hoffman committed
256
  void ExpandTestsToRunInformation(size_t numPossibleTests);
257
  void ExpandTestsToRunInformationForRerunFailed();
Ken Martin's avatar
Ken Martin committed
258

259
260
  std::vector<std::string> CustomPreTest;
  std::vector<std::string> CustomPostTest;
Ken Martin's avatar
Ken Martin committed
261

262
  std::vector<int> TestsToRun;
Ken Martin's avatar
Ken Martin committed
263

264
265
  bool UseIncludeLabelRegExpFlag;
  bool UseExcludeLabelRegExpFlag;
Andy Cedilnik's avatar
Andy Cedilnik committed
266
267
268
  bool UseIncludeRegExpFlag;
  bool UseExcludeRegExpFlag;
  bool UseExcludeRegExpFirst;
269
270
  std::string IncludeLabelRegExp;
  std::string ExcludeLabelRegExp;
Andy Cedilnik's avatar
Andy Cedilnik committed
271
272
  std::string IncludeRegExp;
  std::string ExcludeRegExp;
273
274
  cmsys::RegularExpression IncludeLabelRegularExpression;
  cmsys::RegularExpression ExcludeLabelRegularExpression;
Andy Cedilnik's avatar
Andy Cedilnik committed
275
276
  cmsys::RegularExpression IncludeTestsRegularExpression;
  cmsys::RegularExpression ExcludeTestsRegularExpression;
Ken Martin's avatar
Ken Martin committed
277

278
  void GenerateRegressionImages(cmXMLWriter& xml, const std::string& dart);
Bill Hoffman's avatar
Bill Hoffman committed
279
  cmsys::RegularExpression DartStuff1;
280
281
282
  void CheckLabelFilter(cmCTestTestProperties& it);
  void CheckLabelFilterExclude(cmCTestTestProperties& it);
  void CheckLabelFilterInclude(cmCTestTestProperties& it);
Ken Martin's avatar
Ken Martin committed
283
284

  std::string TestsToRunString;
Andy Cedilnik's avatar
Andy Cedilnik committed
285
286
  bool UseUnion;
  ListOfTests TestList;
287
  size_t TotalNumberOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
288
  cmsys::RegularExpression DartStuff;
Andy Cedilnik's avatar
Andy Cedilnik committed
289

Andy Cedilnik's avatar
Andy Cedilnik committed
290
  std::ostream* LogFile;
291
292

  bool RerunFailed;
Ken Martin's avatar
Ken Martin committed
293
294
295
};

#endif