cmake+test: add more automated tests + use properties

main
Anonymous Maarten 2023-03-17 19:23:56 +01:00 committed by Anonymous Maarten
parent 115460a930
commit 81ca9d61d6
1 changed files with 129 additions and 113 deletions

View File

@ -38,7 +38,6 @@ if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
endif()
set(SDL_TEST_EXECUTABLES)
set(SDL_TESTS_NONINTERACTIVE)
# FIXME: can be OBJECT library for CMake 3.16
add_library(sdltests_utils STATIC
@ -53,13 +52,22 @@ foreach(RESOURCE_FILE ${RESOURCE_FILES})
list(APPEND RESOURCE_FILE_NAMES "${res_file_name}")
endforeach()
define_property(TARGET PROPERTY SDL_NONINTERACTIVE BRIEF_DOCS "If true, target is a non-interactive test executable." FULL_DOCS "If true, target is a noninteractive test executable.")
define_property(TARGET PROPERTY SDL_NONINTERACTIVE_ARGUMENTS BRIEF_DOCS "Argument(s) to run executable in non-interactive mode." FULL_DOCS "Argument(s) to run executable in non-interactive mode.")
define_property(TARGET PROPERTY SDL_NONINTERACTIVE_TIMEOUT BRIEF_DOCS "Timeout for noninteractive executable." FULL_DOCS "Timeout for noninteractive executable.")
macro(add_sdl_test_executable TARGET)
cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS" "" "" ${ARGN})
set(SOURCES ${AST_UNPARSED_ARGUMENTS})
if(AST_NEEDS_RESOURCES)
list(APPEND SOURCES ${RESOURCE_FILES})
cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS" "" "NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;SOURCES" ${ARGN})
if(AST_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown argument(s): ${AST_UNPARSED_ARGUMENTS}")
endif()
add_executable(${TARGET} ${SOURCES})
if(NOT AST_SOURCES)
message(FATAL_ERROR "add_sdl_test_executable needs at least one source")
endif()
if(AST_NEEDS_RESOURCES)
list(APPEND AST_SOURCES ${RESOURCE_FILES})
endif()
add_executable(${TARGET} ${AST_SOURCES})
target_link_libraries(${TARGET} PRIVATE SDL3::SDL3_test SDL3::${sdl_name_component})
if(AST_TESTUTILS)
target_link_libraries(${TARGET} PRIVATE sdltests_utils)
@ -67,7 +75,13 @@ macro(add_sdl_test_executable TARGET)
list(APPEND SDL_TEST_EXECUTABLES ${TARGET})
if(AST_NONINTERACTIVE)
list(APPEND SDL_TESTS_NONINTERACTIVE ${TARGET})
set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE 1)
endif()
if(AST_NONINTERACTIVE_ARGS)
set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_ARGUMENTS "${AST_NONINTERACTIVE_ARGS}")
endif()
if(AST_NONINTERACTIVE_TIMEOUT)
set_property(TARGET ${TARGET} PROPERTY SDL_NONINTERACTIVE_TIMEOUT "${AST_NONINTERACTIVE_TIMEOUT}")
endif()
if(AST_NEEDS_RESOURCES)
if(PSP OR PS2)
@ -113,39 +127,40 @@ if(HAVE_LIBUDEV_H)
add_definitions(-DHAVE_LIBUDEV_H)
endif()
add_sdl_test_executable(checkkeys checkkeys.c)
add_sdl_test_executable(checkkeysthreads checkkeysthreads.c)
add_sdl_test_executable(loopwave NEEDS_RESOURCES TESTUTILS loopwave.c)
add_sdl_test_executable(loopwavequeue NEEDS_RESOURCES TESTUTILS loopwavequeue.c)
add_sdl_test_executable(testsurround testsurround.c)
add_sdl_test_executable(testresample NEEDS_RESOURCES testresample.c)
add_sdl_test_executable(testaudioinfo testaudioinfo.c)
add_sdl_test_executable(checkkeys SOURCES checkkeys.c)
add_sdl_test_executable(checkkeysthreads SOURCES checkkeysthreads.c)
add_sdl_test_executable(loopwave NEEDS_RESOURCES TESTUTILS SOURCES loopwave.c)
add_sdl_test_executable(loopwavequeue NEEDS_RESOURCES TESTUTILS SOURCES loopwavequeue.c)
add_sdl_test_executable(testsurround SOURCES testsurround.c)
add_sdl_test_executable(testresample NEEDS_RESOURCES SOURCES testresample.c)
add_sdl_test_executable(testaudioinfo SOURCES testaudioinfo.c)
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_sdl_test_executable(testautomation NEEDS_RESOURCES ${TESTAUTOMATION_SOURCE_FILES})
add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES TESTUTILS testmultiaudio.c)
add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES TESTUTILS testaudiohotplug.c)
add_sdl_test_executable(testaudiocapture testaudiocapture.c)
add_sdl_test_executable(testatomic NONINTERACTIVE testatomic.c)
add_sdl_test_executable(testintersections testintersections.c)
add_sdl_test_executable(testrelative testrelative.c)
add_sdl_test_executable(testhittesting testhittesting.c)
add_sdl_test_executable(testdraw testdraw.c)
add_sdl_test_executable(testdrawchessboard testdrawchessboard.c)
add_sdl_test_executable(testdropfile testdropfile.c)
add_sdl_test_executable(testerror NONINTERACTIVE testerror.c)
add_sdl_test_executable(testautomation NEEDS_RESOURCES SOURCES ${TESTAUTOMATION_SOURCE_FILES})
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(testaudiocapture SOURCES testaudiocapture.c)
add_sdl_test_executable(testatomic NONINTERACTIVE 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 SOURCES testdropfile.c)
add_sdl_test_executable(testerror NONINTERACTIVE SOURCES testerror.c)
if(LINUX AND TARGET sdl-build-options)
set(build_options_dependent_tests )
add_sdl_test_executable(testevdev NONINTERACTIVE testevdev.c)
add_sdl_test_executable(testevdev NONINTERACTIVE SOURCES testevdev.c)
list(APPEND build_options_dependent_tests testevdev)
if(APPLE)
add_sdl_test_executable(testnative NEEDS_RESOURCES TESTUTILS
testnative.c
testnativecocoa.m
testnativex11.c
SOURCES
testnative.c
testnativecocoa.m
testnativex11.c
)
target_compile_definitions(testnative PRIVATE TEST_NATIVE_COCOA)
@ -157,10 +172,10 @@ if(LINUX AND TARGET sdl-build-options)
endif()
list(APPEND build_options_dependent_tests testnative)
elseif(WINDOWS)
add_sdl_test_executable(testnative NEEDS_RESOURCES TESTUTILS testnative.c testnativew32.c)
add_sdl_test_executable(testnative NEEDS_RESOURCES TESTUTILS SOURCES testnative.ctestnativew32.c)
list(APPEND build_options_dependent_tests testnative)
elseif(HAVE_X11)
add_sdl_test_executable(testnative NEEDS_RESOURCES TESTUTILS testnative.c testnativex11.c)
add_sdl_test_executable(testnative NEEDS_RESOURCES TESTUTILS SOURCES testnative.c testnativex11.c)
target_link_libraries(testnative PRIVATE X11)
list(APPEND build_options_dependent_tests testnative)
endif()
@ -171,56 +186,56 @@ if(LINUX AND TARGET sdl-build-options)
endforeach()
endif()
add_sdl_test_executable(testfile testfile.c)
add_sdl_test_executable(testgamepad NEEDS_RESOURCES TESTUTILS testgamepad.c)
add_sdl_test_executable(testgeometry TESTUTILS testgeometry.c)
add_sdl_test_executable(testgl testgl.c)
add_sdl_test_executable(testgles testgles.c)
add_sdl_test_executable(testgles2 testgles2.c)
add_sdl_test_executable(testgles2_sdf TESTUTILS testgles2_sdf.c)
add_sdl_test_executable(testhaptic testhaptic.c)
add_sdl_test_executable(testhotplug testhotplug.c)
add_sdl_test_executable(testrumble testrumble.c)
add_sdl_test_executable(testthread NONINTERACTIVE testthread.c)
add_sdl_test_executable(testiconv NEEDS_RESOURCES TESTUTILS testiconv.c)
add_sdl_test_executable(testime NEEDS_RESOURCES TESTUTILS testime.c)
add_sdl_test_executable(testjoystick testjoystick.c)
add_sdl_test_executable(testkeys testkeys.c)
add_sdl_test_executable(testloadso testloadso.c)
add_sdl_test_executable(testlocale NONINTERACTIVE testlocale.c)
add_sdl_test_executable(testlock testlock.c)
add_sdl_test_executable(testmouse testmouse.c)
add_sdl_test_executable(testfile NONINTERACTIVE SOURCES testfile.c)
add_sdl_test_executable(testgamepad NEEDS_RESOURCES TESTUTILS SOURCES testgamepad.c)
add_sdl_test_executable(testgeometry TESTUTILS SOURCES testgeometry.c)
add_sdl_test_executable(testgl SOURCES testgl.c)
add_sdl_test_executable(testgles SOURCES testgles.c)
add_sdl_test_executable(testgles2 SOURCES testgles2.c)
add_sdl_test_executable(testgles2_sdf TESTUTILS SOURCES testgles2_sdf.c)
add_sdl_test_executable(testhaptic SOURCES testhaptic.c)
add_sdl_test_executable(testhotplug SOURCES testhotplug.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(testiconv NEEDS_RESOURCES TESTUTILS SOURCES testiconv.c)
add_sdl_test_executable(testime NEEDS_RESOURCES TESTUTILS SOURCES testime.c)
add_sdl_test_executable(testjoystick SOURCES testjoystick.c)
add_sdl_test_executable(testkeys SOURCES testkeys.c)
add_sdl_test_executable(testloadso SOURCES testloadso.c)
add_sdl_test_executable(testlocale NONINTERACTIVE SOURCES testlocale.c)
add_sdl_test_executable(testlock SOURCES testlock.c)
add_sdl_test_executable(testmouse SOURCES testmouse.c)
add_sdl_test_executable(testoverlay NEEDS_RESOURCES TESTUTILS testoverlay.c)
add_sdl_test_executable(testplatform NONINTERACTIVE testplatform.c)
add_sdl_test_executable(testpower NONINTERACTIVE testpower.c)
add_sdl_test_executable(testfilesystem NONINTERACTIVE testfilesystem.c)
add_sdl_test_executable(testrendertarget NEEDS_RESOURCES TESTUTILS testrendertarget.c)
add_sdl_test_executable(testscale NEEDS_RESOURCES TESTUTILS testscale.c)
add_sdl_test_executable(testsem testsem.c)
add_sdl_test_executable(testsensor testsensor.c)
add_sdl_test_executable(testshader NEEDS_RESOURCES TESTUTILS testshader.c)
add_sdl_test_executable(testshape NEEDS_RESOURCES testshape.c)
add_sdl_test_executable(testsprite NEEDS_RESOURCES TESTUTILS testsprite.c)
add_sdl_test_executable(testspriteminimal NEEDS_RESOURCES TESTUTILS testspriteminimal.c)
add_sdl_test_executable(teststreaming NEEDS_RESOURCES TESTUTILS teststreaming.c)
add_sdl_test_executable(testtimer NONINTERACTIVE testtimer.c)
add_sdl_test_executable(testurl testurl.c)
add_sdl_test_executable(testver NONINTERACTIVE testver.c)
add_sdl_test_executable(testviewport NEEDS_RESOURCES TESTUTILS testviewport.c)
add_sdl_test_executable(testwm testwm.c)
add_sdl_test_executable(testyuv NEEDS_RESOURCES TESTUTILS testyuv.c testyuv_cvt.c)
add_sdl_test_executable(torturethread torturethread.c)
add_sdl_test_executable(testrendercopyex NEEDS_RESOURCES TESTUTILS testrendercopyex.c)
add_sdl_test_executable(testmessage testmessage.c)
add_sdl_test_executable(testdisplayinfo testdisplayinfo.c)
add_sdl_test_executable(testqsort NONINTERACTIVE testqsort.c)
add_sdl_test_executable(testbounds testbounds.c)
add_sdl_test_executable(testcustomcursor testcustomcursor.c)
add_sdl_test_executable(gamepadmap NEEDS_RESOURCES TESTUTILS gamepadmap.c)
add_sdl_test_executable(testvulkan testvulkan.c)
add_sdl_test_executable(testoffscreen testoffscreen.c)
add_sdl_test_executable(testpopup testpopup.c)
add_sdl_test_executable(testoverlay NEEDS_RESOURCES TESTUTILS SOURCES testoverlay.c)
add_sdl_test_executable(testplatform NONINTERACTIVE SOURCES testplatform.c)
add_sdl_test_executable(testpower NONINTERACTIVE SOURCES testpower.c)
add_sdl_test_executable(testfilesystem NONINTERACTIVE SOURCES testfilesystem.c)
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(testsensor SOURCES testsensor.c)
add_sdl_test_executable(testshader NEEDS_RESOURCES TESTUTILS SOURCES testshader.c)
add_sdl_test_executable(testshape NEEDS_RESOURCES SOURCES testshape.c)
add_sdl_test_executable(testsprite NEEDS_RESOURCES TESTUTILS SOURCES testsprite.c)
add_sdl_test_executable(testspriteminimal NEEDS_RESOURCES TESTUTILS SOURCES testspriteminimal.c)
add_sdl_test_executable(teststreaming NEEDS_RESOURCES TESTUTILS SOURCES teststreaming.c)
add_sdl_test_executable(testtimer NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60 SOURCES testtimer.c)
add_sdl_test_executable(testurl SOURCES testurl.c)
add_sdl_test_executable(testver NONINTERACTIVE SOURCES testver.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(testrendercopyex NEEDS_RESOURCES TESTUTILS SOURCES testrendercopyex.c)
add_sdl_test_executable(testmessage SOURCES testmessage.c)
add_sdl_test_executable(testdisplayinfo SOURCES testdisplayinfo.c)
add_sdl_test_executable(testqsort NONINTERACTIVE SOURCES testqsort.c)
add_sdl_test_executable(testbounds NONINTERACTIVE SOURCES testbounds.c)
add_sdl_test_executable(testcustomcursor SOURCES testcustomcursor.c)
add_sdl_test_executable(gamepadmap NEEDS_RESOURCES TESTUTILS SOURCES gamepadmap.c)
add_sdl_test_executable(testvulkan SOURCES testvulkan.c)
add_sdl_test_executable(testoffscreen SOURCES testoffscreen.c)
add_sdl_test_executable(testpopup SOURCES testpopup.c)
check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
if(HAVE_WFORMAT_OVERFLOW)
@ -248,18 +263,14 @@ if(NOT HAVE_X11)
endif()
if(SDL_DUMMYAUDIO)
list(APPEND SDL_TESTS_NONINTERACTIVE
testaudioinfo
testsurround
)
set_property(TARGET testaudioinfo PROPERTY SDL_NONINTERACTIVE 1)
set_property(TARGET testsurround PROPERTY SDL_NONINTERACTIVE 1)
endif()
if(SDL_DUMMYVIDEO)
list(APPEND SDL_TESTS_NONINTERACTIVE
testkeys
testbounds
testdisplayinfo
)
set_property(TARGET testkeys PROPERTY SDL_NONINTERACTIVE 1)
set_property(TARGET testbounds PROPERTY SDL_NONINTERACTIVE 1)
set_property(TARGET testdisplayinfo PROPERTY SDL_NONINTERACTIVE 1)
endif()
if(OPENGL_FOUND)
@ -381,33 +392,38 @@ set(TESTS_ENVIRONMENT
PATH=$<TARGET_FILE_DIR:SDL3::${sdl_name_component}>
)
function(sdl_set_test_timeout TEST TIMEOUT)
math(EXPR TIMEOUT "${TIMEOUT}*${SDL_TESTS_TIMEOUT_MULTIPLIER}")
set_tests_properties(${test} PROPERTIES TIMEOUT "${TIMEOUT}")
endfunction()
foreach(TESTCASE ${SDL_TESTS_NONINTERACTIVE})
add_test(
NAME ${TESTCASE}
COMMAND ${TESTCASE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_tests_properties(${TESTCASE} PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}")
sdl_set_test_timeout(${TESTCASE} 10)
if(SDL_INSTALL_TESTS)
set(exe ${TESTCASE})
set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL3")
configure_file(template.test.in "${exe}.test" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL3
foreach(TEST ${SDL_TEST_EXECUTABLES})
get_property(noninteractive TARGET ${TEST} PROPERTY SDL_NONINTERACTIVE)
if(noninteractive)
set(command ${TEST})
get_property(noninteractive_arguments TARGET ${TEST} PROPERTY SDL_NONINTERACTIVE_ARGUMENTS)
if(noninteractive_arguments)
list(APPEND command ${noninteractive_arguments})
endif()
add_test(
NAME ${TEST}
COMMAND ${command}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_tests_properties(${TEST} PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}")
get_property(noninteractive_timeout TARGET ${TEST} PROPERTY SDL_NONINTERACTIVE_TIMEOUT)
if(NOT noninteractive_timeout)
set(noninteractive_timeout 10)
endif()
math(EXPR noninteractive_timeout "${noninteractive_timeout}*${SDL_TESTS_TIMEOUT_MULTIPLIER}")
set_tests_properties(${TEST} PROPERTIES TIMEOUT "${noninteractive_timeout}")
if(SDL_INSTALL_TESTS)
set(exe ${TEST})
set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL3")
configure_file(template.test.in "${exe}.test" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL3
)
endif()
endif()
endforeach()
sdl_set_test_timeout(testthread 40)
sdl_set_test_timeout(testtimer 60)
if(SDL_INSTALL_TESTS)
if(RISCOS)
install(