test: use Selenium to run Emscripten tests

This commit is contained in:
Anonymous Maarten
2024-05-30 21:08:30 +02:00
committed by Anonymous Maarten
parent 46bafda7ab
commit 161761653f
5 changed files with 341 additions and 32 deletions

View File

@@ -52,6 +52,20 @@ if(WIN32 AND NOT WINDOWS_STORE)
endif()
endif()
if(EMSCRIPTEN)
set(SDLTEST_BROWSER "firefox" CACHE STRING "Browser in which to run SDL unit tests (chrome or firefox)")
set(SDLTEST_PORT "8080" CACHE STRING "Port on which to serve the tests")
set(SDLTEST_CHROME_BINARY "" CACHE STRING "Chrome/Chromium browser binary (optional)")
find_package(Python3 COMPONENTS Interpreter)
if(TARGET Python3::Interpreter)
add_custom_target(serve-sdl-tests
COMMAND Python3::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/emscripten/server.py"
"${SDLTEST_PORT}"
-d "${CMAKE_CURRENT_BINARY_DIR}"
--map "${CMAKE_CURRENT_SOURCE_DIR}/..:/SDL")
endif()
endif()
if(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(test_bin_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
if(NOT IS_ABSOLUTE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
@@ -99,7 +113,7 @@ if(WINDOWS_STORE)
endif()
macro(add_sdl_test_executable TARGET)
cmake_parse_arguments(AST "BUILD_DEPENDENT;NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS;NO_C90;MAIN_CALLBACKS;NOTRACKMEM" "" "NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;SOURCES" ${ARGN})
cmake_parse_arguments(AST "BUILD_DEPENDENT;NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS;THREADS;NO_C90;MAIN_CALLBACKS;NOTRACKMEM" "" "DISABLE_THREADS_ARGS;NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;SOURCES" ${ARGN})
if(AST_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown argument(s): ${AST_UNPARSED_ARGUMENTS}")
endif()
@@ -157,6 +171,8 @@ macro(add_sdl_test_executable TARGET)
if(AST_NONINTERACTIVE)
set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE 1)
endif()
set_property(TARGET ${TARGET} PROPERTY SDL_DISABLE_THREADS_ARGS "${AST_DISABLE_THREADS_ARGS}")
set_property(TARGET ${TARGET} PROPERTY SDL_THREADS "${AST_THREADS}")
if(AST_NONINTERACTIVE_ARGS)
set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_ARGUMENTS "${AST_NONINTERACTIVE_ARGS}")
endif()
@@ -221,6 +237,9 @@ macro(add_sdl_test_executable TARGET)
if(EMSCRIPTEN)
set_property(TARGET ${TARGET} PROPERTY SUFFIX ".html")
target_link_options(${TARGET} PRIVATE "SHELL:--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/emscripten/pre.js")
target_link_options(${TARGET} PRIVATE "-sEXIT_RUNTIME=1")
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/emscripten/pre.js")
endif()
if(OPENGL_FOUND)
@@ -279,17 +298,20 @@ add_sdl_test_executable(testaudiostreamdynamicresample NEEDS_RESOURCES TESTUTILS
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_sdl_test_executable(testautomation NONINTERACTIVE NONINTERACTIVE_TIMEOUT 120 NEEDS_RESOURCES NO_C90 SOURCES ${TESTAUTOMATION_SOURCE_FILES})
if(EMSCRIPTEN)
target_link_options(testautomation PRIVATE -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb)
endif()
add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES TESTUTILS SOURCES testmultiaudio.c)
add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES TESTUTILS SOURCES testaudiohotplug.c)
add_sdl_test_executable(testaudiorecording MAIN_CALLBACKS SOURCES testaudiorecording.c)
add_sdl_test_executable(testatomic NONINTERACTIVE SOURCES testatomic.c)
add_sdl_test_executable(testatomic NONINTERACTIVE DISABLE_THREADS_ARGS "--no-threads" SOURCES testatomic.c)
add_sdl_test_executable(testintersections SOURCES testintersections.c)
add_sdl_test_executable(testrelative SOURCES testrelative.c)
add_sdl_test_executable(testhittesting SOURCES testhittesting.c)
add_sdl_test_executable(testdraw SOURCES testdraw.c)
add_sdl_test_executable(testdrawchessboard SOURCES testdrawchessboard.c)
add_sdl_test_executable(testdropfile MAIN_CALLBACKS SOURCES testdropfile.c)
add_sdl_test_executable(testerror NONINTERACTIVE SOURCES testerror.c)
add_sdl_test_executable(testerror NONINTERACTIVE DISABLE_THREADS_ARGS "--no-threads" SOURCES testerror.c)
set(build_options_dependent_tests )
@@ -320,7 +342,7 @@ elseif(HAVE_X11 OR HAVE_WAYLAND)
endif ()
endif()
find_package(Python3)
find_package(Python3 COMPONENTS Interpreter)
function(files2headers OUTPUT)
set(xxd "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/xxd.py")
set(inputs ${ARGN})
@@ -335,7 +357,7 @@ function(files2headers OUTPUT)
# Don't add the 'output' header to the output, to avoid marking them as GENERATED
# (generated files are removed when running the CLEAN target)
add_custom_command(OUTPUT "${intermediate}"
COMMAND "${Python3_EXECUTABLE}" "${xxd}" -i "${CMAKE_CURRENT_SOURCE_DIR}/${input}" "-o" "${intermediate}"
COMMAND Python3::Interpreter "${xxd}" -i "${CMAKE_CURRENT_SOURCE_DIR}/${input}" "-o" "${intermediate}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${intermediate}" "${output}"
DEPENDS "${xxd}" "${bmp}"
)
@@ -384,7 +406,7 @@ add_sdl_test_executable(testhaptic SOURCES testhaptic.c)
add_sdl_test_executable(testhotplug SOURCES testhotplug.c)
add_sdl_test_executable(testpen SOURCES testpen.c)
add_sdl_test_executable(testrumble SOURCES testrumble.c)
add_sdl_test_executable(testthread NONINTERACTIVE NONINTERACTIVE_TIMEOUT 40 SOURCES testthread.c)
add_sdl_test_executable(testthread NONINTERACTIVE THREADS NONINTERACTIVE_TIMEOUT 40 SOURCES testthread.c)
add_sdl_test_executable(testiconv NEEDS_RESOURCES TESTUTILS SOURCES testiconv.c)
add_sdl_test_executable(testime NEEDS_RESOURCES TESTUTILS SOURCES testime.c)
add_sdl_test_executable(testkeys SOURCES testkeys.c)
@@ -403,7 +425,7 @@ if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
endif()
add_sdl_test_executable(testrendertarget NEEDS_RESOURCES TESTUTILS SOURCES testrendertarget.c)
add_sdl_test_executable(testscale NEEDS_RESOURCES TESTUTILS SOURCES testscale.c)
add_sdl_test_executable(testsem NONINTERACTIVE NONINTERACTIVE_ARGS 10 NONINTERACTIVE_TIMEOUT 30 SOURCES testsem.c)
add_sdl_test_executable(testsem NONINTERACTIVE DISABLE_THREADS_ARGS "--no-threads" NONINTERACTIVE_ARGS 10 NONINTERACTIVE_TIMEOUT 30 SOURCES testsem.c)
add_sdl_test_executable(testsensor SOURCES testsensor.c)
add_sdl_test_executable(testshader NEEDS_RESOURCES TESTUTILS SOURCES testshader.c)
if(EMSCRIPTEN)
@@ -421,7 +443,7 @@ add_sdl_test_executable(testcamera MAIN_CALLBACKS SOURCES testcamera.c)
add_sdl_test_executable(testviewport NEEDS_RESOURCES TESTUTILS SOURCES testviewport.c)
add_sdl_test_executable(testwm SOURCES testwm.c)
add_sdl_test_executable(testyuv NONINTERACTIVE NONINTERACTIVE_ARGS "--automated" NEEDS_RESOURCES TESTUTILS SOURCES testyuv.c testyuv_cvt.c)
add_sdl_test_executable(torturethread NONINTERACTIVE NONINTERACTIVE_TIMEOUT 30 SOURCES torturethread.c)
add_sdl_test_executable(torturethread NONINTERACTIVE THREADS NONINTERACTIVE_TIMEOUT 30 SOURCES torturethread.c)
add_sdl_test_executable(testrendercopyex NEEDS_RESOURCES TESTUTILS SOURCES testrendercopyex.c)
add_sdl_test_executable(testmessage SOURCES testmessage.c)
add_sdl_test_executable(testdisplayinfo SOURCES testdisplayinfo.c)
@@ -489,15 +511,6 @@ if(OPENGL_FOUND)
target_link_libraries(testgl PRIVATE ${OPENGL_gl_LIBRARY})
endif()
endif()
if(EMSCRIPTEN)
set_property(TARGET testshader APPEND_STRING PROPERTY LINK_FLAGS " -sLEGACY_GL_EMULATION")
find_package(Python3 COMPONENTS Interpreter)
if(TARGET Python3::Interpreter)
add_custom_target(serve-sdl-tests
COMMAND Python3::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/emscripten/server.py" -d "${CMAKE_CURRENT_BINARY_DIR}")
endif()
endif()
if(MACOS)
target_link_options(testnative PRIVATE "-Wl,-framework,Cocoa")
endif()
@@ -605,15 +618,29 @@ endif()
set(TESTS_ENVIRONMENT
SDL_AUDIO_DRIVER=dummy
SDL_VIDEO_DRIVER=dummy
PATH=$<TARGET_FILE_DIR:SDL3::${sdl_name_component}>
)
set(SDLTEST_TIMEOUT_MULTIPLIER "1" CACHE STRING "SDL test time-out multiplier")
function(add_sdl_test TEST TARGET)
cmake_parse_arguments(ast "INSTALL" "" "" ${ARGN})
get_property(noninteractive TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE)
if(noninteractive)
set(command ${TARGET})
if(EMSCRIPTEN)
if(NOT PYTHON3_EXECUTABLE)
set(PYTHON3_EXECUTABLE "python3")
endif()
set(command "${PYTHON3_EXECUTABLE};${CMAKE_CURRENT_SOURCE_DIR}/emscripten/driver.py;--server;http://localhost:${SDLTEST_PORT};--browser;${SDLTEST_BROWSER}")
if(SDLTEST_CHROME_BINARY)
list(APPEND command "--chrome-binary;${SDLTEST_CHROME_BINARY}")
endif()
list(APPEND command "--;${TARGET}")
else()
set(command ${TARGET})
endif()
get_property(noninteractive_arguments TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_ARGUMENTS)
get_property(disable_threads_args TARGET ${TARGET} PROPERTY SDL_DISABLE_THREADS_ARGS)
get_property(uses_threads TARGET ${TARGET} PROPERTY SDL_THREADS)
if(noninteractive_arguments)
list(APPEND command ${noninteractive_arguments})
endif()
@@ -623,20 +650,29 @@ function(add_sdl_test TEST TARGET)
list(APPEND command --trackmem)
endif()
endif()
if(EMSCRIPTEN)
list(APPEND command ${disable_threads_args})
endif()
add_test(
NAME ${TEST}
COMMAND ${command}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
NAME ${TEST}
COMMAND ${command}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.27")
set_property(TEST ${TEST} APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_RUNTIME_DLL_DIRS:${TEST}>")
endif()
if(NOT notrackmem)
set_property(TEST ${TEST} PROPERTY FAIL_REGULAR_EXPRESSION "Total: [0-9]+\\.[0-9]+ Kb in [1-9][0-9]* allocations")
endif()
set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}")
if(EMSCRIPTEN AND uses_threads)
set_tests_properties(${TEST} PROPERTIES DISABLED 1)
endif()
get_property(noninteractive_timeout TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_TIMEOUT)
if(NOT noninteractive_timeout)
set(noninteractive_timeout 10)
endif()
math(EXPR noninteractive_timeout "${noninteractive_timeout}*${SDL_TESTS_TIMEOUT_MULTIPLIER}")
math(EXPR noninteractive_timeout "${noninteractive_timeout}*${SDLTEST_TIMEOUT_MULTIPLIER}")
set_tests_properties(${TEST} PROPERTIES TIMEOUT "${noninteractive_timeout}")
if(ast_INSTALL AND SDL_INSTALL_TESTS)
set(exe ${TARGET})
@@ -657,12 +693,14 @@ foreach(TARGET ${SDL_TEST_EXECUTABLES})
add_sdl_test(${TARGET} ${TARGET} INSTALL)
endforeach()
add_sdl_test(testautomation-no-simd testautomation)
add_sdl_test(testplatform-no-simd testplatform)
set_property(TEST testautomation-no-simd testplatform-no-simd APPEND PROPERTY ENVIRONMENT "SDL_CPU_FEATURE_MASK=-all")
if(NOT EMSCRIPTEN)
add_sdl_test(testautomation-no-simd testautomation)
add_sdl_test(testplatform-no-simd testplatform)
set_property(TEST testautomation-no-simd testplatform-no-simd APPEND PROPERTY ENVIRONMENT "SDL_CPU_FEATURE_MASK=-all")
# testautomation creates temporary files which might conflict
set_property(TEST testautomation-no-simd testautomation PROPERTY RUN_SERIAL TRUE)
# testautomation creates temporary files which might conflict
set_property(TEST testautomation-no-simd testautomation PROPERTY RUN_SERIAL TRUE)
endif()
if(SDL_INSTALL_TESTS)
if(RISCOS)