RunCMakeTest.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. # Verify that new tests are started when the load average falls below
  17. # our threshold.
  18. run_ctest_test(TestLoadPass TEST_LOAD 6)
  19. # Verify that new tests are not started when the load average exceeds
  20. # our threshold and that they then run once the load average drops.
  21. run_ctest_test(TestLoadWait TEST_LOAD 2)
  22. # Verify that when an invalid "TEST_LOAD" value is given, a warning
  23. # message is displayed and the value is ignored.
  24. run_ctest_test(TestLoadInvalid TEST_LOAD "ERR1")
  25. # Verify that new tests are started when the load average falls below
  26. # our threshold.
  27. set(CASE_CTEST_TEST_LOAD 7)
  28. run_ctest_test(CTestTestLoadPass)
  29. # Verify that new tests are not started when the load average exceeds
  30. # our threshold and that they then run once the load average drops.
  31. set(CASE_CTEST_TEST_LOAD 4)
  32. run_ctest_test(CTestTestLoadWait)
  33. # Verify that when an invalid "CTEST_TEST_LOAD" value is given,
  34. # a warning message is displayed and the value is ignored.
  35. set(CASE_CTEST_TEST_LOAD "ERR2")
  36. run_ctest_test(CTestTestLoadInvalid)
  37. # Verify that the "TEST_LOAD" value has higher precedence than
  38. # the "CTEST_TEST_LOAD" value
  39. set(CASE_CTEST_TEST_LOAD "ERR3")
  40. run_ctest_test(TestLoadOrder TEST_LOAD "ERR4")
  41. unset(ENV{__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING})
  42. unset(CASE_CTEST_TEST_LOAD)
  43. function(run_TestChangeId)
  44. set(CASE_TEST_PREFIX_CODE [[
  45. set(CTEST_CHANGE_ID "<>1")
  46. ]])
  47. run_ctest(TestChangeId)
  48. endfunction()
  49. run_TestChangeId()
  50. function(run_TestOutputSize)
  51. set(CASE_CTEST_TEST_ARGS EXCLUDE RunCMakeVersion)
  52. set(CASE_TEST_PREFIX_CODE [[
  53. set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 10)
  54. set(CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE 12)
  55. ]])
  56. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  57. add_test(NAME PassingTest COMMAND ${CMAKE_COMMAND} -E echo PassingTestOutput)
  58. add_test(NAME FailingTest COMMAND ${CMAKE_COMMAND} -E no_such_command)
  59. ]])
  60. run_ctest(TestOutputSize)
  61. endfunction()
  62. run_TestOutputSize()
  63. run_ctest_test(TestRepeatBad1 REPEAT UNKNOWN:3)
  64. run_ctest_test(TestRepeatBad2 REPEAT UNTIL_FAIL:-1)
  65. function(run_TestRepeat case return_value )
  66. set(CASE_CTEST_TEST_ARGS RETURN_VALUE result EXCLUDE RunCMakeVersion ${ARGN})
  67. string(CONCAT suffix_code [[
  68. add_test(NAME testRepeat
  69. COMMAND ${CMAKE_COMMAND} -D COUNT_FILE=${CMAKE_CURRENT_BINARY_DIR}/count.cmake
  70. -P "]] "${RunCMake_SOURCE_DIR}/TestRepeat${case}" [[.cmake")
  71. set_property(TEST testRepeat PROPERTY TIMEOUT 5)
  72. ]])
  73. string(APPEND CASE_CMAKELISTS_SUFFIX_CODE "${suffix_code}")
  74. run_ctest(TestRepeat${case})
  75. #write to end of the test file logic to Verify we get the expected
  76. #return code
  77. string(REPLACE "RETURN_VALUE:" "" return_value "${return_value}" )
  78. file(APPEND "${RunCMake_BINARY_DIR}/TestRepeat${case}/test.cmake"
  79. "
  80. set(expected_result ${return_value})
  81. message(STATUS \${result})
  82. if(NOT result EQUAL expected_result)
  83. message(FATAL_ERROR \"expected a return value of: \${expected_result},
  84. instead got: \${result}\")
  85. endif()
  86. "
  87. )
  88. endfunction()
  89. run_TestRepeat(UntilFail RETURN_VALUE:1 REPEAT UNTIL_FAIL:3)
  90. run_TestRepeat(UntilPass RETURN_VALUE:0 REPEAT UNTIL_PASS:3)
  91. run_TestRepeat(AfterTimeout RETURN_VALUE:0 REPEAT AFTER_TIMEOUT:3)
  92. # test repeat and not run tests interact correctly
  93. set(CASE_CMAKELISTS_SUFFIX_CODE [[
  94. add_test(NAME testNotRun
  95. COMMAND ${CMAKE_COMMAND}/doesnt_exist)
  96. set_property(TEST testNotRun PROPERTY TIMEOUT 5)
  97. ]])
  98. run_TestRepeat(NotRun RETURN_VALUE:1 REPEAT UNTIL_PASS:3)
  99. unset(CASE_CMAKELISTS_SUFFIX_CODE)