cmCTestTestHandler.h 8.06 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
  /**
   * This method is called when reading CTest custom file
   */
49
  void PopulateCustomVectors(cmMakefile *mf);
Andy Cedilnik's avatar
Andy Cedilnik committed
50

Ken Martin's avatar
Ken Martin committed
51
52
53
54
55
56
  ///! 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
57

58
59
  void SetMaxIndex(int n) {this->MaxIndex = n;}
  int GetMaxIndex() {return this->MaxIndex;}
Ken Martin's avatar
Ken Martin committed
60
61
62
63

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

64
  cmCTestTestHandler();
Ken Martin's avatar
Ken Martin committed
65

66
67
68
  /*
   * Add the test to the list of tests to be executed
   */
69
  bool AddTest(const std::vector<std::string>& args);
70

71
72
73
74
75
  /*
   * Set tests properties
   */
  bool SetTestsProperties(const std::vector<std::string>& args);

76
77
  void Initialize();

Bill Hoffman's avatar
Bill Hoffman committed
78
79
80
81
  // 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
82
83
  struct cmCTestTestProperties
  {
Andy Cedilnik's avatar
Andy Cedilnik committed
84
85
86
    cmStdString Name;
    cmStdString Directory;
    std::vector<std::string> Args;
87
    std::vector<std::string> RequiredFiles;
88
    std::vector<std::string> Depends;
89
    std::vector<std::string> AttachedFiles;
90
    std::vector<std::string> AttachOnFail;
Bill Hoffman's avatar
Bill Hoffman committed
91
92
93
94
    std::vector<std::pair<cmsys::RegularExpression,
                          std::string> > ErrorRegularExpressions;
    std::vector<std::pair<cmsys::RegularExpression,
                          std::string> > RequiredRegularExpressions;
95
    std::map<cmStdString, cmStdString> Measurements;
Andy Cedilnik's avatar
Andy Cedilnik committed
96
97
    bool IsInBasedOnREOptions;
    bool WillFail;
98
    float Cost;
99
    int PreviousRuns;
100
    bool RunSerial;
101
    double Timeout;
102
    bool ExplicitTimeout;
103
    int Index;
104
105
    //Requested number of process slots
    int Processors;
106
    std::vector<std::string> Environment;
107
    std::vector<std::string> Labels;
Zach's avatar
Zach committed
108
    std::set<std::string> LockedResources;
Andy Cedilnik's avatar
Andy Cedilnik committed
109
110
  };

111
112
113
114
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
115
    std::string Reason;
116
117
118
119
    std::string FullCommandLine;
    double      ExecutionTime;
    int         ReturnValue;
    int         Status;
120
    bool        CompressOutput;
121
122
123
124
125
126
127
    std::string CompletionStatus;
    std::string Output;
    std::string RegressionImages;
    int         TestCount;
    cmCTestTestProperties* Properties;
  };

128
129
130
131
132
133
134
135
136
137
  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
138
  static void AddConfigurations(cmCTest *ctest,
139
140
141
142
143
144
145
146
147
148
149
150
                                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);

151
  typedef std::vector<cmCTestTestProperties> ListOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
152
protected:
153
  // compute a final test list
154
155
  virtual int PreProcessHandler();
  virtual int PostProcessHandler();
Zach's avatar
Zach committed
156
  virtual void GenerateTestCommand(std::vector<std::string>& args);
157
158
  int ExecuteCommands(std::vector<cmStdString>& vec);

159
160
  void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
  void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);
161
162
  // Write attached test files into the xml
  void AttachFiles(std::ostream& os, cmCTestTestResult* result);
163

164
165
166
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

Andy Cedilnik's avatar
Andy Cedilnik committed
167
  double                  ElapsedTestingTime;
168

Andy Cedilnik's avatar
Andy Cedilnik committed
169
170
  typedef std::vector<cmCTestTestResult> TestResultsVector;
  TestResultsVector    TestResults;
Ken Martin's avatar
Ken Martin committed
171

Andy Cedilnik's avatar
Andy Cedilnik committed
172
173
174
  std::vector<cmStdString> CustomTestsIgnore;
  std::string             StartTest;
  std::string             EndTest;
175
176
  unsigned int            StartTestTime;
  unsigned int            EndTestTime;
Andy Cedilnik's avatar
Andy Cedilnik committed
177
  bool MemCheck;
178
179
  int CustomMaximumPassedTestOutputSize;
  int CustomMaximumFailedTestOutputSize;
