From a2e17852d9d8e3b80fca64dc2ce42da41a21e707 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 8 Sep 2023 03:28:01 +0200
Subject: [PATCH] cmake: make sure SDL_GetPrefPath is run before testfilesystem
60 seconds timeout ought to be sufficient.
---
test/CMakeLists.txt | 7 +++++++
test/testfilesystem_pre.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+)
create mode 100644 test/testfilesystem_pre.c
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index b762ffe92d2e..14764824d6d0 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -296,6 +296,9 @@ add_sdl_test_executable(testoverlay NEEDS_RESOURCES TESTUTILS SOURCES testoverla
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)
+if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
+ add_sdl_test_executable(testfilesystem_pre SOURCES testfilesystem_pre.c NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60)
+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)
@@ -504,6 +507,10 @@ foreach(TEST ${SDL_TEST_EXECUTABLES})
endif()
endforeach()
+if(TARGET testfilesystem_pre)
+ set_property(TEST testfilesystem APPEND PROPERTY DEPENDS testfilesystem_pre)
+endif()
+
if(SDL_INSTALL_TESTS)
if(RISCOS)
install(
diff --git a/test/testfilesystem_pre.c b/test/testfilesystem_pre.c
new file mode 100644
index 000000000000..1a7e0d617534
--- /dev/null
+++ b/test/testfilesystem_pre.c
@@ -0,0 +1,33 @@
+/*
+ Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely.
+*/
+/* Call SDL_GetPrefPath to warm the SHGetFolderPathW cache */
+
+/**
+ * We noticed frequent ci timeouts running testfilesystem on 32-bit Windows.
+ * Internally, this functions calls Shell32.SHGetFolderPathW.
+ */
+
+#include <SDL3/SDL.h>
+#include <SDL3/SDL_main.h>
+
+int main(int argc, char *argv[])
+{
+ Uint64 start;
+ (void)argc;
+ (void)argv;
+ SDL_Init(0);
+ start = SDL_GetTicks();
+ SDL_GetPrefPath("libsdl", "test_filesystem");
+ SDL_Log("SDL_GetPrefPath took %" SDL_PRIu64 "ms", SDL_GetTicks() - start);
+ SDL_Quit();
+ return 0;
+}