cmCTestTestCommand.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include "cmMakefile.h"
  14. #include "cmSystemTools.h"
  15. #include <sstream>
  16. #include <stdlib.h>
  17. #include <vector>
  18. cmCTestTestCommand::cmCTestTestCommand()
  19. {
  20. this->Arguments[ctt_START] = "START";
  21. this->Arguments[ctt_END] = "END";
  22. this->Arguments[ctt_STRIDE] = "STRIDE";
  23. this->Arguments[ctt_EXCLUDE] = "EXCLUDE";
  24. this->Arguments[ctt_INCLUDE] = "INCLUDE";
  25. this->Arguments[ctt_EXCLUDE_LABEL] = "EXCLUDE_LABEL";
  26. this->Arguments[ctt_INCLUDE_LABEL] = "INCLUDE_LABEL";
  27. this->Arguments[ctt_PARALLEL_LEVEL] = "PARALLEL_LEVEL";
  28. this->Arguments[ctt_SCHEDULE_RANDOM] = "SCHEDULE_RANDOM";
  29. this->Arguments[ctt_STOP_TIME] = "STOP_TIME";
  30. this->Arguments[ctt_TEST_LOAD] = "TEST_LOAD";
  31. this->Arguments[ctt_LAST] = CM_NULLPTR;
  32. this->Last = ctt_LAST;
  33. }
  34. cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
  35. {
  36. const char* ctestTimeout =
  37. this->Makefile->GetDefinition("CTEST_TEST_TIMEOUT");
  38. double timeout = this->CTest->GetTimeOut();
  39. if (ctestTimeout) {
  40. timeout = atof(ctestTimeout);
  41. } else {
  42. if (timeout <= 0) {
  43. // By default use timeout of 10 minutes
  44. timeout = 600;
  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_PARALLEL_LEVEL]) {
  81. handler->SetOption("ParallelLevel", this->Values[ctt_PARALLEL_LEVEL]);
  82. }
  83. if (this->Values[ctt_SCHEDULE_RANDOM]) {
  84. handler->SetOption("ScheduleRandom", this->Values[ctt_SCHEDULE_RANDOM]);
  85. }
  86. if (this->Values[ctt_STOP_TIME]) {
  87. this->CTest->SetStopTime(this->Values[ctt_STOP_TIME]);
  88. }
  89. // Test load is determined by: TEST_LOAD argument,
  90. // or CTEST_TEST_LOAD script variable, or ctest --test-load
  91. // command line argument... in that order.
  92. unsigned long testLoad;
  93. const char* ctestTestLoad = this->Makefile->GetDefinition("CTEST_TEST_LOAD");
  94. if (this->Values[ctt_TEST_LOAD] && *this->Values[ctt_TEST_LOAD]) {
  95. if (!cmSystemTools::StringToULong(this->Values[ctt_TEST_LOAD],
  96. &testLoad)) {
  97. testLoad = 0;
  98. cmCTestLog(this->CTest, WARNING, "Invalid value for 'TEST_LOAD' : "
  99. << this->Values[ctt_TEST_LOAD] << std::endl);
  100. }
  101. } else if (ctestTestLoad && *ctestTestLoad) {
  102. if (!cmSystemTools::StringToULong(ctestTestLoad, &testLoad)) {
  103. testLoad = 0;
  104. cmCTestLog(this->CTest, WARNING, "Invalid value for 'CTEST_TEST_LOAD' : "
  105. << ctestTestLoad << std::endl);
  106. }
  107. } else {
  108. testLoad = this->CTest->GetTestLoad();
  109. }
  110. handler->SetTestLoad(testLoad);
  111. handler->SetQuiet(this->Quiet);
  112. return handler;
  113. }
  114. cmCTestGenericHandler* cmCTestTestCommand::InitializeActualHandler()
  115. {
  116. return this->CTest->GetInitializedHandler("test");
  117. }