RunCMakeTest.cmake 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. include(RunCTest)
  2. set(RunCMake_TEST_TIMEOUT 60)
  3. unset(ENV{CTEST_PARALLEL_LEVEL})
  4. unset(ENV{CTEST_OUTPUT_ON_FAILURE})
  5. set(CASE_CTEST_TEST_ARGS "")
  6. set(CASE_CTEST_TEST_LOAD "")
  7. function(run_ctest_test CASE_NAME)
  8. set(CASE_CTEST_TEST_ARGS "${ARGN}")
  9. run_ctest(${CASE_NAME})
  10. endfunction()
  11. run_ctest_test(TestQuiet QUIET)
  12. # Tests for the 'Test Load' feature of ctest
  13. #
  14. # Spoof a load average value to make these tests more reliable.
  15. set(ENV{__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING} 5)
  16. set(RunCTest_VERBOSE_FLAG -VV)
  17. # Verify that new tests are started when the load average falls below
  18. # our threshold.
  19. run_ctest_test(TestLoadPass TEST_LOAD 6)
  20. # Verify that new tests are not started when the load average exceeds
  21. # our threshold and that they then run once the load average drops.
  22. run_ctest_test(TestLoadWait TEST_LOAD 2)
  23. # Verify that when an invalid "TEST_LOAD" value is given, a warning
  24. # message is displayed and the value is ignored.
  25. run_ctest_test(TestLoadInvalid TEST_LOAD "ERR1")
  26. # Verify that new tests are started when the load average falls below
  27. # our threshold.
  28. set(CASE_CTEST_TEST_LOAD 7)
  29. run_ctest_test(CTestTestLoadPass)
  30. # Verify that new tests are not started when the load average exceeds
  31. # our threshold and that they then run once the load average drops.
  32. set(CASE_CTEST_TEST_LOAD 4)
  33. run_ctest_test(CTestTestLoadWait)
  34. # Verify that when an invalid "CTEST_TEST_LOAD" value is given,
  35. # a warning message is displayed and the value is ignored.
  36. set(CASE_CTEST_TEST_LOAD "ERR2")
  37. run_ctest_test(CTestTestLoadInvalid)
  38. # Verify that the "TEST_LOAD" value has higher precedence than
  39. # the "CTEST_TEST_LOAD" value
  40. set(CASE_CTEST_TEST_LOAD "ERR3")
  41. run_ctest_test(TestLoadOrder TEST_LOAD "ERR4")
  42. unset(ENV{__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING})
  43. unset(CASE_CTEST_TEST_LOAD)
  44. unset(RunCTest_VERBOSE_FLAG)
  45. function(run_TestChangeId)
  46. set(CASE_TEST_PREFIX_CODE [[
  47. set(CTEST_CHANGE_ID "<>1")
  48. ]])
  49. run_ctest(TestChangeId)
  50. endfunction()
  51. run_TestChangeId()
  52. function(run_TestOutputSize)
  53. set(CASE_CTEST_TEST_ARGS EXCLUDE RunCMakeVersion)
  54. set(CASE_TEST_PREFIX_CODE [[
  55. set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 10)
  56. set(CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE 12)
  57. ]])
  58. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  59. add_test(NAME PassingTest COMMAND ${CMAKE_COMMAND} -E echo PassingTestOutput)
  60. add_test(NAME FailingTest COMMAND ${CMAKE_COMMAND} -E no_such_command)
  61. ]])
  62. run_ctest(TestOutputSize)
  63. endfunction()
  64. run_TestOutputSize()
  65. run_ctest_test(TestRepeatBad1 REPEAT UNKNOWN:3)
  66. run_ctest_test(TestRepeatBad2 REPEAT UNTIL_FAIL:-1)
  67. function(run_TestRepeat case return_value )
  68. set(CASE_CTEST_TEST_ARGS RETURN_VALUE result EXCLUDE RunCMakeVersion ${ARGN})
  69. string(CONCAT suffix_code [[
  70. add_test(NAME testRepeat
  71. COMMAND ${CMAKE_COMMAND} -D COUNT_FILE=${CMAKE_CURRENT_BINARY_DIR}/count.cmake
  72. -P "]] "${RunCMake_SOURCE_DIR}/TestRepeat${case}" [[.cmake")
  73. set_property(TEST testRepeat PROPERTY TIMEOUT 5)
  74. ]])
  75. string(APPEND CASE_CMAKELISTS_SUFFIX_CODE "${suffix_code}")
  76. run_ctest(TestRepeat${case})
  77. #write to end of the test file logic to Verify we get the expected
  78. #return code
  79. string(REPLACE "RETURN_VALUE:" "" return_value "${return_value}" )
  80. file(APPEND "${RunCMake_BINARY_DIR}/TestRepeat${case}/test.cmake"
  81. "
  82. set(expected_result ${return_value})
  83. message(STATUS \${result})
  84. if(NOT result EQUAL expected_result)
  85. message(FATAL_ERROR \"expected a return value of: \${expected_result},
  86. instead got: \${result}\")
  87. endif()
  88. "
  89. )
  90. endfunction()
  91. run_TestRepeat(UntilFail RETURN_VALUE:1 REPEAT UNTIL_FAIL:3)
  92. run_TestRepeat(UntilPass RETURN_VALUE:0 REPEAT UNTIL_PASS:3)
  93. run_TestRepeat(AfterTimeout RETURN_VALUE:0 REPEAT AFTER_TIMEOUT:3)
  94. # test repeat and not run tests interact correctly
  95. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  96. add_test(NAME testNotRun
  97. COMMAND ${CMAKE_COMMAND}/doesnt_exist)
  98. set_property(TEST testNotRun PROPERTY TIMEOUT 5)
  99. ]])
  100. run_TestRepeat(NotRun RETURN_VALUE:1 REPEAT UNTIL_PASS:3)
  101. unset(CASE_CMAKELISTS_SUFFIX_CODE)
  102. # test --stop-on-failure
  103. function(run_stop_on_failure)
  104. set(CASE_CTEST_TEST_ARGS EXCLUDE RunCMakeVersion)
  105. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  106. add_test(NAME StoppingTest COMMAND ${CMAKE_COMMAND} -E false)
  107. add_test(NAME NotRunTest COMMAND ${CMAKE_COMMAND} -E true)
  108. ]])
  109. run_ctest_test(stop-on-failure STOP_ON_FAILURE)
  110. endfunction()
  111. run_stop_on_failure()
  112. # Make sure environment gets logged
  113. function(run_environment)
  114. set(ENV{BAD_ENVIRONMENT_VARIABLE} "Bad environment variable")
  115. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  116. set_property(TEST RunCMakeVersion PROPERTY ENVIRONMENT "ENV1=env1;ENV2=env2")
  117. ]])
  118. run_ctest(TestEnvironment)
  119. endfunction()
  120. run_environment()
  121. # test for OUTPUT_JUNIT
  122. run_ctest_test(OutputJUnit OUTPUT_JUNIT junit.xml REPEAT UNTIL_FAIL:2)
  123. # Verify that extra measurements get reported.
  124. function(run_measurements)
  125. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  126. add_test(
  127. NAME double_measurement
  128. COMMAND ${CMAKE_COMMAND} -E
  129. echo <DartMeasurement type="numeric/double" name="my_custom_value">1.4847</DartMeasurement>)
  130. add_test(
  131. NAME img_measurement
  132. COMMAND ${CMAKE_COMMAND} -E
  133. echo <DartMeasurementFile name="TestImage" type="image/png">]] ${IMAGE_DIR}/cmake-logo-16.png [[</DartMeasurementFile>)
  134. add_test(
  135. NAME file_measurement
  136. COMMAND ${CMAKE_COMMAND} -E
  137. echo <DartMeasurementFile name="my_test_input_data" type="file">]] ${IMAGE_DIR}/cmake-logo-16.png [[</DartMeasurementFile>)
  138. ]])
  139. run_ctest(TestMeasurements)
  140. endfunction()
  141. run_measurements()
  142. # Verify that test output can override the Completion Status.
  143. function(run_completion_status)
  144. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  145. add_test(
  146. NAME custom_details
  147. COMMAND ${CMAKE_COMMAND} -E
  148. echo test output\n<CTestDetails>CustomDetails</CTestDetails>\nmore output)
  149. ]])
  150. run_ctest(TestCompletionStatus)
  151. endfunction()
  152. run_completion_status()
  153. # Verify that running ctest_test() multiple times with different label arguments
  154. # doesn't break.
  155. function(run_changing_labels)
  156. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  157. add_test(NAME a COMMAND ${CMAKE_COMMAND} -E true)
  158. set_property(TEST a PROPERTY LABELS a)
  159. add_test(NAME b COMMAND ${CMAKE_COMMAND} -E true)
  160. set_property(TEST b PROPERTY LABELS b)
  161. ]])
  162. run_ctest(TestChangingLabels)
  163. endfunction()
  164. run_changing_labels()