ctest.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTest.h"
  14. #include "cmSystemTools.h"
  15. // Need these for documentation support.
  16. #include "cmake.h"
  17. #include "cmDocumentation.h"
  18. //----------------------------------------------------------------------------
  19. static const cmDocumentationEntry cmDocumentationName[] =
  20. {
  21. {0,
  22. " ctest - Testing driver provided by CMake.", 0},
  23. {0,0,0}
  24. };
  25. //----------------------------------------------------------------------------
  26. static const cmDocumentationEntry cmDocumentationUsage[] =
  27. {
  28. {0,
  29. " ctest [options]", 0},
  30. {0,0,0}
  31. };
  32. //----------------------------------------------------------------------------
  33. static const cmDocumentationEntry cmDocumentationDescription[] =
  34. {
  35. {0,
  36. "The \"ctest\" executable is the CMake test driver program. "
  37. "CMake-generated build trees created for projects that use "
  38. "the ENABLE_TESTING and ADD_TEST commands have testing support. "
  39. "This program will run the tests and report results.", 0},
  40. CMAKE_STANDARD_INTRODUCTION,
  41. {0,0,0}
  42. };
  43. //----------------------------------------------------------------------------
  44. static const cmDocumentationEntry cmDocumentationOptions[] =
  45. {
  46. {"-C <cfg>, --build-config <cfg>", "Choose configuration to test.",
  47. "Some CMake-generated build trees can have multiple build configurations "
  48. "in the same tree. This option can be used to specify which one should "
  49. "be tested. Example configurations are \"Debug\" and \"Release\"."},
  50. {"-V,--verbose", "Enable verbose output from tests.",
  51. "Test output is normally suppressed and only summary information is "
  52. "displayed. This option will show all test output."},
  53. {"-VV,--extra-verbose", "Enable more verbose output from tests.",
  54. "Test output is normally suppressed and only summary information is "
  55. "displayed. This option will show even more test output."},
  56. {"--debug", "Displaying more verbose internals of CTest.",
  57. "This feature will result in large number of output that is mostly useful "
  58. "for debugging dashboard problems."},
  59. {"-Q,--quiet", "Make ctest quiet.",
  60. "This option will suppress all the output. The output log file will still be "
  61. "generated if the --output-log is specified. Options such as --verbose, "
  62. "--extra-verbose, and --debug are ignored if --quiet is specified."},
  63. {"-O <file>, --output-log <file>", "Output to log file",
  64. "This option tells ctest to write all its output to a log file."},
  65. {"-N,--show-only", "Disable actual execution of tests.",
  66. "This option tells ctest to list the tests that would be run but not "
  67. "actually run them. Useful in conjunction with the -R and -E options."},
  68. {"-R <regex>, --tests-regex <regex>", "Run tests matching regular expression.",
  69. "This option tells ctest to run only the tests whose names match the "
  70. "given regular expression."},
  71. {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular expression.",
  72. "This option tells ctest to NOT run the tests whose names match the "
  73. "given regular expression."},
  74. {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test",
  75. "This option tells ctest to perform act as a Dart client and perform "
  76. "a dashboard test. All tests are <Mode><Test>, where Mode can be Experimental, "
  77. "Nightly, and Continuous, and Test can be Start, Update, Configure, "
  78. "Build, Test, Coverage, and Submit."},
  79. {"-M <model>, --test-model <model>", "Sets the model for a dashboard",
  80. "This option tells ctest to act as a Dart client "
  81. "where the TestModel can be Experimental, "
  82. "Nightly, and Continuous. Combining -M and -T is similar to -D"},
  83. {"-T <action>, --test-action <action>", "Sets the dashboard action to perform",
  84. "This option tells ctest to act as a Dart client "
  85. "and perform some action such as start, build, test etc. "
  86. "Combining -M and -T is similar to -D"},
  87. {"-S <script>, --script <script>", "Execute a dashboard for a configuration",
  88. "This option tells ctest to load in a configuration script which sets "
  89. "a number of parameters such as the binary and source directories. Then "
  90. "ctest will do what is required to create and run a dashboard. This "
  91. "option basically sets up a dashboard and then runs ctest -D with the "
  92. "appropriate options."},
  93. {"-A <file>, --add-notes <file>", "Add a notes file with submission",
  94. "This option tells ctest to include a notes file when submitting dashboard. "},
  95. {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
  96. "Run a specific number of tests by number.",
  97. "This option causes ctest to run tests starting at number Start, ending "
  98. "at number End, and incrementing by Stride. Any additional numbers after "
  99. "Stride are considered individual test numbers. Start, End,or stride "
  100. "can be empty. Optionally a file can be given that contains the same "
  101. "syntax as the command line."},
  102. {"-U, --union", "Take the Union of -I and -R",
  103. "When both -R and -I are specified by default the intersection of "
  104. "tests are run. By specifying -U the union of tests is run instead."},
  105. {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1.",
  106. "This option causes ctest to run tests in either an interactive mode or "
  107. "a non-interactive mode. On Windows this means that in non-interactive "
  108. "mode, all system debug pop up windows are blocked. In dashboard mode "
  109. "(Experimental, Nightly, Continuous), the default is non-interactive. "
  110. "When just running tests not for a dashboard the default is to allow "
  111. "popups and interactive "
  112. "debugging."},
  113. {"--build-and-test", "Configure, build and run a test.",
  114. "This option tells ctest to configure (i.e. run cmake on), build, and or "
  115. "execute a test. The configure and test steps are optional. The arguments "
  116. "to this command line are the source and binary directories. By default "
  117. "this will run CMake on the Source/Bin directories specified unless "
  118. "--build-nocmake is specified. Both --build-makeprogram and "
  119. "--build-generator MUST be provided to use --built-and-test. If "
  120. "--test-command is specified then that will be run after the build is "
  121. "complete. Other options that affect this mode are --build-target "
  122. "--build-nocmake, --build-run-dir, "
  123. "--build-two-config, --build-exe-dir, --build-project,"
  124. "--build-noclean, --build-options"},
  125. {"--build-target", "Specify a specific target to build.",
  126. "This option goes with the --build-and-test option, if left out the all target is built." },
  127. {"--build-nocmake", "Run the build without running cmake first.",
  128. "Skip the cmake step." },
  129. {"--build-run-dir", "Specify directory to run programs from.",
  130. "Directory where programs will be after it has been compiled." },
  131. {"--build-two-config", "Run CMake twice", "" },
  132. {"--build-exe-dir", "Specify the directory for the executable.", "" },
  133. {"--build-generator", "Specify the generator to use.", "" },
  134. {"--build-project", "Specify the name of the project to build.", "" },
  135. {"--build-makeprogram", "Specify the make program to use.", "" },
  136. {"--build-noclean", "Skip the make clean step.", "" },
  137. {"--build-options", "Add extra options to the build step.",
  138. "This option must be the last option with the exception of --test-command" },
  139. {"--test-command", "The test to run with the --build-and-test option.", "" },
  140. {"--tomorrow-tag", "Nightly or experimental starts with next day tag.",
  141. "This is useful if the build will not finish in one day." },
  142. {"--ctest-config", "The configuration file used to initialize CTest state when submitting dashboards.",
  143. "This option tells CTest to use different initialization file instead of "
  144. "DartConfiguration.tcl. This way multiple initialization files can be used "
  145. "for example to submit to multiple dashboards." },
  146. {"--overwrite", "Overwrite CTest configuration option.",
  147. "By default ctest uses configuration options from configuration file. "
  148. "This option will overwrite the configuration option." },
  149. {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard.",
  150. "This option will submit extra files to the dashboard." },
  151. {"--force-new-ctest-process", "Run child CTest instances as new processes",
  152. "By default CTest will run child CTest instances within the same process. "
  153. "If this behavior is not desired, this argument will enforce new processes "
  154. "for child CTest processes." },
  155. {"--submit-index", "Submit individual dashboard tests with specific index",
  156. "This option allows performing the same CTest action (such as test) multiple "
  157. "times and submit all stages to the same dashboard (Dart2 required). "
  158. "Each execution requires different index." },
  159. {0,0,0}
  160. };
  161. //----------------------------------------------------------------------------
  162. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  163. {
  164. {0, "cmake", 0},
  165. {0, "ccmake", 0},
  166. {0, 0, 0}
  167. };
  168. // this is a test driver program for cmCTest.
  169. int main (int argc, char *argv[])
  170. {
  171. cmSystemTools::EnableMSVCDebugHook();
  172. int nocwd = 0;
  173. cmCTest inst;
  174. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  175. {
  176. cmCTestLog(&inst, ERROR_MESSAGE, "Current working directory cannot be established." << std::endl);
  177. nocwd = 1;
  178. }
  179. // If there is a testing input file, check for documentation options
  180. // only if there are actually arguments. We want running without
  181. // arguments to run tests.
  182. if(argc > 1 || !cmSystemTools::FileExists("DartTestfile.txt") &&
  183. !cmSystemTools::FileExists("CTestTestfile.cmake"))
  184. {
  185. if(argc == 1)
  186. {
  187. cmCTestLog(&inst, ERROR_MESSAGE, "*********************************" << std::endl
  188. << "No test configuration file found!" << std::endl
  189. << "*********************************" << std::endl);
  190. }
  191. cmDocumentation doc;
  192. if(doc.CheckOptions(argc, argv) || nocwd)
  193. {
  194. // Construct and print requested documentation.
  195. doc.SetName("ctest");
  196. doc.SetNameSection(cmDocumentationName);
  197. doc.SetUsageSection(cmDocumentationUsage);
  198. doc.SetDescriptionSection(cmDocumentationDescription);
  199. doc.SetOptionsSection(cmDocumentationOptions);
  200. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  201. #ifdef cout
  202. # undef cout
  203. #endif
  204. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  205. #define cout no_cout_use_cmCTestLog
  206. }
  207. }
  208. #ifdef _WIN32
  209. std::string comspec = "cmw9xcom.exe";
  210. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  211. #endif
  212. // copy the args to a vector
  213. std::vector<std::string> args;
  214. for(int i =0; i < argc; ++i)
  215. {
  216. args.push_back(argv[i]);
  217. }
  218. // run ctest
  219. std::string output;
  220. int res = inst.Run(args,&output);
  221. cmCTestLog(&inst, OUTPUT, output);
  222. cmListFileCache::ClearCache();
  223. return res;
  224. }