cmCTestTestCommand.cxx 5.1 KB

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