Merge upstream main and preserve routed Home input

Integrate upstream 213c2da5, keeping Home/Guide player-slot handling compatible with remapped controls and disabled routing. Preserve the input-settings overlay gate for Home and Steam volume keys.

Validation: 2,707 JVM tests across 389 suites pass. Device validation and latency measurements were not repeated.
This commit is contained in:
Delete228 committed 2026-10-28 12:45:41 +03:00
commit b245017593
121 files changed
+7170 -348

No files matched your search

+10 -2
View File
@@ -44,6 +44,7 @@ typedef struct pa_sink {
struct android_volume;
struct userdata { struct android_volume *android_volume; };
static int restarts, frees;
static uint64_t last_delay;
static char *pa_sprintf_malloc(const char *format, ...) {
va_list ap; va_start(ap,format); char *result; assert(vasprintf(&result,format,ap)>=0); va_end(ap); return result;
}
@@ -57,7 +58,7 @@ static void pa_sink_set_set_volume_callback(pa_sink *sink, void (*callback)(pa_s
static void pa_sink_set_set_mute_callback(pa_sink *sink, void (*callback)(pa_sink*)) { sink->set_mute=callback; }
static void pa_subscription_post(pa_core *core, int event, unsigned index) {}
static uint64_t pa_rtclock_now(void) { return 0; }
static void pa_core_rttime_restart(pa_core *core, pa_time_event *event, uint64_t time) { restarts++; }
static void pa_core_rttime_restart(pa_core *core, pa_time_event *event, uint64_t time) { restarts++; last_delay=time; }
static pa_time_event *pa_core_rttime_new(pa_core *core, uint64_t time,
void (*callback)(pa_mainloop_api*,pa_time_event*,const struct timeval*,void*), void *userdata) {
return calloc(1,sizeof(pa_time_event));
@@ -76,11 +77,18 @@ int main(int argc, char **argv) {
assert(userdata.android_volume && userdata.android_volume->timer && sink.set_volume && sink.set_mute);
state(argv[1],"invalid\n");
android_volume_refresh(&api,userdata.android_volume->timer,NULL,userdata.android_volume);
assert(sink.real_volume.value==PA_VOLUME_NORM && restarts==1);
assert(sink.real_volume.value==PA_VOLUME_NORM && restarts==1 && last_delay==100*PA_USEC_PER_MSEC);
state(argv[1],"3 15 1\n");
android_volume_refresh(&api,userdata.android_volume->timer,NULL,userdata.android_volume);
assert(sink.real_volume.value==3*PA_VOLUME_NORM/15 && sink.muted && sink.n_volume_steps==16);
assert(sink.soft_volume.value==PA_VOLUME_NORM && restarts==2);
assert(last_delay==16*PA_USEC_PER_MSEC);
state(argv[1],"4 15 1\n");
android_volume_refresh(&api,userdata.android_volume->timer,NULL,userdata.android_volume);
assert(sink.real_volume.value==4*PA_VOLUME_NORM/15 && last_delay==16*PA_USEC_PER_MSEC);
for (int i = 0; i < ANDROID_VOLUME_ACTIVE_TICKS + 1; i++)
android_volume_refresh(&api,userdata.android_volume->timer,NULL,userdata.android_volume);
assert(last_delay==100*PA_USEC_PER_MSEC);
sink.real_volume.value=2*PA_VOLUME_NORM/3; sink.set_volume(&sink);
char *request=pa_sprintf_malloc("%s/volume.request",argv[1]);
FILE *f=fopen(request,"r"); unsigned level; assert(f && fscanf(f,"%u",&level)==1 && level==10); fclose(f); free(request);
+211
View File
@@ -28,6 +28,121 @@ def config_text(entries):
return '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }' % mapping
class GameDebugLoggingTest(unittest.TestCase):
def test_real_game_launch_without_config_file_keeps_the_base_environment(self):
with tempfile.TemporaryDirectory() as tmp:
home = Path(tmp)
probe = home / "proton"
probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ['PROTON_LOG'])\n")
probe.chmod(0o755)
result = subprocess.run(
[sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun"],
env={**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42"),
"BL_DEBUG_DIR": tmp, "PROTON_LOG": "0"},
text=True, capture_output=True, check=True,
)
self.assertEqual(result.stdout.strip(), "0")
def test_game_debug_logs_override_only_diagnostic_values_and_keep_raw_settings(self):
with tempfile.TemporaryDirectory(prefix="game logs '") as debug_dir:
inherited = {"BL_DEBUG_DIR": debug_dir, "PROTON_LOG": "0", "WINEDEBUG": "-all,+relay",
"PROTON_LOG_DIR": "/old", "PROTON_CRASH_REPORT_DIR": "/old-crashes",
"DXVK_LOG_PATH": "/old-dxvk", "DXVK_LOG_LEVEL": "none", "VKD3D_DEBUG": "none",
"CUSTOM": "$(touch never); 'quoted' = literal", "DXVK_CONFIG": "dxvk.tearFree = True"}
config = {"version": 1, "gameDebugLogs": True,
"shared": {"PROTON_LOG": "0", "BL_DEBUG_DIR": "/profile-redirect"},
"games": {"42": {"PROTON_LOG_DIR": None, "DXVK_LOG_PATH": "/game-redirect"}}}
normal = MODULE["apply_config"](inherited, config, "42")
debug = MODULE["apply_game_debug_logs"](normal, config, inherited["BL_DEBUG_DIR"])
self.assertEqual(debug["PROTON_LOG"], "1")
for key in ("PROTON_LOG_DIR", "PROTON_CRASH_REPORT_DIR", "DXVK_LOG_PATH"):
self.assertEqual(debug[key], debug_dir)
self.assertEqual(debug["DXVK_LOG_LEVEL"], "debug")
self.assertEqual(debug["VKD3D_DEBUG"], "info")
self.assertIn("+relay", debug["WINEDEBUG"].split(","))
self.assertTrue(debug["WINEDEBUG"].endswith("+loaddll,+mscoree"))
for key in ("CUSTOM", "DXVK_CONFIG", "BL_DEBUG_DIR"):
self.assertEqual(debug[key], normal[key])
self.assertEqual(normal["PROTON_LOG"], "0")
self.assertEqual(inherited["PROTON_LOG_DIR"], "/old")
self.assertIs(MODULE["apply_game_debug_logs"](normal, {**config, "gameDebugLogs": False}, debug_dir), normal)
self.assertEqual(MODULE["apply_game_debug_logs"](debug, config, debug_dir), debug)
def test_wine_debug_channels_are_formatted_deduplicated_and_diagnostics_win(self):
formatted = MODULE["game_debug_channels"](
" +relay, trace-vulkan, -all, -seh, +relay, trace+vulkan, garbage, $(touch never) ",
"+seh,warn-foo,warn+foo,+relay",
)
self.assertEqual(formatted, "-all,trace+vulkan,warn+foo,+relay," +
"+timestamp,+pid,+tid,+seh,+unwind,+threadname,+debugstr,+loaddll,+mscoree")
self.assertEqual(MODULE["game_debug_channels"](formatted, "1"), formatted)
self.assertNotIn("-seh", formatted)
for value in ("x\0,+relay", "+" + "x" * 8192, 1, None):
self.assertEqual(MODULE["game_debug_channels"](value), MODULE["game_debug_channels"]())
oversized = ",".join("+channel_" + str(i) for i in range(550))
other = ",".join("+other_" + str(i) for i in range(550))
self.assertLessEqual(len(MODULE["game_debug_channels"](oversized, other)), 8192)
self.assertTrue(MODULE["game_debug_channels"](oversized, other).endswith("+loaddll,+mscoree"))
def test_game_debug_logs_require_opt_in_and_a_real_session_log_directory(self):
env = {"PROTON_LOG": "user", "CUSTOM": "keep"}
for config in ({}, {"version": 1}, {"version": 1, "gameDebugLogs": False},
{"version": 1, "gameDebugLogs": "true"}, {"version": 2, "gameDebugLogs": True}):
self.assertIs(MODULE["apply_game_debug_logs"](env, config, "/"), env)
with tempfile.TemporaryDirectory() as tmp:
not_a_directory = Path(tmp) / "file"
not_a_directory.write_text("file")
for path in (None, "", "relative", "bad\0path", str(not_a_directory), str(Path(tmp) / "missing")):
with self.subTest(path=path):
self.assertIs(MODULE["apply_game_debug_logs"](env, {"version": 1, "gameDebugLogs": True}, path), env)
def test_game_debug_toggle_is_live_preserves_command_and_excludes_probes(self):
with tempfile.TemporaryDirectory() as tmp:
home = Path(tmp)
config_path = home / ".config/droiddeck/game-environment.json"
config_path.parent.mkdir(parents=True)
debug_dir = home / "session logs '$literal; directory'"
debug_dir.mkdir()
probe = home / "fake proton"
probe.write_text("#!" + sys.executable + "\nimport json, os, sys\n"
"print(json.dumps({'env': dict(os.environ), 'argv': sys.argv[1:]}))\n")
probe.chmod(0o755)
literal = "$(touch " + str(home / "never-created") + "); 'literal'=value"
config = {"version": 1, "gameDebugLogs": True,
"shared": {"PROTON_LOG": "0", "WINEDEBUG": "-all,+relay", "CUSTOM": literal,
"BL_DEBUG_DIR": "/profile-must-not-redirect"}}
env = {**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42"),
"BL_DEBUG_DIR": str(debug_dir), "PROTON_LOG": "0", "WINEDEBUG": "-all"}
command = [str(probe), "waitforexitandrun", "game 'with quotes'.exe", "argument with spaces", "$(literal)", "%command%"]
def launch(arguments, environment):
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), *arguments],
env=environment, text=True, capture_output=True, check=True)
return json.loads(result.stdout)
for enabled in (True, False, True):
config_path.write_text(json.dumps({**config, "gameDebugLogs": enabled}))
result = launch(command, env)
self.assertEqual(result["argv"], command[1:])
self.assertEqual(result["env"]["CUSTOM"], literal)
self.assertEqual(result["env"]["PROTON_LOG"], "1" if enabled else "0")
if enabled:
self.assertEqual(result["env"]["PROTON_LOG_DIR"], str(debug_dir))
self.assertIn("+relay", result["env"]["WINEDEBUG"].split(","))
self.assertIn("+seh", result["env"]["WINEDEBUG"].split(","))
else:
self.assertEqual(result["env"]["WINEDEBUG"], "-all,+relay")
for verb, prefix in (("run", "42"), ("waitforexitandrun", "0"), ("waitforexitandrun", "not-a-game")):
result = launch([str(probe), verb], {**env, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata" / prefix)})
self.assertEqual(result["env"]["PROTON_LOG"], "0")
self.assertEqual(result["env"]["WINEDEBUG"], "-all")
# Non-Steam shortcuts use the same normalized unsigned compatdata identity.
result = launch(command, {**env, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/-1")})
self.assertEqual(result["env"]["PROTON_LOG"], "1")
self.assertFalse((home / "never-created").exists())
self.assertEqual(json.loads(config_path.read_text())["shared"], config["shared"])
class ReadConfigMappingTest(unittest.TestCase):
def test_missing_parent_or_unbalanced_vdf_is_not_treated_as_absent_choices(self):
with tempfile.TemporaryDirectory() as tmp:
@@ -464,12 +579,78 @@ class GameEnvironmentTest(unittest.TestCase):
({"BL_GAME_CPUS": "9"}, {9}, None, None),
]
for env, affinity, expected, proton in cases:
env["DROIDDECK_FASTEST_CORES"] = "0"
with mock.patch.dict(MODULE["cpu_topology"].__globals__, online), \
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
MODULE["cpu_topology"](env)
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
self.assertEqual(env.get("PROTON_CPU_TOPOLOGY"), proton, env)
def test_windows_cpu_0_is_the_fastest_core(self):
os_mod = MODULE["os"]
pocket_fit = {0: 379, 1: 379, 2: 923, 3: 923, 4: 923, 5: 867, 6: 867, 7: 1024}
every = set(range(8))
with tempfile.TemporaryDirectory() as tmp:
proton = Path(tmp) / "proton"
proton.write_text('default_cpu_limit = {\n "19900" : "16", # Far Cry 2\n'
' "2229830" : "1", # Command & Conquer\n "11440" : "4", # DiRT\n'
' "1038250" : "P", # DIRT 5\n "618970" : 4, # Outcast, written as Proton 10 does\n'
'}\n\nother = {\n "620" : "2",\n}\n')
command = [str(proton), "waitforexitandrun", "/game/game.exe"]
cases = [
({}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
({"BL_GAME_CPUS": "6,7"}, {6, 7}, pocket_fit, "2:7,6", "2:7,6"),
({"DROIDDECK_GAME_CORES": "0-2"}, {0, 1, 2}, pocket_fit, "3:2,0,1", "3:2,0,1"),
({"BL_GAME_CPUS": "0-7"}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
({"WINE_CPU_TOPOLOGY": "2:0,1"}, every, pocket_fit, "2:0,1", "2:0,1"),
({"WINE_CPU_TOPOLOGY": ""}, every, pocket_fit, "", None),
({"PROTON_CPU_TOPOLOGY": "1:0"}, every, pocket_fit, None, "1:0"),
({"DROIDDECK_FASTEST_CORES": "0"}, every, pocket_fit, None, None),
({"SteamGameId": "2229830"}, every, pocket_fit, "1:7", "1:7"),
({"SteamGameId": "11440"}, every, pocket_fit, "4:7,2,3,4", "4:7,2,3,4"),
({"SteamGameId": "19900"}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
({"SteamGameId": "1038250"}, every, pocket_fit, None, None),
({"SteamGameId": "618970"}, every, pocket_fit, "4:7,2,3,4", "4:7,2,3,4"),
({"SteamGameId": "620"}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
({"SteamGameId": "2229830", "BL_GAME_CPUS": "0,1"}, {0, 1}, pocket_fit, "2:0,1", "2:0,1"),
({"SteamGameId": "2229830", "DROIDDECK_GAME_CORES": "12-13"}, every, pocket_fit, "1:7", "1:7"),
({"SteamGameId": "11440", "BL_GAME_CPUS": "0-7"}, every, pocket_fit, "4:7,2,3,4", "4:7,2,3,4"),
({}, every, {core: 100 for core in every}, None, None),
({}, every, None, None, None),
({"SteamGameId": "11440"}, every, None, "4:0,1,2,3", "4:0,1,2,3"),
({"BL_GAME_CPUS": "9"}, {9}, pocket_fit, None, None),
]
cases += [
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0"}, every, pocket_fit, None, None),
({"STEAM_COMPAT_DATA_PATH": ""}, every, pocket_fit, None, None),
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0", "BL_GAME_CPUS": "6,7"}, {6, 7}, pocket_fit, "2:6,7", "2:6,7"),
]
for env, affinity, speeds, expected, proton_topology in cases:
env.setdefault("STEAM_COMPAT_DATA_PATH", "/steam/compatdata/3608888694")
with mock.patch.dict(MODULE["cpu_topology"].__globals__, {"online_cores": lambda: every}), \
mock.patch.dict(MODULE["fastest_first"].__globals__, {"core_speeds": lambda cores, speeds=speeds: speeds}), \
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
MODULE["cpu_topology"](env, command)
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
self.assertEqual(env.get("PROTON_CPU_TOPOLOGY"), proton_topology, env)
self.assertIsNone(MODULE["proton_cpu_limit"](["/missing/proton"], {"SteamGameId": "11440"}))
self.assertIsNone(MODULE["proton_cpu_limit"](command, {}))
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "1038250"}), "P")
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "618970"}), 4)
def test_core_speeds_read_capacity_then_top_clock(self):
with tempfile.TemporaryDirectory() as tmp:
for core, capacity, clock in ((0, "379", "2265600"), (1, None, "3302400")):
folder = Path(tmp) / ("cpu%d" % core) / "cpufreq"
folder.mkdir(parents=True)
(folder / "cpuinfo_max_freq").write_text(clock + "\n")
if capacity:
(folder.parent / "cpu_capacity").write_text(capacity + "\n")
speeds = MODULE["core_speeds"]
self.assertEqual(speeds([0], tmp), {0: 379})
self.assertEqual(speeds([0, 1], tmp), {0: 2265600, 1: 3302400})
self.assertIsNone(speeds([0, 2], tmp))
def test_reskate_runs_at_feature_level_12_1(self):
with tempfile.TemporaryDirectory() as tmp:
reskate = Path(tmp) / "ReSkate"
@@ -790,6 +971,36 @@ class GameEnvironmentTest(unittest.TestCase):
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
self.assertIn('bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', script)
def test_both_proton_wrappers_answer_steams_driver_query_without_wine(self):
scripts = (COMPAT["launcher_sh"](), COMPAT["extra_wrapper_sh"]("proton"))
query = "/root/.local/share/Steam/steamrtarm64/../bin/d3ddriverquery64.exe"
probe = "/root/.local/share/Steam/steamapps/compatdata/0"
for script in scripts:
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
self.assertLess(script.index('case "$verb:${1##*/}:'), script.index("bl_components "))
for args, prefix in (([query, "-d3d12"], probe), ([query], probe + "/"),
([query.replace("64.exe", ".exe")], probe)):
result = subprocess.run(["bash", "-s", "run"] + args, input=script, text=True, capture_output=True,
env={"PATH": os.defpath, "HOME": "/nonexistent", "STEAM_COMPAT_DATA_PATH": prefix},
timeout=10)
self.assertEqual(result.returncode, 1, result.stderr)
self.assertEqual(result.stdout, "")
self.assertIn("D3D driver query is not run", result.stderr)
skip = COMPAT["BL_DRIVER_QUERY_SKIP"]
for verb, args, prefix in (
("getcompatpath", [query], probe),
("run", [query], "/root/.local/share/Steam/steamapps/compatdata/2276548447"),
("run", [query], None),
("waitforexitandrun", ["/games/AIO/AIO-Graphics-Test-64bit.exe", "--cube", "dx11"], probe),
("run", ["/games/Tool/tool.exe", query], probe),
("run", ["/games/d3ddriverquery64.exe.bak"], probe)):
env = {"PATH": os.defpath}
if prefix is not None:
env["STEAM_COMPAT_DATA_PATH"] = prefix
out = subprocess.run(["bash", "-c", "verb=" + verb + "\n" + skip + "echo continued", "_"] + args,
env=env, capture_output=True, text=True, check=True).stdout
self.assertEqual(out, "continued\n", (verb, args, prefix))
def test_wrappers_preload_the_session_library_before_the_input_shim(self):
overlay = "/root/.local/share/Steam/ubuntu12_64/gameoverlayrenderer.so"
with tempfile.TemporaryDirectory() as tmp:
+223
View File
@@ -0,0 +1,223 @@
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
import unittest
from test_output_refresh import SOURCE, extract_function
PREAMBLE = r'''
#include <assert.h>
#include <stdatomic.h>
#include <stdint.h>
#include <stdio.h>
struct wl_event_source { int armed; };
static struct wl_event_source idle_source, timer_source;
static void (*idle_func)(void *);
static int idles_added, timers_armed, renders, window_requests, effects_changes, pose_changes;
static int64_t clock_ns;
static int g_display_storage;
static void *g_display = &g_display_storage;
static struct wl_event_source *g_render_idle, *g_fallback_timer;
static int g_fallback_armed, g_dirty, g_hud_fresh, framegen;
static void *g_hud_surface;
static int64_t g_dirty_since_ns, g_last_vsync_ns, g_tick_vsync_ns, g_hud_last_ns, g_rendered_tick_ns;
static int g_tick_held;
static int64_t g_hold_missed_ns;
#define HOLD_RETRY_NS 1000000000LL
static int64_t g_refresh_ns = 16666667;
volatile int g_render_on_commit = 1;
volatile int g_release_unpaced = 1;
static atomic_int g_stream_on;
static struct { unsigned ticks, ticks_late_2ms, commit_renders; int64_t tick_late_ns, tick_late_max_ns; } g_pace;
static struct { unsigned ticks; } g_perf;
static int64_t now_ns(void) { return clock_ns; }
static void *wl_display_get_event_loop(void *display) { return display; }
static struct wl_event_source *wl_event_loop_add_idle(void *loop, void (*func)(void *), void *data) {
idles_added++; idle_func = func; return &idle_source;
}
static struct wl_event_source *wl_event_loop_add_timer(void *loop, int (*func)(void *), void *data) { return &timer_source; }
static int wl_event_source_timer_update(struct wl_event_source *source, int ms) { timers_armed++; return 0; }
static int vkp_framegen_active(void) { return framegen; }
static int vkp_apply_window_request(void) { return window_requests; }
static int vkp_effects_sync(void) { return effects_changes; }
static int vkp_cardboard_pose_changed(void) { return pose_changes; }
static void render_scene(void) { renders++; g_dirty = 0; g_dirty_since_ns = 0; g_rendered_tick_ns = g_tick_vsync_ns; g_tick_held = 0; }
static int on_fallback_timer(void *data) { return 0; }
static void on_commit_idle(void *data);
'''
CHECKS = r'''
static void run_idle(void) {
void (*func)(void *) = idle_func;
idle_func = NULL;
if (func) func(NULL);
}
static void tick(int64_t t) { clock_ns = t; on_vsync(t); }
static void arrive(int64_t after_ns) { clock_ns += after_ns; schedule_render(); }
int main(void) {
const int64_t refresh = 6944444, ms = 1000000;
int64_t t = 1000000000LL;
int r0;
unsigned c0;
g_refresh_ns = refresh;
tick(t);
assert(renders == 0);
/* a new frame is drawn when it arrives */
arrive(2 * ms);
assert(idles_added == 1 && renders == 0);
run_idle();
assert(renders == 1 && g_pace.commit_renders == 1 && g_render_idle == NULL);
/* a second frame in the same refresh is left for the next arrival, which is drawn when it arrives */
arrive(1 * ms);
assert(idles_added == 1);
tick(t += refresh);
assert(renders == 1 && g_tick_held == 1);
arrive(2 * ms);
assert(idles_added == 2);
run_idle();
assert(renders == 2 && g_pace.commit_renders == 2 && g_tick_held == 0);
/* a frame no other frame follows is drawn at the tick after next */
arrive(1 * ms);
tick(t += refresh);
assert(renders == 2);
tick(t += refresh);
assert(renders == 3 && g_pace.commit_renders == 2);
/* after that, the tick draws every frame for a second, then holds one again */
arrive(1 * ms);
tick(t += refresh);
assert(renders == 4 && g_tick_held == 0);
t += HOLD_RETRY_NS;
tick(t);
arrive(1 * ms);
run_idle();
arrive(1 * ms);
tick(t += refresh);
assert(renders == 5 && g_tick_held == 1);
arrive(2 * ms);
run_idle();
assert(renders == 6 && g_pace.commit_renders == 4);
/* one frame per refresh, starting right after a tick draw, settles on drawing every frame when it arrives */
window_requests = 1;
tick(t += refresh);
window_requests = 0;
arrive(2 * ms);
r0 = renders; c0 = g_pace.commit_renders;
for (int i = 0; i < 10; i++) {
tick(t += refresh);
arrive(2 * ms);
run_idle();
}
assert(renders - r0 == 10 && g_pace.commit_renders - c0 == 10);
/* a client that draws again only after its frame callback (sent when the scene is drawn) keeps one frame
per refresh: two held frames in 200 refreshes, about 1.4 s */
r0 = renders; c0 = g_pace.commit_renders;
{
int seen = renders - 1;
for (int i = 0; i < 200; i++) {
if (renders != seen) { seen = renders; arrive(1 * ms); run_idle(); }
tick(t += refresh);
}
}
assert(renders - r0 == 198 && g_pace.commit_renders == c0);
/* a window, effect or headset change at the tick draws the waiting frame now */
t += HOLD_RETRY_NS;
tick(t);
arrive(1 * ms);
run_idle();
r0 = renders;
arrive(1 * ms);
window_requests = 1;
tick(t += refresh);
window_requests = 0;
assert(renders - r0 == 1 && g_tick_held == 0);
/* a draw queued before the tick still draws the frame once */
tick(t += refresh);
r0 = renders; c0 = g_pace.commit_renders;
arrive(1 * ms);
tick(t += refresh);
assert(renders == r0);
run_idle();
assert(renders - r0 == 1 && g_pace.commit_renders - c0 == 1);
tick(t += refresh);
assert(renders - r0 == 1);
/* streaming switched on after the draw was queued leaves the frame for the tick */
tick(t += refresh);
r0 = renders; c0 = g_pace.commit_renders;
arrive(1 * ms);
atomic_store(&g_stream_on, 1);
run_idle();
assert(renders == r0);
tick(t += refresh);
atomic_store(&g_stream_on, 0);
assert(renders - r0 == 1 && g_pace.commit_renders == c0);
/* paced output, frame generation, the switch off and streaming keep drawing on the tick */
const int idles = idles_added;
r0 = renders;
for (int c = 0; c < 4; c++) {
tick(t += refresh);
if (c == 0) g_release_unpaced = 0;
if (c == 1) framegen = 1;
if (c == 2) g_render_on_commit = 0;
if (c == 3) atomic_store(&g_stream_on, 1);
arrive(1 * ms);
assert(idles_added == idles);
tick(t += refresh);
g_release_unpaced = 1; framegen = 0; g_render_on_commit = 1; atomic_store(&g_stream_on, 0);
assert(renders - r0 == c + 1);
}
/* without screen ticks the fallback timer still draws */
clock_ns += 200000000LL;
schedule_render();
assert(idles_added == idles && g_fallback_armed == 1 && timers_armed == 1);
puts("PASS");
return 0;
}
'''
@unittest.skipUnless(sys.platform.startswith('linux'), 'needs a Linux host compiler')
class RenderOnCommitTest(unittest.TestCase):
def test_a_new_frame_is_drawn_on_arrival_at_most_once_per_refresh(self):
compiler = shutil.which(os.environ.get('CC', 'cc'))
if compiler is None:
self.skipTest('A host C compiler is required')
source = SOURCE.read_text()
render = extract_function(source, 'render_scene')
self.assertIn('g_rendered_tick_ns = g_tick_vsync_ns;', render)
self.assertIn('g_tick_held = 0;', render)
functions = ('commit_renders_on', 'render_on_commit', 'schedule_render', 'scene_waits_for_game', 'on_commit_idle', 'on_vsync')
harness = PREAMBLE + '\n'.join(extract_function(source, name) for name in functions) + CHECKS
with tempfile.TemporaryDirectory(prefix='droiddeck-render-on-commit-') as folder:
path = Path(folder)
(path / 'commit.c').write_text(harness)
binary = path / 'commit-test'
build = subprocess.run([compiler, '-std=c11', '-Wall', '-Wextra', '-Werror',
'-Wno-unused-parameter', '-Wno-unused-function', '-O2',
str(path / 'commit.c'), '-o', str(binary)], capture_output=True, text=True)
self.assertEqual(0, build.returncode, build.stderr)
result = subprocess.run([str(binary)], capture_output=True, text=True, timeout=10)
self.assertEqual(0, result.returncode, result.stderr)
self.assertEqual('PASS', result.stdout.strip())
if __name__ == '__main__':
unittest.main()
+79
View File
@@ -0,0 +1,79 @@
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
SCRIPT = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steam-x64'
class SteamX64CpuTest(unittest.TestCase):
def selection(self, features, *, forced=False, same_build=True, unreadable=False):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
arm = root / 'arm'
x64 = root / 'x64'
for base in (arm, x64):
(base / 'package').mkdir(parents=True)
(arm / 'steamrtarm64').mkdir()
(arm / 'steamrtarm64/steamwebhelper').touch(mode=0o700)
shim = root / 'arm-shim'
shim.touch(mode=0o700)
(x64 / 'package/beta').write_text('publicbeta\n')
for base, arch, version in ((x64, 'steamrt64', '123'), (arm, 'linuxarm64', '123' if same_build else '122')):
(base / f'package/steam_client_publicbeta_{arch}.manifest').write_text(f'"version" "{version}"\n')
cpuinfo = root / 'cpuinfo'
if not unreadable:
cpuinfo.write_text(features)
text = SCRIPT.read_text()
start = text.find('x64_arm_webhelper_cpu_supported() {')
helper = text[start:text.index('x64_exec() {')] if start >= 0 else ''
selection = text.split('x64_exec() {', 1)[1].split(' mkdir -p "$STEAM_X64/logs"', 1)[0]
shell = helper + '\nx64_env() { :; }\nx64_webhelper_gpu() { return 1; }\nselect_helper() {' + selection + '\nprintf "%s|%s\\n" "${BL_X64_ARM_WEBHELPER:-x86}" "${BL_WEBHELPER_ARGS:-}";\n}\nselect_helper\n'
shell = shell.replace('/proc/cpuinfo', str(cpuinfo)).replace('/usr/local/bin/droiddeck-x64-arm-webhelper', str(shim))
env = dict(os.environ, STEAM_X64=str(x64), ARM_STEAM=str(arm), X64_CHANNEL='publicbeta', BL_X64_X86_WEBHELPER='1' if forced else '0')
env.pop('BL_X64_ARM_WEBHELPER', None)
env.pop('BL_WEBHELPER_ARGS', None)
result = subprocess.run(['bash', '-eu', '-c', shell], env=env, capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
return result.stdout.strip(), str(shim)
def test_missing_atomics_keeps_x86_helper(self):
result, _ = self.selection('Features : fp asimd aes crc32\n')
self.assertEqual(result, 'x86|stock')
def test_atomics_keeps_same_build_arm_helper(self):
result, arm = self.selection('Features : fp asimd atomics aes\n')
self.assertEqual(result, arm + '|')
def test_exact_token_required(self):
result, _ = self.selection('Features : fp noatomics atomics_extra\n')
self.assertEqual(result, 'x86|stock')
def test_any_explicit_core_without_atomics_keeps_x86_helper(self):
result, _ = self.selection('processor : 0\nFeatures : fp atomics\nprocessor : 1\nFeatures : fp aes\n')
self.assertEqual(result, 'x86|stock')
def test_empty_features_is_explicitly_unsupported(self):
result, _ = self.selection('Features : \n')
self.assertEqual(result, 'x86|stock')
def test_absent_features_preserves_existing_behavior(self):
result, arm = self.selection('processor : 0\n')
self.assertEqual(result, arm + '|')
def test_unreadable_cpuinfo_preserves_existing_behavior(self):
result, arm = self.selection('', unreadable=True)
self.assertEqual(result, arm + '|')
def test_forced_x86_still_wins(self):
result, _ = self.selection('Features : atomics\n', forced=True)
self.assertEqual(result, 'x86|stock')
def test_supported_cpu_still_requires_same_build(self):
result, _ = self.selection('Features : atomics\n', same_build=False)
self.assertEqual(result, 'x86|stock')
if __name__ == '__main__':
unittest.main()