mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
chore: merge main into feat/lse-emu
This commit is contained in:
commit
e87eebfaec
194 files changed
+12217
-1137
No files matched your search
@@ -482,6 +482,83 @@ class ProtonRunTest(Temp):
|
||||
self.assertEqual(found["droiddeck-proton-arm64"],
|
||||
(str(self.root / "compatibilitytools.d/droiddeck-proton-arm64"), "droiddeck-proton"))
|
||||
|
||||
def test_a_valve_depot_is_registered_through_the_droiddeck_wrapper(self):
|
||||
name = "Proton Experimental (ARM64)"
|
||||
folder = "steamapps/common/%s" % name
|
||||
shutil.rmtree(self.root / "compatibilitytools.d/droiddeck-proton-arm64")
|
||||
self.write("Steam/steamapps/appmanifest_4427310.acf", '"AppState" { "appid" "4427310" }')
|
||||
self.write("Steam/%s/toolmanifest.vdf" % folder, '"manifest"\n{\n "commandline" "/proton %verb%"\n}\n')
|
||||
self.write("Steam/%s/proton" % folder, b"#!/bin/sh\n", 0o755)
|
||||
self.write("Steam/%s/files/bin-arm64/proton" % folder, b"#!/bin/sh\n", 0o755)
|
||||
found = RUN["tools"](str(self.root))
|
||||
wrapper = self.root / "compatibilitytools.d/droiddeck-proton-arm64"
|
||||
self.assertEqual(found["droiddeck-proton-arm64"], (str(wrapper), "droiddeck-proton"))
|
||||
self.assertNotIn(name, found)
|
||||
|
||||
def test_an_incomplete_valve_depot_is_not_registered(self):
|
||||
name = "Proton Experimental (ARM64)"
|
||||
folder = "steamapps/common/%s" % name
|
||||
shutil.rmtree(self.root / "compatibilitytools.d/droiddeck-proton-arm64")
|
||||
self.write("Steam/steamapps/appmanifest_4427310.acf", '"AppState" { "appid" "4427310" }')
|
||||
self.write("Steam/%s/toolmanifest.vdf" % folder, '"manifest"\n{\n "commandline" "/proton %verb%"\n}\n')
|
||||
self.write("Steam/%s/files/bin-arm64/proton" % folder, b"#!/bin/sh\n", 0o755)
|
||||
found = RUN["tools"](str(self.root))
|
||||
self.assertNotIn("droiddeck-proton-arm64", found)
|
||||
self.assertFalse((self.root / "compatibilitytools.d/droiddeck-proton-arm64").exists())
|
||||
|
||||
def test_a_failed_wrapper_build_does_not_hide_existing_tools(self):
|
||||
shutil.rmtree(self.root / "compatibilitytools.d/droiddeck-proton-arm64")
|
||||
self.write("Steam/steamapps/appmanifest_4427310.acf", '"AppState" { "appid" "4427310" }')
|
||||
folder = "steamapps/common/Proton Experimental (ARM64)"
|
||||
self.write("Steam/%s/proton" % folder, b"#!/bin/sh\n", 0o755)
|
||||
self.write("Steam/%s/files/bin-arm64/proton" % folder, b"#!/bin/sh\n", 0o755)
|
||||
build = mock.Mock(side_effect=OSError("read-only"))
|
||||
with mock.patch.dict(RUN["compat"](), {"build_tool": build}):
|
||||
found = RUN["tools"](str(self.root))
|
||||
build.assert_called_once()
|
||||
self.assertIn("droiddeck-proton-11-arm64", found)
|
||||
|
||||
def test_a_runnable_depot_is_chosen_over_a_newer_incomplete_one(self):
|
||||
shutil.rmtree(self.root / "compatibilitytools.d/droiddeck-proton-arm64")
|
||||
self.write("Steam/steamapps/appmanifest_4427310.acf", '"AppState" { "appid" "4427310" }')
|
||||
good = "Steam/steamapps/common/Proton Experimental (ARM64)"
|
||||
self.write("%s/proton" % good, b"#!/bin/sh\n", 0o755)
|
||||
self.write("%s/files/bin-arm64/proton" % good, b"#!/bin/sh\n", 0o755)
|
||||
broken = "Library/steamapps/common/Proton Experimental (ARM64)"
|
||||
self.write("Library/steamapps/libraryfolders.vdf", b"")
|
||||
self.write("%s/version" % broken, b"2\n")
|
||||
self.write("%s/files/bin-arm64/proton" % broken, b"#!/bin/sh\n", 0o755)
|
||||
self.write("Steam/steamapps/libraryfolders.vdf", '"path" "%s"' % (self.tmp / "Library"))
|
||||
compat = RUN["compat"]()
|
||||
source = compat["find_source"]
|
||||
self.assertEqual(source(str(self.root), runnable=True), str(self.tmp / good))
|
||||
|
||||
def test_a_registered_wrapper_without_its_launcher_is_rebuilt(self):
|
||||
wrapper = self.root / "compatibilitytools.d/droiddeck-proton-arm64"
|
||||
self.write("Steam/steamapps/appmanifest_4427310.acf", '"AppState" { "appid" "4427310" }')
|
||||
folder = "Steam/steamapps/common/Proton Experimental (ARM64)"
|
||||
self.write("%s/proton" % folder, b"#!/bin/sh\n", 0o755)
|
||||
self.write("%s/files/bin-arm64/proton" % folder, b"#!/bin/sh\n", 0o755)
|
||||
launcher = wrapper / RUN["compat"]()["LAUNCHER"]
|
||||
if launcher.exists():
|
||||
launcher.unlink()
|
||||
found = RUN["tools"](str(self.root))
|
||||
self.assertTrue(os.access(launcher, os.X_OK))
|
||||
self.assertIn("droiddeck-proton-arm64", found)
|
||||
|
||||
def test_a_registered_wrapper_without_its_manifest_is_rebuilt(self):
|
||||
wrapper = self.root / "compatibilitytools.d/droiddeck-proton-arm64"
|
||||
self.write("Steam/steamapps/appmanifest_4427310.acf", '"AppState" { "appid" "4427310" }')
|
||||
folder = "Steam/steamapps/common/Proton Experimental (ARM64)"
|
||||
self.write("%s/proton" % folder, b"#!/bin/sh\n", 0o755)
|
||||
self.write("%s/files/bin-arm64/proton" % folder, b"#!/bin/sh\n", 0o755)
|
||||
manifest = wrapper / "toolmanifest.vdf"
|
||||
if manifest.exists():
|
||||
manifest.unlink()
|
||||
found = RUN["tools"](str(self.root))
|
||||
self.assertTrue(manifest.is_file())
|
||||
self.assertIn("droiddeck-proton-arm64", found)
|
||||
|
||||
def test_steams_choice_for_the_title_then_its_default(self):
|
||||
available = RUN["tools"](str(self.root))
|
||||
current = RUN["mapping"](str(self.root))
|
||||
|
||||
@@ -457,6 +457,26 @@ class AgentTest(unittest.TestCase):
|
||||
self.assertEqual(1, agent.main(["--steam-shortcut-state", game_id]))
|
||||
self.assertEqual(2, agent.main(["--steam-shortcut-state"]))
|
||||
|
||||
def test_steam_ready_uses_steams_initialized_store(self):
|
||||
with patch.object(agent, "cdp_eval", return_value={"value": True}) as evaluate:
|
||||
self.assertTrue(agent.steam_ready(self.dir))
|
||||
self.assertIn("m_bIsInitialized", evaluate.call_args.args[1])
|
||||
with patch.object(agent, "cdp_eval", return_value={"value": False}):
|
||||
self.assertFalse(agent.steam_ready(self.dir))
|
||||
|
||||
def test_pending_interstitial_is_continued_by_steam(self):
|
||||
with patch.object(agent, "cdp_eval", return_value={"value": True}) as evaluate:
|
||||
self.assertTrue(agent.steam_clear_pending_interstitial(self.dir, "3551182975"))
|
||||
expression = evaluate.call_args.args[1]
|
||||
self.assertIn("ContinueGameAction", expression)
|
||||
self.assertIn("ShowInterstitials", expression)
|
||||
self.assertIn('"3551182975"', expression)
|
||||
self.assertIn("await apps.GetActiveGameActions()", expression)
|
||||
with patch.object(agent, "cdp_eval", return_value={"value": False}):
|
||||
self.assertFalse(agent.steam_clear_pending_interstitial(self.dir, "3551182975"))
|
||||
with self.assertRaises(agent.AgentError):
|
||||
agent.steam_clear_pending_interstitial(self.dir, "0")
|
||||
|
||||
def test_asleep_command_reports_steams_own_sleep_state(self):
|
||||
with patch.dict(os.environ, {"BL_LAUNCH_DIR": str(self.dir.parent)}):
|
||||
for value, code in (("yes", 0), ("no", 5), ("unknown", 1), (None, 1)):
|
||||
|
||||
@@ -328,6 +328,15 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
self.assertEqual("222", out["displays"][1]["physicalId"])
|
||||
self.assertEqual([1080, 1240], out["displays"][1]["size"])
|
||||
|
||||
def test_displays_named_with_their_unique_id(self):
|
||||
text = DUMPSYS_DISPLAY.replace("mPrimaryDisplayDevice=Screen-2",
|
||||
"mPrimaryDisplayDevice=Screen-2(local:222)")
|
||||
self.configure({}, dumpsys_display=text)
|
||||
code, out = self.run_ctl("screenshot", str(self.dir / "shot.png"), "--display", "4")
|
||||
self.assertEqual(0, code)
|
||||
shot = [c for c in self.calls() if c["args"][:2] == ["exec-out", "screencap"]][0]
|
||||
self.assertEqual(["exec-out", "screencap", "-p", "-d", "222"], shot["args"])
|
||||
|
||||
def test_unknown_display_is_an_error(self):
|
||||
self.configure({}, dumpsys_display=DUMPSYS_DISPLAY)
|
||||
code, out = self.run_ctl("screenshot", str(self.dir / "x.png"), "--display", "9")
|
||||
@@ -398,6 +407,28 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
self.assertEqual(4, code)
|
||||
self.assertEqual("NO_FRAMES", out["error"]["code"])
|
||||
|
||||
def test_provider_call_falls_back_to_a_broadcast_without_content(self):
|
||||
calls = []
|
||||
answers = iter([b"", b'{"ok": true, "command": "state"}'])
|
||||
|
||||
def adb(_adb, _serial, *args, timeout=30):
|
||||
calls.append(args)
|
||||
if args[:2] == ("shell", "content"):
|
||||
return ctl.subprocess.CompletedProcess(args, 127, b"", b"/system/bin/sh: content: inaccessible or not found")
|
||||
if args[:2] == ("shell", "am"):
|
||||
return ctl.subprocess.CompletedProcess(args, 0, b"Broadcast completed: result=0", b"")
|
||||
return ctl.subprocess.CompletedProcess(args, 0, next(answers), b"")
|
||||
|
||||
with unittest.mock.patch.object(ctl, "run_adb", adb), unittest.mock.patch.object(ctl.time, "sleep"):
|
||||
answer = ctl.provider_call("adb", "fake-1", "state", arg="a b", request={"x": 1})
|
||||
self.assertEqual({"ok": True, "command": "state"}, answer)
|
||||
broadcast = calls[1]
|
||||
self.assertEqual(("shell", "am", "broadcast", "-a", ctl.PACKAGE + ".AGENT_CALL", "-p", ctl.PACKAGE), broadcast[:7])
|
||||
self.assertIn("'a b'", broadcast)
|
||||
self.assertEqual(ctl.encode_request({"x": 1}), broadcast[broadcast.index("request") + 1])
|
||||
call_id = broadcast[broadcast.index("id") + 1]
|
||||
self.assertIn("agent-calls/%s.json" % call_id, calls[-1][1])
|
||||
|
||||
def test_pacing_turns_timestats_off_when_the_dump_fails(self):
|
||||
calls = []
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[2] / "app/src/main/cpp/fakeinput_steam.cpp"
|
||||
|
||||
# Stands in for an allocator like mimalloc that calls access() while it starts up (Claude Code
|
||||
# probes /sys/devices/system/node/node1 on its first allocation, which comes from fakeinput's
|
||||
# constructor when it is preloaded).
|
||||
PROGRAM = r"""
|
||||
#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern void *__libc_malloc(size_t);
|
||||
static int started;
|
||||
|
||||
void *malloc(size_t size) {
|
||||
if (!started) {
|
||||
started = 1;
|
||||
access("/sys/devices/system/node/node1", R_OK);
|
||||
}
|
||||
return __libc_malloc(size);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
puts("ok");
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == "linux" and shutil.which("gcc") and shutil.which("g++"),
|
||||
"needs Linux, gcc and g++")
|
||||
class FakeinputReentryTest(unittest.TestCase):
|
||||
def test_allocator_calling_hooks_during_first_allocation_survives_preload(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp)
|
||||
(path / "program.c").write_text(PROGRAM)
|
||||
subprocess.run(["gcc", "-rdynamic", "-o", str(path / "program"), str(path / "program.c")], check=True)
|
||||
subprocess.run(["g++", "-shared", "-fPIC", "-O2", "-Wno-attributes", "-pthread",
|
||||
"-std=c++17", "-static-libstdc++", "-static-libgcc",
|
||||
"-Wl,--exclude-libs,ALL", "-o", str(path / "libfakeinput.so"),
|
||||
str(SOURCE), "-ldl"], check=True)
|
||||
result = subprocess.run([str(path / "program")],
|
||||
env=dict(os.environ, LD_PRELOAD=str(path / "libfakeinput.so")),
|
||||
capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout, "ok\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -708,6 +708,54 @@ class ReadConfigMappingTest(unittest.TestCase):
|
||||
|
||||
|
||||
class GameEnvironmentTest(unittest.TestCase):
|
||||
def test_component_filter_and_prefix_repair_use_per_game_proton_architecture(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
home = Path(tmp)
|
||||
config = home / ".config/droiddeck/game-environment.json"
|
||||
config.parent.mkdir(parents=True)
|
||||
config.write_text(json.dumps({"version": 1, "shared": {"PROTON_USE_ARM64": "1"},
|
||||
"games": {"42": {"PROTON_USE_ARM64": "0"}}}))
|
||||
seen_components, seen_repair, seen_start = [], [], []
|
||||
globals = MODULE["main"].__globals__
|
||||
stubs = {
|
||||
"game_gpu": lambda env: env,
|
||||
"mark_install_scripts": lambda command, env: [],
|
||||
"install_scripts_done": lambda scripts, env: False,
|
||||
"scripts_digest": lambda scripts: None,
|
||||
"win_components": lambda *args: seen_components.append(args[3]) or "",
|
||||
"repair_foreign_system_dlls": lambda *args: seen_repair.append(args[2]) or [],
|
||||
"gl_vsync": lambda env: False,
|
||||
"game_images": lambda env: None,
|
||||
"skip_red_launcher": lambda command: command,
|
||||
"ubisoft_overlay_off": lambda env: None,
|
||||
"project_zomboid_jvm": lambda command: None,
|
||||
"engine_fixes": lambda *args: ({}, [], []),
|
||||
"dirt_ws2_wanted": lambda *args: None,
|
||||
"apply_game_debug_logs": lambda env, config, debug_dir: env,
|
||||
"offline_without_anticheat": lambda command, env: command,
|
||||
"game_logs": lambda command, env, app_id: env,
|
||||
"directaudio_settings": lambda env: env,
|
||||
"vram_cap": lambda env: env,
|
||||
"render_path_defaults": lambda *args: None,
|
||||
"bridge_feature_level": lambda env: None,
|
||||
"force_ssbs": lambda command, env: env,
|
||||
"game_cores": lambda env: None,
|
||||
"cpu_topology": lambda env, command: None,
|
||||
"ego_core_plan": lambda *args: None,
|
||||
"runpy": mock.Mock(run_path=lambda *args: {"launch": lambda command, env: None}),
|
||||
"load_sync": lambda: {},
|
||||
"select_sync": lambda command, env, sync: (command, env),
|
||||
"start": lambda command, env, *args: seen_start.append(env) or 7,
|
||||
}
|
||||
environment = {"HOME": tmp, "STEAM_COMPAT_DATA_PATH": "/compatdata/42", "PROTON_USE_ARM64": "1"}
|
||||
command = ["/stock/proton", "waitforexitandrun", "/game/game.exe"]
|
||||
with patch.dict(os.environ, environment, clear=True), patch.object(sys, "argv", ["game-env", *command]), \
|
||||
patch.dict(globals, stubs):
|
||||
self.assertEqual(MODULE["main"](), 7)
|
||||
self.assertEqual(["0"], [env["PROTON_USE_ARM64"] for env in seen_components])
|
||||
self.assertEqual(["0"], [env["PROTON_USE_ARM64"] for env in seen_repair])
|
||||
self.assertEqual(["0"], [env["PROTON_USE_ARM64"] for env in seen_start])
|
||||
|
||||
def test_optional_xbox_loader_failure_keeps_stock_launch(self):
|
||||
from unittest.mock import patch
|
||||
for error in (FileNotFoundError('missing'), RuntimeError('module initialization failed')):
|
||||
@@ -1076,6 +1124,23 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
scope = MODULE["game_id"](env)
|
||||
expected = "untouched" if scope is None else scope if scope in {"42", "4294967295", "2147483648"} else "*"
|
||||
self.assertEqual(target.read_text(), expected)
|
||||
for app, expected in (("42", "42"), ("4294967295", "4294967295"), ("43", "*"), ("", "*"), ("x", "*")):
|
||||
with self.subTest(shared=app):
|
||||
env = dict(os.environ, HOME=str(root), STEAM_COMPAT_DATA_PATH="/steam/compatdata/2929927072", SteamAppId=app)
|
||||
target.write_text("untouched")
|
||||
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True, capture_output=True)
|
||||
self.assertEqual(MODULE["game_id"](env), app if app in {"42", "4294967295", "43"} else "2929927072")
|
||||
self.assertEqual(target.read_text(), expected)
|
||||
for game, expected in (
|
||||
(str(42 << 32 | 0x02000000), "42"), (str(4294967295 << 32 | 0x02000000), "4294967295"),
|
||||
(str(42 << 32 | 0x02000001), "*"), (str(42 << 32 | 0x02000000 | 1 << 64), "*"), ("33554432", "*"), ("x", "*"),
|
||||
):
|
||||
with self.subTest(direct=game):
|
||||
env = dict(os.environ, HOME=str(root), STEAM_COMPAT_DATA_PATH="/steam/compatdata/2929927072", SteamAppId="0", SteamGameId=game)
|
||||
target.write_text("untouched")
|
||||
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True, capture_output=True)
|
||||
self.assertEqual(MODULE["game_id"](env), expected if expected != "*" else "2929927072")
|
||||
self.assertEqual(target.read_text(), expected)
|
||||
|
||||
def test_engine_fixes_follow_the_games_files(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
@@ -1580,6 +1645,10 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
self.assertIsNone(MODULE["game_id"]({"STEAM_COMPAT_DATA_PATH": prefix}))
|
||||
self.assertEqual(MODULE["game_id"]({"STEAM_COMPAT_DATA_PATH": "/a/compatdata/42/"}), "42")
|
||||
self.assertEqual(MODULE["game_id"]({"STEAM_COMPAT_DATA_PATH": "/a/compatdata/-1"}), "4294967295")
|
||||
shared = {"STEAM_COMPAT_DATA_PATH": "/a/compatdata/2929927072", "SteamAppId": "2424921676"}
|
||||
self.assertEqual(MODULE["game_id"](shared), "2424921676")
|
||||
self.assertEqual(MODULE["game_id"]({"STEAM_COMPAT_DATA_PATH": "/a/compatdata/2929927072"}), "2929927072")
|
||||
self.assertEqual(MODULE["game_id"]({"STEAM_COMPAT_DATA_PATH": "/a/compatdata/42", "SteamAppId": "7"}), "42")
|
||||
|
||||
def test_launch_reads_updates_preserves_argv_and_does_not_execute_values(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
@@ -2585,6 +2654,167 @@ class UbisoftCompositionTest(unittest.TestCase):
|
||||
self.assertEqual(list(prefix.glob(".ubisoft-*.reg")), [])
|
||||
|
||||
|
||||
|
||||
def pe_image(machine):
|
||||
head = bytearray(64)
|
||||
head[:2] = b"MZ"
|
||||
head[60:64] = (64).to_bytes(4, "little")
|
||||
return bytes(head) + b"PE\0\0" + machine.to_bytes(2, "little") + b"\0" * 32
|
||||
|
||||
|
||||
def arm64ec_pe_image():
|
||||
image = bytearray(0x400)
|
||||
image[:2] = b"MZ"
|
||||
image[60:64] = (64).to_bytes(4, "little")
|
||||
image[64:68] = b"PE\0\0"
|
||||
coff = 68
|
||||
image[coff:coff + 2] = (0x8664).to_bytes(2, "little")
|
||||
image[coff + 2:coff + 4] = (1).to_bytes(2, "little")
|
||||
image[coff + 16:coff + 18] = (240).to_bytes(2, "little")
|
||||
optional = coff + 20
|
||||
image[optional:optional + 2] = (0x20B).to_bytes(2, "little")
|
||||
image[optional + 108:optional + 112] = (16).to_bytes(4, "little")
|
||||
directory = optional + 112 + 10 * 8
|
||||
image[directory:directory + 4] = (0x1000).to_bytes(4, "little")
|
||||
image[directory + 4:directory + 8] = (0xD0).to_bytes(4, "little")
|
||||
section = optional + 240
|
||||
image[section + 8:section + 12] = (0x200).to_bytes(4, "little")
|
||||
image[section + 12:section + 16] = (0x1000).to_bytes(4, "little")
|
||||
image[section + 16:section + 20] = (0x200).to_bytes(4, "little")
|
||||
image[section + 20:section + 24] = (0x200).to_bytes(4, "little")
|
||||
image[0x200:0x204] = (0xD0).to_bytes(4, "little")
|
||||
image[0x2C8:0x2D0] = (0x10000000).to_bytes(8, "little")
|
||||
return bytes(image)
|
||||
|
||||
|
||||
class ForeignSystemDllTest(unittest.TestCase):
|
||||
def prefix(self, tmp, arm=True):
|
||||
proton = Path(tmp) / "Proton"
|
||||
dist = proton / "files/lib/wine"
|
||||
if arm:
|
||||
(dist / "aarch64-unix").mkdir(parents=True)
|
||||
else:
|
||||
(dist / "x86_64-unix").mkdir(parents=True)
|
||||
for libdir, machine in (("aarch64-windows", 0xAA64), ("i386-windows", 0x14C)):
|
||||
(dist / libdir).mkdir(parents=True)
|
||||
for name in ("ucrtbase.dll", "rpcrt4.dll"):
|
||||
(dist / libdir / name).write_bytes(pe_image(machine))
|
||||
windows = Path(tmp) / "compat/pfx/drive_c/windows"
|
||||
for folder in ("system32", "syswow64"):
|
||||
(windows / folder).mkdir(parents=True)
|
||||
return proton / "proton", Path(tmp) / "compat", windows
|
||||
|
||||
def run_repair(self, compat, proton):
|
||||
return MODULE["repair_foreign_system_dlls"](str(compat), str(proton))
|
||||
|
||||
def test_x64_dll_in_arm64_system32_is_replaced_by_the_builtin(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton, compat, windows = self.prefix(tmp)
|
||||
(windows / "system32/UCRTBASE.DLL").write_bytes(pe_image(0x8664))
|
||||
(windows / "system32/rpcrt4.dll").write_bytes(pe_image(0xAA64))
|
||||
fixed = self.run_repair(compat, proton)
|
||||
self.assertEqual(["system32/UCRTBASE.DLL (machine 0x8664)"], fixed)
|
||||
self.assertTrue((windows / "system32/UCRTBASE.DLL").is_symlink())
|
||||
self.assertEqual(0xAA64, MODULE["pe_machine"](windows / "system32/UCRTBASE.DLL"))
|
||||
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32/UCRTBASE.DLL.foreign-arch"))
|
||||
self.assertFalse((windows / "system32/rpcrt4.dll").is_symlink())
|
||||
self.assertEqual([], self.run_repair(compat, proton))
|
||||
|
||||
def test_64_bit_dll_in_syswow64_is_replaced(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton, compat, windows = self.prefix(tmp)
|
||||
(windows / "syswow64/ucrtbase.dll").write_bytes(pe_image(0xAA64))
|
||||
self.assertEqual(["syswow64/ucrtbase.dll (machine 0xaa64)"], self.run_repair(compat, proton))
|
||||
self.assertEqual(0x14C, MODULE["pe_machine"](windows / "syswow64/ucrtbase.dll"))
|
||||
|
||||
def test_matching_ec_symlinked_unknown_and_non_pe_files_are_left_alone(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton, compat, windows = self.prefix(tmp)
|
||||
system32 = windows / "system32"
|
||||
(system32 / "ucrtbase.dll").write_bytes(pe_image(0xA641))
|
||||
(system32 / "userlib.dll").write_bytes(pe_image(0x8664))
|
||||
(system32 / "rpcrt4.dll").write_bytes(b"not a pe file")
|
||||
self.assertEqual([], self.run_repair(compat, proton))
|
||||
self.assertFalse((system32 / "ucrtbase.dll").is_symlink())
|
||||
self.assertEqual(0x8664, MODULE["pe_machine"](system32 / "userlib.dll"))
|
||||
|
||||
def test_final_arm64ec_image_is_not_repaired_as_a_foreign_x64_dll(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton, compat, windows = self.prefix(tmp)
|
||||
dll = windows / "system32/ucrtbase.dll"
|
||||
dll.write_bytes(arm64ec_pe_image())
|
||||
self.assertEqual(0x8664, MODULE["pe_machine"](dll))
|
||||
self.assertTrue(MODULE["PE"]["machine_compatible"](dll, frozenset((0xAA64, 0xA641))))
|
||||
self.assertFalse(MODULE["PE"]["machine_compatible"](dll, frozenset((0x8664,))))
|
||||
self.assertEqual([], self.run_repair(compat, proton))
|
||||
self.assertFalse(dll.is_symlink())
|
||||
|
||||
def test_component_owned_and_native_first_foreign_dlls_are_still_replaced(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton, compat, windows = self.prefix(tmp)
|
||||
(windows / "system32/ucrtbase.dll").write_bytes(pe_image(0x8664))
|
||||
(windows / "system32/rpcrt4.dll").write_bytes(pe_image(0x8664))
|
||||
state = {"files": {"drive_c/windows/system32/ucrtbase.dll": {}}}
|
||||
(compat / ".droiddeck-wincomponents.json").write_text(json.dumps(state))
|
||||
reg = 'WINE REGISTRY Version 2\n\n[Software\\\\Wine\\\\DllOverrides] 1\n"RPCRT4.DLL"="native,builtin"\n'
|
||||
(compat / "pfx/user.reg").write_text(reg)
|
||||
env = {"WINEDLLOVERRIDES": "ucrtbase=n,b"}
|
||||
self.assertEqual(["system32/rpcrt4.dll (machine 0x8664)", "system32/ucrtbase.dll (machine 0x8664)"],
|
||||
sorted(MODULE["repair_foreign_system_dlls"](str(compat), str(proton), env)))
|
||||
self.assertEqual(0xAA64, MODULE["pe_machine"](windows / "system32/ucrtbase.dll"))
|
||||
self.assertEqual(0xAA64, MODULE["pe_machine"](windows / "system32/rpcrt4.dll"))
|
||||
|
||||
def test_newest_foreign_copy_is_the_only_backup_and_failed_final_replace_restores_it(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton, compat, windows = self.prefix(tmp)
|
||||
dll = windows / "system32/ucrtbase.dll"
|
||||
dll.write_bytes(pe_image(0x8664))
|
||||
backup = windows / "system32/ucrtbase.dll.foreign-arch"
|
||||
backup.write_bytes(pe_image(0x1234))
|
||||
self.assertEqual(["system32/ucrtbase.dll (machine 0x8664)"], self.run_repair(compat, proton))
|
||||
self.assertEqual(0x1234, MODULE["pe_machine"](backup))
|
||||
self.assertEqual(0x8664, MODULE["pe_machine"](backup.with_name(backup.name + ".1")))
|
||||
self.assertEqual(0xAA64, MODULE["pe_machine"](dll))
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton, compat, windows = self.prefix(tmp)
|
||||
dll = windows / "system32/ucrtbase.dll"
|
||||
dll.write_bytes(pe_image(0x8664))
|
||||
backup = windows / "system32/ucrtbase.dll.foreign-arch"
|
||||
backup.write_bytes(pe_image(0x1234))
|
||||
real = os.replace
|
||||
def flaky_with_backup(src, dst):
|
||||
if str(src).endswith(".bl-new"):
|
||||
raise OSError("boom")
|
||||
return real(src, dst)
|
||||
with mock.patch("os.replace", side_effect=flaky_with_backup):
|
||||
self.assertEqual([], self.run_repair(compat, proton))
|
||||
self.assertEqual(0x8664, MODULE["pe_machine"](dll))
|
||||
self.assertFalse((windows / "system32/ucrtbase.dll.foreign-arch.1").exists())
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton, compat, windows = self.prefix(tmp)
|
||||
dll = windows / "system32/ucrtbase.dll"
|
||||
dll.write_bytes(pe_image(0x8664))
|
||||
real = os.replace
|
||||
def flaky(src, dst):
|
||||
if str(src).endswith(".bl-new"):
|
||||
raise OSError("boom")
|
||||
return real(src, dst)
|
||||
with mock.patch("os.replace", side_effect=flaky):
|
||||
self.assertEqual([], self.run_repair(compat, proton))
|
||||
self.assertEqual(0x8664, MODULE["pe_machine"](dll))
|
||||
self.assertFalse(dll.is_symlink())
|
||||
self.assertFalse((windows / "system32/ucrtbase.dll.foreign-arch").exists())
|
||||
self.assertFalse((windows / "system32/ucrtbase.dll.bl-new").is_symlink())
|
||||
|
||||
def test_non_arm64_proton_and_missing_prefix_are_untouched(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton, compat, windows = self.prefix(tmp, arm=False)
|
||||
(windows / "system32/ucrtbase.dll").write_bytes(pe_image(0x8664))
|
||||
self.assertEqual([], self.run_repair(compat, proton))
|
||||
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32/ucrtbase.dll"))
|
||||
self.assertEqual([], self.run_repair(Path(tmp) / "missing", proton))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
@@ -8,8 +8,12 @@ import unittest
|
||||
from pathlib import Path
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
KEYS = ("TU_DEBUG", "DROIDDECK_GAME_TU_DEBUG")
|
||||
KEYS = ("TU_DEBUG", "DROIDDECK_GAME_TU_DEBUG", "MESA_LOADER_DRIVER_OVERRIDE", "GALLIUM_DRIVER",
|
||||
"LIBGL_KOPPER_DRI2", "VK_ICD_FILENAMES", "VK_DRIVER_FILES")
|
||||
SESSION = {"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": ""}
|
||||
GPU_SESSION = {"MESA_LOADER_DRIVER_OVERRIDE": "zink", "GALLIUM_DRIVER": "zink",
|
||||
"LIBGL_KOPPER_DRI2": "true", "VK_ICD_FILENAMES": "/runtime/turnip.json",
|
||||
"VK_DRIVER_FILES": "/runtime/turnip.json"}
|
||||
|
||||
|
||||
class GameGpuLaunchersTest(unittest.TestCase):
|
||||
@@ -50,11 +54,16 @@ class GameGpuLaunchersTest(unittest.TestCase):
|
||||
return self.run_env(["bash", str(BIN / "droiddeck-flatpak-run"), "--command=app", "org.example.App"], session)
|
||||
|
||||
def test_the_wrapper_gives_a_program_the_game_setting(self):
|
||||
self.assertEqual({"TU_DEBUG": "unset", "DROIDDECK_GAME_TU_DEBUG": "unset"}, self.wrapper())
|
||||
self.assertEqual({key: "unset" for key in KEYS}, self.wrapper())
|
||||
self.assertEqual("gmem", self.wrapper(session={"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "gmem"})["TU_DEBUG"])
|
||||
|
||||
def test_non_flatpak_programs_keep_the_session_gpu_path(self):
|
||||
values = self.wrapper(session=GPU_SESSION)
|
||||
self.assertEqual(GPU_SESSION, {key: values[key] for key in GPU_SESSION})
|
||||
|
||||
def test_the_wrapper_keeps_the_session_setting_for_chromium(self):
|
||||
self.assertEqual({"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "unset"}, self.wrapper("--chromium"))
|
||||
values = self.wrapper("--chromium")
|
||||
self.assertEqual(("sysmem", "unset"), (values["TU_DEBUG"], values["DROIDDECK_GAME_TU_DEBUG"]))
|
||||
self.assertEqual("unset", self.wrapper("--for", str(self.app / "files"))["TU_DEBUG"])
|
||||
self.chromium()
|
||||
self.assertEqual("sysmem", self.wrapper("--for", str(self.app / "files"))["TU_DEBUG"])
|
||||
@@ -71,12 +80,13 @@ class GameGpuLaunchersTest(unittest.TestCase):
|
||||
timeout=30).returncode)
|
||||
|
||||
def test_a_flatpak_app_gets_the_game_setting(self):
|
||||
self.assertEqual({"TU_DEBUG": "unset", "DROIDDECK_GAME_TU_DEBUG": "unset"}, self.flatpak())
|
||||
self.assertEqual({key: "unset" for key in KEYS}, self.flatpak(session=dict(SESSION, **GPU_SESSION)))
|
||||
self.assertEqual("nolrz", self.flatpak({"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "nolrz"})["TU_DEBUG"])
|
||||
|
||||
def test_a_chromium_flatpak_keeps_the_session_setting(self):
|
||||
self.chromium()
|
||||
self.assertEqual({"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "unset"}, self.flatpak())
|
||||
values = self.flatpak()
|
||||
self.assertEqual(("sysmem", "unset"), (values["TU_DEBUG"], values["DROIDDECK_GAME_TU_DEBUG"]))
|
||||
|
||||
def test_a_flatpak_without_the_game_setting_is_unchanged(self):
|
||||
self.assertEqual("sysmem", self.flatpak({"TU_DEBUG": "sysmem"})["TU_DEBUG"])
|
||||
|
||||
@@ -32,7 +32,7 @@ step() { :; }
|
||||
bl_zram_usage() { _bl_rss=$rss _bl_swap=$client_swap; }
|
||||
bl_zram_send() { echo "send:$1:$3"; rss=$((rss - reclaimed)); _bl_pageout_complete=${pageout_complete:-1}; }
|
||||
''' + functions + '\nbl_memory_read\n' + body
|
||||
result = run_bash(harness)
|
||||
result = run_bash('NOW=0\n' + harness.replace('SECONDS', 'NOW'))
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('', result.stderr)
|
||||
return result.stdout.splitlines()
|
||||
@@ -168,7 +168,7 @@ bl_session_others() { _bl_session=(321 654); }
|
||||
bl_zram_usage() { _bl_rss=$rss _bl_swap=$swap; }
|
||||
bl_zram_send() { echo "send:$1:$3"; rss=$((rss - pushed)); swap=$((swap + pushed)); _bl_pageout_complete=$complete; }
|
||||
''' + functions + '\nbl_memory_read\n' + body
|
||||
result = run_bash(harness)
|
||||
result = run_bash('NOW=0\n' + harness.replace('SECONDS', 'NOW'))
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('', result.stderr)
|
||||
return result.stdout.splitlines()
|
||||
@@ -229,9 +229,34 @@ echo "backoff:$_bl_tier_backoff"
|
||||
self.assertEqual(['send:1:game', 'send:1:game'], self.run_policy('''
|
||||
_bl_tier_backoff=300
|
||||
SECONDS=0; bl_session_pressure
|
||||
swap=0
|
||||
SECONDS=20; bl_session_pressure
|
||||
SECONDS=30; bl_session_pressure
|
||||
'''))
|
||||
|
||||
def test_nearly_out_of_memory_still_backs_off_when_the_game_reads_its_pageout_back(self):
|
||||
self.memory(available=512)
|
||||
self.assertEqual(['send:1:game', 'backoff:60', 'send:1:game'], self.run_policy('''
|
||||
SECONDS=0; bl_session_pressure
|
||||
swap=0
|
||||
SECONDS=30; bl_session_pressure
|
||||
echo "backoff:$_bl_tier_backoff"
|
||||
SECONDS=59; bl_session_pressure
|
||||
SECONDS=60; bl_session_pressure
|
||||
SECONDS=90; bl_session_pressure
|
||||
'''))
|
||||
|
||||
def test_nearly_out_of_memory_retries_a_skipped_pageout_after_30_seconds(self):
|
||||
self.memory(available=512)
|
||||
self.assertEqual(['send:1:game', 'send:1:game'], self.run_policy('''
|
||||
SECONDS=0; bl_session_pressure
|
||||
swap=0
|
||||
SECONDS=30; bl_session_pressure
|
||||
_bl_tier_backoff=300
|
||||
saved=$rss; rss=$((128 * 1024))
|
||||
SECONDS=330; bl_session_pressure
|
||||
rss=$saved
|
||||
SECONDS=359; bl_session_pressure
|
||||
SECONDS=360; bl_session_pressure
|
||||
'''))
|
||||
|
||||
def test_small_swap_headroom_skips_the_pageout(self):
|
||||
|
||||
@@ -118,6 +118,7 @@ PROGRAM = r"""
|
||||
#include <sys/resource.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -317,6 +318,8 @@ static void *ordinary_traffic(void *argument) {
|
||||
probe_end(counts);
|
||||
require(counts[0] == 0, "ordinary setup avoids netlink lock");
|
||||
|
||||
int pipes[2];
|
||||
require(pipe(pipes) == 0, "ordinary pipe setup");
|
||||
probe_begin(0);
|
||||
const int rounds = 32;
|
||||
for (int round = 0; round < rounds; round++) {
|
||||
@@ -338,6 +341,15 @@ static void *ordinary_traffic(void *argument) {
|
||||
message.msg_name = &source;
|
||||
message.msg_namelen = sizeof(source);
|
||||
require(recvmsg(server, &message, 0) == 1 && buffer == 'z', "ordinary recvmsg");
|
||||
require(write(client, "w", 1) == 1, "ordinary write");
|
||||
require(read(server, &buffer, 1) == 1 && buffer == 'w', "ordinary read");
|
||||
char pair[2];
|
||||
struct iovec pieces[2] = {{.iov_base = "v", .iov_len = 1}, {.iov_base = "u", .iov_len = 1}};
|
||||
require(writev(client, pieces, 2) == 2, "ordinary writev");
|
||||
require(recv(server, pair, 2, MSG_WAITALL) == 2 && pair[0] == 'v' && pair[1] == 'u',
|
||||
"ordinary writev data");
|
||||
require(write(pipes[1], "p", 1) == 1 && read(pipes[0], &buffer, 1) == 1 && buffer == 'p',
|
||||
"ordinary pipe");
|
||||
length = sizeof(source);
|
||||
require(getpeername(client, (struct sockaddr *)&source, &length) == 0, "ordinary peer");
|
||||
const int options[] = {SO_TYPE, SO_DOMAIN, SO_PROTOCOL};
|
||||
@@ -368,6 +380,8 @@ static void *ordinary_traffic(void *argument) {
|
||||
require(counts[2] == (unsigned)rounds, "ordinary traffic has only requested getpeername");
|
||||
require(counts[3] == 0, "ordinary traffic avoids restoration fstat");
|
||||
require(counts[4] == (unsigned)rounds * 3, "ordinary socket options use one syscall each");
|
||||
close(pipes[0]);
|
||||
close(pipes[1]);
|
||||
close(client);
|
||||
close(server);
|
||||
if (server != listener) close(listener);
|
||||
@@ -798,6 +812,52 @@ static void connect_test(void) {
|
||||
close(descriptor);
|
||||
}
|
||||
|
||||
static ssize_t link_reply(int descriptor, const char *path, unsigned char *buffer, size_t capacity) {
|
||||
struct {
|
||||
struct nlmsghdr header;
|
||||
struct ifinfomsg info;
|
||||
} query = {
|
||||
.header = {.nlmsg_len = sizeof(query), .nlmsg_type = RTM_GETLINK,
|
||||
.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK, .nlmsg_seq = 42},
|
||||
.info = {.ifi_index = 1}
|
||||
};
|
||||
struct iovec parts[2] = {{.iov_base = &query.header, .iov_len = sizeof(query.header)},
|
||||
{.iov_base = &query.info, .iov_len = sizeof(query.info)}};
|
||||
struct msghdr message = {.msg_iov = parts, .msg_iovlen = 2};
|
||||
ssize_t sent;
|
||||
if (!strcmp(path, "send")) sent = send(descriptor, &query, sizeof(query), 0);
|
||||
else if (!strcmp(path, "sendmsg")) sent = sendmsg(descriptor, &message, 0);
|
||||
else if (!strcmp(path, "write")) sent = write(descriptor, &query, sizeof(query));
|
||||
else sent = writev(descriptor, parts, 2);
|
||||
require(sent == sizeof(query), path);
|
||||
ssize_t received = read(descriptor, buffer, capacity);
|
||||
require(received > 0, "read reply");
|
||||
return received;
|
||||
}
|
||||
|
||||
static void write_test(void) {
|
||||
const char *paths[] = {"send", "sendmsg", "write", "writev"};
|
||||
unsigned char expected[4096];
|
||||
int descriptor = route_socket();
|
||||
ssize_t expected_length = link_reply(descriptor, paths[0], expected, sizeof(expected));
|
||||
struct nlmsghdr *header = (struct nlmsghdr *)expected;
|
||||
require(header->nlmsg_type == RTM_NEWLINK && header->nlmsg_seq == 42
|
||||
&& header->nlmsg_pid == port_of(descriptor), "send reply");
|
||||
require(expected_length > (ssize_t)NLMSG_ALIGN(header->nlmsg_len), "acknowledged reply");
|
||||
struct nlmsghdr *acknowledgement = (struct nlmsghdr *)(expected + NLMSG_ALIGN(header->nlmsg_len));
|
||||
require(acknowledgement->nlmsg_type == NLMSG_ERROR
|
||||
&& ((struct nlmsgerr *)NLMSG_DATA(acknowledgement))->error == 0, "send acknowledgement");
|
||||
for (size_t index = 1; index < sizeof(paths) / sizeof(paths[0]); index++) {
|
||||
unsigned char buffer[4096];
|
||||
ssize_t length = link_reply(descriptor, paths[index], buffer, sizeof(buffer));
|
||||
require(length == expected_length, "reply length");
|
||||
require(!memcmp(buffer, expected, length), "reply bytes");
|
||||
}
|
||||
require(recv(descriptor, expected, sizeof(expected), MSG_DONTWAIT) == -1 && errno == EAGAIN,
|
||||
"no extra replies");
|
||||
close(descriptor);
|
||||
}
|
||||
|
||||
static void receive_test(void) {
|
||||
int descriptor = route_socket();
|
||||
send_link(descriptor, 1, 0);
|
||||
@@ -985,6 +1045,7 @@ int main(int argc, char **argv) {
|
||||
else if (!strcmp(argv[1], "nonblocking")) send_timeout_test(1);
|
||||
else if (!strcmp(argv[1], "connect")) connect_test();
|
||||
else if (!strcmp(argv[1], "receive")) receive_test();
|
||||
else if (!strcmp(argv[1], "write")) write_test();
|
||||
else if (!strcmp(argv[1], "replace")) replacement_test(0);
|
||||
else if (!strcmp(argv[1], "raw_replace")) replacement_test(1);
|
||||
else if (!strcmp(argv[1], "shared")) shared_test(0);
|
||||
@@ -1160,6 +1221,9 @@ class NetlinkPreloadTest(unittest.TestCase):
|
||||
def test_kernel_connect_and_disconnect(self):
|
||||
self.run_program("connect")
|
||||
|
||||
def test_write_and_writev_requests_get_the_same_replies_as_send(self):
|
||||
self.run_program("write")
|
||||
|
||||
def test_receive_sources_and_truncation(self):
|
||||
self.run_program("receive")
|
||||
|
||||
|
||||
@@ -14,17 +14,30 @@ class PrDiscordTest(unittest.TestCase):
|
||||
self.discord.request.return_value = {"id": "1557547293375332465"}
|
||||
self.github = patch.object(module, "github").start()
|
||||
self.addCleanup(patch.stopall)
|
||||
self.github.side_effect = lambda path, method="GET", body=None: self.pull if "/pulls/" in path else self.comment
|
||||
def github_request(path, method="GET", body=None):
|
||||
if "/pulls/" in path:
|
||||
return self.pull
|
||||
if "/commits/" in path:
|
||||
return {"commit": {"message": "Fix reconnect behavior\n\nMore details"}}
|
||||
if path.endswith("/issues/comments/10"):
|
||||
if method == "PATCH":
|
||||
self.comment["body"] = body["body"]
|
||||
return self.comment
|
||||
return self.comment
|
||||
self.github.side_effect = github_request
|
||||
patch.object(module, "report_comment", return_value=self.comment).start()
|
||||
|
||||
def publish(self):
|
||||
module.sync("publish", "Droid-Deck/DroidDeck", "410", self.discord, "a" * 40,
|
||||
def publish(self, sha=None):
|
||||
if sha is not None:
|
||||
self.pull["head"]["sha"] = sha
|
||||
sha = sha or "a" * 40
|
||||
module.sync("publish", "Droid-Deck/DroidDeck", "410", self.discord, sha,
|
||||
"https://github.com/Droid-Deck/DroidDeck-CI/releases/download/pr-410/build.apk",
|
||||
"https://github.com/Droid-Deck/DroidDeck-CI/releases/tag/pr-410")
|
||||
|
||||
def save_state(self):
|
||||
self.comment["body"] += '\n<!-- droiddeck-discord: ' + json.dumps({
|
||||
"webhook_id": self.discord.id, "message_id": "1557547293375332465"}) + ' -->'
|
||||
"webhook_id": self.discord.id, "message_id": "1557547293375332465", "sha": "a" * 40}) + ' -->'
|
||||
|
||||
def test_create_confirmed_message_and_persist_reference(self):
|
||||
self.publish()
|
||||
@@ -36,12 +49,76 @@ class PrDiscordTest(unittest.TestCase):
|
||||
self.assertEqual("1557547293375332465", module.saved_message(saved, self.discord.id))
|
||||
self.assertIn("Build download", saved)
|
||||
|
||||
def test_new_build_updates_existing_message(self):
|
||||
def test_same_build_updates_existing_message_without_duplicate(self):
|
||||
self.save_state()
|
||||
self.publish()
|
||||
self.assertEqual("PATCH", self.discord.request.call_args.args[0])
|
||||
saved = self.github.call_args.args[2]["body"]
|
||||
self.assertEqual(1, len(module.STATE.findall(saved)))
|
||||
self.assertIn('"sha": "' + "a" * 40 + '"', saved)
|
||||
|
||||
def test_new_commit_retires_old_message_and_posts_replacement(self):
|
||||
self.save_state()
|
||||
old_content = module.build_content("Droid-Deck/DroidDeck", "410", self.pull["title"], "a" * 40,
|
||||
"apk", "release")
|
||||
self.discord.request.side_effect = [
|
||||
{"content": old_content}, {"id": "1557547293375332465"}, {"id": "1557547293375332466"}]
|
||||
self.publish("b" * 40)
|
||||
calls = self.discord.request.call_args_list
|
||||
self.assertEqual(["GET", "PATCH", "POST"], [call.args[0] for call in calls])
|
||||
self.assertIn("**Superseded by `bbbbbbb`**", calls[1].args[2]["content"])
|
||||
self.assertIn("~~Download:", calls[1].args[2]["content"])
|
||||
self.assertIn("Latest commit: Fix reconnect behavior", calls[2].args[2]["content"])
|
||||
saved = self.github.call_args.args[2]["body"]
|
||||
self.assertEqual("1557547293375332466", module.saved_message(saved, self.discord.id))
|
||||
self.assertIn('"sha": "' + "b" * 40 + '"', saved)
|
||||
|
||||
def test_publish_supersede_rerun_and_close_lifecycle(self):
|
||||
messages = {}
|
||||
created = []
|
||||
next_id = 1
|
||||
|
||||
def discord_request(method, suffix="", body=None):
|
||||
nonlocal next_id
|
||||
if method == "POST":
|
||||
message_id = str(1557547293375332465 + next_id)
|
||||
next_id += 1
|
||||
messages[message_id] = {"id": message_id, "content": body["content"]}
|
||||
created.append(message_id)
|
||||
return messages[message_id]
|
||||
message_id = suffix.split("/")[-1]
|
||||
if method == "GET":
|
||||
return messages.get(message_id)
|
||||
if method == "PATCH":
|
||||
if message_id not in messages:
|
||||
return None
|
||||
messages[message_id].update(body)
|
||||
return messages[message_id]
|
||||
self.fail(f"Unexpected Discord method: {method}")
|
||||
|
||||
self.discord.request.side_effect = discord_request
|
||||
self.publish("a" * 40)
|
||||
first_id = created[-1]
|
||||
self.publish("b" * 40)
|
||||
second_id = created[-1]
|
||||
self.publish("b" * 40)
|
||||
self.assertEqual(2, len(created))
|
||||
self.assertIn("**Superseded by `bbbbbbb`**", messages[first_id]["content"])
|
||||
self.assertIn("`bbbbbbb`", messages[second_id]["content"])
|
||||
|
||||
self.pull.update(state="closed", merged=True)
|
||||
module.sync("retire", "Droid-Deck/DroidDeck", "410", self.discord)
|
||||
self.assertTrue(messages[second_id]["content"].startswith("**Merged**"))
|
||||
self.assertIn("~~Latest commit:", messages[second_id]["content"])
|
||||
|
||||
def test_legacy_state_uses_embedded_short_sha_to_supersede(self):
|
||||
self.save_state()
|
||||
self.comment["body"] = self.comment["body"].replace(', "sha": "' + "a" * 40 + '"', '')
|
||||
old_content = "**Signed test build** `pr-410` · `aaaaaaa`\nold build"
|
||||
self.discord.request.side_effect = [
|
||||
{"content": old_content}, {"id": "1557547293375332465"}, {"id": "1557547293375332466"}]
|
||||
self.publish("b" * 40)
|
||||
self.assertEqual(["GET", "PATCH", "POST"], [call.args[0] for call in self.discord.request.call_args_list])
|
||||
|
||||
def test_deleted_message_is_recreated(self):
|
||||
self.save_state()
|
||||
@@ -78,6 +155,10 @@ class PrDiscordTest(unittest.TestCase):
|
||||
module.sync("retire", "Droid-Deck/DroidDeck", "410", self.discord)
|
||||
self.discord.request.assert_not_called()
|
||||
|
||||
def test_superseded_content_is_idempotent(self):
|
||||
once = module.retired_content("first\n\nlast", superseded_by="a" * 40)
|
||||
self.assertEqual(once, module.retired_content(once, superseded_by="a" * 40))
|
||||
|
||||
def test_old_build_without_saved_id_is_not_guessed(self):
|
||||
self.pull["state"] = "closed"
|
||||
module.sync("retire", "Droid-Deck/DroidDeck", "410", self.discord)
|
||||
@@ -153,6 +234,29 @@ class PrDiscordTest(unittest.TestCase):
|
||||
self.assertLessEqual(len(content), 1800)
|
||||
self.assertLessEqual(len(module.retired_content(content, True)), 2000)
|
||||
|
||||
def test_commit_subject_is_sanitized_and_uses_only_first_line(self):
|
||||
content = module.build_content("Droid-Deck/DroidDeck", "410", "title", "a" * 40,
|
||||
"apk", "release", commit_message="Fix *input* @everyone\nDetails")
|
||||
self.assertIn(r"Latest commit: Fix \*input\* @everyone", content)
|
||||
self.assertNotIn("Details", content)
|
||||
|
||||
def test_commit_lookup_failure_does_not_block_announcement(self):
|
||||
def unavailable_commit(path, method="GET", body=None):
|
||||
if "/commits/" in path:
|
||||
raise RuntimeError("GitHub request failed")
|
||||
return self.pull if "/pulls/" in path else self.comment
|
||||
self.github.side_effect = unavailable_commit
|
||||
self.publish()
|
||||
self.assertEqual("POST", self.discord.request.call_args.args[0])
|
||||
self.assertNotIn("Latest commit:", self.discord.request.call_args.args[2]["content"])
|
||||
|
||||
def test_empty_commit_response_does_not_block_announcement(self):
|
||||
self.github.side_effect = lambda path, method="GET", body=None: (
|
||||
self.pull if "/pulls/" in path else None if "/commits/" in path else self.comment)
|
||||
self.publish()
|
||||
self.assertEqual("POST", self.discord.request.call_args.args[0])
|
||||
self.assertNotIn("Latest commit:", self.discord.request.call_args.args[2]["content"])
|
||||
|
||||
|
||||
original_report = module.report_comment
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
"#!/bin/sh\n"
|
||||
"printf '%s\n' \"$@\" > \"$AGENT_ARGS\"\n"
|
||||
"n=$(cat \"$AGENT_COUNT\" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > \"$AGENT_COUNT\"\n"
|
||||
"[ \"$1\" = --steam-ready ] && exit \"${READY_STATUS:-0}\"\n"
|
||||
"exit \"$AGENT_STATUS\"\n")
|
||||
agent.chmod(0o755)
|
||||
sleep = self.bin / "sleep"
|
||||
@@ -55,12 +56,13 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
pgrep.chmod(0o755)
|
||||
self.block = LAUNCH_BLOCK.replace("/usr/local/bin/droiddeck-agent", str(agent))
|
||||
|
||||
def run_launch(self, target, focus="769", helper_status=0, running_after=999):
|
||||
def run_launch(self, target, focus="769", helper_status=0, running_after=999, ready_status=0):
|
||||
env = dict(os.environ, HOME=str(self.root), BL_LAUNCH_DIR=str(self.launch_dir),
|
||||
PATH=str(self.bin) + os.pathsep + os.environ["PATH"],
|
||||
AGENT_ARGS=str(self.agent_args), SLEEP_ARGS=str(self.sleep_args),
|
||||
AGENT_COUNT=str(self.agent_count), AGENT_STATUS=str(helper_status),
|
||||
FOCUS=focus, FOCUS_COUNT=str(self.focus_count), RUNNING_AFTER=str(running_after))
|
||||
FOCUS=focus, FOCUS_COUNT=str(self.focus_count), RUNNING_AFTER=str(running_after),
|
||||
READY_STATUS=str(ready_status))
|
||||
script = self.block + "\nprintf 'ARG:%s\n' \"$@\"\nwait\n"
|
||||
url = target if target.startswith("steam://") else "steam://rungameid/" + target
|
||||
result = subprocess.run(["bash", "-c", script, "cold-launch", url],
|
||||
@@ -72,28 +74,40 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
return [l for l in result.stdout.splitlines() if "launching the requested game" in l]
|
||||
|
||||
def test_a_shortcut_that_takes_focus_is_handed_over_once_without_waiting_for_the_overview(self):
|
||||
result = self.run_launch(SHORTCUT, focus="769 769 4242")
|
||||
result = self.run_launch(SHORTCUT, focus="769 4242")
|
||||
self.assertEqual(SHORTCUT, (self.launch_dir / "steam-game").read_text().strip())
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertFalse(self.agent_args.exists(), result.stdout)
|
||||
self.assertEqual(["1"], self.sleep_args.read_text().split())
|
||||
self.assertEqual(["--steam-ready"], self.agent_args.read_text().splitlines())
|
||||
self.assertFalse(self.sleep_args.exists())
|
||||
|
||||
def test_a_shortcut_that_never_takes_focus_is_handed_over_again_after_the_overview_wait(self):
|
||||
result = self.run_launch(SHORTCUT, focus="769", helper_status=0)
|
||||
self.assertEqual(2, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertIn("launching the requested game again", result.stdout)
|
||||
self.assertEqual(["--wait-steam-shortcut-overview", SHORTCUT, "45"], self.agent_args.read_text().splitlines())
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertIn("clearing the pending launch interstitial", result.stdout)
|
||||
self.assertEqual(["--steam-clear-pending-interstitial", "3551182975"], self.agent_args.read_text().splitlines())
|
||||
self.assertEqual(["1"] * 20, self.sleep_args.read_text().split())
|
||||
|
||||
def test_a_timed_out_overview_still_gets_one_more_hand_off(self):
|
||||
result = self.run_launch(SHORTCUT, focus="769", helper_status=1)
|
||||
self.assertEqual(2, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertIn("overview status 1", result.stdout)
|
||||
self.assertIn("launching the requested game again", result.stdout)
|
||||
|
||||
def test_a_steam_that_never_reports_ready_still_gets_the_launch(self):
|
||||
result = self.run_launch("413150", ready_status=1)
|
||||
self.assertEqual("413150", (self.launch_dir / "steam-game").read_text().strip())
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertEqual(["1"] * 30, self.sleep_args.read_text().split())
|
||||
|
||||
def test_a_focus_change_does_not_end_the_readiness_wait(self):
|
||||
result = self.run_launch("413150", focus="769 4242", ready_status=1)
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertEqual(["1"] * 30, self.sleep_args.read_text().split())
|
||||
|
||||
def test_a_game_still_starting_without_a_window_is_not_launched_twice(self):
|
||||
result = self.run_launch(SHORTCUT, running_after=1)
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertFalse(self.agent_args.exists())
|
||||
self.assertIn("--steam-ready", self.agent_args.read_text())
|
||||
self.assertEqual(["-f", "reaper SteamLaunch AppId=3551182975( |$)"],
|
||||
(self.root / "pgrep-args").read_text().splitlines())
|
||||
self.assertIn("already starting", result.stdout)
|
||||
@@ -108,15 +122,15 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
focus = " ".join(["769"] * 23) + " 4242"
|
||||
result = self.run_launch(SHORTCUT, focus=focus, helper_status=0)
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertIn("took focus while waiting", result.stdout)
|
||||
self.assertNotIn("clearing the pending launch interstitial", result.stdout)
|
||||
self.assertNotIn("launching the requested game again", result.stdout)
|
||||
|
||||
def test_native_app_id_keeps_the_short_delay_and_is_handed_over_once(self):
|
||||
result = self.run_launch("413150")
|
||||
self.assertEqual("413150", (self.launch_dir / "steam-game").read_text().strip())
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertEqual("4", self.sleep_args.read_text().strip())
|
||||
self.assertFalse(self.agent_args.exists())
|
||||
self.assertFalse(self.sleep_args.exists())
|
||||
self.assertIn("--steam-ready", self.agent_args.read_text())
|
||||
|
||||
def test_a_restart_for_a_game_uses_the_same_hand_off(self):
|
||||
loop = SOURCE[SOURCE.index(' if [ -s "$HOME/.bl-restart-game" ]; then'):SOURCE.index(' if [ -f "$HOME/.bl-restart-once" ]; then')]
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import select
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from tools.tests import test_droiddeck_fex as fixtures
|
||||
from tools.tests import test_steam_compat_live as live
|
||||
from tools.tests.test_steam_compat_mapping import config_text
|
||||
|
||||
|
||||
COMPAT = live.COMPAT
|
||||
TOOL = COMPAT["TOOL"]
|
||||
|
||||
|
||||
class ToolPlatformsTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.steam = self.root / "Steam"
|
||||
self.state = self.root / "state"
|
||||
self.config = self.steam / "config/config.vdf"
|
||||
self.config.parent.mkdir(parents=True)
|
||||
self.state.mkdir()
|
||||
(self.steam / "appcache").mkdir()
|
||||
(self.steam / "steamapps").mkdir()
|
||||
self.entries = {
|
||||
976730: ("windows", "64", "game"),
|
||||
1826330: ("linux", "", "tool"),
|
||||
1161040: ("linux", "", "tool"),
|
||||
900001: ("windows", "64", "tool"),
|
||||
900002: ("linux", "arm64", "tool"),
|
||||
900003: ("osx", "64", "tool"),
|
||||
900004: ("", "", "tool"),
|
||||
900005: ("linux,windows", "64", "tool"),
|
||||
}
|
||||
self.write_appinfo()
|
||||
self.catalog = [{"name": TOOL, "display": "Proton", "dir": "Proton", "valve": True}]
|
||||
self.config.write_text(config_text('"0" { "name" "%s" }' % TOOL))
|
||||
patcher = mock.patch.dict(COMPAT["register_default"].__globals__, COMPAT_DIR=str(self.state))
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
def write_appinfo(self, magic=0x07564429):
|
||||
(self.steam / "appcache/appinfo.vdf").write_bytes(fixtures.AppInfoTest.appinfo(self.entries, magic))
|
||||
|
||||
def platforms(self):
|
||||
return COMPAT["tool_platforms"](str(self.steam))
|
||||
|
||||
def plan(self, current, auto=None, **kwargs):
|
||||
return COMPAT["plan_mapping"](current, ["976730"], [TOOL], TOOL, auto or {},
|
||||
tools=self.platforms(), **kwargs)
|
||||
|
||||
def test_metadata_selects_tools_across_cache_formats(self):
|
||||
for magic in (0x07564427, 0x07564428, 0x07564429):
|
||||
with self.subTest(magic=magic):
|
||||
self.write_appinfo(magic)
|
||||
self.assertEqual(set(self.platforms()), {"1826330", "1161040", "900001", "900002", "900005"})
|
||||
|
||||
def test_tools_are_not_installed_games(self):
|
||||
for app in self.entries:
|
||||
(self.steam / ("steamapps/appmanifest_%s.acf" % app)).write_text("")
|
||||
self.assertEqual(COMPAT["installed_apps"](str(self.steam)), ["976730"])
|
||||
|
||||
def test_linux_tools_clear_proton_and_windows_tools_get_default_before_install(self):
|
||||
current = {"0": TOOL, "976730": TOOL, "1826330": TOOL, "1161040": "proton_experimental"}
|
||||
changes, auto = self.plan(current, {"1826330": TOOL, "976730": TOOL})
|
||||
self.assertEqual(changes, {"1826330": None, "1161040": None, "900001": TOOL})
|
||||
self.assertNotIn("1826330", auto)
|
||||
self.assertEqual(auto["900001"], TOOL)
|
||||
self.assertEqual(auto["976730"], TOOL)
|
||||
|
||||
def test_removed_ge_proton_is_cleared_with_or_without_saved_ownership(self):
|
||||
for saved in ({}, {"1826330": "GE-Proton11-7"}):
|
||||
with self.subTest(saved=saved):
|
||||
changes, auto = self.plan({"0": TOOL, "1826330": "GE-Proton11-7"}, saved)
|
||||
self.assertIsNone(changes["1826330"])
|
||||
self.assertNotIn("1826330", auto)
|
||||
|
||||
def test_removed_ge_proton_game_selection_survives(self):
|
||||
changes, auto = self.plan({"0": TOOL, "976730": "GE-Proton11-7"})
|
||||
self.assertNotIn("976730", changes)
|
||||
self.assertNotIn("976730", auto)
|
||||
|
||||
def test_saved_native_selections_survive(self):
|
||||
for name in (COMPAT["FEX_TOOL"], "custom-native"):
|
||||
with self.subTest(name=name):
|
||||
changes, auto = self.plan({"0": TOOL, "1826330": name}, {"1826330": name})
|
||||
self.assertNotIn("1826330", changes)
|
||||
self.assertNotIn("1826330", auto)
|
||||
|
||||
def test_main_watches_cache_updates_and_replacements(self):
|
||||
class StopWatching(BaseException):
|
||||
pass
|
||||
|
||||
watchers = []
|
||||
|
||||
def capture(files):
|
||||
watcher = live.LIVE["Watcher"](files)
|
||||
watchers.append(watcher)
|
||||
raise StopWatching()
|
||||
|
||||
namespace = live.LIVE["main"].__globals__
|
||||
with mock.patch.dict(namespace, Watcher=capture), mock.patch.dict(os.environ, BL_CDP_PORT="1"), \
|
||||
mock.patch.object(live.LIVE["sys"], "argv", ["compat", str(self.steam)]):
|
||||
with self.assertRaises(StopWatching):
|
||||
live.LIVE["main"]()
|
||||
watcher = watchers[0]
|
||||
if watcher.fd >= 0:
|
||||
self.addCleanup(os.close, watcher.fd)
|
||||
self.assertFalse(watcher.changed())
|
||||
self.entries[900006] = ("linux", "", "tool")
|
||||
self.write_appinfo()
|
||||
self.assertTrue(watcher.changed())
|
||||
self.assertIn("900006", self.platforms())
|
||||
cache = self.steam / "appcache/appinfo.vdf"
|
||||
replacement = cache.with_suffix(".tmp")
|
||||
replacement.write_bytes(cache.read_bytes())
|
||||
replacement.replace(cache)
|
||||
self.assertTrue(watcher.changed())
|
||||
|
||||
def test_watcher_follows_an_appcache_created_after_startup(self):
|
||||
root = self.root / "late"
|
||||
(root / "state").mkdir(parents=True)
|
||||
watcher = live.LIVE["Watcher"]([str(root / "state/request.json"), str(root / "appcache/appinfo.vdf")])
|
||||
self.assertGreaterEqual(watcher.fd, 0)
|
||||
self.addCleanup(os.close, watcher.fd)
|
||||
self.assertFalse(watcher.changed())
|
||||
(root / "appcache").mkdir()
|
||||
self.assertTrue(watcher.changed())
|
||||
(root / "appcache/appinfo.vdf").write_bytes(b"x")
|
||||
self.assertTrue(watcher.changed())
|
||||
|
||||
def test_watcher_follows_each_missing_directory_level(self):
|
||||
root = self.root / "levels"
|
||||
root.mkdir()
|
||||
target = root / "sd/steamapps/appmanifest_1.acf"
|
||||
watcher = live.LIVE["Watcher"]([str(target)])
|
||||
self.assertGreaterEqual(watcher.fd, 0)
|
||||
self.addCleanup(os.close, watcher.fd)
|
||||
(root / "sd").mkdir()
|
||||
self.assertTrue(select.select([watcher.fd], [], [], 1)[0])
|
||||
self.assertFalse(watcher.changed())
|
||||
(root / "sd/steamapps").mkdir()
|
||||
self.assertTrue(select.select([watcher.fd], [], [], 1)[0])
|
||||
self.assertTrue(watcher.changed())
|
||||
target.write_bytes(b"x")
|
||||
self.assertTrue(watcher.changed())
|
||||
|
||||
def test_linux_tool_requests_cannot_restore_windows_platform(self):
|
||||
changes, auto = self.plan({"0": TOOL, "1826330": TOOL}, overrides={"1826330": TOOL})
|
||||
self.assertIsNone(changes["1826330"])
|
||||
self.assertNotIn("1826330", auto)
|
||||
|
||||
def test_linux_execution_tools_and_custom_selections_survive(self):
|
||||
current = {"0": TOOL, "1826330": COMPAT["FEX_TOOL"], "900002": "custom-native",
|
||||
"900001": "custom-windows", "900005": TOOL}
|
||||
changes, auto = self.plan(current)
|
||||
self.assertEqual(changes, {"976730": TOOL})
|
||||
self.assertNotIn("1826330", auto)
|
||||
|
||||
def test_missing_or_malformed_cache_does_not_invent_platforms(self):
|
||||
cache = self.steam / "appcache/appinfo.vdf"
|
||||
cache.unlink()
|
||||
self.assertEqual(self.platforms(), {})
|
||||
cache.write_bytes(b"invalid")
|
||||
self.assertEqual(self.platforms(), {})
|
||||
|
||||
def test_offline_repair_is_idempotent_and_preserves_game_and_neighbor_fields(self):
|
||||
self.config.write_text(config_text(
|
||||
'"0" { "name" "%s" } "976730" { "name" "custom-game" } '
|
||||
'"1826330" { "name" "%s" }' % (TOOL, TOOL)))
|
||||
for _ in range(2):
|
||||
COMPAT["register_default"](str(self.config), ["976730"], catalog=self.catalog,
|
||||
directory=str(self.state), default=TOOL)
|
||||
self.assertEqual(COMPAT["read_config_mapping"](str(self.config)),
|
||||
{"0": TOOL, "976730": "custom-game", "900001": TOOL})
|
||||
self.assertIn('"outside"', self.config.read_text())
|
||||
state = json.loads((self.state / "state.json").read_text())
|
||||
self.assertNotIn("1826330", state["auto"])
|
||||
|
||||
def reconcile(self, page):
|
||||
helper = live.LIVE["Helper"](str(self.steam), 1)
|
||||
helper.page = page
|
||||
with mock.patch.dict(COMPAT, tool_catalog=lambda root: self.catalog):
|
||||
helper.reconcile()
|
||||
return json.loads((self.state / "state.json").read_text())
|
||||
|
||||
def test_live_repair_covers_uninstalled_dependencies_and_stays_idempotent(self):
|
||||
page = live.FakePage({"0": TOOL, "1826330": TOOL, "976730": "custom-game"}, [TOOL])
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [("900001", TOOL), ("1826330", "")])
|
||||
self.assertNotIn("1826330", state["auto"])
|
||||
page.sets.clear()
|
||||
self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(page.mapping["976730"], "custom-game")
|
||||
|
||||
def test_live_removed_ge_proton_is_cleared_and_stays_cleared(self):
|
||||
page = live.FakePage({"0": TOOL, "1826330": "GE-Proton11-7"}, [TOOL])
|
||||
(self.state / "state.json").write_text(json.dumps({"auto": {"1826330": "GE-Proton11-7"}}))
|
||||
state = self.reconcile(page)
|
||||
self.assertIn(("1826330", ""), page.sets)
|
||||
self.assertNotIn("1826330", state["auto"])
|
||||
page.sets.clear()
|
||||
self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
|
||||
def test_live_refused_tools_are_not_written(self):
|
||||
page = live.FakePage({"0": TOOL, "1826330": TOOL}, [TOOL], refused={"1826330", "900001"})
|
||||
self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
@@ -387,6 +387,193 @@ def set_registry(**arguments):
|
||||
return {'install': {'action': 'setRegistry', 'arguments': arguments}, 'name': 'setRegistry'}
|
||||
|
||||
|
||||
def support_data(**arguments):
|
||||
return {'install': {'action': 'supportData', 'arguments': arguments}, 'name': 'supportData'}
|
||||
|
||||
|
||||
class GogSupportData(unittest.TestCase):
|
||||
def prefix(self, root):
|
||||
user = Path(root) / 'compat/pfx/drive_c/users/steamuser'
|
||||
user.mkdir(parents=True)
|
||||
return user
|
||||
|
||||
def test_support_files_reach_the_prefix_once(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
user = self.prefix(root)
|
||||
support = folder / 'support/9'
|
||||
(support / 'Docs').mkdir(parents=True)
|
||||
(support / 'Docs/Fallout4.ini').write_text('[Archive]\n')
|
||||
(support / 'Plugins.txt').write_text('*LondonWorldSpace.esm\n')
|
||||
(folder / '__AppData/Saves').mkdir(parents=True)
|
||||
(folder / '__AppData/Saves/a.txt').write_text('a')
|
||||
gog_script(folder, '9', [
|
||||
set_registry(root='HKLM', subkey='Software\\Game', valueName='a', valueData='b', valueType='string'),
|
||||
support_data(type='folder', target='{userdocs}/My Games/Fallout4'),
|
||||
support_data(type='file', overwrite=True, source='{supportDir}/docs/Fallout4.ini',
|
||||
target='{userdocs}/My Games/Fallout4/Fallout4.ini'),
|
||||
support_data(type='file', overwrite=True, source='{supportDir}/Plugins.txt',
|
||||
target='{localappdata}/Fallout4/Plugins.txt'),
|
||||
support_data(type='folder', overwrite=True, source='{app}/__AppData', target='{localappdata}/Fallout4'),
|
||||
])
|
||||
with patch.object(store, 'create_prefix') as create:
|
||||
self.assertEqual('copied=3', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
create.assert_not_called()
|
||||
self.assertTrue((user / 'Documents/My Games/Fallout4').is_dir())
|
||||
self.assertEqual('[Archive]\n', (user / 'Documents/My Games/Fallout4/Fallout4.ini').read_text())
|
||||
self.assertEqual('*LondonWorldSpace.esm\n', (user / 'AppData/Local/Fallout4/Plugins.txt').read_text())
|
||||
self.assertEqual('a', (user / 'AppData/Local/Fallout4/Saves/a.txt').read_text())
|
||||
(user / 'AppData/Local/Fallout4/Plugins.txt').write_text('player order')
|
||||
self.assertEqual('ready', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
self.assertEqual('player order', (user / 'AppData/Local/Fallout4/Plugins.txt').read_text())
|
||||
|
||||
def test_a_source_the_build_lacks_does_not_recopy_the_rest_every_launch(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
user = self.prefix(root)
|
||||
(folder / 'support/9').mkdir(parents=True)
|
||||
(folder / 'support/9/Plugins.txt').write_text('x')
|
||||
gog_script(folder, '9', [
|
||||
support_data(type='file', overwrite=True, source='{supportDir}/Plugins.txt', target='{localappdata}/G/Plugins.txt'),
|
||||
support_data(type='folder', overwrite=True, source='{app}/__AppData', target='{localappdata}/G'),
|
||||
])
|
||||
self.assertEqual('copied=1 missing=1', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
(user / 'AppData/Local/G/Plugins.txt').write_text('player order')
|
||||
self.assertEqual('ready', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
self.assertEqual('player order', (user / 'AppData/Local/G/Plugins.txt').read_text())
|
||||
|
||||
def test_a_link_never_carries_a_copy_outside(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
user = self.prefix(root)
|
||||
outside = Path(root) / 'outside'
|
||||
outside.mkdir()
|
||||
(outside / 'secret.ini').write_text('s')
|
||||
(folder / '__AppData').mkdir()
|
||||
(folder / '__AppData/linked').symlink_to(outside)
|
||||
(folder / 'support/9').mkdir(parents=True)
|
||||
(folder / 'support/9/a.ini').write_text('a')
|
||||
gog_script(folder, '9', [
|
||||
support_data(type='folder', overwrite=True, source='{app}/__AppData', target='{localappdata}/G'),
|
||||
support_data(type='file', overwrite=True, source='{supportDir}/a.ini', target='{localappdata}/G/linked/a.ini'),
|
||||
support_data(type='file', overwrite=True, source='{app}/__AppData/linked/secret.ini', target='{userdocs}/secret.ini'),
|
||||
])
|
||||
self.assertEqual('copied=1 skipped=2', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
self.assertTrue((user / 'AppData/Local/G/linked').is_symlink())
|
||||
self.assertEqual(['secret.ini'], sorted(p.name for p in outside.iterdir()))
|
||||
self.assertFalse((user / 'Documents/secret.ini').exists())
|
||||
|
||||
def test_a_linked_source_folder_is_copied_as_a_link(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
user = self.prefix(root)
|
||||
outside = Path(root) / 'outside'
|
||||
outside.mkdir()
|
||||
(outside / 'secret.ini').write_text('s')
|
||||
(folder / 'linked').symlink_to(outside)
|
||||
gog_script(folder, '9', [support_data(type='folder', overwrite=True, source='{app}/linked', target='{userdocs}/G')])
|
||||
store.gog_support_data(folder, root + '/compat', '/proton')
|
||||
self.assertTrue((user / 'Documents/G').is_symlink())
|
||||
self.assertEqual(outside, Path(os.readlink(user / 'Documents/G')))
|
||||
|
||||
def test_a_players_own_links_stay_without_overwrite(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
user = self.prefix(root)
|
||||
(folder / 'support/9/Saves').mkdir(parents=True)
|
||||
(folder / 'support/9/a.ini').write_text('a')
|
||||
(folder / 'support/9/Saves/b.ini').write_text('b')
|
||||
(user / 'Documents/G').mkdir(parents=True)
|
||||
(user / 'Documents/a.ini').symlink_to(user / 'mine.ini')
|
||||
(user / 'Documents/G/b.ini').symlink_to(user / 'gone.ini')
|
||||
gog_script(folder, '9', [
|
||||
support_data(type='file', source='{supportDir}/a.ini', target='{userdocs}/a.ini'),
|
||||
support_data(type='folder', source='{supportDir}/Saves', target='{userdocs}/G'),
|
||||
])
|
||||
self.assertEqual('copied=0', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
self.assertEqual(user / 'mine.ini', Path(os.readlink(user / 'Documents/a.ini')))
|
||||
self.assertEqual(user / 'gone.ini', Path(os.readlink(user / 'Documents/G/b.ini')))
|
||||
|
||||
def test_a_changed_script_applies_again(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
user = self.prefix(root)
|
||||
(folder / 'support/9').mkdir(parents=True)
|
||||
(folder / 'support/9/a.ini').write_text('1')
|
||||
action = support_data(type='file', overwrite=True, source='{supportDir}/a.ini', target='{userdocs}/a.ini')
|
||||
gog_script(folder, '9', [action])
|
||||
self.assertEqual('copied=1', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
(folder / 'support/9/b.ini').write_text('2')
|
||||
gog_script(folder, '9', [action, support_data(type='file', overwrite=True, source='{supportDir}/b.ini',
|
||||
target='{userdocs}/b.ini')])
|
||||
self.assertEqual('copied=2', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
self.assertEqual('2', (user / 'Documents/b.ini').read_text())
|
||||
|
||||
def test_a_players_file_is_kept_unless_the_script_overwrites_it(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
user = self.prefix(root)
|
||||
(folder / 'support/9').mkdir(parents=True)
|
||||
(folder / 'support/9/a.ini').write_text('default')
|
||||
(user / 'Documents').mkdir()
|
||||
(user / 'Documents/a.ini').write_text('mine')
|
||||
gog_script(folder, '9', [support_data(type='file', source='{supportDir}/a.ini', target='{userdocs}/a.ini')])
|
||||
self.assertEqual('copied=0', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
self.assertEqual('mine', (user / 'Documents/a.ini').read_text())
|
||||
|
||||
def test_paths_outside_the_known_folders_are_refused(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
self.prefix(root)
|
||||
(folder / 'support/9').mkdir(parents=True)
|
||||
(folder / 'support/9/a.ini').write_text('x')
|
||||
gog_script(folder, '9', [
|
||||
support_data(type='file', overwrite=True, source='{supportDir}/a.ini', target='{userdocs}/../../../../escape.ini'),
|
||||
support_data(type='file', overwrite=True, source='{supportDir}/a.ini', target='C:/escape.ini'),
|
||||
support_data(type='folder', target='{windir}/x'),
|
||||
])
|
||||
self.assertEqual('copied=0 skipped=3', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
self.assertEqual([], list(Path(root).rglob('escape.ini')))
|
||||
self.assertFalse((Path(root) / 'compat/pfx' / store.GOG_SUPPORT_MARK).exists())
|
||||
|
||||
def test_links_in_a_support_folder_are_copied_as_links(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
user = self.prefix(root)
|
||||
outside = Path(root) / 'outside'
|
||||
outside.mkdir()
|
||||
(outside / 'secret.txt').write_text('s')
|
||||
(folder / '__AppData').mkdir()
|
||||
(folder / '__AppData/linked').symlink_to(outside, target_is_directory=True)
|
||||
gog_script(folder, '9', [support_data(type='folder', overwrite=True, source='{app}/__AppData', target='{localappdata}/G')])
|
||||
self.assertEqual('copied=1', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
self.assertTrue((user / 'AppData/Local/G/linked').is_symlink())
|
||||
self.assertEqual('s', (outside / 'secret.txt').read_text())
|
||||
|
||||
def test_without_support_data_no_prefix_is_made(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
gog_script(folder, '9', [set_registry(root='HKLM', subkey='Software\\Game', valueName='a', valueData='b', valueType='string')])
|
||||
with patch.object(store, 'create_prefix') as create:
|
||||
self.assertEqual('none', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
create.assert_not_called()
|
||||
|
||||
def test_a_missing_prefix_is_made_first(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder = game(root, store_id='gog', ident='9')
|
||||
gog_script(folder, '9', [support_data(type='folder', target='{userdocs}/My Games/G')])
|
||||
with patch.object(store, 'create_prefix', return_value='failed') as create:
|
||||
self.assertEqual('no-prefix', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
create.assert_called_once_with(root + '/compat', '/proton')
|
||||
|
||||
def made(compat_data, proton):
|
||||
self.prefix(root)
|
||||
return 'created'
|
||||
with patch.object(store, 'create_prefix', side_effect=made):
|
||||
self.assertEqual('copied=0', store.gog_support_data(folder, root + '/compat', '/proton'))
|
||||
self.assertTrue((Path(root) / 'compat/pfx/drive_c/users/steamuser/Documents/My Games/G').is_dir())
|
||||
|
||||
|
||||
class GogRegistry(unittest.TestCase):
|
||||
def test_patch_registration_uses_authentic_build_and_the_prefix_registry_executable(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
@@ -605,6 +792,107 @@ class GogRegistry(unittest.TestCase):
|
||||
folder = game(root, store_id='gog')
|
||||
with patch.dict(os.environ, {'BL_LAUNCH_DIR': root, 'STEAM_COMPAT_DATA_PATH': root + '/compat/', 'BL_STORE_PROTON': '/chosen/proton'}), \
|
||||
patch.object(store, 'prepare_gog', return_value=False), patch.object(store, 'ask', return_value=None), \
|
||||
patch.object(store, 'apply_gog_registry', return_value='ready') as apply:
|
||||
patch.object(store, 'apply_gog_registry', return_value='ready') as apply, \
|
||||
patch.object(store, 'gog_support_data', return_value='ready') as support:
|
||||
store.main([str(folder / store.LAUNCHER)])
|
||||
apply.assert_called_once_with(folder, root + '/compat', '/chosen/proton')
|
||||
support.assert_called_once_with(folder, root + '/compat', '/chosen/proton')
|
||||
|
||||
|
||||
class Ubisoft(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.root = Path(self.tmp.name)
|
||||
self.compat_data = self.root / 'compatdata/2929927072'
|
||||
(self.compat_data / 'pfx').mkdir(parents=True)
|
||||
(self.compat_data / 'pfx/system.reg').write_text('WINE REGISTRY Version 2\n')
|
||||
(self.compat_data / 'pfx/user.reg').write_text('WINE REGISTRY Version 2\n')
|
||||
self.folder = self.root / 'Games/Stores/Ubisoft/Splinter Cell'
|
||||
(self.folder / 'system').mkdir(parents=True)
|
||||
self.sidecar = {'store': 'ubisoft', 'id': 'space-1', 'exe': 'system/SplinterCell.exe', 'extra': {'productId': '109'}}
|
||||
service = self.root / 'droiddeck-upc.exe'
|
||||
service.write_bytes(b'MZ')
|
||||
for patcher in (patch.object(store, 'UBISOFT_SERVICE', service), patch.object(store, 'UBISOFT_CACHE', self.root / 'cache'),
|
||||
patch.object(store, 'wait_for_server', return_value=True)):
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def runtime(self):
|
||||
folder = store.ubisoft_runtime_dir(self.compat_data)
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
for name in store.UBISOFT_RUNTIME:
|
||||
(folder / name).write_bytes(b'MZ')
|
||||
|
||||
def answer(self, *_args, **_kwargs):
|
||||
return {'ok': True, 'ticket': 'PC', 'owned': [82, 109], 'appId': 'app',
|
||||
'account': {'userId': 'u1', 'username': 'name', 'nameOnPlatform': 'name', 'email': 'e@x', 'country': 'US'}}
|
||||
|
||||
def prepare(self, ask_app):
|
||||
return store.prepare_ubisoft(self.folder, self.sidecar, str(self.compat_data), str(self.root / 'launch'), '/proton', ask_app=ask_app)
|
||||
|
||||
def test_an_extracted_runtime_is_not_extracted_again(self):
|
||||
self.runtime()
|
||||
with patch.object(store.subprocess, 'run') as run:
|
||||
self.assertEqual('present', store.install_runtime(str(self.compat_data)))
|
||||
run.assert_not_called()
|
||||
|
||||
def test_the_runtime_comes_from_the_installer_through_7z(self):
|
||||
installer = self.root / 'UbisoftConnectInstaller.exe'
|
||||
|
||||
def run(command, **_kwargs):
|
||||
self.assertEqual(['7z', 'e', '-y'], command[:3])
|
||||
self.assertEqual(str(installer), command[4])
|
||||
out = Path(command[3][2:])
|
||||
for name in command[5:]:
|
||||
(out / name).write_bytes(b'MZ')
|
||||
|
||||
(self.root / 'cache').mkdir()
|
||||
with patch.object(store, 'fetch_installer', return_value=installer), patch.object(store.subprocess, 'run', side_effect=run):
|
||||
self.assertEqual('installed', store.install_runtime(str(self.compat_data)))
|
||||
self.assertTrue(store.ubisoft_runtime_ready(str(self.compat_data)))
|
||||
|
||||
def test_a_launch_registers_the_game_and_writes_the_session_for_the_service(self):
|
||||
self.runtime()
|
||||
result = self.prepare(self.answer)
|
||||
self.assertEqual('runtime present, registered 109, 0 manifest value(s), session ready', result)
|
||||
reg = (self.compat_data / 'pfx/system.reg').read_text()
|
||||
for view in ('[Software\\\\Ubisoft\\\\Launcher]', '[Software\\\\Wow6432Node\\\\Ubisoft\\\\Launcher]'):
|
||||
self.assertIn(view, reg)
|
||||
self.assertIn('[Software\\\\Wow6432Node\\\\Ubisoft\\\\Launcher\\\\Installs\\\\109]', reg)
|
||||
self.assertIn('"InstallDir"="C:\\\\Program Files (x86)\\\\Ubisoft\\\\Ubisoft Game Launcher\\\\"', reg)
|
||||
launch = json.loads((self.folder / store.UBISOFT_LAUNCH).read_text())
|
||||
self.assertEqual(109, launch['productId'])
|
||||
self.assertEqual('PC', launch['ticket'])
|
||||
self.assertEqual([82, 109], launch['owned'])
|
||||
self.assertEqual(store.windows_path(str(self.folder / 'system/SplinterCell.exe')), launch['exe'])
|
||||
self.assertEqual('C:/users/steamuser/Saved Games/Ubisoft/u1/109/', launch['saves'])
|
||||
self.assertTrue((self.compat_data / 'pfx/drive_c/users/steamuser/Saved Games/Ubisoft/u1/109').is_dir())
|
||||
|
||||
def test_without_a_session_the_launch_file_is_removed_and_the_game_starts_as_is(self):
|
||||
self.runtime()
|
||||
(self.folder / store.UBISOFT_LAUNCH).write_text('{}')
|
||||
result = self.prepare(lambda *_a, **_k: {'ok': False, 'reason': 'signed-out'})
|
||||
self.assertEqual('runtime present, registered 109, session signed-out', result)
|
||||
self.assertFalse((self.folder / store.UBISOFT_LAUNCH).exists())
|
||||
|
||||
def test_a_game_without_a_product_is_left_alone(self):
|
||||
self.sidecar['extra'] = {}
|
||||
self.assertEqual('no-product', self.prepare(self.answer))
|
||||
|
||||
def test_the_manifest_registry_lands_in_both_views_with_the_install_folder_and_language(self):
|
||||
self.runtime()
|
||||
registry = [{'key': r'HKEY_LOCAL_MACHINE\SOFTWARE\Ubisoft\Launcher\Installs\109\Language',
|
||||
'values': [{'name': 'French', 'value': 'fr-FR'}, {'name': 'English', 'value': 'en-US'}]},
|
||||
{'key': r'HKEY_LOCAL_MACHINE\SOFTWARE\Ubisoft\Splinter Cell\GamePath', 'values': [{'name': '$INSTALL_DIR', 'value': ''}]}]
|
||||
answer = dict(self.answer(), registry=registry, language='en-US')
|
||||
result = self.prepare(lambda *_a, **_k: answer)
|
||||
self.assertEqual('runtime present, registered 109, 4 manifest value(s), session ready', result)
|
||||
reg = (self.compat_data / 'pfx/system.reg').read_text()
|
||||
self.assertIn(r'[SOFTWARE\\Wow6432Node\\Ubisoft\\Launcher\\Installs\\109]', reg)
|
||||
self.assertIn(r'[SOFTWARE\\Ubisoft\\Launcher\\Installs\\109]', reg)
|
||||
self.assertIn('"Language"="en-US"', reg)
|
||||
folder = store.windows_path(str(self.folder)).replace('\\', '\\\\')
|
||||
self.assertIn('"GamePath"="%s\\\\"' % folder, reg)
|
||||
@@ -0,0 +1,129 @@
|
||||
import base64
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin'
|
||||
loader = importlib.machinery.SourceFileLoader('droiddeck_store_launch_ea', str(BIN / 'droiddeck-store-launch'))
|
||||
spec = importlib.util.spec_from_loader(loader.name, loader)
|
||||
store = importlib.util.module_from_spec(spec)
|
||||
loader.exec_module(store)
|
||||
|
||||
|
||||
class EaHook(unittest.TestCase):
|
||||
def test_wmi_output_reads_the_value_under_the_header(self):
|
||||
text = 'Manufacturer \r\r\nThe Wine Project \r\r\n\r\r\n'
|
||||
self.assertEqual(store.wmi_value(text), 'The Wine Project')
|
||||
self.assertEqual(store.wmi_value(store.decode_output('Name\r\nFEX CPU\r\n'.encode('utf-16'))), 'FEX CPU')
|
||||
self.assertEqual(store.wmi_value(''), '')
|
||||
|
||||
def test_registry_points_the_game_keys_at_the_install_folder(self):
|
||||
sidecar = {'id': 'Origin.OFR.50.0001', 'title': 'Mass Effect 3', 'extra': {'registry': json.dumps([
|
||||
[r'HKEY_LOCAL_MACHINE\SOFTWARE\EA Games\Game', 'Install Dir'],
|
||||
[r'HKLM\SOFTWARE\Respawn\Titanfall2', 'Install Dir'],
|
||||
[r'HKEY_CLASSES_ROOT\x', 'y'],
|
||||
])}}
|
||||
entries = store.ea_registry_entries(Path('/root/Games/Stores/EA/Game'), sidecar)
|
||||
self.assertIn((r'HKEY_LOCAL_MACHINE\SOFTWARE\Origin', 'ClientPath', store.EA_CLIENT), entries)
|
||||
game = [e for e in entries if e[1] == 'Install Dir']
|
||||
self.assertEqual([e[0] for e in game], [r'HKEY_LOCAL_MACHINE\SOFTWARE\EA Games\Game', r'HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2'])
|
||||
self.assertEqual(game[0][2], 'Z:' + '\\'.join(['', 'root', 'Games', 'Stores', 'EA', 'Game', '']))
|
||||
self.assertIn((r'HKEY_LOCAL_MACHINE\SOFTWARE\EA Games\Game', 'DisplayName', 'Mass Effect 3'), entries)
|
||||
self.assertIn((r'HKEY_LOCAL_MACHINE\SOFTWARE\Respawn\Titanfall2', 'DisplayName', 'Mass Effect 3'), entries)
|
||||
|
||||
def test_legacy_games_are_registered_by_content_id(self):
|
||||
sidecar = {'id': 'Origin.OFR.50.0005237', 'title': 'Mass Effect 3 (2012)',
|
||||
'extra': {'contentIds': '71073,71183, bad id', 'displayName': 'Mass Effect 3', 'locale': 'fr_FR'}}
|
||||
entries = store.ea_registry_entries(Path('/root/Games/ME3'), sidecar)
|
||||
key = r'HKEY_LOCAL_MACHINE\SOFTWARE\Origin Games' + '\\'
|
||||
self.assertIn((key + '71073', 'DisplayName', 'Mass Effect 3'), entries)
|
||||
self.assertIn((key + '71183', 'Locale', 'fr_FR'), entries)
|
||||
self.assertFalse(any('bad id' in e[0] for e in entries))
|
||||
|
||||
def test_cpuid_probe_is_a_32_bit_console_program(self):
|
||||
import struct
|
||||
exe = store.cpuid_exe()
|
||||
self.assertEqual(exe[:2], b'MZ')
|
||||
self.assertEqual(exe[0x40:0x44], b'PE\0\0')
|
||||
self.assertEqual(struct.unpack_from('<H', exe, 0x44)[0], 0x14C)
|
||||
self.assertEqual(struct.unpack_from('<H', exe, 0x58)[0], 0x10B)
|
||||
self.assertEqual(struct.unpack_from('<H', exe, 0x58 + 68)[0], 3)
|
||||
self.assertIn(b'KERNEL32.dll', exe)
|
||||
self.assertEqual(len(exe), 0x400)
|
||||
|
||||
def test_origin_stub_is_a_windowless_program_installed_once(self):
|
||||
import struct
|
||||
exe = store.origin_stub_exe()
|
||||
self.assertEqual(exe[:2], b'MZ')
|
||||
self.assertEqual(struct.unpack_from('<H', exe, 0x58 + 68)[0], 2)
|
||||
self.assertIn(b'Sleep', exe)
|
||||
self.assertEqual(exe[0x208:0x20A], b'\xeb\xf6')
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
self.assertEqual(store.install_origin_stub(tmp), 'written')
|
||||
self.assertEqual(store.install_origin_stub(tmp), 'ready')
|
||||
self.assertTrue((Path(tmp) / 'pfx/drive_c/Program Files (x86)/Origin/Origin.exe').is_file())
|
||||
self.assertTrue(store.EA_CLIENT.endswith('Origin.exe'))
|
||||
|
||||
def test_cpuid_output_is_decoded_as_the_game_sees_it(self):
|
||||
raw = bytes.fromhex('1600000047656e756e74656c696e654961060a00000805000f23d882fffb8b27436f727465782d4135323000000000000000000000000000000000000000000000000000000000000000000000000000')
|
||||
self.assertEqual(store.cpuid_values(raw), {'cpuVendor': 'GenuineIntel', 'cpuEax': '000A0661', 'cpuEdx': '278BFBFF',
|
||||
'cpuEcx': '82d8230f', 'cpuBrand': 'Cortex-A520'})
|
||||
self.assertEqual(store.cpuid_values(b''), {})
|
||||
|
||||
def test_touchup_arguments_fill_locale_and_folder(self):
|
||||
install = r'Z:\root\My Game'
|
||||
args = store.touchup_args('-locale {locale} -installPath "{installLocation}" /silent', 'fr_FR', install)
|
||||
self.assertEqual(args, ['-locale', 'fr_FR', '-installPath', install, '/silent'])
|
||||
|
||||
def test_licences_stay_inside_the_prefix(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
data = base64.b64encode(b'licence').decode()
|
||||
written = store.write_licenses(tmp, [
|
||||
{'path': 'ProgramData/Electronic Arts/EA Services/License/X.dlf', 'data': data},
|
||||
{'path': '../escape.dlf', 'data': data},
|
||||
{'path': '/abs.dlf', 'data': data},
|
||||
])
|
||||
self.assertEqual(written, 1)
|
||||
self.assertEqual((Path(tmp) / 'pfx/drive_c/ProgramData/Electronic Arts/EA Services/License/X.dlf').read_bytes(), b'licence')
|
||||
|
||||
def test_prepare_asks_the_app_and_writes_the_licence(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
compat = Path(tmp) / 'compat'
|
||||
(compat / 'pfx').mkdir(parents=True)
|
||||
(compat / 'pfx/user.reg').write_text('')
|
||||
probe = {key: 'x' for key in store.EA_PROBE_FIELDS}
|
||||
(compat / 'pfx' / store.EA_HARDWARE).write_text(json.dumps(probe))
|
||||
folder = Path(tmp) / 'game'
|
||||
folder.mkdir()
|
||||
asked = {}
|
||||
|
||||
def fake_ask(channel, request, timeout=5.0):
|
||||
asked.update(request)
|
||||
return {'ok': True, 'lsx': True, 'license': 'ok v4', 'licenses': [{'path': 'ProgramData/L/x.dlf', 'data': base64.b64encode(b'z').decode()}]}
|
||||
|
||||
with patch.object(store, 'ask', fake_ask), patch.object(store, 'ea_registry', lambda *a, **k: 'ready'), \
|
||||
patch.object(store, 'ea_touchup', lambda *a, **k: 'none'), patch.dict('os.environ', {'BL_STORE_PROTON': ''}):
|
||||
store.prepare_ea(folder, {'id': 'Origin.OFR.1'}, str(compat), str(Path(tmp) / 'launch'))
|
||||
self.assertEqual(asked['op'], 'ea-prepare')
|
||||
self.assertEqual(asked['hardware'], probe)
|
||||
self.assertEqual((compat / 'pfx/drive_c/ProgramData/L/x.dlf').read_bytes(), b'z')
|
||||
|
||||
def test_an_incomplete_cached_probe_is_probed_again(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
pfx = Path(tmp) / 'pfx'
|
||||
pfx.mkdir()
|
||||
partial = {key: 'x' for key in store.EA_PROBE_FIELDS if key != 'osInstallDate'}
|
||||
(pfx / store.EA_HARDWARE).write_text(json.dumps(partial))
|
||||
self.assertFalse(store.probe_complete(partial))
|
||||
self.assertEqual(store.ea_hardware(tmp, ''), ({}, 'no-proton'))
|
||||
whole = dict(partial, osInstallDate='20261108')
|
||||
(pfx / store.EA_HARDWARE).write_text(json.dumps(whole))
|
||||
self.assertEqual(store.ea_hardware(tmp, ''), (whole, 'cached'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -35,8 +35,134 @@ class WinComponentsTest(unittest.TestCase):
|
||||
def pick(self, *ids):
|
||||
self.selection.write_text(json.dumps({"version": 1, "games": {"2571976725": list(ids)}}))
|
||||
|
||||
def apply(self):
|
||||
return MODULE["apply"](self.compat, "2571976725", self.selection, self.store)
|
||||
def apply(self, proton=None, env=None):
|
||||
return MODULE["apply"](self.compat, "2571976725", self.selection, self.store, proton=proton, env=env)
|
||||
|
||||
def proton(self, arm=True):
|
||||
root = Path(self.tmp.name) / ("arm-proton" if arm else "x64-proton")
|
||||
(root / "files/lib/wine" / ("aarch64-unix" if arm else "x86_64-unix")).mkdir(parents=True)
|
||||
return root / "proton"
|
||||
|
||||
def pe_image(self, machine):
|
||||
head = bytearray(64)
|
||||
head[:2] = b"MZ"
|
||||
head[60:64] = (64).to_bytes(4, "little")
|
||||
return bytes(head) + b"PE\0\0" + machine.to_bytes(2, "little") + b"\0" * 32
|
||||
|
||||
def arm64ec_pe_image(self):
|
||||
image = bytearray(0x400)
|
||||
image[:2] = b"MZ"
|
||||
image[60:64] = (64).to_bytes(4, "little")
|
||||
image[64:68] = b"PE\0\0"
|
||||
coff = 68
|
||||
image[coff:coff + 2] = (0x8664).to_bytes(2, "little")
|
||||
image[coff + 2:coff + 4] = (1).to_bytes(2, "little")
|
||||
image[coff + 16:coff + 18] = (240).to_bytes(2, "little")
|
||||
optional = coff + 20
|
||||
image[optional:optional + 2] = (0x20B).to_bytes(2, "little")
|
||||
image[optional + 108:optional + 112] = (16).to_bytes(4, "little")
|
||||
directory = optional + 112 + 10 * 8
|
||||
image[directory:directory + 4] = (0x1000).to_bytes(4, "little")
|
||||
image[directory + 4:directory + 8] = (0xD0).to_bytes(4, "little")
|
||||
section = optional + 240
|
||||
image[section + 8:section + 12] = (0x200).to_bytes(4, "little")
|
||||
image[section + 12:section + 16] = (0x1000).to_bytes(4, "little")
|
||||
image[section + 16:section + 20] = (0x200).to_bytes(4, "little")
|
||||
image[section + 20:section + 24] = (0x200).to_bytes(4, "little")
|
||||
image[0x200:0x204] = (0xD0).to_bytes(4, "little")
|
||||
image[0x2C8:0x2D0] = (0x10000000).to_bytes(8, "little")
|
||||
return bytes(image)
|
||||
|
||||
def test_foreign_component_dll_is_skipped_and_override_dropped(self):
|
||||
proton = self.proton()
|
||||
self.component("vc", ["ucrtbase"], {"system32/ucrtbase.dll": self.pe_image(0x8664)})
|
||||
self.pick("vc")
|
||||
names, _ = self.apply(proton)
|
||||
self.assertEqual(names, [])
|
||||
self.assertFalse((self.pfx / "system32/ucrtbase.dll").exists())
|
||||
names, notes = self.apply(proton)
|
||||
self.assertEqual(names, [])
|
||||
self.assertEqual(notes, [])
|
||||
|
||||
def test_component_final_arm64ec_dll_is_placed_and_keeps_its_override(self):
|
||||
proton = self.proton()
|
||||
self.component("vc", ["ucrtbase"], {"system32/ucrtbase.dll": self.arm64ec_pe_image()})
|
||||
self.pick("vc")
|
||||
names, _ = self.apply(proton)
|
||||
self.assertEqual(names, ["ucrtbase"])
|
||||
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/ucrtbase.dll"), 0x8664)
|
||||
|
||||
def test_compatible_copy_keeps_override_when_other_architecture_copy_is_skipped(self):
|
||||
proton = self.proton()
|
||||
self.component("vc", ["ucrtbase"], {
|
||||
"system32/ucrtbase.dll": self.pe_image(0x8664),
|
||||
"syswow64/ucrtbase.dll": self.pe_image(0x14C),
|
||||
})
|
||||
self.pick("vc")
|
||||
names, _ = self.apply(proton)
|
||||
self.assertEqual(names, ["ucrtbase"])
|
||||
self.assertFalse((self.pfx / "system32/ucrtbase.dll").exists())
|
||||
self.assertEqual(MODULE["pe_machine"](self.pfx / "syswow64/ucrtbase.dll"), 0x14C)
|
||||
|
||||
def test_existing_foreign_component_dll_is_removed_for_repair(self):
|
||||
proton = self.proton()
|
||||
self.component("vc", ["ucrtbase"], {"system32/ucrtbase.dll": self.pe_image(0x8664)})
|
||||
self.pick("vc")
|
||||
self.pfx.joinpath("system32").mkdir(parents=True)
|
||||
self.pfx.joinpath("system32/ucrtbase.dll").write_bytes(self.pe_image(0x8664))
|
||||
self.compat.joinpath(".droiddeck-wincomponents.json").write_text(json.dumps({
|
||||
"files": {"drive_c/windows/system32/ucrtbase.dll": "vc"}, "components": ["vc"]}))
|
||||
self.apply(proton)
|
||||
self.assertFalse((self.pfx / "system32/ucrtbase.dll").exists())
|
||||
self.assertEqual([], GAME_ENV["repair_foreign_system_dlls"](str(self.compat), str(proton)))
|
||||
self.assertEqual([], GAME_ENV["repair_foreign_system_dlls"](str(self.compat), str(proton)))
|
||||
|
||||
def test_foreign_component_restore_does_not_override_repair_with_native_override(self):
|
||||
proton = self.proton()
|
||||
builtin = Path(self.tmp.name) / "arm-proton/files/lib/wine/aarch64-windows/ucrtbase.dll"
|
||||
builtin.parent.mkdir(parents=True, exist_ok=True)
|
||||
builtin.write_bytes(self.pe_image(0xAA64))
|
||||
system32 = self.pfx / "system32"
|
||||
system32.mkdir(parents=True)
|
||||
dll = system32 / "ucrtbase.dll"
|
||||
dll.write_bytes(self.pe_image(0x8664))
|
||||
backup = self.compat / ".droiddeck-wincomponents-backup/drive_c/windows/system32/ucrtbase.dll"
|
||||
backup.parent.mkdir(parents=True)
|
||||
backup.write_bytes(self.pe_image(0x8664))
|
||||
self.compat.joinpath(".droiddeck-wincomponents.json").write_text(json.dumps({
|
||||
"files": {"drive_c/windows/system32/ucrtbase.dll": "vc"}, "components": ["vc"]}))
|
||||
self.compat.joinpath("pfx/user.reg").parent.mkdir(parents=True, exist_ok=True)
|
||||
self.compat.joinpath("pfx/user.reg").write_text(
|
||||
'WINE REGISTRY Version 2\n\n[Software\\\\Wine\\\\DllOverrides] 1\n"ucrtbase"="native,builtin"\n')
|
||||
fixed = GAME_ENV["repair_foreign_system_dlls"](str(self.compat), str(proton))
|
||||
self.assertEqual(["system32/ucrtbase.dll (machine 0x8664)"], fixed)
|
||||
self.apply(proton)
|
||||
self.assertTrue(dll.is_symlink())
|
||||
self.assertEqual(0xAA64, MODULE["pe_machine"](dll))
|
||||
|
||||
def test_matching_component_dll_is_placed(self):
|
||||
proton = self.proton()
|
||||
self.component("vc", ["ucrtbase"], {"system32/ucrtbase.dll": self.pe_image(0xAA64)})
|
||||
self.pick("vc")
|
||||
names, _ = self.apply(proton)
|
||||
self.assertEqual(names, ["ucrtbase"])
|
||||
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/ucrtbase.dll"), 0xAA64)
|
||||
|
||||
def test_x64_proton_places_x64_component_dll(self):
|
||||
proton = self.proton(arm=False)
|
||||
self.component("vc", ["ucrtbase"], {"system32/ucrtbase.dll": self.pe_image(0x8664)})
|
||||
self.pick("vc")
|
||||
names, _ = self.apply(proton)
|
||||
self.assertEqual(names, ["ucrtbase"])
|
||||
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/ucrtbase.dll"), 0x8664)
|
||||
|
||||
def test_arm_proton_with_x64_selection_places_x64_component_dll(self):
|
||||
proton = self.proton()
|
||||
self.component("vc", ["ucrtbase"], {"system32/ucrtbase.dll": self.pe_image(0x8664)})
|
||||
self.pick("vc")
|
||||
names, _ = self.apply(proton, {"PROTON_USE_ARM64": "0"})
|
||||
self.assertEqual(names, ["ucrtbase"])
|
||||
self.assertEqual(MODULE["pe_machine"](self.pfx / "system32/ucrtbase.dll"), 0x8664)
|
||||
|
||||
def test_places_files_before_the_prefix_exists_and_returns_overrides(self):
|
||||
self.component("openal", ["openal32"], {"syswow64/OpenAL32.dll": b"x86", "system32/OpenAL32.dll": b"x64"})
|
||||
@@ -235,7 +361,7 @@ class WinComponentsTest(unittest.TestCase):
|
||||
self.pick("openal")
|
||||
globals_ = GAME_ENV["win_components"].__globals__
|
||||
real = runpy.run_path(str(BIN / "droiddeck-wincomponents"))
|
||||
real["apply"].__defaults__ = (self.selection, self.store, self.selection.parent / "no-pending.json", None)
|
||||
real["apply"].__defaults__ = (self.selection, self.store, self.selection.parent / "no-pending.json", None, None, None)
|
||||
with mock.patch.dict(globals_, {"runpy": mock.Mock(run_path=lambda _path: real)}):
|
||||
self.assertEqual(GAME_ENV["win_components"](str(self.compat) + "/", "2571976725"), "openal32=n,b")
|
||||
self.assertEqual(GAME_ENV["win_components"]("", "2571976725"), "")
|
||||
|
||||
Reference in new issue
Block a user