cmCTestTestCommand.cxx 5.1 KB

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