cmCTestTestCommand.cxx 5.7 KB

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