cmCTestTestHandler.h 7.37 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
2
3
4
5
6
7
8
9
10
11
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc. All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

Andy Cedilnik's avatar
Andy Cedilnik committed
12
13
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Ken Martin's avatar
Ken Martin committed
14
15
16
17
18
19
20
21
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#ifndef cmCTestTestHandler_h
#define cmCTestTestHandler_h


22
#include "cmCTestGenericHandler.h"
23
#include <cmsys/RegularExpression.hxx>
Ken Martin's avatar
Ken Martin committed
24
25
26
27
28
29
30

class cmMakefile;

/** \class cmCTestTestHandler
 * \brief A class that handles ctest -S invocations
 *
 */
31
class cmCTestTestHandler : public cmCTestGenericHandler
Ken Martin's avatar
Ken Martin committed
32
{
33
  friend class cmCTestRunTest;
34
  friend class cmCTestMultiProcessHandler;
Ken Martin's avatar
Ken Martin committed
35
public:
36
  cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
Ken Martin's avatar
Ken Martin committed
37

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

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

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

Ken Martin's avatar
Ken Martin committed
55
56
57
58
59
60
  ///! 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
61

Ken Martin's avatar
Ken Martin committed
62
63
64
65

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

66
  cmCTestTestHandler();
Ken Martin's avatar
Ken Martin committed
67

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

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

78
79
  void Initialize();

Bill Hoffman's avatar
Bill Hoffman committed
80
81
82
83
  // 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
84
85
  struct cmCTestTestProperties
  {
Andy Cedilnik's avatar
Andy Cedilnik committed
86
87
88
    cmStdString Name;
    cmStdString Directory;
    std::vector<std::string> Args;
89
    std::vector<std::string> Depends;
Bill Hoffman's avatar
Bill Hoffman committed
90
91
92
93
    std::vector<std::pair<cmsys::RegularExpression,
                          std::string> > ErrorRegularExpressions;
    std::vector<std::pair<cmsys::RegularExpression,
                          std::string> > RequiredRegularExpressions;
94
    std::map<cmStdString, cmStdString> Measurements;
Andy Cedilnik's avatar
Andy Cedilnik committed
95
96
    bool IsInBasedOnREOptions;
    bool WillFail;
97
    double Timeout;
98
    int Index;
99
    std::vector<std::string> Environment;
100
    std::vector<std::string> Labels;
Andy Cedilnik's avatar
Andy Cedilnik committed
101
102
  };

103
104
105
106
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
107
    std::string Reason;
108
109
110
111
112
113
114
115
116
117
118
    std::string FullCommandLine;
    double      ExecutionTime;
    int         ReturnValue;
    int         Status;
    std::string CompletionStatus;
    std::string Output;
    std::string RegressionImages;
    int         TestCount;
    cmCTestTestProperties* Properties;
  };

119
120
121
122
123
124
125
126
127
128
129
130
131
132
  // add configuraitons to a search path for an executable
  static void AddConfigurations(cmCTest *ctest, 
                                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);

133
  typedef std::vector<cmCTestTestProperties> ListOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
134
protected:
135
  // comput a final test list
136
137
  virtual int PreProcessHandler();
  virtual int PostProcessHandler();
Zach's avatar
Zach committed
138
  virtual void GenerateTestCommand(std::vector<std::string>& args);
139
140
  int ExecuteCommands(std::vector<cmStdString>& vec);

141
142
143
  void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result);
  void WriteTestResultFooter(std::ostream& os, cmCTestTestResult* result);

144
145
146
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

Andy Cedilnik's avatar
Andy Cedilnik committed
147
  double                  ElapsedTestingTime;
148

Andy Cedilnik's avatar
Andy Cedilnik committed
149
150
  typedef std::vector<cmCTestTestResult> TestResultsVector;
  TestResultsVector    TestResults;
Ken Martin's avatar
Ken Martin committed
151

Andy Cedilnik's avatar
Andy Cedilnik committed
152
153
154
  std::vector<cmStdString> CustomTestsIgnore;
  std::string             StartTest;
  std::string             EndTest;
