cmCTestTestCommand.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestTestCommand.h"
  11. #include "cmCTest.h"
  12. #include "cmCTestGenericHandler.h"
  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_PARALLEL_LEVEL] = "PARALLEL_LEVEL";
  23. this->Arguments[ctt_SCHEDULE_RANDOM] = "SCHEDULE_RANDOM";
  24. this->Arguments[ctt_STOP_TIME] = "STOP_TIME";
  25. this->Arguments[ctt_TEST_LOAD] = "TEST_LOAD";
  26. this->Arguments[ctt_LAST] = CM_NULLPTR;
  27. this->Last = ctt_LAST;
  28. }
  29. cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
  30. {
  31. const char* ctestTimeout =
  32. this->Makefile->GetDefinition("CTEST_TEST_TIMEOUT");
  33. double timeout = this->CTest->GetTimeOut();
  34. if (ctestTimeout) {
  35. timeout = atof(ctestTimeout);
  36. } else {
  37. if (timeout <= 0) {
  38. // By default use timeout of 10 minutes
  39. timeout = 600;
  40. }
  41. }
  42. this->CTest->SetTimeOut(timeout);
  43. cmCTestGenericHandler* handler = this->InitializeActualHandler();
  44. if (this->Values[ctt_START] || this->Values[ctt_END] ||
  45. this->Values[ctt_STRIDE]) {
  46. std::ostringstream testsToRunString;
  47. if (this->Values[ctt_START]) {
  48. testsToRunString << this->Values[ctt_START];
  49. }
  50. testsToRunString << ",";
  51. if (this->Values[ctt_END]) {
  52. testsToRunString << this->Values[ctt_END];
  53. }
  54. testsToRunString << ",";
  55. if (this->Values[ctt_STRIDE]) {
  56. testsToRunString << this->Values[ctt_STRIDE];
  57. }
  58. handler->SetOption("TestsToRunInformation",
  59. testsToRunString.str().c_str());
  60. }
  61. if (this->Values[ctt_EXCLUDE]) {
  62. handler->SetOption("ExcludeRegularExpression", this->Values[ctt_EXCLUDE]);
  63. }
  64. if (this->Values[ctt_INCLUDE]) {
  65. handler->SetOption("IncludeRegularExpression", this->Values[ctt_INCLUDE]);
  66. }
  67. if (this->Values[ctt_EXCLUDE_LABEL]) {
  68. handler->SetOption("ExcludeLabelRegularExpression",
  69. this->Values[ctt_EXCLUDE_LABEL]);
  70. }
  71. if (this->Values[ctt_INCLUDE_LABEL]) {
  72. handler->SetOption("LabelRegularExpression",
  73. this->Values[ctt_INCLUDE_LABEL]);
  74. }
  75. if (this->Values[ctt_PARALLEL_LEVEL]) {
  76. handler->SetOption("ParallelLevel", this->Values[ctt_PARALLEL_LEVEL]);
  77. }
  78. if (this->Values[ctt_SCHEDULE_RANDOM]) {
  79. handler->SetOption("ScheduleRandom", this->Values[ctt_SCHEDULE_RANDOM]);
  80. }
  81. if (this->Values[ctt_STOP_TIME]) {
  82. this->CTest->SetStopTime(this->Values[ctt_STOP_TIME]);
  83. }
  84. // Test load is determined by: TEST_LOAD argument,
  85. // or CTEST_TEST_LOAD script variable, or ctest --test-load
  86. // command line argument... in that order.
  87. unsigned long testLoad;
  88. const char* ctestTestLoad = this->Makefile->GetDefinition("CTEST_TEST_LOAD");
  89. if (this->Values[ctt_TEST_LOAD] && *this->Values[ctt_TEST_LOAD]) {
  90. if (!cmSystemTools::StringToULong(this->Values[ctt_TEST_LOAD],
  91. &testLoad)) {
  92. testLoad = 0;
  93. cmCTestLog(this->CTest, WARNING, "Invalid value for 'TEST_LOAD' : "
  94. << this->Values[ctt_TEST_LOAD] << std::endl);
  95. }
  96. } else if (ctestTestLoad && *ctestTestLoad) {
  97. if (!cmSystemTools::StringToULong(ctestTestLoad, &testLoad)) {
  98. testLoad = 0;
  99. cmCTestLog(this->CTest, WARNING, "Invalid value for 'CTEST_TEST_LOAD' : "
  100. << ctestTestLoad << std::endl);
  101. }
  102. } else {
  103. testLoad = this->CTest->GetTestLoad();
  104. }
  105. handler->SetTestLoad(testLoad);
  106. handler->SetQuiet(this->Quiet);
  107. return handler;
  108. }
  109. cmCTestGenericHandler* cmCTestTestCommand::InitializeActualHandler()
  110. {
  111. return this->CTest->GetInitializedHandler("test");
  112. }