cmCTestTestCommand.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "cmCTest.h"
  5. #include "cmCTestGenericHandler.h"
  6. #include "cmDuration.h"
  7. #include "cmMakefile.h"
  8. #include "cmSystemTools.h"
  9. #include <chrono>
  10. #include <sstream>
  11. #include <stdlib.h>
  12. #include <vector>
  13. cmCTestTestCommand::cmCTestTestCommand()
  14. {
  15. this->Arguments[ctt_START] = "START";
  16. this->Arguments[ctt_END] = "END";
  17. this->Arguments[ctt_STRIDE] = "STRIDE";
  18. this->Arguments[ctt_EXCLUDE] = "EXCLUDE";
  19. this->Arguments[ctt_INCLUDE] = "INCLUDE";
  20. this->Arguments[ctt_EXCLUDE_LABEL] = "EXCLUDE_LABEL";
  21. this->Arguments[ctt_INCLUDE_LABEL] = "INCLUDE_LABEL";
  22. this->Arguments[ctt_EXCLUDE_FIXTURE] = "EXCLUDE_FIXTURE";
  23. this->Arguments[ctt_EXCLUDE_FIXTURE_SETUP] = "EXCLUDE_FIXTURE_SETUP";
  24. this->Arguments[ctt_EXCLUDE_FIXTURE_CLEANUP] = "EXCLUDE_FIXTURE_CLEANUP";
  25. this->Arguments[ctt_PARALLEL_LEVEL] = "PARALLEL_LEVEL";
  26. this->Arguments[ctt_SCHEDULE_RANDOM] = "SCHEDULE_RANDOM";
  27. this->Arguments[ctt_STOP_TIME] = "STOP_TIME";
  28. this->Arguments[ctt_TEST_LOAD] = "TEST_LOAD";
  29. this->Arguments[ctt_LAST] = nullptr;
  30. this->Last = ctt_LAST;
  31. }
  32. cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
  33. {
  34. const char* ctestTimeout =
  35. this->Makefile->GetDefinition("CTEST_TEST_TIMEOUT");
  36. cmDuration timeout;
  37. if (ctestTimeout) {
  38. timeout = cmDuration(atof(ctestTimeout));
  39. } else {
  40. timeout = this->CTest->GetTimeOut();
  41. if (timeout <= cmDuration::zero()) {
  42. // By default use timeout of 10 minutes
  43. timeout = std::chrono::minutes(10);
  44. }
  45. }
  46. this->CTest->SetTimeOut(timeout);
  47. cmCTestGenericHandler* handler = this->InitializeActualHandler();
  48. if (this->Values[ctt_START] || this->Values[ctt_END] ||
  49. this->Values[ctt_STRIDE]) {
  50. std::ostringstream testsToRunString;
  51. if (this->Values[ctt_START]) {
  52. testsToRunString << this->Values[ctt_START];
  53. }
  54. testsToRunString << ",";
  55. if (this->Values[ctt_END]) {
  56. testsToRunString << this->Values[ctt_END];
  57. }
  58. testsToRunString << ",";
  59. if (this->Values[ctt_STRIDE]) {
  60. testsToRunString << this->Values[ctt_STRIDE];
  61. }
  62. handler->SetOption("TestsToRunInformation",
  63. testsToRunString.str().c_str());
  64. }
  65. if (this->Values[ctt_EXCLUDE]) {
  66. handler->SetOption("ExcludeRegularExpression", this->Values[ctt_EXCLUDE]);
  67. }
  68. if (this->Values[ctt_INCLUDE]) {
  69. handler->SetOption("IncludeRegularExpression", this->Values[ctt_INCLUDE]);
  70. }
  71. if (this->Values[ctt_EXCLUDE_LABEL]) {
  72. handler->SetOption("ExcludeLabelRegularExpression",
  73. this->Values[ctt_EXCLUDE_LABEL]);
  74. }
  75. if (this->Values[ctt_INCLUDE_LABEL]) {
  76. handler->SetOption("LabelRegularExpression",
  77. this->Values[ctt_INCLUDE_LABEL]);
  78. }
  79. if (this->Values[ctt_EXCLUDE_FIXTURE]) {
  80. handler->SetOption("ExcludeFixtureRegularExpression",
  81. this->Values[ctt_EXCLUDE_FIXTURE]);
  82. }
  83. if (this->Values[ctt_EXCLUDE_FIXTURE_SETUP]) {
  84. handler->SetOption("ExcludeFixtureSetupRegularExpression",
  85. this->Values[ctt_EXCLUDE_FIXTURE_SETUP]);
  86. }
  87. if (this->Values[ctt_EXCLUDE_FIXTURE_CLEANUP]) {
  88. handler->SetOption("ExcludeFixtureCleanupRegularExpression",
  89. this->Values[ctt_EXCLUDE_FIXTURE_CLEANUP]);
  90. }
  91. if (this->Values[ctt_PARALLEL_LEVEL]) {
  92. handler->SetOption("ParallelLevel", this->Values[ctt_PARALLEL_LEVEL]);
  93. }
  94. if (this->Values[ctt_SCHEDULE_RANDOM]) {
  95. handler->SetOption("ScheduleRandom", this->Values[ctt_SCHEDULE_RANDOM]);
  96. }
  97. if (this->Values[ctt_STOP_TIME]) {
  98. this->CTest->SetStopTime(this->Values[ctt_STOP_TIME]);
  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->Values[ctt_TEST_LOAD] && *this->Values[ctt_TEST_LOAD]) {
  106. if (!cmSystemTools::StringToULong(this->Values[ctt_TEST_LOAD],
  107. &testLoad)) {
  108. testLoad = 0;
  109. cmCTestLog(this->CTest, WARNING, "Invalid value for 'TEST_LOAD' : "
  110. << this->Values[ctt_TEST_LOAD] << std::endl);
  111. }
  112. } else if (ctestTestLoad && *ctestTestLoad) {
  113. if (!cmSystemTools::StringToULong(ctestTestLoad, &testLoad)) {
  114. testLoad = 0;
  115. cmCTestLog(this->CTest, WARNING, "Invalid value for 'CTEST_TEST_LOAD' : "
  116. << ctestTestLoad << std::endl);
  117. }
  118. } else {
  119. testLoad = this->CTest->GetTestLoad();
  120. }
  121. handler->SetTestLoad(testLoad);
  122. if (const char* labelsForSubprojects =
  123. this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) {
  124. this->CTest->SetCTestConfiguration("LabelsForSubprojects",
  125. labelsForSubprojects, this->Quiet);
  126. }
  127. handler->SetQuiet(this->Quiet);
  128. return handler;
  129. }
  130. cmCTestGenericHandler* cmCTestTestCommand::InitializeActualHandler()
  131. {
  132. return this->CTest->GetInitializedHandler("test");
  133. }