From 564765d22b68cfc94bfa23d217354f7a86674067 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 30 Aug 2024 17:41:16 +0200
Subject: [PATCH] ctest: fail if there are outstanding allocations
backport of b68ac011e0bce42b2c5142e200c1441f846b4faa
---
test/CMakeLists.txt | 51 ++++++++++++++++++++++++++++-----------------
1 file changed, 32 insertions(+), 19 deletions(-)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 0d00763c891c6..dfc6a1e6b3bf5 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -9,6 +9,8 @@ set(SDL_TEST_EXECUTABLES)
set(SDL_TESTS_NONINTERACTIVE)
set(SDL_TESTS_NEEDS_RESOURCES)
+option(SDLTEST_TRACKMEM "Run tests with --trackmem" OFF)
+
if(WIN32 AND NOT WINDOWS_STORE)
option(SDLTEST_PROCDUMP "Run tests using sdlprocdump for minidump generation" OFF)
add_executable(sdlprocdump win32/sdlprocdump.c)
@@ -34,7 +36,7 @@ macro(sdltest_add_definitions)
endmacro()
macro(add_sdl_test_executable TARGET)
- cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES" "" "" ${ARGN})
+ cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES;NOTRACKMEM" "" "" ${ARGN})
list(APPEND SDLTEST_TARGETS ${TARGET})
if(ANDROID)
add_library(${TARGET} SHARED ${AST_UNPARSED_ARGUMENTS})
@@ -43,6 +45,7 @@ macro(add_sdl_test_executable TARGET)
endif()
list(APPEND SDL_TEST_EXECUTABLES ${TARGET})
+ set_property(TARGET ${TARGET} PROPERTY SDL_NOTRACKMEM ${AST_NOTRACKMEM})
if(AST_NONINTERACTIVE)
list(APPEND SDL_TESTS_NONINTERACTIVE ${TARGET})
endif()
@@ -109,26 +112,26 @@ add_sdl_test_executable(checkkeys checkkeys.c)
add_sdl_test_executable(checkkeysthreads checkkeysthreads.c)
add_sdl_test_executable(loopwave NEEDS_RESOURCES loopwave.c testutils.c)
add_sdl_test_executable(loopwavequeue NEEDS_RESOURCES loopwavequeue.c testutils.c)
-add_sdl_test_executable(testsurround testsurround.c)
+add_sdl_test_executable(testsurround NOTRACKMEM testsurround.c)
add_sdl_test_executable(testresample NEEDS_RESOURCES testresample.c)
-add_sdl_test_executable(testaudioinfo testaudioinfo.c)
+add_sdl_test_executable(testaudioinfo NOTRACKMEM testaudioinfo.c)
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_sdl_test_executable(testautomation NONINTERACTIVE NEEDS_RESOURCES ${TESTAUTOMATION_SOURCE_FILES})
add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES testmultiaudio.c testutils.c)
add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES testaudiohotplug.c testutils.c)
add_sdl_test_executable(testaudiocapture testaudiocapture.c)
-add_sdl_test_executable(testatomic NONINTERACTIVE testatomic.c)
+add_sdl_test_executable(testatomic NOTRACKMEM 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(testdraw2 testdraw2.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(testerror NOTRACKMEM NONINTERACTIVE testerror.c)
if(LINUX)
- add_sdl_test_executable(testevdev NONINTERACTIVE testevdev.c)
+ add_sdl_test_executable(testevdev NOTRACKMEM NONINTERACTIVE testevdev.c)
endif()
add_sdl_test_executable(testfile testfile.c)
@@ -145,13 +148,13 @@ endif()
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(testthread NOTRACKMEM NONINTERACTIVE testthread.c)
add_sdl_test_executable(testiconv NEEDS_RESOURCES testiconv.c testutils.c)
add_sdl_test_executable(testime NEEDS_RESOURCES testime.c testutils.c)
add_sdl_test_executable(testjoystick testjoystick.c)
-add_sdl_test_executable(testkeys testkeys.c)
+add_sdl_test_executable(testkeys NOTRACKMEM testkeys.c)
add_sdl_test_executable(testloadso testloadso.c)
-add_sdl_test_executable(testlocale NONINTERACTIVE testlocale.c)
+add_sdl_test_executable(testlocale NOTRACKMEM NONINTERACTIVE testlocale.c)
add_sdl_test_executable(testlock testlock.c)
add_sdl_test_executable(testmouse testmouse.c)
@@ -179,11 +182,11 @@ elseif(OS2)
endif()
add_sdl_test_executable(testoverlay2 NEEDS_RESOURCES testoverlay2.c testyuv_cvt.c testutils.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(testplatform NOTRACKMEM NONINTERACTIVE testplatform.c)
+add_sdl_test_executable(testpower NOTRACKMEM NONINTERACTIVE testpower.c)
+add_sdl_test_executable(testfilesystem NOTRACKMEM NONINTERACTIVE testfilesystem.c)
if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
- add_sdl_test_executable(testfilesystem_pre NONINTERACTIVE testfilesystem_pre.c)
+ add_sdl_test_executable(testfilesystem_pre NOTRACKMEM NONINTERACTIVE testfilesystem_pre.c)
endif()
add_sdl_test_executable(testrendertarget NEEDS_RESOURCES testrendertarget.c testutils.c)
add_sdl_test_executable(testscale NEEDS_RESOURCES testscale.c testutils.c)
@@ -194,18 +197,18 @@ add_sdl_test_executable(testshape NEEDS_RESOURCES testshape.c)
add_sdl_test_executable(testsprite2 NEEDS_RESOURCES testsprite2.c testutils.c)
add_sdl_test_executable(testspriteminimal NEEDS_RESOURCES testspriteminimal.c testutils.c)
add_sdl_test_executable(teststreaming NEEDS_RESOURCES teststreaming.c testutils.c)
-add_sdl_test_executable(testtimer NONINTERACTIVE testtimer.c)
+add_sdl_test_executable(testtimer NOTRACKMEM NONINTERACTIVE testtimer.c)
add_sdl_test_executable(testurl testurl.c)
-add_sdl_test_executable(testver NONINTERACTIVE testver.c)
+add_sdl_test_executable(testver NOTRACKMEM NONINTERACTIVE testver.c)
add_sdl_test_executable(testviewport NEEDS_RESOURCES testviewport.c testutils.c)
add_sdl_test_executable(testwm2 testwm2.c)
add_sdl_test_executable(testyuv NEEDS_RESOURCES testyuv.c testyuv_cvt.c)
add_sdl_test_executable(torturethread torturethread.c)
add_sdl_test_executable(testrendercopyex NEEDS_RESOURCES testrendercopyex.c testutils.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(testdisplayinfo NOTRACKMEM testdisplayinfo.c)
+add_sdl_test_executable(testqsort NOTRACKMEM NONINTERACTIVE testqsort.c)
+add_sdl_test_executable(testbounds NOTRACKMEM testbounds.c)
add_sdl_test_executable(testcustomcursor testcustomcursor.c)
add_sdl_test_executable(controllermap NEEDS_RESOURCES controllermap.c testutils.c)
add_sdl_test_executable(testvulkan testvulkan.c)
@@ -500,9 +503,16 @@ set(TESTS_ENVIRONMENT
)
foreach(TESTCASE ${SDL_TESTS_NONINTERACTIVE})
+ set(command ${TESTCASE})
+ if(SDLTEST_TRACKMEM)
+ get_property(notrackmem TARGET ${TESTCASE} PROPERTY SDL_NOTRACKMEM)
+ if(NOT notrackmem)
+ list(APPEND command --trackmem)
+ endif()
+ endif()
add_test(
NAME ${TESTCASE}
- COMMAND ${TESTCASE}
+ COMMAND ${command}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_tests_properties(${TESTCASE}
@@ -510,6 +520,9 @@ foreach(TESTCASE ${SDL_TESTS_NONINTERACTIVE})
ENVIRONMENT "${TESTS_ENVIRONMENT}"
TIMEOUT 10
)
+ if(NOT notrackmem)
+ set_property(TEST ${TESTCASE} PROPERTY FAIL_REGULAR_EXPRESSION "Total: [0-9]+\\.[0-9]+ Kb in [1-9][0-9]* allocations")
+ endif()
if(SDL_INSTALL_TESTS)
set(exe ${TESTCASE})
set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL2")