mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
feat: fetch Proton, FEX and the runtimes automatically, and make Linux games run under FEX (#1045)
* fix: x86 Linux games that also ship for Windows run under Proton again Since #749 the live compatibility helper treated every installed game with both Windows and x86 Linux builds as a user's native choice, because the client reports an empty tool for unmapped games. Those games were left on the Steam Linux Runtime, which cannot start them here (bwrap fails, or FEX looks for a RootFS that is not shipped), so Valheim, Moonlighter, Half-Life 2, TF2 and others exited within seconds. - An unmapped game the helper never managed now gets the default Proton. Clearing a mapping the helper set is still kept as a native choice. - Native choices are stored under "native_choices". The old "native" list also held games nobody picked, so it is dropped. * feat: Linux builds run under FEX by default, with the runtimes fetched automatically - Steam fetches Proton, FEX, Steam Linux Runtime 3.0 and 4.0 on the first start and keeps them updated instead of leaving them pending. - Games that ship a Linux build go to FEX once it can run them; Windows-only games and installed Windows builds keep the Proton default. - FEX runs games on a combined x86 runtime with the newer glibc and libstdc++ the GL and Vulkan thunks need. - Vulkan display extensions the driver cannot handle are hidden in front of the thunk, without an audit module. - Mono's incremental garbage collector is turned off under FEX, which stops Unity games crashing. - x86 Steamworks finds the x86 steamclient. - 32-bit games read the virtual controller. * fix: controllers work in Linux Unity games such as Valheim Joystick ioctls on an event node now fail with EINVAL like the kernel's evdev, so the SDL2 that Unity embeds reads the pad's real ID instead of ignoring it as 0000:0000. * test: skip the switch script test without node, and the ring tests without gcc * fix: games with a Linux build keep the Proton default The Windows build often runs better, so titles that ship both builds stay on the default Proton again. Users can still pick FEX for one, and that choice is kept. Linux-only titles still go to FEX. * fix: unmapped dual-platform games get Proton even when config.vdf cannot be read
This commit is contained in:
1 parent
e7bc4b03a5
commit
41abcd203a
17 files changed
+1035
-144
No files matched your search
@@ -92,6 +92,38 @@ class FexTestCase(unittest.TestCase):
|
||||
self.write(self.steam / "steamapps/appmanifest_1628350.acf", '"AppState" { "installdir" "SteamLinuxRuntime_sniper" }')
|
||||
return platform
|
||||
|
||||
def graphics(self, sniper, libc=b"GLIBC_2.2.5 GLIBC_2.31 GLIBC_2.34 GLIBC_2.41", libstdcxx=b"GLIBCXX_3.4.28 GLIBCXX_3.4.33"):
|
||||
files = Path(sniper) / "files"
|
||||
x86 = files / "lib/x86_64-linux-gnu"
|
||||
self.write(x86 / "libc-2.31.so", b"GLIBC_2.2.5 GLIBC_2.31")
|
||||
os.unlink(x86 / "libc.so.6")
|
||||
os.symlink("libc-2.31.so", x86 / "libc.so.6")
|
||||
self.write(x86 / "ld-2.31.so", b"old ld")
|
||||
os.symlink("ld-2.31.so", x86 / "ld-linux-x86-64.so.2")
|
||||
self.write(x86 / "libstdc++.so.6", b"GLIBCXX_3.4.28")
|
||||
self.write(x86 / "libSegFault.so", b"old")
|
||||
self.write(x86 / "libSDL2-2.0.so.0", b"sdl")
|
||||
self.write(x86 / "libfoo.so.1.2", b"foo")
|
||||
os.symlink("libfoo.so.1.2", x86 / "libfoo.so.1")
|
||||
self.write(x86 / "gconv/OLD.so", b"old gconv")
|
||||
self.write(files / "lib/i386-linux-gnu/libc.so.6", b"GLIBC_2.31")
|
||||
self.write(files / "lib/i386-linux-gnu/ld-2.31.so", b"old ld32")
|
||||
os.symlink("i386-linux-gnu/ld-2.31.so", files / "lib/ld-linux.so.2")
|
||||
os.unlink(files / "lib64/ld-linux-x86-64.so.2")
|
||||
os.symlink("../lib/x86_64-linux-gnu/ld-2.31.so", files / "lib64/ld-linux-x86-64.so.2")
|
||||
platform = self.steam / "steamapps/common/SteamLinuxRuntime_4/steamrt4_platform_4.0.20260928.262390"
|
||||
provided = platform / "files/lib/x86_64-linux-gnu"
|
||||
self.write(provided / "libc.so.6", libc)
|
||||
self.write(provided / "libstdc++.so.6", libstdcxx)
|
||||
self.write(provided / "ld-linux-x86-64.so.2", b"new ld")
|
||||
self.write(provided / "gconv/NEW.so", b"new gconv")
|
||||
self.write(platform / "files/lib/i386-linux-gnu/libc.so.6", b"GLIBC_2.41")
|
||||
self.write(platform / "files/lib/i386-linux-gnu/ld-linux.so.2", b"new ld32")
|
||||
with gzip.open(platform / "usr-mtree.txt.gz", "wt") as out:
|
||||
out.write("#mtree\n. type=dir\n")
|
||||
self.write(self.steam / "steamapps/appmanifest_4183110.acf", '"AppState" { "installdir" "SteamLinuxRuntime_4" }')
|
||||
return platform
|
||||
|
||||
def quiet(self, function, *args):
|
||||
with contextlib.redirect_stderr(io.StringIO()) as err:
|
||||
return function(*args), err.getvalue()
|
||||
@@ -198,12 +230,11 @@ class PrepareTest(FexTestCase):
|
||||
for arch in ("x86_64", "i386"):
|
||||
for name in ("libblsession.so", "libfakeinput.so"):
|
||||
self.write(self.tmp / "preloads" / arch / name, arch.encode() + name.encode())
|
||||
self.write(self.tmp / "preloads/x86_64/libthunkaudit.so", b"audit")
|
||||
self.write(self.tmp / "preloads/x86_64/libvulkan-thunk.so", b"pin")
|
||||
self.write(self.tmp / "ld.so.preload", "/usr/local/lib/libblsession.so\n/usr/local/lib/libfakeinput.so\n")
|
||||
FEX["install_preloads"](str(root))
|
||||
self.assertEqual((root / "lib/x86_64-linux-gnu/droiddeck/libthunkaudit.so").read_bytes(), b"audit")
|
||||
self.assertEqual((root / "lib/x86_64-linux-gnu/droiddeck/libvulkan-thunk.so").read_bytes(), b"pin")
|
||||
self.assertEqual((root / "lib/x86_64-linux-gnu/droiddeck/vulkan/libvulkan.so.1").read_bytes(), b"pin")
|
||||
self.assertEqual(os.readlink(root / "lib/x86_64-linux-gnu/droiddeck/vulkan/libvulkan.so"), "libvulkan.so.1")
|
||||
self.assertEqual((root / "etc/ld.so.preload").read_text(),
|
||||
"/usr/$LIB/droiddeck/libblsession.so\n/usr/$LIB/droiddeck/libfakeinput.so\n")
|
||||
self.assertEqual((root / "lib/i386-linux-gnu/droiddeck/libfakeinput.so").read_bytes(), b"i386libfakeinput.so")
|
||||
@@ -252,7 +283,71 @@ class PrepareTest(FexTestCase):
|
||||
status = json.loads((self.home / ".local/share/droiddeck-fex/status.json").read_text())
|
||||
self.assertEqual((status["ready"], status["runtime"], status["thunks"]), (True, str(platform), True))
|
||||
self.assertFalse((self.home / ".config/droiddeck/fex-wanted").exists())
|
||||
self.assertEqual(self.quiet(FEX["prepare"])[1], "")
|
||||
self.assertNotIn("prepared", self.quiet(FEX["prepare"])[1])
|
||||
|
||||
def test_a_newer_runtime_supplies_the_c_and_cxx_libraries(self):
|
||||
self.fex_tool()
|
||||
sniper = self.runtime()
|
||||
FEX["materialize"](str(sniper))
|
||||
provider = self.graphics(sniper)
|
||||
fex, said = self.quiet(FEX["prepare"])
|
||||
root = self.home / ".local/share/droiddeck-fex/rootfs"
|
||||
self.assertIn("built the x86 runtime from sniper_platform_", said)
|
||||
self.assertEqual(fex["rootfs"], str(root))
|
||||
config = json.loads((self.home / ".local/share/droiddeck-fex/config/Config.json").read_text())
|
||||
self.assertEqual(config["Config"]["RootFS"], str(root))
|
||||
x86 = root / "lib/x86_64-linux-gnu"
|
||||
self.assertEqual((x86 / "libc.so.6").read_bytes(), b"GLIBC_2.2.5 GLIBC_2.31 GLIBC_2.34 GLIBC_2.41")
|
||||
self.assertEqual((x86 / "libstdc++.so.6").read_bytes(), b"GLIBCXX_3.4.28 GLIBCXX_3.4.33")
|
||||
self.assertEqual((x86 / "ld-linux-x86-64.so.2").read_bytes(), b"new ld")
|
||||
self.assertEqual((x86 / "gconv/NEW.so").read_bytes(), b"new gconv")
|
||||
self.assertEqual((root / "lib/i386-linux-gnu/libc.so.6").read_bytes(), b"GLIBC_2.41")
|
||||
self.assertEqual((x86 / "libSDL2-2.0.so.0").read_bytes(), b"sdl")
|
||||
self.assertEqual(os.readlink(x86 / "libfoo.so.1"), "libfoo.so.1.2")
|
||||
self.assertEqual((x86 / "libfoo.so.1").read_bytes(), b"foo")
|
||||
for stale in ("libc-2.31.so", "ld-2.31.so", "libSegFault.so"):
|
||||
self.assertFalse(os.path.lexists(x86 / stale), stale)
|
||||
self.assertEqual(os.readlink(root / "lib/ld-linux.so.2"), "i386-linux-gnu/ld-linux.so.2")
|
||||
self.assertEqual((root / "lib/ld-linux.so.2").read_bytes(), b"new ld32")
|
||||
self.assertEqual(os.readlink(root / "lib64/ld-linux-x86-64.so.2"), "../lib/x86_64-linux-gnu/ld-linux-x86-64.so.2")
|
||||
self.assertEqual((root / "lib64/ld-linux-x86-64.so.2").read_bytes(), b"new ld")
|
||||
self.assertEqual(os.readlink(root / "usr"), ".")
|
||||
self.assertEqual((root / "usr/bin/[").read_bytes(), b"blob")
|
||||
self.assertEqual((sniper / "files/lib/x86_64-linux-gnu/libc.so.6").read_bytes(), b"GLIBC_2.2.5 GLIBC_2.31")
|
||||
status = json.loads((self.home / ".local/share/droiddeck-fex/status.json").read_text())
|
||||
self.assertEqual(status["graphics"], str(provider))
|
||||
self.assertNotIn("built", self.quiet(FEX["prepare"])[1])
|
||||
os.utime(provider / "usr-mtree.txt.gz", ns=(1, 1))
|
||||
self.assertIn("built the x86 runtime", self.quiet(FEX["prepare"])[1])
|
||||
self.assertEqual(sorted(os.listdir(root.parent)), ["config", "lock", "rootfs", "status.json"])
|
||||
|
||||
def test_a_runtime_that_is_not_newer_is_left_out(self):
|
||||
self.fex_tool()
|
||||
sniper = self.runtime()
|
||||
FEX["materialize"](str(sniper))
|
||||
self.graphics(sniper, libc=b"GLIBC_2.2.5 GLIBC_2.31", libstdcxx=b"GLIBCXX_3.4.28")
|
||||
fex, said = self.quiet(FEX["prepare"])
|
||||
self.assertEqual(fex["rootfs"], str(sniper / "files"))
|
||||
self.assertIn("has no newer C and C++ libraries than sniper_platform_", said)
|
||||
self.assertFalse((self.home / ".local/share/droiddeck-fex/rootfs").exists())
|
||||
|
||||
def test_x86_steamworks_finds_the_x86_client(self):
|
||||
for directory, machine in (("linux64", 62), ("linux32", 3), ("linuxarm64", 183)):
|
||||
self.write(self.steam / directory / "steamclient.so", elf(machine))
|
||||
sdk = self.home / ".steam"
|
||||
sdk.mkdir(parents=True)
|
||||
os.symlink(self.steam / "linuxarm64", sdk / "sdk64")
|
||||
os.symlink(self.steam / "linuxarm64", sdk / "sdkarm64")
|
||||
FEX["link_steam_sdk"]()
|
||||
self.assertEqual(os.readlink(sdk / "sdk64"), str(self.steam / "linux64"))
|
||||
self.assertEqual(os.readlink(sdk / "sdk32"), str(self.steam / "linux32"))
|
||||
self.assertEqual(os.readlink(sdk / "sdkarm64"), str(self.steam / "linuxarm64"))
|
||||
os.unlink(sdk / "sdk32")
|
||||
os.symlink(self.tmp / "elsewhere", sdk / "sdk32")
|
||||
self.write(self.tmp / "elsewhere/steamclient.so", elf(3))
|
||||
FEX["link_steam_sdk"]()
|
||||
self.assertEqual(os.readlink(sdk / "sdk32"), str(self.tmp / "elsewhere"))
|
||||
self.assertEqual(sorted(os.listdir(sdk)), ["sdk32", "sdk64", "sdkarm64"])
|
||||
|
||||
def test_status_refreshes_what_the_app_reads_once_steam_installed_fex(self):
|
||||
with mock.patch.dict(G, {"steam_running": lambda: False}):
|
||||
@@ -397,7 +492,7 @@ class LaunchTest(FexTestCase):
|
||||
arm = self.write(self.tmp / "arm.so", elf(183))
|
||||
x86 = self.write(self.tmp / "x86.so", elf(62))
|
||||
env = {"LD_PRELOAD": "%s:%s %s" % (arm, x86, self.tmp / "gone.so"),
|
||||
"LD_LIBRARY_PATH": "/steam/steamrtarm64:/usr/lib/aarch64-linux-gnu:/game/lib",
|
||||
"LD_LIBRARY_PATH": "/steam/steamrtarm64:/usr/lib/aarch64-linux-gnu:/game/lib:/steam/linuxarm64",
|
||||
"FEX_ROOTFS": "/usr/share/guestos/fex-mesa", "FEX_TSOENABLED": "1"}
|
||||
guest = FEX["guest_environment"]({"portable": True}, env)
|
||||
self.assertEqual((guest["LD_PRELOAD"], guest["LD_LIBRARY_PATH"], guest["FEX_PORTABLE"]), (str(x86), "/game/lib", "1"))
|
||||
@@ -405,8 +500,10 @@ class LaunchTest(FexTestCase):
|
||||
self.assertEqual(guest["FEX_TSOENABLED"], "1")
|
||||
self.assertTrue(guest["FEX_APP_CONFIG_LOCATION"].endswith("/config/"))
|
||||
self.assertEqual((guest["FEX_SILENTLOG"], guest["FEX_OUTPUTLOG"]), ("0", "stderr"))
|
||||
guest = FEX["guest_environment"]({"portable": False}, {"LD_PRELOAD": str(arm), "FEX_PORTABLE": "1", "FEX_OUTPUTLOG": "/tmp/fex.log"})
|
||||
self.assertEqual(guest["FEX_OUTPUTLOG"], "/tmp/fex.log")
|
||||
self.assertEqual(guest["GC_DISABLE_INCREMENTAL"], "1")
|
||||
guest = FEX["guest_environment"]({"portable": False}, {"LD_PRELOAD": str(arm), "FEX_PORTABLE": "1", "FEX_OUTPUTLOG": "/tmp/fex.log",
|
||||
"GC_DISABLE_INCREMENTAL": "0"})
|
||||
self.assertEqual((guest["FEX_OUTPUTLOG"], guest["GC_DISABLE_INCREMENTAL"]), ("/tmp/fex.log", "0"))
|
||||
self.assertNotIn("LD_PRELOAD", guest)
|
||||
self.assertNotIn("FEX_PORTABLE", guest)
|
||||
|
||||
@@ -470,9 +567,8 @@ class LaunchTest(FexTestCase):
|
||||
self.runtime()
|
||||
self.write(tool / "usr/share/fex-emu/GuestThunks/libvulkan-guest.so",
|
||||
elf(62) + b"\0libstdc++.so.6\0GLIBCXX_3.4\0GLIBCXX_3.4.29\0libc.so.6\0GLIBC_2.2.5\0GLIBC_2.34\0")
|
||||
self.write(self.tmp / "preloads/x86_64/libthunkaudit.so", elf(62))
|
||||
pin = self.write(self.tmp / "preloads/x86_64/libvulkan-thunk.so", elf(62))
|
||||
audit = "/usr/lib/x86_64-linux-gnu/droiddeck/libthunkaudit.so"
|
||||
pin = self.write(self.tmp / "preloads/x86_64/libvulkan-thunk.so", elf(62) + b"\0libc.so.6\0GLIBC_2.2.5\0")
|
||||
pinned = "/usr/lib/x86_64-linux-gnu/droiddeck/vulkan"
|
||||
|
||||
def app(name, glibc=b"GLIBC_2.34\0GLIBC_2.44", glibcxx=b"GLIBCXX_3.4.29\0GLIBCXX_3.4.36", bundled=True):
|
||||
run = self.write(self.tmp / name / "AppRun", elf(62), 0o755)
|
||||
@@ -487,25 +583,32 @@ class LaunchTest(FexTestCase):
|
||||
_, said = self.quiet(FEX["launch"], [str(program)], dict(env or {}), "on", decide)
|
||||
return emulated.call_args[0][2], said
|
||||
|
||||
def search(env):
|
||||
return env.get("LD_LIBRARY_PATH", "").split(":")[0]
|
||||
|
||||
env, said = started(app("new"))
|
||||
self.assertEqual(env["LD_AUDIT"], audit)
|
||||
self.assertIn("thunks on, its own Vulkan loader too", said)
|
||||
env, _ = started(app("kept"), {"LD_AUDIT": "/opt/audit.so"})
|
||||
self.assertEqual(env["LD_AUDIT"], audit + ":/opt/audit.so")
|
||||
env, _ = started(self.write(self.tmp / "elsewhere/run.sh", "#!/bin/sh\n", 0o755), decide=str(self.tmp / "new"))
|
||||
self.assertEqual(env["LD_AUDIT"], audit)
|
||||
env, said = started(app("old-cxx", glibcxx=b"GLIBCXX_3.4.28"))
|
||||
self.assertEqual(search(env), pinned)
|
||||
self.assertNotIn("LD_AUDIT", env)
|
||||
self.assertNotIn("LD_BIND_NOW", env)
|
||||
self.assertIn("thunks on, its own Vulkan loader too", said)
|
||||
env, _ = started(app("kept"), {"LD_LIBRARY_PATH": "/game/lib"})
|
||||
self.assertEqual(env["LD_LIBRARY_PATH"], pinned + ":/game/lib")
|
||||
env, _ = started(self.write(self.tmp / "elsewhere/run.sh", "#!/bin/sh\n", 0o755), decide=str(self.tmp / "new"))
|
||||
self.assertEqual(search(env), pinned)
|
||||
env, said = started(app("old-cxx", glibcxx=b"GLIBCXX_3.4.28"))
|
||||
self.assertNotEqual(search(env), pinned)
|
||||
self.assertIn("thunks on)", said)
|
||||
self.assertNotIn("LD_AUDIT", started(app("old-libc", glibc=b"GLIBC_2.31"))[0])
|
||||
self.assertNotIn("LD_AUDIT", started(app("runtime-only", bundled=False))[0])
|
||||
self.assertNotEqual(search(started(app("old-libc", glibc=b"GLIBC_2.31"))[0]), pinned)
|
||||
self.assertNotEqual(search(started(app("runtime-only", bundled=False))[0]), pinned)
|
||||
i386 = self.write(self.tmp / "new/game.i386", elf(3), 0o755)
|
||||
self.assertNotIn("LD_AUDIT", started(i386)[0])
|
||||
self.assertNotEqual(search(started(i386)[0]), pinned)
|
||||
self.write(pin, elf(62) + b"\0libc.so.6\0GLIBC_2.45\0")
|
||||
self.assertNotEqual(search(started(app("new"))[0]), pinned)
|
||||
pin.unlink()
|
||||
self.assertNotIn("LD_AUDIT", started(app("no-pin"))[0])
|
||||
self.assertNotEqual(search(started(app("no-pin"))[0]), pinned)
|
||||
self.write(pin, elf(62))
|
||||
(tool / "usr/share/fex-emu/GuestThunks/libvulkan-guest.so").unlink()
|
||||
self.assertNotIn("LD_AUDIT", started(app("no-thunk"))[0])
|
||||
self.assertNotEqual(search(started(app("no-thunk"))[0]), pinned)
|
||||
|
||||
def test_steam_verbs(self):
|
||||
with mock.patch.dict(G, {"launch": mock.Mock(return_value=0)}):
|
||||
@@ -573,6 +676,53 @@ class AppInfoTest(unittest.TestCase):
|
||||
"40": None, "41": None, "50": "droiddeck-fex",
|
||||
}, hex(magic))
|
||||
|
||||
@staticmethod
|
||||
def manifest(steam, app, flags="4"):
|
||||
(steam / "steamapps").mkdir(exist_ok=True)
|
||||
(steam / ("steamapps/appmanifest_%s.acf" % app)).write_text('"AppState" { "appid" "%s" "StateFlags" "%s" }' % (app, flags))
|
||||
|
||||
def test_dual_platform_titles_keep_the_proton_default_unless_the_user_picks_fex(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
steam = Path(tmp) / "Steam"
|
||||
(steam / "appcache").mkdir(parents=True)
|
||||
(steam / "appcache/appinfo.vdf").write_bytes(self.appinfo({
|
||||
10: ("windows,linux", "", "game"), 20: ("windows,linux", "", "game"), 30: ("windows,linux", "", "game"),
|
||||
40: ("linux", "", "game"),
|
||||
}))
|
||||
self.COMPAT["APPINFO_CACHE"].clear()
|
||||
for app in ("3127680", "1628350", "4183110"):
|
||||
self.manifest(steam, app)
|
||||
tool, fex = self.COMPAT["TOOL"], self.COMPAT["FEX_TOOL"]
|
||||
state = Path(tmp) / "state"
|
||||
state.mkdir()
|
||||
(state / "state.json").write_text(json.dumps({"auto": {"20": fex}}))
|
||||
catalog = [{"name": tool, "display": "Proton Experimental ARM64", "dir": "Proton Experimental (ARM64)", "valve": True}]
|
||||
config = steam / "config/config.vdf"
|
||||
config.parent.mkdir()
|
||||
config.write_text('"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { '
|
||||
'"0" { "name" "%s" "config" "" "priority" "75" } '
|
||||
'"20" { "name" "%s" "config" "" "priority" "250" } '
|
||||
'"30" { "name" "%s" "config" "" "priority" "250" } } } } } }' % (tool, fex, fex))
|
||||
self.COMPAT["register_default"](str(config), ["10", "20", "30", "40"], catalog=catalog, directory=str(state))
|
||||
self.assertEqual(self.COMPAT["read_config_mapping"](str(config)),
|
||||
{"0": tool, "10": tool, "20": tool, "30": fex, "40": fex})
|
||||
|
||||
def test_tools_are_fetched_until_fully_installed_and_up_to_date(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
steam = Path(tmp)
|
||||
(steam / "steamapps").mkdir()
|
||||
downloads = self.COMPAT["tool_downloads"]
|
||||
self.assertEqual(downloads(str(steam)), [
|
||||
("4427310", "install"), ("3127680", "install"), ("1628350", "install"), ("4183110", "install")])
|
||||
self.manifest(steam, "4427310", flags="6")
|
||||
self.manifest(steam, "3127680", flags="1026")
|
||||
self.manifest(steam, "1628350", flags="4")
|
||||
(steam / "steamapps/appmanifest_4183110.acf").write_text('"AppState" { "appid" "4183110" }')
|
||||
self.assertEqual(downloads(str(steam)), [("4427310", "update"), ("3127680", "update"), ("4183110", "update")])
|
||||
for app in ("4427310", "3127680", "4183110"):
|
||||
self.manifest(steam, app)
|
||||
self.assertEqual(downloads(str(steam)), [])
|
||||
|
||||
def test_titles_with_a_valve_pick_are_found_installed_or_not(self):
|
||||
def deck(oslist, runtime, kind="game"):
|
||||
common = {"type": kind, "oslist": oslist, "steam_deck_compatibility": {"configuration": {"recommended_runtime": runtime}}}
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[2] / "app/src/main/cpp/fakeinput_steam.cpp"
|
||||
RING_MAGIC = 0x46494252
|
||||
DESCRIPTION_MAGIC = 0x46495544
|
||||
HEADER = 64
|
||||
EVENT = 24
|
||||
CAPACITY = 4096
|
||||
DESCRIPTION = 1824
|
||||
READER = r"""
|
||||
#include <fcntl.h>
|
||||
#include <linux/input.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct input_event events[64];
|
||||
int fd = open("/dev/input/event16", O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
while (read(fd, events, sizeof(events)) > 0)
|
||||
;
|
||||
puts("ready");
|
||||
fflush(stdout);
|
||||
char go;
|
||||
if (read(0, &go, 1) != 1)
|
||||
return 1;
|
||||
ssize_t got = read(fd, events, sizeof(events));
|
||||
for (ssize_t i = 0; i < got / (ssize_t)sizeof(events[0]); i++)
|
||||
printf("%ld.%06ld %u %u %d\n", (long)events[i].time.tv_sec, (long)events[i].time.tv_usec, events[i].type,
|
||||
events[i].code, events[i].value);
|
||||
return got > 0 ? 0 : 1;
|
||||
}
|
||||
"""
|
||||
PROBE = r"""
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/joystick.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char name[128] = "";
|
||||
struct input_id id = {0};
|
||||
int fd = open("/dev/input/event16", O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
return 1;
|
||||
int joydev = ioctl(fd, JSIOCGNAME(sizeof(name)), name);
|
||||
printf("JSIOCGNAME %d %s\n", joydev, joydev < 0 && errno == EINVAL ? "EINVAL" : name);
|
||||
if (ioctl(fd, EVIOCGID, &id) < 0 || ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0)
|
||||
return 1;
|
||||
printf("%04x:%04x %s\n", id.vendor, id.product, name);
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def can_build(bits):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
probe = Path(tmp) / "probe.cpp"
|
||||
probe.write_text("#include <string>\nint main() { return std::string().size(); }\n")
|
||||
return subprocess.run(["g++", bits, "-static-libstdc++", "-o", str(Path(tmp) / "probe"), str(probe)],
|
||||
capture_output=True).returncode == 0
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == "linux" and os.uname().machine == "x86_64" and shutil.which("g++")
|
||||
and shutil.which("gcc"), "needs gcc and g++ on an x86-64 Linux host")
|
||||
class FakeinputRingTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(shutil.rmtree, self.tmp, True)
|
||||
|
||||
def ring(self):
|
||||
hooks = self.tmp / "hooks"
|
||||
hooks.mkdir()
|
||||
(hooks / "event16").touch()
|
||||
ring = bytearray(HEADER + CAPACITY * EVENT + DESCRIPTION)
|
||||
struct.pack_into("<IIIIQQQ", ring, 0, RING_MAGIC, 2, EVENT, CAPACITY, 5, 0, 0)
|
||||
struct.pack_into("<IiHHHHI80s", ring, HEADER + CAPACITY * EVENT, DESCRIPTION_MAGIC, os.getpid(),
|
||||
3, 0x28de, 0x11ff, 1, 16, b"Microsoft X-Box 360 pad 0")
|
||||
path = hooks / ".uinput-event16"
|
||||
path.write_bytes(bytes(ring))
|
||||
return hooks, path
|
||||
|
||||
def build(self, bits, program, name):
|
||||
if not can_build(bits):
|
||||
self.skipTest("no %s C++ toolchain" % bits)
|
||||
library = self.tmp / ("libfakeinput%s.so" % bits)
|
||||
subprocess.run(["g++", bits, "-shared", "-fPIC", "-O2", "-Wno-attributes", "-pthread", "-std=c++17",
|
||||
"-static-libstdc++", "-static-libgcc", "-Wl,--exclude-libs,ALL", "-o", str(library),
|
||||
str(SOURCE), "-ldl"], check=True, capture_output=True)
|
||||
binary = self.tmp / (name + bits)
|
||||
(self.tmp / (name + ".c")).write_text(program)
|
||||
subprocess.run(["gcc", bits, "-o", str(binary), str(self.tmp / (name + ".c"))], check=True)
|
||||
return library, binary
|
||||
|
||||
def read_through(self, bits):
|
||||
library, reader = self.build(bits, READER, "reader")
|
||||
hooks, path = self.ring()
|
||||
env = dict(os.environ, LD_PRELOAD=str(library), FAKE_EVDEV_DIR=str(hooks))
|
||||
process = subprocess.Popen([str(reader)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=env, text=True)
|
||||
self.addCleanup(process.kill)
|
||||
self.assertEqual(process.stdout.readline(), "ready\n")
|
||||
with open(path, "r+b") as ring:
|
||||
for i, (kind, code, value) in enumerate(((1, 304, 1), (3, 1, -32768), (0, 0, 0))):
|
||||
ring.seek(HEADER + (5 + i) * EVENT)
|
||||
ring.write(struct.pack("<qqHHi", 1700000000 + i, 250000, kind, code, value))
|
||||
ring.seek(16)
|
||||
ring.write(struct.pack("<Q", 8))
|
||||
output, _ = process.communicate("g", timeout=10)
|
||||
self.assertEqual(process.returncode, 0)
|
||||
return output
|
||||
|
||||
def test_a_32_bit_guest_reads_the_64_bit_ring(self):
|
||||
self.assertEqual(self.read_through("-m32"),
|
||||
"1700000000.250000 1 304 1\n1700000001.250000 3 1 -32768\n1700000002.250000 0 0 0\n")
|
||||
|
||||
def test_a_64_bit_guest_reads_the_same_ring(self):
|
||||
self.assertEqual(self.read_through("-m64"),
|
||||
"1700000000.250000 1 304 1\n1700000001.250000 3 1 -32768\n1700000002.250000 0 0 0\n")
|
||||
|
||||
def test_an_event_node_rejects_joydev_requests_so_sdl_reads_its_id(self):
|
||||
library, probe = self.build("-m64", PROBE, "probe")
|
||||
hooks, _ = self.ring()
|
||||
run = subprocess.run([str(probe)], capture_output=True, text=True, timeout=10,
|
||||
env=dict(os.environ, LD_PRELOAD=str(library), FAKE_EVDEV_DIR=str(hooks)))
|
||||
self.assertEqual(run.returncode, 0, run.stderr)
|
||||
self.assertEqual(run.stdout, "JSIOCGNAME -1 EINVAL\n28de:11ff Microsoft X-Box 360 pad 0\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -522,7 +522,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
(root / "state.json").write_text(json.dumps({
|
||||
"default": self.TOOL,
|
||||
"auto": {},
|
||||
"native": [app],
|
||||
"native_choices": [app],
|
||||
}))
|
||||
|
||||
globals_ = COMPAT["register_default"].__globals__
|
||||
@@ -534,7 +534,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL})
|
||||
state = json.loads((root / "state.json").read_text())
|
||||
self.assertEqual(state["auto"], {})
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
finally:
|
||||
globals_["native_targets"] = original_native_targets
|
||||
|
||||
@@ -551,7 +551,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
(root / "state.json").write_text(json.dumps({
|
||||
"default": self.TOOL,
|
||||
"auto": {},
|
||||
"native": [app],
|
||||
"native_choices": [app],
|
||||
}))
|
||||
|
||||
globals_ = COMPAT["register_default"].__globals__
|
||||
@@ -562,12 +562,12 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
try:
|
||||
COMPAT["register_default"](
|
||||
str(config), [app], catalog=self.CATALOG, directory=tmp)
|
||||
self.assertEqual(json.loads((root / "state.json").read_text())["native"], [app])
|
||||
self.assertEqual(json.loads((root / "state.json").read_text())["native_choices"], [app])
|
||||
|
||||
COMPAT["register_default"](
|
||||
str(config), [added_shortcut], catalog=self.CATALOG, directory=tmp)
|
||||
state = json.loads((root / "state.json").read_text())
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
self.assertEqual(state["auto"], {added_shortcut: self.TOOL})
|
||||
self.assertEqual(mapping_of(config.read_text()), {
|
||||
"0": self.TOOL,
|
||||
@@ -613,7 +613,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
self.assertEqual(COMPAT["tokenize"](first.decode()),
|
||||
COMPAT["tokenize"](config_text([("0", self.TOOL)])))
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["auto"], {})
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native"], ["427520"])
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native_choices"], ["427520"])
|
||||
|
||||
COMPAT["register_default"](
|
||||
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
||||
@@ -625,7 +625,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
native_choice = config.read_bytes()
|
||||
self.assertEqual(mapping_of(native_choice.decode()), {"0": self.TOOL, "427520": ""})
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["auto"], {})
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native"], ["427520"])
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native_choices"], ["427520"])
|
||||
COMPAT["register_default"](
|
||||
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
||||
self.assertEqual(config.read_bytes(), native_choice)
|
||||
@@ -635,10 +635,10 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
COMPAT["register_default"](
|
||||
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
||||
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, "427520": choice})
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native"], [])
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native_choices"], [])
|
||||
|
||||
state = json.loads((Path(tmp) / "state.json").read_text())
|
||||
state["native"] = ["427520"]
|
||||
state["native_choices"] = ["427520"]
|
||||
state["auto"] = {}
|
||||
(Path(tmp) / "state.json").write_text(json.dumps(state))
|
||||
config.write_text(config_text([("0", self.TOOL), ("427520", "proton_experimental")]))
|
||||
@@ -646,7 +646,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
||||
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, "427520": self.TOOL})
|
||||
saved = json.loads((Path(tmp) / "state.json").read_text())
|
||||
self.assertEqual(saved["native"], [])
|
||||
self.assertEqual(saved["native_choices"], [])
|
||||
self.assertEqual(saved["auto"], {"427520": self.TOOL})
|
||||
finally:
|
||||
globals_["appinfo_platforms"] = original_platforms
|
||||
|
||||
@@ -32,8 +32,10 @@ class RequestFexTest(unittest.TestCase):
|
||||
"start steam://install/1628350", "end steam://install/1628350"],
|
||||
self.log.read_text().splitlines())
|
||||
self.install("1628350")
|
||||
self.assertEqual(["4183110"], COMPAT["request_fex"](str(self.root), asked))
|
||||
self.install("4183110")
|
||||
self.assertEqual([], COMPAT["request_fex"](str(self.root), asked))
|
||||
self.assertEqual({"3127680", "1628350"}, asked)
|
||||
self.assertEqual({"3127680", "1628350", "4183110"}, asked)
|
||||
|
||||
def test_a_declined_install_is_not_asked_again_in_the_same_session(self):
|
||||
asked = set()
|
||||
|
||||
@@ -117,6 +117,47 @@ class PageScriptTest(unittest.TestCase):
|
||||
capture_output=True, text=True, timeout=20)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_tool_installs_skip_only_their_own_install_dialog(self):
|
||||
harness_source = r"""
|
||||
const assert = require('assert');
|
||||
globalThis.window = globalThis;
|
||||
const script = require('fs').readFileSync(process.argv[2], 'utf8');
|
||||
globalThis.SteamClient = { Installs: {}, Downloads: {} };
|
||||
assert.throws(() => eval(script), /install calls are not ready/);
|
||||
const opened = [], queued = [];
|
||||
let wizard = null, continued = 0;
|
||||
globalThis.SteamClient = {
|
||||
Installs: {
|
||||
OpenInstallWizard(apps, client) { opened.push([apps, client]); },
|
||||
RegisterForShowInstallWizard(callback) { assert.strictEqual(wizard, null); wizard = callback; return { unregister() {} }; },
|
||||
ContinueInstall() { continued++; },
|
||||
},
|
||||
Downloads: { QueueAppUpdate(app, client) { queued.push([app, client]); } },
|
||||
};
|
||||
assert.strictEqual(eval(script), 'installed');
|
||||
assert.strictEqual(eval(script), 'present');
|
||||
const tools = window.__droiddeckTools;
|
||||
wizard({ eInstallState: 7, currentAppID: 4183110 });
|
||||
assert.strictEqual(continued, 0);
|
||||
tools.install(4183110);
|
||||
assert.deepStrictEqual(opened, [[[4183110], '0']]);
|
||||
wizard({ eInstallState: 8, currentAppID: 4183110 });
|
||||
wizard({ eInstallState: 7, currentAppID: 892970 });
|
||||
assert.strictEqual(continued, 0);
|
||||
wizard({ eInstallState: 7, currentAppID: 4183110 });
|
||||
wizard({ eInstallState: 7, currentAppID: 4183110 });
|
||||
assert.strictEqual(continued, 1);
|
||||
tools.update(4427310);
|
||||
assert.deepStrictEqual(queued, [[4427310, '0']]);
|
||||
"""
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
script = Path(tmp) / "tools.js"
|
||||
script.write_text(LIVE["TOOLS_JS"])
|
||||
harness = Path(tmp) / "harness.js"
|
||||
harness.write_text(harness_source)
|
||||
result = subprocess.run(["node", str(harness), str(script)], capture_output=True, text=True, timeout=20)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_steamvr_library_launch_uses_binding_and_other_games_pass_through(self):
|
||||
harness_source = r"""
|
||||
const assert = require('assert');
|
||||
@@ -334,19 +375,19 @@ class ReconcileTest(unittest.TestCase):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["auto"], {})
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
self.assertEqual(COMPAT["read_config_mapping"](str(config)), {"0": TOOL})
|
||||
|
||||
page.sets.clear()
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
restarted = LIVE["Helper"](str(self.steam), 1)
|
||||
restarted.page = page
|
||||
restarted.reconcile()
|
||||
state = json.loads((self.state / "state.json").read_text())
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
|
||||
config.write_text(
|
||||
'"InstallConfigStore" { "Software" { "Valve" { "Steam" { '
|
||||
@@ -356,13 +397,13 @@ class ReconcileTest(unittest.TestCase):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.mapping[app], "GE-Proton11-7")
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native"], [])
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
|
||||
for choice in ("steamlinuxruntime", COMPAT["FEX_TOOL"], TOOL_11):
|
||||
(self.state / "state.json").write_text(json.dumps({
|
||||
"default": TOOL,
|
||||
"auto": {},
|
||||
"native": [app],
|
||||
"native_choices": [app],
|
||||
}))
|
||||
config.write_text(
|
||||
'"InstallConfigStore" { "Software" { "Valve" { "Steam" { '
|
||||
@@ -373,7 +414,7 @@ class ReconcileTest(unittest.TestCase):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.mapping[app], choice)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native"], [], choice)
|
||||
self.assertEqual(state["native_choices"], [], choice)
|
||||
finally:
|
||||
COMPAT["native_targets"] = original_native_targets
|
||||
|
||||
@@ -387,7 +428,7 @@ class ReconcileTest(unittest.TestCase):
|
||||
(self.state / "state.json").write_text(json.dumps({
|
||||
"default": TOOL,
|
||||
"auto": {},
|
||||
"native": [app],
|
||||
"native_choices": [app],
|
||||
}))
|
||||
|
||||
original_native_targets = COMPAT["native_targets"]
|
||||
@@ -396,14 +437,14 @@ class ReconcileTest(unittest.TestCase):
|
||||
page = FakePage({"0": TOOL, app: "proton"}, [TOOL, TOOL_11])
|
||||
state = self.reconcile(page)
|
||||
self.assertNotIn(app, self.helper.installed)
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
self.assertNotIn(app, state["auto"])
|
||||
self.assertNotIn((app, TOOL), page.sets)
|
||||
self.assertEqual(COMPAT["read_config_mapping"](str(config)), {"0": TOOL})
|
||||
|
||||
config.write_text('"InstallConfigStore" { "Software" { "Other" {} } }')
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
self.assertNotIn((app, TOOL), page.sets)
|
||||
|
||||
config.write_text(
|
||||
@@ -412,12 +453,72 @@ class ReconcileTest(unittest.TestCase):
|
||||
'"%s" { "name" "GE-Proton11-7" } } } } } }' % (TOOL, app))
|
||||
page.mapping[app] = "proton"
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(state["native"], [])
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
self.assertNotIn((app, TOOL), page.sets)
|
||||
self.assertEqual(COMPAT["read_config_mapping"](str(config))[app], "GE-Proton11-7")
|
||||
finally:
|
||||
COMPAT["native_targets"] = original_native_targets
|
||||
|
||||
def dual_platform_game(self, state):
|
||||
app = "892970"
|
||||
(self.steam / ("steamapps/appmanifest_%s.acf" % app)).write_text("")
|
||||
config = self.steam / "config/config.vdf"
|
||||
config.parent.mkdir(parents=True)
|
||||
config.write_text(
|
||||
'"InstallConfigStore" { "Software" { "Valve" { "Steam" { '
|
||||
'"CompatToolMapping" { "0" { "name" "%s" } } } } } }' % TOOL)
|
||||
(self.state / "state.json").write_text(json.dumps(state))
|
||||
patcher = mock.patch.dict(COMPAT, {"native_targets": lambda _root, apps: {
|
||||
app: COMPAT["NATIVE_CHOICE"]
|
||||
} if app in apps else {}})
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
return app, FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11])
|
||||
|
||||
def test_unmapped_dual_platform_game_gets_the_default_live(self):
|
||||
app, page = self.dual_platform_game({"default": TOOL, "auto": {"10": TOOL, "11": TOOL}})
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, TOOL)])
|
||||
self.assertEqual(state["auto"][app], TOOL)
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
|
||||
page.mapping[app] = ""
|
||||
page.sets.clear()
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
|
||||
def test_unmapped_dual_platform_game_gets_the_default_without_a_readable_config(self):
|
||||
app, page = self.dual_platform_game({"default": TOOL, "auto": {"10": TOOL}, "native_choices": ["11"]})
|
||||
(self.steam / "config/config.vdf").unlink()
|
||||
page.mapping["11"] = ""
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, TOOL)])
|
||||
self.assertEqual(state["auto"][app], TOOL)
|
||||
self.assertEqual(state["native_choices"], ["11"])
|
||||
|
||||
def test_a_tool_set_live_is_kept_before_the_client_writes_its_config(self):
|
||||
app, page = self.dual_platform_game({"default": TOOL, "auto": {"10": TOOL, "11": TOOL, "892970": TOOL}})
|
||||
page.known.append(COMPAT["FEX_TOOL"])
|
||||
page.mapping[app] = TOOL
|
||||
config = self.steam / "config/config.vdf"
|
||||
config.write_text(
|
||||
'"InstallConfigStore" { "Software" { "Valve" { "Steam" { '
|
||||
'"CompatToolMapping" { "0" { "name" "%s" } "%s" { "name" "%s" } } } } } }' % (TOOL, app, TOOL))
|
||||
with mock.patch.dict(COMPAT, {"native_targets": lambda _root, apps: {app: COMPAT["FEX_TOOL"]} if app in apps else {}}):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, COMPAT["FEX_TOOL"])])
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, COMPAT["FEX_TOOL"])])
|
||||
self.assertEqual(state["auto"][app], COMPAT["FEX_TOOL"])
|
||||
|
||||
def test_native_list_from_earlier_builds_is_not_trusted(self):
|
||||
app, page = self.dual_platform_game({"default": TOOL, "auto": {"10": TOOL, "11": TOOL}, "native": ["892970"]})
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, TOOL)])
|
||||
self.assertNotIn("native", state)
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
|
||||
def test_factorio_without_prior_auto_state_uses_the_default_proton(self):
|
||||
app = "427520"
|
||||
(self.steam / ("steamapps/appmanifest_%s.acf" % app)).write_text("")
|
||||
@@ -436,7 +537,7 @@ class ReconcileTest(unittest.TestCase):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, TOOL)])
|
||||
self.assertEqual(state["auto"], {app: TOOL})
|
||||
self.assertEqual(state["native"], [])
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
self.assertEqual(COMPAT["read_config_mapping"](str(config)), {"0": TOOL})
|
||||
finally:
|
||||
COMPAT["native_targets"] = original_native_targets
|
||||
@@ -485,6 +586,79 @@ console.log(JSON.stringify({ sent: sent.length, asked: asked.length }));
|
||||
"""
|
||||
|
||||
|
||||
class ToolPage(FakePage):
|
||||
def __init__(self, fail=False):
|
||||
super().__init__({"0": TOOL}, [TOOL])
|
||||
self.calls = []
|
||||
self.fail = fail
|
||||
|
||||
def tools(self, call):
|
||||
self.calls.append(call)
|
||||
if self.fail:
|
||||
raise RuntimeError("the client's install calls are not ready")
|
||||
return True
|
||||
|
||||
|
||||
class ToolDownloadTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
self.steam = Path(tmp.name) / "Steam"
|
||||
(self.steam / "steamapps").mkdir(parents=True)
|
||||
self.helper = LIVE["Helper"](str(self.steam), 1)
|
||||
self.now = [1000.0]
|
||||
self.running = [False]
|
||||
self.requested = []
|
||||
patcher = mock.patch.dict(COMPAT, {
|
||||
"game_running": lambda: self.running[0],
|
||||
"request_fex": lambda root, asked: self.requested.append(root) or ["3127680"],
|
||||
})
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
clock = mock.patch.object(LIVE["time"], "monotonic", lambda: self.now[0])
|
||||
clock.start()
|
||||
self.addCleanup(clock.stop)
|
||||
|
||||
def manifest(self, app, flags):
|
||||
(self.steam / ("steamapps/appmanifest_%s.acf" % app)).write_text('"AppState" { "StateFlags" "%s" }' % flags)
|
||||
|
||||
def test_missing_tools_are_installed_and_deferred_ones_queued(self):
|
||||
self.manifest("4427310", "6")
|
||||
self.manifest("3127680", "4")
|
||||
self.manifest("1628350", "1026")
|
||||
self.helper.page = page = ToolPage()
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(page.calls, ["update(4427310)", "update(1628350)", "install(4183110)"])
|
||||
self.now[0] += 30
|
||||
self.helper.ensure_tools()
|
||||
self.now[0] += 60
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(len(page.calls), 3)
|
||||
self.now[0] += 300
|
||||
self.manifest("4427310", "4")
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(page.calls[3:], ["update(1628350)", "install(4183110)"])
|
||||
self.assertEqual(self.requested, [])
|
||||
|
||||
def test_nothing_is_queued_while_a_game_runs(self):
|
||||
self.running[0] = True
|
||||
self.helper.page = page = ToolPage()
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(page.calls, [])
|
||||
self.running[0] = False
|
||||
self.now[0] += 60
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(len(page.calls), 4)
|
||||
|
||||
def test_an_install_falls_back_to_the_steam_url(self):
|
||||
for app in ("4427310", "1628350", "4183110"):
|
||||
self.manifest(app, "4")
|
||||
self.helper.page = page = ToolPage(fail=True)
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(page.calls, ["install(3127680)"])
|
||||
self.assertEqual(self.requested, [str(self.steam)])
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("node"), "node is not installed")
|
||||
class SwitchScriptTest(unittest.TestCase):
|
||||
def test_the_request_is_reported_and_still_sent(self):
|
||||
|
||||
@@ -121,7 +121,7 @@ class CompatLibrariesTest(unittest.TestCase):
|
||||
manifest(self.pc / "steamapps", 30)
|
||||
manifest(self.pc / "steamapps", 3127680, installdir="FEX")
|
||||
self.assertEqual(["20", "30"], COMPAT["installed_apps"](str(self.steam)))
|
||||
self.assertEqual(["1628350"], COMPAT["fex_missing"](str(self.steam)))
|
||||
self.assertEqual(["1628350", "4183110"], COMPAT["fex_missing"](str(self.steam)))
|
||||
|
||||
def test_newest_proton_across_libraries_wins(self):
|
||||
for root, build in ((self.steam, "100"), (self.pc, "200")):
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[1] / "linuxfs/fex/vulkanpin.c"
|
||||
THUNK = r"""
|
||||
#include <string.h>
|
||||
typedef struct { char extensionName[256]; unsigned int specVersion; } VkExtensionProperties;
|
||||
typedef void (*Function)(void);
|
||||
static const char *names[] = {"VK_KHR_surface", "VK_KHR_display", "VK_KHR_xlib_surface", "VK_EXT_direct_mode_display",
|
||||
"VK_KHR_get_display_properties2", "VK_EXT_swapchain_colorspace"};
|
||||
|
||||
int vkEnumerateInstanceExtensionProperties(const char *layer, unsigned int *count, VkExtensionProperties *properties)
|
||||
{
|
||||
unsigned int total = layer ? 0 : sizeof(names) / sizeof(names[0]);
|
||||
if (!properties) {
|
||||
*count = total;
|
||||
return 0;
|
||||
}
|
||||
unsigned int n = *count < total ? *count : total;
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
memset(&properties[i], 0, sizeof(properties[i]));
|
||||
strcpy(properties[i].extensionName, names[i]);
|
||||
properties[i].specVersion = i + 1;
|
||||
}
|
||||
*count = n;
|
||||
return n < total ? 5 : 0;
|
||||
}
|
||||
|
||||
int vkCreateInstance(void) { return 42; }
|
||||
|
||||
Function vkGetInstanceProcAddr(void *instance, const char *name)
|
||||
{
|
||||
(void)instance;
|
||||
if (!strcmp(name, "vkEnumerateInstanceExtensionProperties"))
|
||||
return (Function)vkEnumerateInstanceExtensionProperties;
|
||||
if (!strcmp(name, "vkCreateInstance"))
|
||||
return (Function)vkCreateInstance;
|
||||
if (!strcmp(name, "vkGetInstanceProcAddr"))
|
||||
return (Function)vkGetInstanceProcAddr;
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
GAME = r"""
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
typedef struct { char extensionName[256]; unsigned int specVersion; } VkExtensionProperties;
|
||||
typedef void (*Function)(void);
|
||||
typedef int (*Enumerate)(const char *, unsigned int *, VkExtensionProperties *);
|
||||
typedef Function (*ProcAddr)(void *, const char *);
|
||||
#ifdef LINKED
|
||||
int vkCreateInstance(void);
|
||||
Function vkGetInstanceProcAddr(void *, const char *);
|
||||
#endif
|
||||
|
||||
static void list(Enumerate enumerate)
|
||||
{
|
||||
VkExtensionProperties found[8];
|
||||
unsigned int count = 0;
|
||||
int result = enumerate(0, &count, 0);
|
||||
printf("count %u %d\n", count, result);
|
||||
enumerate(0, &count, found);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
printf("%s %u\n", found[i].extensionName, found[i].specVersion);
|
||||
count = 1;
|
||||
result = enumerate(0, &count, found);
|
||||
printf("short %u %d %s\n", count, result, found[0].extensionName);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#ifdef LINKED
|
||||
ProcAddr proc = vkGetInstanceProcAddr;
|
||||
printf("linked %d\n", vkCreateInstance());
|
||||
#else
|
||||
void *vulkan = dlopen("libvulkan.so.1", RTLD_NOW | RTLD_LOCAL);
|
||||
if (!vulkan)
|
||||
return 1;
|
||||
ProcAddr proc = (ProcAddr)dlsym(vulkan, "vkGetInstanceProcAddr");
|
||||
printf("same handle %d\n", dlopen("libvulkan.so", RTLD_NOW | RTLD_NOLOAD) == vulkan);
|
||||
printf("create %d\n", ((int (*)(void))dlsym(vulkan, "vkCreateInstance"))());
|
||||
list((Enumerate)dlsym(vulkan, "vkEnumerateInstanceExtensionProperties"));
|
||||
#endif
|
||||
printf("same proc %d create %d missing %d\n", proc(0, "vkGetInstanceProcAddr") == (Function)proc,
|
||||
((int (*)(void))proc(0, "vkCreateInstance"))(), proc(0, "vkNothing") == 0);
|
||||
list((Enumerate)proc(0, "vkEnumerateInstanceExtensionProperties"));
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
LISTED = """count 3 0
|
||||
VK_KHR_surface 1
|
||||
VK_KHR_xlib_surface 3
|
||||
VK_EXT_swapchain_colorspace 6
|
||||
short 1 5 VK_KHR_surface
|
||||
"""
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("gcc") and os.uname().machine == "x86_64", "needs gcc on an x86-64 host")
|
||||
class VulkanPinTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(shutil.rmtree, self.tmp, ignore_errors=True)
|
||||
|
||||
def gcc(self, *args):
|
||||
made = subprocess.run(["gcc"] + [str(a) for a in args], capture_output=True, text=True)
|
||||
self.assertEqual(made.returncode, 0, made.stderr)
|
||||
|
||||
def test_display_extensions_are_hidden_in_front_of_the_thunk(self):
|
||||
thunk = self.tmp / "usr/lib/libvulkan.so.1"
|
||||
thunk.parent.mkdir(parents=True)
|
||||
(self.tmp / "thunk.c").write_text(THUNK)
|
||||
self.gcc("-shared", "-fPIC", "-Wl,-soname,libvulkan.so.1", "-o", thunk, self.tmp / "thunk.c")
|
||||
stub = self.tmp / "stub/libvulkan.so.1"
|
||||
stub.parent.mkdir()
|
||||
self.gcc("-shared", "-nostdlib", "-Wl,-soname," + str(thunk), "-o", stub, "-x", "c", "/dev/null")
|
||||
pinned = self.tmp / "pin"
|
||||
pinned.mkdir()
|
||||
self.gcc("-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror", "-fvisibility=hidden", '-DVULKAN_THUNK="%s"' % thunk,
|
||||
"-Wl,-soname,libvulkan.so.1", "-Wl,-z,nodelete", "-Wl,--no-as-needed", "-o", pinned / "libvulkan.so.1",
|
||||
SOURCE, stub, "-ldl")
|
||||
os.symlink("libvulkan.so.1", pinned / "libvulkan.so")
|
||||
exported = subprocess.run(["nm", "-D", "--defined-only", pinned / "libvulkan.so.1"], capture_output=True, text=True)
|
||||
self.assertEqual(sorted(line.split()[-1] for line in exported.stdout.splitlines()),
|
||||
["vkEnumerateInstanceExtensionProperties", "vkGetInstanceProcAddr"])
|
||||
(self.tmp / "game.c").write_text(GAME)
|
||||
env = dict(os.environ, LD_LIBRARY_PATH=str(pinned))
|
||||
self.gcc("-o", self.tmp / "loader", self.tmp / "game.c", "-ldl")
|
||||
run = subprocess.run([self.tmp / "loader"], capture_output=True, text=True, env=env)
|
||||
self.assertEqual(run.returncode, 0, run.stderr)
|
||||
self.assertEqual(run.stdout, "same handle 1\ncreate 42\n" + LISTED + "same proc 1 create 42 missing 1\n" + LISTED)
|
||||
self.gcc("-DLINKED", "-o", self.tmp / "linked", self.tmp / "game.c", "-L", thunk.parent, "-l:libvulkan.so.1", "-ldl")
|
||||
run = subprocess.run([self.tmp / "linked"], capture_output=True, text=True, env=env)
|
||||
self.assertEqual(run.returncode, 0, run.stderr)
|
||||
self.assertEqual(run.stdout, "linked 42\nsame proc 1 create 42 missing 1\n" + LISTED)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user