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

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

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

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

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

83
84
  void Initialize();

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

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

137
138
139
140
141
142
143
144
145
146
  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
147
  static void AddConfigurations(cmCTest *ctest,
148
149
150
151
152
153
154
155
156
157
158
159
                                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);

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

168
169
  void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result);
  void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result);
170
  // Write attached test files into the xml
171
  void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result);
172

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

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

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

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

204
private:
Ken Martin's avatar
Ken Martin committed
205
206
207
  /**
   * Generate the Dart compatible output
   */
208
  virtual void GenerateDartOutput(cmXMLWriter& xml);
Ken Martin's avatar
Ken Martin committed
209

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

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

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

  void UpdateMaxTestNameWidth();

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

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

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

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

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

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

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

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

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

#endif