cmCTestTestCommand.cxx 5.0 KB

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