cmTest.cxx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 "cmTest.h"
  11. #include "cmSystemTools.h"
  12. #include "cmake.h"
  13. #include "cmMakefile.h"
  14. //----------------------------------------------------------------------------
  15. cmTest::cmTest(cmMakefile* mf)
  16. {
  17. this->Makefile = mf;
  18. this->OldStyle = true;
  19. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  20. this->Backtrace = new cmListFileBacktrace;
  21. this->Makefile->GetBacktrace(*this->Backtrace);
  22. }
  23. //----------------------------------------------------------------------------
  24. cmTest::~cmTest()
  25. {
  26. delete this->Backtrace;
  27. }
  28. //----------------------------------------------------------------------------
  29. cmListFileBacktrace const& cmTest::GetBacktrace() const
  30. {
  31. return *this->Backtrace;
  32. }
  33. //----------------------------------------------------------------------------
  34. void cmTest::SetName(const char* name)
  35. {
  36. if ( !name )
  37. {
  38. name = "";
  39. }
  40. this->Name = name;
  41. }
  42. //----------------------------------------------------------------------------
  43. void cmTest::SetCommand(std::vector<std::string> const& command)
  44. {
  45. this->Command = command;
  46. }
  47. //----------------------------------------------------------------------------
  48. const char *cmTest::GetProperty(const char* prop) const
  49. {
  50. bool chain = false;
  51. const char *retVal =
  52. this->Properties.GetPropertyValue(prop, cmProperty::TEST, chain);
  53. if (chain)
  54. {
  55. return this->Makefile->GetProperty(prop,cmProperty::TEST);
  56. }
  57. return retVal;
  58. }
  59. //----------------------------------------------------------------------------
  60. bool cmTest::GetPropertyAsBool(const char* prop) const
  61. {
  62. return cmSystemTools::IsOn(this->GetProperty(prop));
  63. }
  64. //----------------------------------------------------------------------------
  65. void cmTest::SetProperty(const char* prop, const char* value)
  66. {
  67. if (!prop)
  68. {
  69. return;
  70. }
  71. this->Properties.SetProperty(prop, value, cmProperty::TEST);
  72. }
  73. //----------------------------------------------------------------------------
  74. void cmTest::AppendProperty(const char* prop, const char* value, bool asString)
  75. {
  76. if (!prop)
  77. {
  78. return;
  79. }
  80. this->Properties.AppendProperty(prop, value, cmProperty::TEST, asString);
  81. }
  82. //----------------------------------------------------------------------------
  83. void cmTest::DefineProperties(cmake *cm)
  84. {
  85. cm->DefineProperty
  86. ("ATTACHED_FILES", cmProperty::TEST,
  87. "Attach a list of files to a dashboard submission.",
  88. "Set this property to a list of files that will be encoded and "
  89. "submitted to the dashboard as an addition to the test result.");
  90. cm->DefineProperty
  91. ("ATTACHED_FILES_ON_FAIL", cmProperty::TEST,
  92. "Attach a list of files to a dashboard submission if the test fails.",
  93. "Same as ATTACHED_FILES, but these files will only be included if the "
  94. "test does not pass.");
  95. cm->DefineProperty
  96. ("COST", cmProperty::TEST,
  97. "Set this to a floating point value. Tests in a test set will be "
  98. "run in descending order of cost.", "This property describes the cost "
  99. "of a test. You can explicitly set this value; tests with higher COST "
  100. "values will run first.");
  101. cm->DefineProperty
  102. ("DEPENDS", cmProperty::TEST,
  103. "Specifies that this test should only be run after the specified "
  104. "list of tests.",
  105. "Set this to a list of tests that must finish before this test is run.");
  106. cm->DefineProperty
  107. ("ENVIRONMENT", cmProperty::TEST,
  108. "Specify environment variables that should be defined for running "
  109. "a test.",
  110. "If set to a list of environment variables and values of the form "
  111. "MYVAR=value those environment variables will be defined while "
  112. "running the test. The environment is restored to its previous state "
  113. "after the test is done.");
  114. cm->DefineProperty
  115. ("FAIL_REGULAR_EXPRESSION", cmProperty::TEST,
  116. "If the output matches this regular expression the test will fail.",
  117. "If set, if the output matches one of "
  118. "specified regular expressions, the test will fail."
  119. "For example: FAIL_REGULAR_EXPRESSION \"[^a-z]Error;ERROR;Failed\"");
  120. cm->DefineProperty
  121. ("LABELS", cmProperty::TEST,
  122. "Specify a list of text labels associated with a test.",
  123. "The list is reported in dashboard submissions.");
  124. cm->DefineProperty
  125. ("RESOURCE_LOCK", cmProperty::TEST,
  126. "Specify a list of resources that are locked by this test.",
  127. "If multiple tests specify the same resource lock, they are guaranteed "
  128. "not to run concurrently.");
  129. cm->DefineProperty
  130. ("MEASUREMENT", cmProperty::TEST,
  131. "Specify a CDASH measurement and value to be reported for a test.",
  132. "If set to a name then that name will be reported to CDASH as a "
  133. "named measurement with a value of 1. You may also specify a value "
  134. "by setting MEASUREMENT to \"measurement=value\".");
  135. cm->DefineProperty
  136. ("PASS_REGULAR_EXPRESSION", cmProperty::TEST,
  137. "The output must match this regular expression for the test to pass.",
  138. "If set, the test output will be checked "
  139. "against the specified regular expressions and at least one of the"
  140. " regular expressions has to match, otherwise the test will fail.");
  141. cm->DefineProperty
  142. ("PROCESSORS", cmProperty::TEST,
  143. "How many process slots this test requires",
  144. "Denotes the number of processors that this test will require. This is "
  145. "typically used for MPI tests, and should be used in conjunction with "
  146. "the ctest_test PARALLEL_LEVEL option.");
  147. cm->DefineProperty
  148. ("REQUIRED_FILES", cmProperty::TEST,
  149. "List of files required to run the test.",
  150. "If set to a list of files, the test will not be run unless all of the "
  151. "files exist.");
  152. cm->DefineProperty
  153. ("RUN_SERIAL", cmProperty::TEST,
  154. "Do not run this test in parallel with any other test.",
  155. "Use this option in conjunction with the ctest_test PARALLEL_LEVEL "
  156. "option to specify that this test should not be run in parallel with "
  157. "any other tests.");
  158. cm->DefineProperty
  159. ("TIMEOUT", cmProperty::TEST,
  160. "How many seconds to allow for this test.",
  161. "This property if set will limit a test to not take more than "
  162. "the specified number of seconds to run. If it exceeds that the "
  163. "test process will be killed and ctest will move to the next test. "
  164. "This setting takes precedence over "
  165. "CTEST_TESTING_TIMEOUT.");
  166. cm->DefineProperty
  167. ("WILL_FAIL", cmProperty::TEST,
  168. "If set to true, this will invert the pass/fail flag of the test.",
  169. "This property can be used for tests that are expected to fail and "
  170. "return a non zero return code.");
  171. cm->DefineProperty
  172. ("WORKING_DIRECTORY", cmProperty::TEST,
  173. "The directory from which the test executable will be called.",
  174. "If this is not set it is called from the directory the test executable "
  175. "is located in.");
  176. }