cmCTestTestCommand.cxx 5.3 KB

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