ctest.cxx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTest.h"
  11. #include "cmSystemTools.h"
  12. // Need these for documentation support.
  13. #include "cmake.h"
  14. #include "cmDocumentation.h"
  15. #include "CTest/cmCTestScriptHandler.h"
  16. #include "CTest/cmCTestLaunch.h"
  17. //----------------------------------------------------------------------------
  18. static const char * cmDocumentationName[][2] =
  19. {
  20. {0,
  21. " ctest - Testing driver provided by CMake."},
  22. {0,0}
  23. };
  24. //----------------------------------------------------------------------------
  25. static const char * cmDocumentationUsage[][2] =
  26. {
  27. {0,
  28. " ctest [options]"},
  29. {0,0}
  30. };
  31. //----------------------------------------------------------------------------
  32. //----------------------------------------------------------------------------
  33. static const char * cmDocumentationOptions[][2] =
  34. {
  35. {"-C <cfg>, --build-config <cfg>", "Choose configuration to test."},
  36. {"-V,--verbose", "Enable verbose output from tests."},
  37. {"-VV,--extra-verbose", "Enable more verbose output from tests."},
  38. {"--debug", "Displaying more verbose internals of CTest."},
  39. {"--output-on-failure"},
  40. {"-F", "Enable failover."},
  41. {"-j <jobs>, --parallel <jobs>", "Run the tests in parallel using the"
  42. "given number of jobs."},
  43. {"-Q,--quiet", "Make ctest quiet."},
  44. {"-O <file>, --output-log <file>", "Output to log file"},
  45. {"-N,--show-only", "Disable actual execution of tests."},
  46. {"-L <regex>, --label-regex <regex>", "Run tests with labels matching "
  47. "regular expression."},
  48. {"-R <regex>, --tests-regex <regex>", "Run tests matching regular "
  49. "expression."},
  50. {"-E <regex>, --exclude-regex <regex>", "Exclude tests matching regular "
  51. "expression."},
  52. {"-LE <regex>, --label-exclude <regex>", "Exclude tests with labels "
  53. "matching regular expression."},
  54. {"-D <dashboard>, --dashboard <dashboard>", "Execute dashboard test"},
  55. {"-D <var>:<type>=<value>", "Define a variable for script mode"},
  56. {"-M <model>, --test-model <model>", "Sets the model for a dashboard"},
  57. {"-T <action>, --test-action <action>", "Sets the dashboard action to "
  58. "perform"},
  59. {"--track <track>", "Specify the track to submit dashboard to"},
  60. {"-S <script>, --script <script>", "Execute a dashboard for a "
  61. "configuration"},
  62. {"-SP <script>, --script-new-process <script>", "Execute a dashboard for a "
  63. "configuration"},
  64. {"-A <file>, --add-notes <file>", "Add a notes file with submission"},
  65. {"-I [Start,End,Stride,test#,test#|Test file], --tests-information",
  66. "Run a specific number of tests by number."},
  67. {"-U, --union", "Take the Union of -I and -R"},
  68. {"--rerun-failed", "Run only the tests that failed previously"},
  69. {"--max-width <width>", "Set the max width for a test name to output"},
  70. {"--interactive-debug-mode [0|1]", "Set the interactive mode to 0 or 1."},
  71. {"--no-label-summary", "Disable timing summary information for labels."},
  72. {"--build-and-test", "Configure, build and run a test."},
  73. {"--build-target", "Specify a specific target to build."},
  74. {"--build-nocmake", "Run the build without running cmake first."},
  75. {"--build-run-dir", "Specify directory to run programs from."},
  76. {"--build-two-config", "Run CMake twice"},
  77. {"--build-exe-dir", "Specify the directory for the executable."},
  78. {"--build-generator", "Specify the generator to use."},
  79. {"--build-generator-toolset", "Specify the generator-specific toolset."},
  80. {"--build-project", "Specify the name of the project to build."},
  81. {"--build-makeprogram", "Specify the make program to use."},
  82. {"--build-noclean", "Skip the make clean step."},
  83. {"--build-config-sample",
  84. "A sample executable to use to determine the configuration"},
  85. {"--build-options", "Add extra options to the build step."},
  86. {"--test-command", "The test to run with the --build-and-test option."},
  87. {"--test-timeout", "The time limit in seconds, internal use only."},
  88. {"--tomorrow-tag", "Nightly or experimental starts with next day tag."},
  89. {"--ctest-config", "The configuration file used to initialize CTest state "
  90. "when submitting dashboards."},
  91. {"--overwrite", "Overwrite CTest configuration option."},
  92. {"--extra-submit <file>[;<file>]", "Submit extra files to the dashboard."},
  93. {"--force-new-ctest-process", "Run child CTest instances as new processes"},
  94. {"--schedule-random", "Use a random order for scheduling tests"},
  95. {"--submit-index", "Submit individual dashboard tests with specific index"},
  96. {"--timeout <seconds>", "Set a global timeout on all tests."},
  97. {"--stop-time <time>",
  98. "Set a time at which all tests should stop running."},
  99. {"--http1.0", "Submit using HTTP 1.0."},
  100. {"--no-compress-output", "Do not compress test output when submitting."},
  101. {"--print-labels", "Print all available test labels."},
  102. {0,0}
  103. };
  104. // this is a test driver program for cmCTest.
  105. int main (int argc, char *argv[])
  106. {
  107. cmSystemTools::DoNotInheritStdPipes();
  108. cmSystemTools::EnableMSVCDebugHook();
  109. cmSystemTools::FindExecutableDirectory(argv[0]);
  110. // Dispatch 'ctest --launch' mode directly.
  111. if(argc >= 2 && strcmp(argv[1], "--launch") == 0)
  112. {
  113. return cmCTestLaunch::Main(argc, argv);
  114. }
  115. cmCTest inst;
  116. if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
  117. {
  118. cmCTestLog(&inst, ERROR_MESSAGE,
  119. "Current working directory cannot be established." << std::endl);
  120. return 1;
  121. }
  122. // If there is a testing input file, check for documentation options
  123. // only if there are actually arguments. We want running without
  124. // arguments to run tests.
  125. if(argc > 1 || !(cmSystemTools::FileExists("CTestTestfile.cmake") ||
  126. cmSystemTools::FileExists("DartTestfile.txt")))
  127. {
  128. if(argc == 1)
  129. {
  130. cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
  131. << std::endl
  132. << "No test configuration file found!" << std::endl
  133. << "*********************************" << std::endl);
  134. }
  135. cmDocumentation doc;
  136. doc.addCTestStandardDocSections();
  137. if(doc.CheckOptions(argc, argv))
  138. {
  139. cmake hcm;
  140. hcm.AddCMakePaths();
  141. doc.SetCMakeRoot(hcm.GetCacheDefinition("CMAKE_ROOT"));
  142. // Construct and print requested documentation.
  143. cmCTestScriptHandler* ch =
  144. static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
  145. ch->CreateCMake();
  146. doc.SetShowGenerators(false);
  147. doc.SetName("ctest");
  148. doc.SetSection("Name",cmDocumentationName);
  149. doc.SetSection("Usage",cmDocumentationUsage);
  150. doc.PrependSection("Options",cmDocumentationOptions);
  151. #ifdef cout
  152. # undef cout
  153. #endif
  154. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  155. #define cout no_cout_use_cmCTestLog
  156. }
  157. }
  158. #ifdef _WIN32
  159. std::string comspec = "cmw9xcom.exe";
  160. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  161. #endif
  162. // copy the args to a vector
  163. std::vector<std::string> args;
  164. for(int i =0; i < argc; ++i)
  165. {
  166. args.push_back(argv[i]);
  167. }
  168. // run ctest
  169. std::string output;
  170. int res = inst.Run(args,&output);
  171. cmCTestLog(&inst, OUTPUT, output);
  172. return res;
  173. }