180
  int MaxIndex;
181
public:
182
183
184
185
186
187
188
189
190
191
192
193
  enum { // Program statuses
    NOT_RUN = 0,
    TIMEOUT,
    SEGFAULT,
    ILLEGAL,
    INTERRUPT,
    NUMERICAL,
    OTHER_FAULT,
    FAILED,
    BAD_COMMAND,
    COMPLETED
  };
Ken Martin's avatar
Ken Martin committed
194

195
private:
Ken Martin's avatar
Ken Martin committed
196
197
198
  /**
   * Generate the Dart compatible output
   */
199
  virtual void GenerateDartOutput(std::ostream& os);
Ken Martin's avatar
Ken Martin committed
200

201
  void PrintLabelSummary();
Ken Martin's avatar
Ken Martin committed
202
  /**
203
   * Run the tests for a directory and any subdirectories
Ken Martin's avatar
Ken Martin committed
204
   */
Andy Cedilnik's avatar
Andy Cedilnik committed
205
  void ProcessDirectory(std::vector<cmStdString> &passed,
206
                        std::vector<cmStdString> &failed);
Andy Cedilnik's avatar
Andy Cedilnik committed
207

Ken Martin's avatar
Ken Martin committed
208
209
210
  /**
   * Get the list of tests in directory and subdirectories.
   */
211
  void GetListOfTests();
212
213
214
  // 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
215

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
  bool GetValue(const char* tag,
                std::string& value,
                std::ifstream& fin);
  bool GetValue(const char* tag,
                int& value,
                std::ifstream& fin);
  bool GetValue(const char* tag,
                size_t& value,
                std::ifstream& fin);
  bool GetValue(const char* tag,
                bool& value,
                std::ifstream& fin);
  bool GetValue(const char* tag,
                double& value,
                std::ifstream& fin);
Ken Martin's avatar
Ken Martin committed
231
232
233
234
235
236
  /**
   * Find the executable for a test
   */
  std::string FindTheExecutable(const char *exe);

  const char* GetTestStatus(int status);
Bill Hoffman's avatar
Bill Hoffman committed
237
  void ExpandTestsToRunInformation(size_t numPossibleTests);
Ken Martin's avatar
Ken Martin committed
238

Andy Cedilnik's avatar
Andy Cedilnik committed
239
240
  std::vector<cmStdString> CustomPreTest;
  std::vector<cmStdString> CustomPostTest;
Ken Martin's avatar
Ken Martin committed
241

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

244
245
  bool UseIncludeLabelRegExpFlag;
  bool UseExcludeLabelRegExpFlag;
Andy Cedilnik's avatar
Andy Cedilnik committed
246
247
248
  bool UseIncludeRegExpFlag;
  bool UseExcludeRegExpFlag;
  bool UseExcludeRegExpFirst;
249
250
  std::string IncludeLabelRegExp;
  std::string ExcludeLabelRegExp;
Andy Cedilnik's avatar
Andy Cedilnik committed
251
252
  std::string IncludeRegExp;
  std::string ExcludeRegExp;
253
254
  cmsys::RegularExpression IncludeLabelRegularExpression;
  cmsys::RegularExpression ExcludeLabelRegularExpression;
Andy Cedilnik's avatar
Andy Cedilnik committed
255
256
  cmsys::RegularExpression IncludeTestsRegularExpression;
  cmsys::RegularExpression ExcludeTestsRegularExpression;
Ken Martin's avatar
Ken Martin committed
257
258

  std::string GenerateRegressionImages(const std::string& xml);
Bill Hoffman's avatar
Bill Hoffman committed
259
  cmsys::RegularExpression DartStuff1;
260
261
262
  void CheckLabelFilter(cmCTestTestProperties& it);
  void CheckLabelFilterExclude(cmCTestTestProperties& it);
  void CheckLabelFilterInclude(cmCTestTestProperties& it);
Ken Martin's avatar
Ken Martin committed
263
264

  std::string TestsToRunString;
Andy Cedilnik's avatar
Andy Cedilnik committed
265
266
  bool UseUnion;
  ListOfTests TestList;
267
  size_t TotalNumberOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
268
  cmsys::RegularExpression DartStuff;
Andy Cedilnik's avatar
Andy Cedilnik committed
269

Andy Cedilnik's avatar
Andy Cedilnik committed
270
  std::ostream* LogFile;
Ken Martin's avatar
Ken Martin committed
271
272
273
};

#endif