cmCTestTestCommand.cxx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCTestTestCommand.h"
  4. #include <chrono>
  5. #include <cstdlib>
  6. #include <sstream>
  7. #include <cmext/string_view>
  8. #include "cmCTest.h"
  9. #include "cmCTestGenericHandler.h"
  10. #include "cmCTestTestHandler.h"
  11. #include "cmDuration.h"
  12. #include "cmMakefile.h"
  13. #include "cmProperty.h"
  14. #include "cmStringAlgorithms.h"
  15. void cmCTestTestCommand::BindArguments()
  16. {
  17. this->cmCTestHandlerCommand::BindArguments();
  18. this->Bind("START"_s, this->Start);
  19. this->Bind("END"_s, this->End);
  20. this->Bind("STRIDE"_s, this->Stride);
  21. this->Bind("EXCLUDE"_s, this->Exclude);
  22. this->Bind("INCLUDE"_s, this->Include);
  23. this->Bind("EXCLUDE_LABEL"_s, this->ExcludeLabel);
  24. this->Bind("INCLUDE_LABEL"_s, this->IncludeLabel);
  25. this->Bind("EXCLUDE_FIXTURE"_s, this->ExcludeFixture);
  26. this->Bind("EXCLUDE_FIXTURE_SETUP"_s, this->ExcludeFixtureSetup);
  27. this->Bind("EXCLUDE_FIXTURE_CLEANUP"_s, this->ExcludeFixtureCleanup);
  28. this->Bind("PARALLEL_LEVEL"_s, this->ParallelLevel);
  29. this->Bind("REPEAT"_s, this->Repeat);
  30. this->Bind("SCHEDULE_RANDOM"_s, this->ScheduleRandom);
  31. this->Bind("STOP_TIME"_s, this->StopTime);
  32. this->Bind("TEST_LOAD"_s, this->TestLoad);
  33. this->Bind("RESOURCE_SPEC_FILE"_s, this->ResourceSpecFile);
  34. this->Bind("STOP_ON_FAILURE"_s, this->StopOnFailure);
  35. }
  36. cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
  37. {
  38. const char* ctestTimeout =
  39. this->Makefile->GetDefinition("CTEST_TEST_TIMEOUT");
  40. cmDuration timeout;
  41. if (ctestTimeout) {
  42. timeout = cmDuration(atof(ctestTimeout));
  43. } else {
  44. timeout = this->CTest->GetTimeOut();
  45. if (timeout <= cmDuration::zero()) {
  46. // By default use timeout of 10 minutes
  47. timeout = std::chrono::minutes(10);
  48. }
  49. }
  50. this->CTest->SetTimeOut(timeout);
  51. const char* resourceSpecFile =
  52. this->Makefile->GetDefinition("CTEST_RESOURCE_SPEC_FILE");
  53. if (this->ResourceSpecFile.empty() && resourceSpecFile) {
  54. this->ResourceSpecFile = resourceSpecFile;
  55. }
  56. cmCTestGenericHandler* handler = this->InitializeActualHandler();
  57. if (!this->Start.empty() || !this->End.empty() || !this->Stride.empty()) {
  58. handler->SetOption(
  59. "TestsToRunInformation",
  60. cmStrCat(this->Start, ',', this->End, ',', this->Stride).c_str());
  61. }
  62. if (!this->Exclude.empty()) {
  63. handler->SetOption("ExcludeRegularExpression", this->Exclude.c_str());
  64. }
  65. if (!this->Include.empty()) {
  66. handler->SetOption("IncludeRegularExpression", this->Include.c_str());
  67. }
  68. if (!this->ExcludeLabel.empty()) {
  69. handler->SetOption("ExcludeLabelRegularExpression",
  70. this->ExcludeLabel.c_str());
  71. }
  72. if (!this->IncludeLabel.empty()) {
  73. handler->SetOption("LabelRegularExpression", this->IncludeLabel.c_str());
  74. }
  75. if (!this->ExcludeFixture.empty()) {
  76. handler->SetOption("ExcludeFixtureRegularExpression",
  77. this->ExcludeFixture.c_str());
  78. }
  79. if (!this->ExcludeFixtureSetup.empty()) {
  80. handler->SetOption("ExcludeFixtureSetupRegularExpression",
  81. this->ExcludeFixtureSetup.c_str());
  82. }
  83. if (!this->ExcludeFixtureCleanup.empty()) {
  84. handler->SetOption("ExcludeFixtureCleanupRegularExpression",
  85. this->ExcludeFixtureCleanup.c_str());
  86. }
  87. if (this->StopOnFailure) {
  88. handler->SetOption("StopOnFailure", "ON");
  89. }
  90. if (!this->ParallelLevel.empty()) {
  91. handler->SetOption("ParallelLevel", this->ParallelLevel.c_str());
  92. }
  93. if (!this->Repeat.empty()) {
  94. handler->SetOption("Repeat", this->Repeat.c_str());
  95. }
  96. if (!this->ScheduleRandom.empty()) {
  97. handler->SetOption("ScheduleRandom", this->ScheduleRandom.c_str());
  98. }
  99. if (!this->ResourceSpecFile.empty()) {
  100. handler->SetOption("ResourceSpecFile", this->ResourceSpecFile.c_str());
  101. }
  102. if (!this->StopTime.empty()) {
  103. this->CTest->SetStopTime(this->StopTime);
  104. }
  105. // Test load is determined by: TEST_LOAD argument,
  106. // or CTEST_TEST_LOAD script variable, or ctest --test-load
  107. // command line argument... in that order.
  108. unsigned long testLoad;
  109. const char* ctestTestLoad = this->Makefile->GetDefinition("CTEST_TEST_LOAD");
  110. if (!this->TestLoad.empty()) {
  111. if (!cmStrToULong(this->TestLoad.c_str(), &testLoad)) {
  112. testLoad = 0;
  113. cmCTestLog(this->CTest, WARNING,
  114. "Invalid value for 'TEST_LOAD' : " << this->TestLoad
  115. << std::endl);
  116. }
  117. } else if (ctestTestLoad && *ctestTestLoad) {
  118. if (!cmStrToULong(ctestTestLoad, &testLoad)) {
  119. testLoad = 0;
  120. cmCTestLog(this->CTest, WARNING,
  121. "Invalid value for 'CTEST_TEST_LOAD' : " << ctestTestLoad
  122. << std::endl);
  123. }
  124. } else {
  125. testLoad = this->CTest->GetTestLoad();
  126. }
  127. handler->SetTestLoad(testLoad);
  128. if (cmProp labelsForSubprojects =
  129. this->Makefile->GetDef("CTEST_LABELS_FOR_SUBPROJECTS")) {
  130. this->CTest->SetCTestConfiguration("LabelsForSubprojects",
  131. *labelsForSubprojects, this->Quiet);
  132. }
  133. handler->SetQuiet(this->Quiet);
  134. return handler;
  135. }
  136. cmCTestGenericHandler* cmCTestTestCommand::InitializeActualHandler()
  137. {
  138. cmCTestTestHandler* handler = this->CTest->GetTestHandler();
  139. handler->Initialize();
  140. return handler;
  141. }