cmCTestTestCommand.cxx 5.2 KB

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