155
156
  unsigned int            StartTestTime;
  unsigned int            EndTestTime;
Andy Cedilnik's avatar
Andy Cedilnik committed
157
  bool MemCheck;
158
159
  int CustomMaximumPassedTestOutputSize;
  int CustomMaximumFailedTestOutputSize;
160
public:
161
162
163
164
165
166
167
168
169
170
171
172
  enum { // Program statuses
    NOT_RUN = 0,
    TIMEOUT,
    SEGFAULT,
    ILLEGAL,
    INTERRUPT,
    NUMERICAL,
    OTHER_FAULT,
    FAILED,
    BAD_COMMAND,
    COMPLETED
  };
Ken Martin's avatar
Ken Martin committed
173

174
private:
Ken Martin's avatar
Ken Martin committed
175
176
177
  /**
   * Generate the Dart compatible output
   */
178
  virtual void GenerateDartOutput(std::ostream& os);
Ken Martin's avatar
Ken Martin committed
179

180
  void PrintLabelSummary();
Ken Martin's avatar
Ken Martin committed
181
  /**
182
   * Run the tests for a directory and any subdirectories
Ken Martin's avatar
Ken Martin committed
183
   */
Andy Cedilnik's avatar
Andy Cedilnik committed
184
  void ProcessDirectory(std::vector<cmStdString> &passed,
185
                        std::vector<cmStdString> &failed);
Andy Cedilnik's avatar
Andy Cedilnik committed
186

Ken Martin's avatar
Ken Martin committed
187
188
189
  /**
   * Get the list of tests in directory and subdirectories.
   */
190
  void GetListOfTests();
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  // compute the lists of tests that will actually run
  // based on union regex and -I stuff
  void ComputeTestList();
  
  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
210
211
212
213
214
215
  /**
   * Find the executable for a test
   */
  std::string FindTheExecutable(const char *exe);

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

Andy Cedilnik's avatar
Andy Cedilnik committed
218
219
  std::vector<cmStdString> CustomPreTest;
  std::vector<cmStdString> CustomPostTest;
Ken Martin's avatar
Ken Martin committed
220

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

223
224
  bool UseIncludeLabelRegExpFlag;
  bool UseExcludeLabelRegExpFlag;
Andy Cedilnik's avatar
Andy Cedilnik committed
225
226
227
  bool UseIncludeRegExpFlag;
  bool UseExcludeRegExpFlag;
  bool UseExcludeRegExpFirst;
228
229
  std::string IncludeLabelRegExp;
  std::string ExcludeLabelRegExp;
Andy Cedilnik's avatar
Andy Cedilnik committed
230
231
  std::string IncludeRegExp;
  std::string ExcludeRegExp;
232
233
  cmsys::RegularExpression IncludeLabelRegularExpression;
  cmsys::RegularExpression ExcludeLabelRegularExpression;
Andy Cedilnik's avatar
Andy Cedilnik committed
234
235
  cmsys::RegularExpression IncludeTestsRegularExpression;
  cmsys::RegularExpression ExcludeTestsRegularExpression;
Ken Martin's avatar
Ken Martin committed
236
237

  std::string GenerateRegressionImages(const std::string& xml);
Bill Hoffman's avatar
Bill Hoffman committed
238
  cmsys::RegularExpression DartStuff1;
239
240
241
  void CheckLabelFilter(cmCTestTestProperties& it);
  void CheckLabelFilterExclude(cmCTestTestProperties& it);
  void CheckLabelFilterInclude(cmCTestTestProperties& it);
Ken Martin's avatar
Ken Martin committed
242
243

  std::string TestsToRunString;
Andy Cedilnik's avatar
Andy Cedilnik committed
244
245
  bool UseUnion;
  ListOfTests TestList;
246
  size_t TotalNumberOfTests;
Andy Cedilnik's avatar
Andy Cedilnik committed
247
  cmsys::RegularExpression DartStuff;
Andy Cedilnik's avatar
Andy Cedilnik committed
248

Andy Cedilnik's avatar
Andy Cedilnik committed
249
  std::ostream* LogFile;
Ken Martin's avatar
Ken Martin committed
250
251
252
};

#endif