cmCTestTestCommand.cxx 4.8 KB

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