cmCTestTestCommand.cxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_PARALLEL_LEVEL] = "PARALLEL_LEVEL";
  21. this->Arguments[ctt_SCHEDULE_RANDOM] = "SCHEDULE_RANDOM";
  22. this->Arguments[ctt_STOP_TIME] = "STOP_TIME";
  23. this->Arguments[ctt_TEST_LOAD] = "TEST_LOAD";
  24. this->Arguments[ctt_LAST] = CM_NULLPTR;
  25. this->Last = ctt_LAST;
  26. }
  27. cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
  28. {
  29. const char* ctestTimeout =
  30. this->Makefile->GetDefinition("CTEST_TEST_TIMEOUT");
  31. double timeout = this->CTest->GetTimeOut();
  32. if (ctestTimeout) {
  33. timeout = atof(ctestTimeout);
  34. } else {
  35. if (timeout <= 0) {
  36. // By default use timeout of 10 minutes
  37. timeout = 600;
  38. }
  39. }
  40. this->CTest->SetTimeOut(timeout);
  41. cmCTestGenericHandler* handler = this->InitializeActualHandler();
  42. if (this->Values[ctt_START] || this->Values[ctt_END] ||
  43. this->Values[ctt_STRIDE]) {
  44. std::ostringstream testsToRunString;
  45. if (this->Values[ctt_START]) {
  46. testsToRunString << this->Values[ctt_START];
  47. }
  48. testsToRunString << ",";
  49. if (this->Values[ctt_END]) {
  50. testsToRunString << this->Values[ctt_END];
  51. }
  52. testsToRunString << ",";
  53. if (this->Values[ctt_STRIDE]) {
  54. testsToRunString << this->Values[ctt_STRIDE];
  55. }
  56. handler->SetOption("TestsToRunInformation",
  57. testsToRunString.str().c_str());
  58. }
  59. if (this->Values[ctt_EXCLUDE]) {
  60. handler->SetOption("ExcludeRegularExpression", this->Values[ctt_EXCLUDE]);
  61. }
  62. if (this->Values[ctt_INCLUDE]) {
  63. handler->SetOption("IncludeRegularExpression", this->Values[ctt_INCLUDE]);
  64. }
  65. if (this->Values[ctt_EXCLUDE_LABEL]) {
  66. handler->SetOption("ExcludeLabelRegularExpression",
  67. this->Values[ctt_EXCLUDE_LABEL]);
  68. }
  69. if (this->Values[ctt_INCLUDE_LABEL]) {
  70. handler->SetOption("LabelRegularExpression",
  71. this->Values[ctt_INCLUDE_LABEL]);
  72. }
  73. if (this->Values[ctt_PARALLEL_LEVEL]) {
  74. handler->SetOption("ParallelLevel", this->Values[ctt_PARALLEL_LEVEL]);
  75. }
  76. if (this->Values[ctt_SCHEDULE_RANDOM]) {
  77. handler->SetOption("ScheduleRandom", this->Values[ctt_SCHEDULE_RANDOM]);
  78. }
  79. if (this->Values[ctt_STOP_TIME]) {
  80. this->CTest->SetStopTime(this->Values[ctt_STOP_TIME]);
  81. }
  82. // Test load is determined by: TEST_LOAD argument,
  83. // or CTEST_TEST_LOAD script variable, or ctest --test-load
  84. // command line argument... in that order.
  85. unsigned long testLoad;
  86. const char* ctestTestLoad = this->Makefile->GetDefinition("CTEST_TEST_LOAD");
  87. if (this->Values[ctt_TEST_LOAD] && *this->Values[ctt_TEST_LOAD]) {
  88. if (!cmSystemTools::StringToULong(this->Values[ctt_TEST_LOAD],
  89. &testLoad)) {
  90. testLoad = 0;
  91. cmCTestLog(this->CTest, WARNING, "Invalid value for 'TEST_LOAD' : "
  92. << this->Values[ctt_TEST_LOAD] << std::endl);
  93. }
  94. } else if (ctestTestLoad && *ctestTestLoad) {
  95. if (!cmSystemTools::StringToULong(ctestTestLoad, &testLoad)) {
  96. testLoad = 0;
  97. cmCTestLog(this->CTest, WARNING, "Invalid value for 'CTEST_TEST_LOAD' : "
  98. << ctestTestLoad << std::endl);
  99. }
  100. } else {
  101. testLoad = this->CTest->GetTestLoad();
  102. }
  103. handler->SetTestLoad(testLoad);
  104. handler->SetQuiet(this->Quiet);
  105. return handler;
  106. }
  107. cmCTestGenericHandler* cmCTestTestCommand::InitializeActualHandler()
  108. {
  109. return this->CTest->GetInitializedHandler("test");
  110. }