From cabf98a94f444f969132897441eb3ad0bbf82cbd Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 3 Jul 2023 16:59:03 +0200
Subject: [PATCH] cmake: add non-interactive tests to test matrix
---
CMakeLists.txt | 229 +++++++++++++++++++++++++++----------------------
1 file changed, 127 insertions(+), 102 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 64d020c..7127acb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,6 +5,11 @@
cmake_minimum_required(VERSION 3.0.0...3.5)
project(sdl2_compat VERSION 2.28.50 LANGUAGES C)
+if(POLICY CMP0074)
+ # CMP0074: find_package() uses <PackageName>_ROOT variables.
+ cmake_policy(SET CMP0074 NEW)
+endif()
+
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(SDL2COMPAT_SUBPROJECT OFF)
else()
@@ -72,6 +77,7 @@ include(CheckCSourceCompiles)
include(CheckIncludeFile)
include(CheckCCompilerFlag)
include(CMakePackageConfigHelpers)
+include(CMakeParseArguments)
include(CMakePushCheckState)
include(GNUInstallDirs)
include("${CMAKE_CURRENT_LIST_DIR}/cmake/CheckCPUArchitecture.cmake")
@@ -94,8 +100,6 @@ if(NOT MSVC AND NOT APPLE AND NOT OPENBSD)
endif()
endif()
-set(CMAKE_SKIP_RPATH TRUE)
-
if(NOT TARGET SDL3::Headers)
find_package(SDL3 QUIET COMPONENTS Headers)
endif()
@@ -335,6 +339,8 @@ target_include_directories(SDL2_test
)
if(SDL2COMPAT_TESTS)
+ enable_testing()
+
if(NOT (WIN32 OR APPLE OR CYGWIN OR HAIKU OR BEOS))
find_library(MATH_LIBRARY m)
endif()
@@ -352,59 +358,76 @@ if(SDL2COMPAT_TESTS)
endif()
endif()
- macro(test_program _NAME _SRCS)
- add_executable(${_NAME} ${_SRCS})
- target_link_libraries(${_NAME} PRIVATE SDL2::SDL2main SDL2::SDL2test SDL2::SDL2)
+ function(test_program NAME)
+ cmake_parse_arguments(args "NONINTERACTIVE" "TIMEOUT" "SRC" ${ARGN})
+ add_executable(${NAME} ${args_SRC})
+ target_link_libraries(${NAME} PRIVATE SDL2::SDL2main SDL2::SDL2test SDL2::SDL2)
# Turn off MSVC's aggressive C runtime warnings for the old test programs.
if(MSVC)
- target_compile_definitions(${_NAME} PRIVATE ${HAVE_OPENGL_DEFINE} _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE)
+ target_compile_definitions(${NAME} PRIVATE ${HAVE_OPENGL_DEFINE} _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE)
elseif(APPLE)
- target_compile_definitions(${_NAME} PRIVATE ${HAVE_OPENGL_DEFINE} GL_SILENCE_DEPRECATION=1)
- target_link_libraries(${_NAME} PRIVATE "-Wl,-framework,Cocoa")
+ target_compile_definitions(${NAME} PRIVATE ${HAVE_OPENGL_DEFINE} GL_SILENCE_DEPRECATION=1)
+ target_link_libraries(${NAME} PRIVATE "-Wl,-framework,Cocoa")
else()
- target_compile_definitions(${_NAME} PRIVATE ${HAVE_OPENGL_DEFINE})
+ target_compile_definitions(${NAME} PRIVATE ${HAVE_OPENGL_DEFINE})
endif()
if(MATH_LIBRARY)
- target_link_libraries(${_NAME} PRIVATE ${MATH_LIBRARY})
+ target_link_libraries(${NAME} PRIVATE ${MATH_LIBRARY})
endif()
- endmacro()
-
- test_program(checkkeys "test/checkkeys.c")
- test_program(checkkeysthreads "test/checkkeysthreads.c")
- test_program(controllermap "test/controllermap.c;test/testutils.c")
- test_program(loopwave "test/loopwave.c;test/testutils.c")
- test_program(loopwavequeue "test/loopwavequeue.c;test/testutils.c")
- test_program(testatomic "test/testatomic.c")
- test_program(testaudiocapture "test/testaudiocapture.c")
- test_program(testaudiohotplug "test/testaudiohotplug.c;test/testutils.c")
- test_program(testaudioinfo "test/testaudioinfo.c")
- test_program(testbounds "test/testbounds.c")
- test_program(testcustomcursor "test/testcustomcursor.c")
- test_program(testdisplayinfo "test/testdisplayinfo.c")
- test_program(testdraw2 "test/testdraw2.c")
- test_program(testdrawchessboard "test/testdrawchessboard.c")
- test_program(testdropfile "test/testdropfile.c")
- test_program(testerror "test/testerror.c")
- test_program(testevdev "test/testevdev.c")
- test_program(testfile "test/testfile.c")
- test_program(testfilesystem "test/testfilesystem.c")
- test_program(testgamecontroller "test/testgamecontroller.c;test/testutils.c")
- test_program(testgeometry "test/testgeometry.c;test/testutils.c")
- test_program(testgesture "test/testgesture.c")
- test_program(testhaptic "test/testhaptic.c")
- test_program(testhittesting "test/testhittesting.c")
- test_program(testhotplug "test/testhotplug.c")
- test_program(testiconv "test/testiconv.c;test/testutils.c")
- test_program(testime "test/testime.c;test/testutils.c")
- test_program(testintersections "test/testintersections.c")
- test_program(testjoystick "test/testjoystick.c")
- test_program(testkeys "test/testkeys.c")
- test_program(testloadso "test/testloadso.c")
- test_program(testlocale "test/testlocale.c")
- test_program(testlock "test/testlock.c")
- test_program(testmessage "test/testmessage.c")
- test_program(testmouse "test/testmouse.c")
- test_program(testmultiaudio "test/testmultiaudio.c;test/testutils.c")
+ if(args_NONINTERACTIVE)
+ add_test(
+ NAME ${NAME}
+ COMMAND ${NAME}
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+ )
+ set(timeout 10)
+ if(args_TIMEOUT)
+ set(timeout ${args_TIMEOUT})
+ endif()
+ set_tests_properties(${NAME}
+ PROPERTIES
+ ENVIRONMENT "SDL_AUDIODRIVER=dummy;SDL_VIDEODRIVER=dummy"
+ TIMEOUT ${timeout}
+ )
+ endif()
+ endfunction()
+
+ test_program(checkkeys SRC "test/checkkeys.c")
+ test_program(checkkeysthreads SRC "test/checkkeysthreads.c")
+ test_program(controllermap SRC "test/controllermap.c" "test/testutils.c")
+ test_program(loopwave SRC "test/loopwave.c" "test/testutils.c")
+ test_program(loopwavequeue SRC "test/loopwavequeue.c" "test/testutils.c")
+ test_program(testatomic NONINTERACTIVE SRC "test/testatomic.c")
+ test_program(testaudiocapture SRC "test/testaudiocapture.c")
+ test_program(testaudiohotplug SRC "test/testaudiohotplug.c" "test/testutils.c")
+ test_program(testaudioinfo SRC "test/testaudioinfo.c")
+ test_program(testbounds SRC "test/testbounds.c")
+ test_program(testcustomcursor SRC "test/testcustomcursor.c")
+ test_program(testdisplayinfo SRC "test/testdisplayinfo.c")
+ test_program(testdraw2 SRC "test/testdraw2.c")
+ test_program(testdrawchessboard SRC "test/testdrawchessboard.c")
+ test_program(testdropfile SRC "test/testdropfile.c")
+ test_program(testerror NONINTERACTIVE SRC "test/testerror.c")
+ test_program(testevdev NONINTERACTIVE SRC "test/testevdev.c")
+ test_program(testfile NONINTERACTIVE SRC "test/testfile.c")
+ test_program(testfilesystem NONINTERACTIVE SRC "test/testfilesystem.c")
+ test_program(testgamecontroller SRC "test/testgamecontroller.c" "test/testutils.c")
+ test_program(testgeometry SRC "test/testgeometry.c" "test/testutils.c")
+ test_program(testgesture SRC "test/testgesture.c")
+ test_program(testhaptic SRC "test/testhaptic.c")
+ test_program(testhittesting SRC "test/testhittesting.c")
+ test_program(testhotplug SRC "test/testhotplug.c")
+ test_program(testiconv SRC "test/testiconv.c" "test/testutils.c")
+ test_program(testime SRC "test/testime.c" "test/testutils.c")
+ test_program(testintersections SRC "test/testintersections.c")
+ test_program(testjoystick SRC "test/testjoystick.c")
+ test_program(testkeys SRC "test/testkeys.c")
+ test_program(testloadso SRC "test/testloadso.c")
+ test_program(testlocale NONINTERACTIVE SRC "test/testlocale.c")
+ test_program(testlock SRC "test/testlock.c")
+ test_program(testmessage SRC "test/testmessage.c")
+ test_program(testmouse SRC "test/testmouse.c")
+ test_program(testmultiaudio SRC "test/testmultiaudio.c" "test/testutils.c")
if(APPLE)
set(TESTNATIVE_EXTRA "test/testnativecocoa.m")
elseif(WIN32)
@@ -413,65 +436,67 @@ if(SDL2COMPAT_TESTS)
find_package(X11 REQUIRED)
set(TESTNATIVE_EXTRA "test/testnativex11.c")
endif()
- test_program(testnative "test/testnative.c;test/testutils.c;${TESTNATIVE_EXTRA}")
- test_program(testoverlay2 "test/testoverlay2.c;test/testutils.c;test/testyuv_cvt.c")
- test_program(testplatform "test/testplatform.c")
- test_program(testpower "test/testpower.c")
- test_program(testqsort "test/testqsort.c")
- test_program(testrelative "test/testrelative.c")
- test_program(testrendercopyex "test/testrendercopyex.c;test/testutils.c")
- test_program(testrendertarget "test/testrendertarget.c;test/testutils.c")
- test_program(testresample "test/testresample.c")
- test_program(testrumble "test/testrumble.c")
- test_program(testscale "test/testscale.c;test/testutils.c")
- test_program(testsem "test/testsem.c")
- test_program(testsensor "test/testsensor.c")
- test_program(testshape "test/testshape.c")
- test_program(testsprite2 "test/testsprite2.c;test/testutils.c")
- test_program(testspriteminimal "test/testspriteminimal.c;test/testutils.c")
- test_program(teststreaming "test/teststreaming.c;test/testutils.c")
- test_program(testsurround "test/testsurround.c")
- test_program(testthread "test/testthread.c")
- test_program(testtimer "test/testtimer.c")
- test_program(testurl "test/testurl.c")
- test_program(testver "test/testver.c")
- test_program(testviewport "test/testviewport.c;test/testutils.c")
- test_program(testvulkan "test/testvulkan.c")
- test_program(testwm2 "test/testwm2.c")
- test_program(testyuv "test/testyuv.c;test/testyuv_cvt.c")
- test_program(torturethread "test/torturethread.c")
- test_program(testgl2 "test/testgl2.c")
+ test_program(testnative SRC "test/testnative.c" "test/testutils.c" "${TESTNATIVE_EXTRA}")
+ test_program(testoverlay2 SRC "test/testoverlay2.c" "test/testutils.c" "test/testyuv_cvt.c")
+ test_program(testplatform NONINTERACTIVE SRC "test/testplatform.c")
+ test_program(testpower NONINTERACTIVE SRC "test/testpower.c")
+ test_program(testqsort NONINTERACTIVE SRC "test/testqsort.c")
+ test_program(testrelative SRC "test/testrelative.c")
+ test_program(testrendercopyex SRC "test/testrendercopyex.c" "test/testutils.c")
+ test_program(testrendertarget SRC "test/testrendertarget.c" "test/testutils.c")
+ test_program(testresample SRC "test/testresample.c")
+ test_program(testrumble SRC "test/testrumble.c")
+ test_program(testscale SRC "test/testscale.c" "test/testutils.c")
+ test_program(testsem SRC "test/testsem.c")
+ test_program(testsensor SRC "test/testsensor.c")
+ test_program(testshape SRC "test/testshape.c")
+ test_program(testsprite2 SRC "test/testsprite2.c" "test/testutils.c")
+ test_program(testspriteminimal SRC "test/testspriteminimal.c" "test/testutils.c")
+ test_program(teststreaming SRC "test/teststreaming.c" "test/testutils.c")
+ test_program(testsurround SRC "test/testsurround.c")
+ test_program(testthread NONINTERACTIVE TIMEOUT 40 SRC "test/testthread.c")
+ test_program(testtimer NONINTERACTIVE TIMEOUT 60 SRC "test/testtimer.c")
+ test_program(testurl SRC "test/testurl.c")
+ test_program(testver NONINTERACTIVE SRC "test/testver.c")
+ test_program(testviewport SRC "test/testviewport.c" "test/testutils.c")
+ test_program(testvulkan SRC "test/testvulkan.c")
+ test_program(testwm2 SRC "test/testwm2.c")
+ test_program(testyuv SRC "test/testyuv.c" "test/testyuv_cvt.c")
+ test_program(torturethread SRC "test/torturethread.c")
+ test_program(testgl2 SRC "test/testgl2.c")
if(HAVE_OPENGLES)
- test_program(testgles "test/testgles.c")
+ test_program(testgles SRC "test/testgles.c")
endif()
if(HAVE_OPENGLES_V2)
- test_program(testgles2 "test/testgles2.c")
- test_program(testgles2_sdf "test/testgles2_sdf.c;test/testutils.c")
+ test_program(testgles2 SRC "test/testgles2.c")
+ test_program(testgles2_sdf SRC "test/testgles2_sdf.c" "test/testutils.c")
endif()
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_audio.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_guid.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_main.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_platform.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_sdltest.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_syswm.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_hints.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_math.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_rect.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_stdlib.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_timer.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_clipboard.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_joystick.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_mouse.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_render.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_video.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_events.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_keyboard.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_pixels.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_rwops.c")
- list(APPEND TESTAUTOMATION_SRCS "test/testautomation_surface.c")
- test_program(testautomation "${TESTAUTOMATION_SRCS}")
+ test_program(testautomation NONINTERACTIVE TIMEOUT 40
+ SRC
+ "test/testautomation.c"
+ "test/testautomation_audio.c"
+ "test/testautomation_guid.c"
+ "test/testautomation_main.c"
+ "test/testautomation_platform.c"
+ "test/testautomation_sdltest.c"
+ "test/testautomation_syswm.c"
+ "test/testautomation_hints.c"
+ "test/testautomation_math.c"
+ "test/testautomation_rect.c"
+ "test/testautomation_stdlib.c"
+ "test/testautomation_timer.c"
+ "test/testautomation_clipboard.c"
+ "test/testautomation_joystick.c"
+ "test/testautomation_mouse.c"
+ "test/testautomation_render.c"
+ "test/testautomation_video.c"
+ "test/testautomation_events.c"
+ "test/testautomation_keyboard.c"
+ "test/testautomation_pixels.c"
+ "test/testautomation_rwops.c"
+ "test/testautomation_surface.c"
+ )
if(OPENGL_FOUND)
if(CMAKE_VERSION VERSION_LESS 3.10 OR NOT OPENGL_opengl_LIBRARY)