cmCTestTestCommand.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmCTestTestCommand.h"
  4. #include <chrono>
  5. #include <cstdlib>
  6. #include <ratio>
  7. #include <sstream>
  8. #include <utility>
  9. #include <vector>
  10. #include <cm/memory>
  11. #include "cmCTest.h"
  12. #include "cmCTestGenericHandler.h"
  13. #include "cmCTestTestHandler.h"
  14. #include "cmDuration.h"
  15. #include "cmExecutionStatus.h"
  16. #include "cmMakefile.h"
  17. #include "cmStringAlgorithms.h"
  18. #include "cmValue.h"
  19. std::unique_ptr<cmCTestGenericHandler> cmCTestTestCommand::InitializeHandler(
  20. HandlerArguments& arguments, cmExecutionStatus& status) const
  21. {
  22. cmMakefile& mf = status.GetMakefile();
  23. auto& args = static_cast<TestArguments&>(arguments);
  24. cmValue ctestTimeout = mf.GetDefinition("CTEST_TEST_TIMEOUT");
  25. cmDuration timeout;
  26. if (ctestTimeout) {
  27. timeout = cmDuration(atof(ctestTimeout->c_str()));
  28. } else {
  29. timeout = this->CTest->GetTimeOut();
  30. if (timeout <= cmDuration::zero()) {
  31. // By default use timeout of 10 minutes
  32. timeout = std::chrono::minutes(10);
  33. }
  34. }
  35. this->CTest->SetTimeOut(timeout);
  36. cmValue resourceSpecFile = mf.GetDefinition("CTEST_RESOURCE_SPEC_FILE");
  37. if (args.ResourceSpecFile.empty() && resourceSpecFile) {
  38. args.ResourceSpecFile = *resourceSpecFile;
  39. }
  40. auto handler = this->InitializeActualHandler(args, status);
  41. if (!args.Start.empty() || !args.End.empty() || !args.Stride.empty()) {
  42. handler->TestOptions.TestsToRunInformation =
  43. cmStrCat(args.Start, ',', args.End, ',', args.Stride);
  44. }
  45. if (!args.Exclude.empty()) {
  46. handler->TestOptions.ExcludeRegularExpression = args.Exclude;
  47. }
  48. if (!args.Include.empty()) {
  49. handler->TestOptions.IncludeRegularExpression = args.Include;
  50. }
  51. if (!args.ExcludeLabel.empty()) {
  52. handler->TestOptions.ExcludeLabelRegularExpression.push_back(
  53. args.ExcludeLabel);
  54. }
  55. if (!args.IncludeLabel.empty()) {
  56. handler->TestOptions.LabelRegularExpression.push_back(args.IncludeLabel);
  57. }
  58. if (!args.ExcludeTestsFromFile.empty()) {
  59. handler->TestOptions.ExcludeTestListFile = args.ExcludeTestsFromFile;
  60. }
  61. if (!args.IncludeTestsFromFile.empty()) {
  62. handler->TestOptions.TestListFile = args.IncludeTestsFromFile;
  63. }
  64. if (!args.ExcludeFixture.empty()) {
  65. handler->TestOptions.ExcludeFixtureRegularExpression = args.ExcludeFixture;
  66. }
  67. if (!args.ExcludeFixtureSetup.empty()) {
  68. handler->TestOptions.ExcludeFixtureSetupRegularExpression =
  69. args.ExcludeFixtureSetup;
  70. }
  71. if (!args.ExcludeFixtureCleanup.empty()) {
  72. handler->TestOptions.ExcludeFixtureCleanupRegularExpression =
  73. args.ExcludeFixtureCleanup;
  74. }
  75. if (args.StopOnFailure) {
  76. handler->TestOptions.StopOnFailure = true;
  77. }
  78. if (args.ParallelLevel) {
  79. handler->ParallelLevel = *args.ParallelLevel;
  80. }
  81. if (!args.Repeat.empty()) {
  82. handler->Repeat = args.Repeat;
  83. }
  84. if (!args.ScheduleRandom.empty()) {
  85. handler->TestOptions.ScheduleRandom = cmValue(args.ScheduleRandom).IsOn();
  86. }
  87. if (!args.ResourceSpecFile.empty()) {
  88. handler->TestOptions.ResourceSpecFile = args.ResourceSpecFile;
  89. }
  90. if (!args.StopTime.empty()) {
  91. this->CTest->SetStopTime(args.StopTime);
  92. }
  93. // Test load is determined by: TEST_LOAD argument,
  94. // or CTEST_TEST_LOAD script variable, or ctest --test-load
  95. // command line argument... in that order.
  96. unsigned long testLoad;
  97. cmValue ctestTestLoad = mf.GetDefinition("CTEST_TEST_LOAD");
  98. if (!args.TestLoad.empty()) {
  99. if (!cmStrToULong(args.TestLoad, &testLoad)) {
  100. testLoad = 0;
  101. cmCTestLog(this->CTest, WARNING,
  102. "Invalid value for 'TEST_LOAD' : " << args.TestLoad
  103. << std::endl);
  104. }
  105. } else if (cmNonempty(ctestTestLoad)) {
  106. if (!cmStrToULong(*ctestTestLoad, &testLoad)) {
  107. testLoad = 0;
  108. cmCTestLog(this->CTest, WARNING,
  109. "Invalid value for 'CTEST_TEST_LOAD' : " << *ctestTestLoad
  110. << std::endl);
  111. }
  112. } else {
  113. testLoad = this->CTest->GetTestLoad();
  114. }
  115. handler->SetTestLoad(testLoad);
  116. if (cmValue labelsForSubprojects =
  117. mf.GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) {
  118. this->CTest->SetCTestConfiguration("LabelsForSubprojects",
  119. *labelsForSubprojects, args.Quiet);
  120. }
  121. if (!args.OutputJUnit.empty()) {
  122. handler->SetJUnitXMLFileName(args.OutputJUnit);
  123. }
  124. handler->SetQuiet(args.Quiet);
  125. return std::unique_ptr<cmCTestGenericHandler>(std::move(handler));
  126. }
  127. std::unique_ptr<cmCTestTestHandler>
  128. cmCTestTestCommand::InitializeActualHandler(HandlerArguments&,
  129. cmExecutionStatus&) const
  130. {
  131. return cm::make_unique<cmCTestTestHandler>(this->CTest);
  132. }
  133. bool cmCTestTestCommand::InitialPass(std::vector<std::string> const& args,
  134. cmExecutionStatus& status) const
  135. {
  136. static auto const parser = MakeTestParser<TestArguments>();
  137. return this->Invoke(parser, args, status, [&](TestArguments& a) {
  138. return this->ExecuteHandlerCommand(a, status);
  139. });
  140. }