cmCTestTestHandler.h 8.57 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
16

#ifndef cmCTestTestHandler_h
#define cmCTestTestHandler_h


17
#include "cmCTestGenericHandler.h"
18
#include <cmsys/RegularExpression.hxx>
Ken Martin's avatar
Ken Martin committed
19
20
21
22
23
24
25

class cmMakefile;

/** \class cmCTestTestHandler
 * \brief A class that handles ctest -S invocations
 *
 */
26
class cmCTestTestHandler : public cmCTestGenericHandler
Ken Martin's avatar
Ken Martin committed
27
{
28
  friend class cmCTestRunTest;
29
  friend class cmCTestMultiProcessHandler;
30
  friend class cmCTestBatchTestHandler;
Ken Martin's avatar
Ken Martin committed
31
public:
32
  cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
Ken Martin's avatar
Ken Martin committed
33

34
  /**
Ken Martin's avatar
Ken Martin committed
35
36
   * The main entry point for this class
   */
37
  int ProcessHandler();
Andy Cedilnik's avatar
Andy Cedilnik committed
38

39
  /**
40
41
42
43
   * 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
44
  void SetUseUnion(bool val) { this->UseUnion = val; }
45

46
47
48
49
50
51
  /**
   * 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; }

52
53
54
  /**
   * This method is called when reading CTest custom file
   */
55
  void PopulateCustomVectors(cmMakefile *mf);
Andy Cedilnik's avatar
Andy Cedilnik committed
56

Ken Martin's avatar
Ken Martin committed
57
58
59
60
61
62
  ///! Control the use of the regular expresisons, call these methods to turn
  ///them on
  void UseIncludeRegExp();
  void UseExcludeRegExp();
  void SetIncludeRegExp(const char *);
  void SetExcludeRegExp(const char *);
Andy Cedilnik's avatar
Andy Cedilnik committed
63

64
65
  void SetMaxIndex(int n) {this->MaxIndex = n;}
  int GetMaxIndex() {return this->MaxIndex;}
Ken Martin's avatar
Ken Martin committed
66
67
68
69

  ///! pass the -I argument down
  void SetTestsToRunInformation(const char*);

70
  cmCTestTestHandler();
Ken Martin's avatar
Ken Martin committed
71

72
73
74
  /*
   * Add the test to the list of tests to be executed
   */
75
  bool AddTest(const std::vector<std::string>& args);
76

77
78
79
80
81
  /*
   * Set tests properties
   */
  bool SetTestsProperties(const std::vector<std::string>& args);

82
83
  void Initialize();

Bill Hoffman's avatar
Bill Hoffman committed
84
85
86
87
  // 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
88
89
  struct cmCTestTestProperties
  {
90
91
    std::string Name;
    std::string Directory;
Andy Cedilnik's avatar
Andy Cedilnik committed
92
    std::vector<std::string> Args;
93
    std::vector<std::string> RequiredFiles;
94
    std::vector<std::string> Depends;
95
    std::vector<std::string> AttachedFiles;
96
    std::vector<std::string> AttachOnFail;
Bill Hoffman's avatar
Bill Hoffman committed
97
98
99
100
    std::vector<std::pair<cmsys::RegularExpression,
                          std::string> > ErrorRegularExpressions;
    std::vector<std::pair<cmsys::RegularExpression,
                          std::string> > RequiredRegularExpressions;
101
    std::map<std::string, std::string> Measurements;
Andy Cedilnik's avatar
Andy Cedilnik committed
102
103
    bool IsInBasedOnREOptions;
    bool WillFail;
104
    float Cost;
105
    int PreviousRuns;
106
    bool RunSerial;
107
    double Timeout;
108
    bool ExplicitTimeout;
109
    int Index;
110
111
    //Requested number of process slots
    int Processors;
112
113
    // return code of test which will mark test as "not run"
    int SkipReturnCode;
114
    std::vector<std::string> Environment;
115
    std::vector<std::string> Labels;
Zach's avatar
Zach committed
116
    std::set<std::string> LockedResources;
Andy Cedilnik's avatar
Andy Cedilnik committed
117
118
  };

119
120
121
122
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
123
    std::string Reason;
124
125
126
127
    std::string FullCommandLine;
    double      ExecutionTime;
    int         ReturnValue;
    int         Status;
128
    bool        CompressOutput;
129
130
131
132
133
134
135
    std::string CompletionStatus;
    std::string Output;
    std::string RegressionImages;
    int         TestCount;
    cmCTestTestProperties* Properties;
  };

136
137
138
139
140
141
142
143
144
145
  struct cmCTestTestResultLess
  {
    bool operator() (const cmCTestTestResult &lhs,
                     const cmCTestTestResult &rhs) const
    {
    return lhs.TestCount < rhs.TestCount;
    }
  };

  // add configurations to a search path for an executable
Brad King's avatar
Brad King committed
146
  static void AddConfigurations(cmCTest *ctest,
147
148
149
150
151
152
153
154
155
156
157
158
                                std::vector<std::string> &attempted,
                                std::vector<std::string> &attemptedConfigs,
                                std::string filepath,
                                std::string &filename);

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

