cmCTestTestHandler.h 4.73 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
{
public:
34
  cmTypeMacro(cmCTestTestHandler, cmCTestGenericHandler);
Ken Martin's avatar
Ken Martin committed
35

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

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

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

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

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
69
70
  /*
   * Add the test to the list of tests to be executed
   */
  bool AddTest(const std::vector<std::string>& args);

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

76
77
  void Initialize();

Andy Cedilnik's avatar
Andy Cedilnik committed
78
79
  struct cmCTestTestProperties
  {
Andy Cedilnik's avatar
Andy Cedilnik committed
80
81
82
83
84
    cmStdString Name;
    cmStdString Directory;
    std::vector<std::string> Args;
    std::vector<cmsys::RegularExpression> ErrorRegularExpressions;
    std::vector<cmsys::RegularExpression> RequiredRegularExpressions;
85
    std::map<cmStdString, cmStdString> Measurements;
Andy Cedilnik's avatar
Andy Cedilnik committed
86
87
    bool IsInBasedOnREOptions;
    bool WillFail;
Andy Cedilnik's avatar
Andy Cedilnik committed
88
89
  };

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  struct cmCTestTestResult
  {
    std::string Name;
    std::string Path;
    std::string FullCommandLine;
    double      ExecutionTime;
    int         ReturnValue;
    int         Status;
    std::string CompletionStatus;
    std::string Output;
    std::string RegressionImages;
    int         TestCount;
    cmCTestTestProperties* Properties;
  };

Andy Cedilnik's avatar
Andy Cedilnik committed
105
protected:
106
107
108
109
110
  virtual int PreProcessHandler();
  virtual int PostProcessHandler();
  virtual void GenerateTestCommand(std::vector<const char*>& args);
  int ExecuteCommands(std::vector<cmStdString>& vec);

111
112
113
  //! Clean test output to specified length
  bool CleanTestOutput(std::string& output, size_t length);

Andy Cedilnik's avatar
Andy Cedilnik committed
114
  double                  ElapsedTestingTime;
115

Andy Cedilnik's avatar
Andy Cedilnik committed
116
117
  typedef std::vector<cmCTestTestResult> TestResultsVector;
  TestResultsVector    TestResults;
Ken Martin's avatar
Ken Martin committed
118

Andy Cedilnik's avatar
Andy Cedilnik committed
119
120
121
122
  std::vector<cmStdString> CustomTestsIgnore;
  std::string             StartTest;
  std::string             EndTest;
  bool MemCheck;
123
124
125
  int CustomMaximumPassedTestOutputSize;
  int CustomMaximumFailedTestOutputSize;

126
127
128
129
130
131
132
133
134
135
136
137
138
139

private:
  enum { // Program statuses
    NOT_RUN = 0,
    TIMEOUT,
    SEGFAULT,
    ILLEGAL,
    INTERRUPT,
    NUMERICAL,
    OTHER_FAULT,
    FAILED,
    BAD_COMMAND,
    COMPLETED
  };
Ken Martin's avatar
Ken Martin committed
140
141
142
143
144


  /**
   * Generate the Dart compatible output
   */
145
  virtual void GenerateDartOutput(std::ostream& os);
Ken Martin's avatar
Ken Martin committed
146
147
148
149

  /**
   * Run the test for a directory and any subdirectories
   */
Andy Cedilnik's avatar
Andy Cedilnik committed
150
  void ProcessDirectory(std::vector<cmStdString> &passed,
151
                        std::vector<cmStdString> &failed);
Andy Cedilnik's avatar
Andy Cedilnik committed
152

Ken Martin's avatar
Ken Martin committed
153

Andy Cedilnik's avatar
Andy Cedilnik committed
154
  typedef std::vector<cmCTestTestProperties> ListOfTests;
Ken Martin's avatar
Ken Martin committed
155
156
157
  /**
   * Get the list of tests in directory and subdirectories.
   */
158
  void GetListOfTests();
Ken Martin's avatar
Ken Martin committed
159
160
161
162
163
164
165
166
167

  /**
   * Find the executable for a test
   */
  std::string FindTheExecutable(const char *exe);

  const char* GetTestStatus(int status);
  void ExpandTestsToRunInformation(int numPossibleTests);

Andy Cedilnik's avatar
Andy Cedilnik committed
168
169
  std::vector<cmStdString> CustomPreTest;
  std::vector<cmStdString> CustomPostTest;
Ken Martin's avatar
Ken Martin committed
170

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

Andy Cedilnik's avatar
Andy Cedilnik committed
173
174
175
176
177
178
179
  bool UseIncludeRegExpFlag;
  bool UseExcludeRegExpFlag;
  bool UseExcludeRegExpFirst;
  std::string IncludeRegExp;
  std::string ExcludeRegExp;
  cmsys::RegularExpression IncludeTestsRegularExpression;
  cmsys::RegularExpression ExcludeTestsRegularExpression;
Ken Martin's avatar
Ken Martin committed
180
181
182
183

  std::string GenerateRegressionImages(const std::string& xml);

  std::string TestsToRunString;
Andy Cedilnik's avatar
Andy Cedilnik committed
184
185
186
  bool UseUnion;
  ListOfTests TestList;
  cmsys::RegularExpression DartStuff;
Andy Cedilnik's avatar
Andy Cedilnik committed
187

Andy Cedilnik's avatar
Andy Cedilnik committed
188
  std::ostream* LogFile;
Ken Martin's avatar
Ken Martin committed
189
190
191
};

#endif