SDL: ctest/emscripten: make audio and video driver configurable

From 9eac3a434e328bd6f7470eb59076dcf7dae237be Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Wed, 21 Aug 2024 20:14:55 +0200
Subject: [PATCH] ctest/emscripten: make audio and video driver configurable

---
 test/CMakeLists.txt       | 18 ++++++++++++++----
 test/emscripten/driver.py |  8 ++++++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 279d1e2bcd4f2..80348499d6647 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -615,13 +615,23 @@ if(APPLE)
   endforeach()
 endif()
 
+set(SDLTEST_TIMEOUT_MULTIPLIER "1" CACHE STRING "SDL test time-out multiplier")
+
+set(SDLTEST_AUDIO_DRIVER_DEFAULT "dummy")
+set(SDLTEST_VIDEO_DRIVER_DEFAULT "dummy")
+if(EMSCRIPTEN)
+    set(SDLTEST_AUDIO_DRIVER_DEFAULT "emscripten")
+    set(SDLTEST_VIDEO_DRIVER_DEFAULT "emscripten")
+endif()
+set(SDLTEST_AUDIO_DRIVER "${SDLTEST_AUDIO_DRIVER_DEFAULT}" CACHE STRING "SDL audio driver for CTest")
+set(SDLTEST_VIDEO_DRIVER "${SDLTEST_VIDEO_DRIVER_DEFAULT}" CACHE STRING "SDL video driver for CTest")
+
 set(TESTS_ENVIRONMENT
-    SDL_AUDIO_DRIVER=dummy
-    SDL_VIDEO_DRIVER=dummy
+    "SDL_AUDIO_DRIVER=${SDLTEST_AUDIO_DRIVER}"
+    "SDL_VIDEO_DRIVER=${SDLTEST_VIDEO_DRIVER}"
+    "SDL_ASSERT=abort"
 )
 
-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)
diff --git a/test/emscripten/driver.py b/test/emscripten/driver.py
index 78b7a49e05fb6..9735e95b9255a 100755
--- a/test/emscripten/driver.py
+++ b/test/emscripten/driver.py
@@ -3,12 +3,13 @@
 import argparse
 import contextlib
 import logging
-import urllib.parse
+import os
+import pathlib
 import shlex
 import sys
 import time
-import pathlib
 from typing import Optional
+import urllib.parse
 
 from selenium import webdriver
 import selenium.common.exceptions
@@ -68,6 +69,9 @@ def url(self):
             "loghtml": "1",
             "SDL_ASSERT": "abort",
         }
+        for key, value in os.environ.items():
+            if key.startswith("SDL_"):
+                req[key] = value
         req.update({f"arg_{i}": a for i, a in enumerate(self.arguments, 1) })
         req_str = urllib.parse.urlencode(req)
         return f"{self.server}/{self.test}.html?{req_str}"