159
  typedef std::vector<cmCTestTestProperties> ListOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
160
protected:
161
  // compute a final test list
162
163
  virtual int PreProcessHandler();
  virtual int PostProcessHandler();
164
  virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
165
  int ExecuteCommands(std::vector<std::string>& vec);
166

167
168
  void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
  void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
169
170
  // Write attached test files into the xml
  void AttachFiles(std::ostream& os, cmCTestTestResult* result);
171

172
173
174
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

Andy Cedilnik's avatar
Andy Cedilnik committed
175
  double                  ElapsedTestingTime;
176

Andy Cedilnik's avatar
Andy Cedilnik committed
177
178
  typedef std::vector<cmCTestTestResult> TestResultsVector;
  TestResultsVector    TestResults;
Ken Martin's avatar
Ken Martin committed
179

180
  std::vector<std::string> CustomTestsIgnore;
Andy Cedilnik's avatar
Andy Cedilnik committed
181
182
  std::string             StartTest;
  std::string             EndTest;
183
184
  unsigned int            StartTestTime;
  unsigned int            EndTestTime;
Andy Cedilnik's avatar
Andy Cedilnik committed
185
  bool MemCheck;
186
187
  int CustomMaximumPassedTestOutputSize;
  int CustomMaximumFailedTestOutputSize;
188
  int MaxIndex;
189
public:
190
191
192
193
194
195
196
197
198
199
200
201
  enum { // Program statuses
    NOT_RUN = 0,
    TIMEOUT,
    SEGFAULT,
    ILLEGAL,
    INTERRUPT,
    NUMERICAL,
    OTHER_FAULT,
    FAILED,
    BAD_COMMAND,
    COMPLETED
  };
Ken Martin's avatar
Ken Martin committed
202

203
private:
Ken Martin's avatar
Ken Martin committed
204
205
206
  /**
   * Generate the Dart compatible output
   */
207
  virtual void GenerateDartOutput(std::ostream& os);
Ken Martin's avatar
Ken Martin committed
208

209
  void PrintLabelSummary();
Ken Martin's avatar
Ken Martin committed
210
  /**
211
   * Run the tests for a directory and any subdirectories
Ken Martin's avatar
Ken Martin committed
212
   */
213
214
  void ProcessDirectory(std::vector<std::string> &passed,
                        std::vector<std::string> &failed);
Andy Cedilnik's avatar
Andy Cedilnik committed
215

Ken Martin's avatar
Ken Martin committed
216
217
218
  /**
   * Get the list of tests in directory and subdirectories.
   */
219
  void GetListOfTests();
220
221
222
  // 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
223

224
225
226
227
228
229
  // compute the lists of tests that will actually run
  // based on LastTestFailed.log
  void ComputeTestListForRerunFailed();

  void UpdateMaxTestNameWidth();

230
231
  bool GetValue(const char* tag,
                std::string& value,
232
                std::istream& fin);
233
234
  bool GetValue(const char* tag,
                int& value,
235
                std::istream& fin);
236
237
  bool GetValue(const char* tag,
                size_t& value,
238
                std::istream& fin);
239
240
  bool GetValue(const char* tag,
                bool& value,
241
                std::istream& fin);
242
243
  bool GetValue(const char* tag,
                double& value,
244
                std::istream& fin);
Ken Martin's avatar
Ken Martin committed
245
246
247
248
249
250
  /**
   * Find the executable for a test
   */
  std::string FindTheExecutable(const char *exe);

  const char* GetTestStatus(int status);
Bill Hoffman's avatar
Bill Hoffman committed
251
  void ExpandTestsToRunInformation(size_t numPossibleTests);
252
  void ExpandTestsToRunInformationForRerunFailed();
Ken Martin's avatar
Ken Martin committed
253

254
255
  std::vector<std::string> CustomPreTest;
  std::vector<std::string> CustomPostTest;
Ken Martin's avatar
Ken Martin committed
256

Andy Cedilnik's avatar
Andy Cedilnik committed
257
  std::vector<int>        TestsToRun;
Ken Martin's avatar
Ken Martin committed
258

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

  std::string GenerateRegressionImages(const std::string& xml);
Bill Hoffman's avatar
Bill Hoffman committed
274
  cmsys::RegularExpression DartStuff1;
275
276
277
  void CheckLabelFilter(cmCTestTestProperties& it);
  void CheckLabelFilterExclude(cmCTestTestProperties& it);
  void CheckLabelFilterInclude(cmCTestTestProperties& it);
Ken Martin's avatar
Ken Martin committed
278
279

  std::string TestsToRunString;
Andy Cedilnik's avatar
Andy Cedilnik committed
280
281
  bool UseUnion;
  ListOfTests TestList;
282
  size_t TotalNumberOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
283
  cmsys::RegularExpression DartStuff;
Andy Cedilnik's avatar
Andy Cedilnik committed
284

Andy Cedilnik's avatar
Andy Cedilnik committed
285
  std::ostream* LogFile;
286
287

  bool RerunFailed;
Ken Martin's avatar
Ken Martin committed
288
289
290
};

#endif