RunCMakeTest.cmake 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. cmake_minimum_required(VERSION 3.12)
  2. include(RunCMake)
  3. # We do not contact any remote URLs, but may use a local one.
  4. # Remove any proxy configuration that may change behavior.
  5. unset(ENV{http_proxy})
  6. unset(ENV{https_proxy})
  7. run_cmake(IncludeScope-Add)
  8. run_cmake(IncludeScope-Add_Step)
  9. run_cmake(NoOptions)
  10. run_cmake(SourceEmpty)
  11. run_cmake(SourceMissing)
  12. run_cmake(CMAKE_CACHE_ARGS)
  13. run_cmake(CMAKE_CACHE_DEFAULT_ARGS)
  14. run_cmake(CMAKE_CACHE_mix)
  15. run_cmake(NO_DEPENDS)
  16. run_cmake(Add_StepDependencies)
  17. run_cmake(Add_StepDependencies_iface)
  18. run_cmake(Add_StepDependencies_iface_step)
  19. run_cmake(Add_StepDependencies_no_target)
  20. run_cmake(UsesTerminal)
  21. # Run both cmake and build steps. We always do a clean before the
  22. # build to ensure that the download step re-runs each time.
  23. function(__ep_test_with_build testName)
  24. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  25. set(RunCMake_TEST_NO_CLEAN 1)
  26. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  27. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  28. run_cmake(${testName})
  29. run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean)
  30. run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
  31. endfunction()
  32. find_package(Python3)
  33. function(__ep_test_with_build_with_server testName)
  34. if(NOT Python3_EXECUTABLE)
  35. return()
  36. endif()
  37. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
  38. set(RunCMake_TEST_NO_CLEAN 1)
  39. set(RunCMake_TEST_TIMEOUT 20)
  40. set(RunCMake_TEST_OUTPUT_MERGE TRUE)
  41. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  42. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  43. set(URL_FILE ${RunCMake_BINARY_DIR}/${testName}.url)
  44. if(EXISTS "${URL_FILE}")
  45. file(REMOVE "${URL_FILE}")
  46. endif()
  47. execute_process(
  48. COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/DownloadServer.py --file "${URL_FILE}" ${ARGN}
  49. OUTPUT_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt
  50. ERROR_FILE ${RunCMake_BINARY_DIR}/${testName}-python.txt
  51. RESULT_VARIABLE result
  52. TIMEOUT 30
  53. )
  54. if(NOT result EQUAL 0)
  55. message(FATAL_ERROR "Failed to start download server:\n ${result}")
  56. endif()
  57. foreach(i RANGE 1 8)
  58. if(EXISTS ${URL_FILE})
  59. break()
  60. endif()
  61. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${i})
  62. endforeach()
  63. if(NOT EXISTS ${URL_FILE})
  64. message(FATAL_ERROR "Failed to load download server URL from:\n ${URL_FILE}")
  65. endif()
  66. file(READ ${URL_FILE} SERVER_URL)
  67. message(STATUS "URL : ${URL_FILE} - ${SERVER_URL}")
  68. run_cmake_with_options(${testName} ${CMAKE_COMMAND} -DSERVER_URL=${SERVER_URL} )
  69. run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean)
  70. run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
  71. endfunction()
  72. __ep_test_with_build(MultiCommand)
  73. set(RunCMake_TEST_OUTPUT_MERGE 1)
  74. __ep_test_with_build(PreserveEmptyArgs)
  75. set(RunCMake_TEST_OUTPUT_MERGE 0)
  76. # Output is not predictable enough to be able to verify it reliably
  77. # when using the various different Visual Studio generators
  78. if(NOT RunCMake_GENERATOR MATCHES "Visual Studio")
  79. __ep_test_with_build(LogOutputOnFailure)
  80. __ep_test_with_build(LogOutputOnFailureMerged)
  81. __ep_test_with_build(DownloadTimeout)
  82. __ep_test_with_build_with_server(DownloadInactivityTimeout --speed_limit --limit_duration 40)
  83. __ep_test_with_build_with_server(DownloadInactivityResume --speed_limit --limit_duration 1)
  84. endif()
  85. # We can't test the substitution when using the old MSYS due to
  86. # make/sh mangling the paths (substitution is performed correctly,
  87. # but the mangling means we can't reliably test the output).
  88. # There is no such issue when using the newer MSYS though. Therefore,
  89. # we need to bypass the substitution test if using old MSYS.
  90. # See merge request 1537 for discussion.
  91. set(doSubstitutionTest YES)
  92. if(RunCMake_GENERATOR STREQUAL "MSYS Makefiles")
  93. execute_process(COMMAND uname OUTPUT_VARIABLE uname)
  94. if(uname MATCHES "^MINGW32_NT")
  95. set(doSubstitutionTest NO)
  96. endif()
  97. endif()
  98. if(doSubstitutionTest)
  99. __ep_test_with_build(Substitutions)
  100. endif()