cmCTestTestHandler.h 8.78 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

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;
Ken Martin's avatar
Ken Martin committed
32
public:
33
  cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
Ken Martin's avatar
Ken Martin committed
34

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

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

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

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

Ken Martin's avatar
Ken Martin committed
58
59
60
61
62
63
  ///! 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
64

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

68
69
70
71
72
  void SetTestOutputSizePassed(int n)
    { this->CustomMaximumPassedTestOutputSize = n; }
  void SetTestOutputSizeFailed(int n)
    { this->CustomMaximumFailedTestOutputSize = n; }

Ken Martin's avatar
Ken Martin committed
73
74
75
  ///! pass the -I argument down
  void SetTestsToRunInformation(const char*);

76
  cmCTestTestHandler();
Ken Martin's avatar
Ken Martin committed
77

78
79
80
  /*
   * Add the test to the list of tests to be executed
   */
81
  bool AddTest(const std::vector<std::string>& args);
82

83
84
85
86
87
  /*
   * Set tests properties
   */
  bool SetTestsProperties(const std::vector<std::string>& args);

88
89
  void Initialize();

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

125
126
127
128
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
129
    std::string Reason;
130
131
132
133
    std::string FullCommandLine;
    double      ExecutionTime;
    int         ReturnValue;
    int         Status;
134
    bool        CompressOutput;
135
136
    std::string CompletionStatus;
    std::string Output;
137
    std::string DartString;
138
139
140
141
    int         TestCount;
    cmCTestTestProperties* Properties;
  };

142
143
144
145
146
147
148
149
150
151
  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
152
  static void AddConfigurations(cmCTest *ctest,
153
154
155
156
157
158
159
160
161
162
163
164
                                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);

165
  typedef std::vector<cmCTestTestProperties> ListOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
166
protected:
167
  // compute a final test list
168
169
  virtual int PreProcessHandler();
  virtual int PostProcessHandler();
170
  virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
171
  int ExecuteCommands(std::vector<std::string>& vec);
172

173
174
  void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result);
  void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result);
175
  // Write attached test files into the xml
176
  void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result);
177

178
179
180
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

Andy Cedilnik's avatar
Andy Cedilnik committed
181
  double                  ElapsedTestingTime;
182

Andy Cedilnik's avatar
Andy Cedilnik committed
183
184
  typedef std::vector<cmCTestTestResult> TestResultsVector;
  TestResultsVector    TestResults;
Ken Martin's avatar
Ken Martin committed
185

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

209
private:
Ken Martin's avatar
Ken Martin committed
210
211
212
  /**
   * Generate the Dart compatible output
   */
213
  virtual void GenerateDartOutput(cmXMLWriter& xml);
Ken Martin's avatar
Ken Martin committed
214

215
  void PrintLabelSummary();
Ken Martin's avatar
Ken Martin committed
216
  /**
217
   * Run the tests for a directory and any subdirectories
Ken Martin's avatar
Ken Martin committed
218
   */
219
220
  void ProcessDirectory(std::vector<std::string> &passed,
                        std::vector<std::string> &failed);
Andy Cedilnik's avatar
Andy Cedilnik committed
221

Ken Martin's avatar
Ken Martin committed
222
223
224
  /**
   * Get the list of tests in directory and subdirectories.
   */
225
  void GetListOfTests();
226
227
228
  // 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
229

230
231
232
233
234
235
  // compute the lists of tests that will actually run
  // based on LastTestFailed.log
  void ComputeTestListForRerunFailed();

  void UpdateMaxTestNameWidth();

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

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

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

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

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

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

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

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

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

#endif