Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / ctest.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmCTest.h"
13 #include "cmSystemTools.h"
14
15 // Need these for documentation support.
16 #include "cmake.h"
17 #include "cmDocumentation.h"
18
19 #include "CTest/cmCTestScriptHandler.h"
20 #include "CTest/cmCTestLaunch.h"
21
22 //----------------------------------------------------------------------------
23 static const char * cmDocumentationName[][3] =
24 {
25   {0,
26    "  ctest - Testing driver provided by CMake.", 0},
27   {0,0,0}
28 };
29
30 //----------------------------------------------------------------------------
31 static const char * cmDocumentationUsage[][3] =
32 {
33   {0,
34    "  ctest [options]", 0},
35   {0,0,0}
36 };
37
38 //----------------------------------------------------------------------------
39 static const char * cmDocumentationDescription[][3] =
40 {
41   {0,
42    "The \"ctest\" executable is the CMake test driver program.  "
43    "CMake-generated build trees created for projects that use "
44    "the ENABLE_TESTING and ADD_TEST commands have testing support.  "
45    "This program will run the tests and report results.", 0},
46   {0,0,0}
47 };
48
49 //----------------------------------------------------------------------------
50 static const char * cmDocumentationOptions[][3] =
51 {
52   {"-C <cfg>, --build-config <cfg>", "Choose configuration to test.",
53    "Some CMake-generated build trees can have multiple build configurations "
54    "in the same tree.  This option can be used to specify which one should "
55    "be tested.  Example configurations are \"Debug\" and \"Release\"."},
56   {"-V,--verbose", "Enable verbose output from tests.",
57    "Test output is normally suppressed and only summary information is "
58    "displayed.  This option will show all test output."},
59   {"-VV,--extra-verbose", "Enable more verbose output from tests.",
60    "Test output is normally suppressed and only summary information is "
61    "displayed.  This option will show even more test output."},
62   {"--debug", "Displaying more verbose internals of CTest.",
63     "This feature will result in large number of output that is mostly "
64     "useful for debugging dashboard problems."},
65   {"--output-on-failure", "Output anything outputted by the test program "
66    "if the test should fail.  This option can also be enabled by setting "
67    "the environment variable CTEST_OUTPUT_ON_FAILURE"},
68   {"-F", "Enable failover.", "This option allows ctest to resume a test "
69    "set execution that was previously interrupted.  If no interruption "
70    "occurred, the -F option will have no effect."},
71   {"-j <jobs>, --parallel <jobs>", "Run the tests in parallel using the"
72    "given number of jobs.",
73    "This option tells ctest to run the tests in parallel using given "
74    "number of jobs."},
75   {"-Q,--quiet", "Make ctest quiet.",
76     "This option will suppress all the output. The output log file will "
77     "still be generated if the --output-log is specified. Options such "
78     "as --verbose, --extra-verbose, and --debug are ignored if --quiet is "
79     "specified."},
80   {"-O <file>, --output-log <file>", "Output to log file",
81    "This option tells ctest to write all its output to a log file."},
82   {"-N,--show-only", "Disable actual execution of tests.",
83    "This option tells ctest to list the tests that would be run but not "
84    "actually run them.  Useful in conjunction with the -R and -E options."},
85   {"-L <regex>, --label-regex <regex>", "Run tests with labels matching "
86    "regular expression.",
87    "This option tells ctest to run only the tests whose labels match the "
88    "given regular expression."},
89   {"-R <regex>, --tests-regex <regex>", "Run tests matching regular "
90    "expression.",
91    "This option tells ctest to run only the tests whose names match the "
92    "given regular expression."},
93   {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular "
94    "expression.",
95    "This option tells ctest to NOT run the tests whose names match the "
96    "given regular expression."},
97   {"-LE <regex>, --label-exclude <regex>", "Exclude tests with labels "
98    "matching regular expression.",
99    "This option tells ctest to NOT run the tests whose labels match the "
100    "given regular expression."},
101   {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test",
102    "This option tells ctest to perform act as a Dart client and perform "
103    "a dashboard test. All tests are <Mode><Test>, where Mode can be "
104    "Experimental, Nightly, and Continuous, and Test can be Start, Update, "
105    "Configure, Build, Test, Coverage, and Submit."},
106   {"-D <var>:<type>=<value>", "Define a variable for script mode",
107    "Pass in variable values on the command line. Use in "
108    "conjunction with -S to pass variable values to a dashboard script. "
109    "Parsing -D arguments as variable values is only attempted if "
110    "the value following -D does not match any of the known dashboard "
111    "types."},
112   {"-M <model>, --test-model <model>", "Sets the model for a dashboard",
113    "This option tells ctest to act as a Dart client "
114    "where the TestModel can be Experimental, "
115    "Nightly, and Continuous. Combining -M and -T is similar to -D"},
116   {"-T <action>, --test-action <action>", "Sets the dashboard action to "
117    "perform",
118    "This option tells ctest to act as a Dart client "
119    "and perform some action such as start, build, test etc. "
120    "Combining -M and -T is similar to -D"},
121   {"--track <track>", "Specify the track to submit dashboard to",
122    "Submit dashboard to specified track instead of default one. By "
123    "default, the dashboard is submitted to Nightly, Experimental, or "
124    "Continuous track, but by specifying this option, the track can be "
125    "arbitrary."},
126   {"-S <script>, --script <script>", "Execute a dashboard for a "
127    "configuration",
128    "This option tells ctest to load in a configuration script which sets "
129    "a number of parameters such as the binary and source directories. Then "
130    "ctest will do what is required to create and run a dashboard. This "
131    "option basically sets up a dashboard and then runs ctest -D with the "
132    "appropriate options."},
133   {"-SP <script>, --script-new-process <script>", "Execute a dashboard for a "
134    "configuration",
135    "This option does the same operations as -S but it will do them in a "
136    "separate process. This is primarily useful in cases where the script "
137    "may modify the environment and you do not want the modified environment "
138    "to impact other -S scripts."},
139   {"-A <file>, --add-notes <file>", "Add a notes file with submission",
140    "This option tells ctest to include a notes file when submitting "
141    "dashboard. "},
142   {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
143    "Run a specific number of tests by number.",
144    "This option causes ctest to run tests starting at number Start, ending "
145    "at number End, and incrementing by Stride. Any additional numbers after "
146    "Stride are considered individual test numbers.  Start, End,or stride "
147    "can be empty.  Optionally a file can be given that contains the same "
148    "syntax as the command line."},
149   {"-U, --union", "Take the Union of -I and -R",
150    "When both -R and -I are specified by default the intersection of "
151    "tests are run. By specifying -U the union of tests is run instead."},
152   {"--max-width <width>", "Set the max width for a test name to output",
153    "Set the maximum width for each test name to show in the output.  This "
154    "allows the user to widen the output to avoid clipping the test name which "
155    "can be very annoying."},
156   {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1.",
157    "This option causes ctest to run tests in either an interactive mode or "
158    "a non-interactive mode. On Windows this means that in non-interactive "
159    "mode, all system debug pop up windows are blocked. In dashboard mode "
160    "(Experimental, Nightly, Continuous), the default is non-interactive.  "
161    "When just running tests not for a dashboard the default is to allow "
162    "popups and interactive "
163    "debugging."},
164   {"--no-label-summary", "Disable timing summary information for labels.",
165    "This option tells ctest not to print summary information for each label "
166    "associated with the tests run. If there are no labels on the "
167    "tests, nothing extra is printed."},
168   {"--build-and-test", "Configure, build and run a test.",
169    "This option tells ctest to configure (i.e. run cmake on), build, and or "
170    "execute a test. The configure and test steps are optional. The arguments "
171    "to this command line are the source and binary directories. By default "
172    "this will run CMake on the Source/Bin directories specified unless "
173    "--build-nocmake is specified. Both --build-makeprogram and "
174    "--build-generator MUST be provided to use --built-and-test. If "
175    "--test-command is specified then that will be run after the build is "
176    "complete. Other options that affect this mode are --build-target "
177    "--build-nocmake, --build-run-dir, "
178    "--build-two-config, --build-exe-dir, --build-project,"
179    "--build-noclean, --build-options"},
180   {"--build-target", "Specify a specific target to build.",
181    "This option goes with the --build-and-test option, if left out the all "
182    "target is built." },
183   {"--build-nocmake", "Run the build without running cmake first.",
184    "Skip the cmake step." },
185   {"--build-run-dir", "Specify directory to run programs from.",
186    "Directory where programs will be after it has been compiled." },
187   {"--build-two-config", "Run CMake twice", "" },
188   {"--build-exe-dir", "Specify the directory for the executable.", "" },
189   {"--build-generator", "Specify the generator to use.", "" },
190   {"--build-project", "Specify the name of the project to build.", "" },
191   {"--build-makeprogram", "Specify the make program to use.", "" },
192   {"--build-noclean", "Skip the make clean step.", "" },
193   {"--build-config-sample",
194    "A sample executable to use to determine the configuration",
195    "A sample executable to use to determine the configuration that "
196    "should be used. e.g. Debug/Release/etc" },
197   {"--build-options", "Add extra options to the build step.",
198    "This option must be the last option with the exception of --test-command"
199   },
200
201   {"--test-command", "The test to run with the --build-and-test option.", ""
202   },
203   {"--test-timeout", "The time limit in seconds, internal use only.", ""
204   },
205   {"--tomorrow-tag", "Nightly or experimental starts with next day tag.",
206    "This is useful if the build will not finish in one day." },
207   {"--ctest-config", "The configuration file used to initialize CTest state "
208   "when submitting dashboards.",
209    "This option tells CTest to use different initialization file instead of "
210    "CTestConfiguration.tcl. This way multiple initialization files can be "
211    "used for example to submit to multiple dashboards." },
212   {"--overwrite", "Overwrite CTest configuration option.",
213    "By default ctest uses configuration options from configuration file. "
214    "This option will overwrite the configuration option." },
215   {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard.",
216    "This option will submit extra files to the dashboard." },
217   {"--force-new-ctest-process", "Run child CTest instances as new processes",
218    "By default CTest will run child CTest instances within the same process. "
219    "If this behavior is not desired, this argument will enforce new "
220    "processes for child CTest processes." },
221   {"--schedule-random", "Use a random order for scheduling tests",
222    "This option will run the tests in a random order. It is commonly used to "
223    "detect implicit dependencies in a test suite." },
224   {"--submit-index", "Submit individual dashboard tests with specific index",
225    "This option allows performing the same CTest action (such as test) "
226    "multiple times and submit all stages to the same dashboard (Dart2 "
227    "required). Each execution requires different index." },
228   {"--timeout <seconds>", "Set a global timeout on all tests.",
229    "This option will set a global timeout on all tests that do not already "
230    "have a timeout set on them."},
231   {"--stop-time <time>", "Set a time at which all tests should stop running.",
232    "Set a real time of day at which all tests should timeout. Example: "
233    "7:00:00 -0400. Any time format understood by the curl date parser is "
234    "accepted. Local time is assumed if no timezone is specified."},
235   {"--http1.0", "Submit using HTTP 1.0.",
236   "This option will force CTest to use HTTP 1.0 to submit files to the "
237   "dashboard, instead of HTTP 1.1."},
238   {"--no-compress-output", "Do not compress test output when submitting.",
239    "This flag will turn off automatic compression of test output.  Use this "
240    "to maintain compatibility with an older version of CDash which doesn't "
241    "support compressed test output."},
242   {"--print-labels", "Print all available test labels.",
243    "This option will not run any tests, it will simply print the list of "
244    "all labels associated with the test set."},
245   {"--help-command <cmd> [<file>]", "Show help for a single command and exit.",
246    "Prints the help for the command to stdout or to the specified file." },
247   {"--help-command-list [<file>]", "List available commands and exit.",
248    "Prints the list of all available listfile commands to stdout or the "
249    "specified file." },
250   {"--help-commands [<file>]", "Print help for all commands and exit.",
251    "Prints the help for all commands to stdout or to the specified file." },
252   {0,0,0}
253 };
254
255 //----------------------------------------------------------------------------
256 static const char * cmDocumentationSeeAlso[][3] =
257 {
258   {0, "cmake", 0},
259   {0, "ccmake", 0},
260   {0, 0, 0}
261 };
262
263 // this is a test driver program for cmCTest.
264 int main (int argc, char *argv[])
265 {
266   cmSystemTools::DoNotInheritStdPipes();
267   cmSystemTools::EnableMSVCDebugHook();
268   cmSystemTools::FindExecutableDirectory(argv[0]);
269
270   // Dispatch 'ctest --launch' mode directly.
271   if(argc >= 2 && strcmp(argv[1], "--launch") == 0)
272     {
273     return cmCTestLaunch::Main(argc, argv);
274     }
275
276   int nocwd = 0;
277   cmCTest inst;
278
279   if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
280     {
281     cmCTestLog(&inst, ERROR_MESSAGE,
282       "Current working directory cannot be established." << std::endl);
283     nocwd = 1;
284     }
285
286   // If there is a testing input file, check for documentation options
287   // only if there are actually arguments.  We want running without
288   // arguments to run tests.
289   if(argc > 1 || !(cmSystemTools::FileExists("CTestTestfile.cmake") ||
290                    cmSystemTools::FileExists("DartTestfile.txt")))
291     {
292     if(argc == 1)
293       {
294       cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
295         << std::endl
296         << "No test configuration file found!" << std::endl
297         << "*********************************" << std::endl);
298       }
299     cmDocumentation doc;
300     doc.addCTestStandardDocSections();
301     if(doc.CheckOptions(argc, argv) || nocwd)
302       {
303       // Construct and print requested documentation.
304       std::vector<cmDocumentationEntry> commands;
305       cmCTestScriptHandler* ch =
306                  static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
307       ch->CreateCMake();
308       ch->GetCommandDocumentation(commands);
309
310       doc.SetShowGenerators(false);
311       doc.SetName("ctest");
312       doc.SetSection("Name",cmDocumentationName);
313       doc.SetSection("Usage",cmDocumentationUsage);
314       doc.SetSection("Description",cmDocumentationDescription);
315       doc.PrependSection("Options",cmDocumentationOptions);
316       doc.SetSection("Commands",commands);
317       doc.SetSeeAlsoList(cmDocumentationSeeAlso);
318 #ifdef cout
319 #  undef cout
320 #endif
321       return doc.PrintRequestedDocumentation(std::cout)? 0:1;
322 #define cout no_cout_use_cmCTestLog
323       }
324     }
325
326 #ifdef _WIN32
327   std::string comspec = "cmw9xcom.exe";
328   cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
329 #endif
330   // copy the args to a vector
331   std::vector<std::string> args;
332   for(int i =0; i < argc; ++i)
333     {
334     args.push_back(argv[i]);
335     }
336   // run ctest
337   std::string output;
338   int res = inst.Run(args,&output);
339   cmCTestLog(&inst, OUTPUT, output);
340
341   return res;
342 }
343