mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
* FEX: emulate x86-64 ptrace, seccomp and /proc for anti-cheat launchers * Guest hook: route raw execve/execveat through the exec wrapper and pass self-sent SIGSYS to the program A program that execs with syscall(SYS_execveat, ...) bypassed the environment the guest needs, so re-executing /proc/self/exe died in the loader. /proc/self/exe now maps to the real program on exec as it already does on open. A SIGSYS the program queues itself, or one from a filter for another architecture, went to the Android-filter emulation instead of the program's handler. * FEX: list only guest mappings in /proc/<pid>/maps on hosts below 47 address bits Credit the anti-cheat emulation source in the patch header. * Preloads: leave poll, ppoll and select buffers untouched when no emulated device is open A bad user pointer now reaches the kernel and returns EFAULT instead of crashing the caller inside the wrapper. * Emulate only host-architecture seccomp traps in the guest hook; report the calling thread's seccomp mode in FEX's /proc/self/status A SIGSYS carrying another architecture's seccomp siginfo now takes its default action when the program has no handler, so a process whose emulated filter traps a syscall while SIGSYS is blocked or ignored dies as on Linux. * FEX: read the host status file through the raw openat syscall * README: credit StonkGuy's FEX anti-cheat emulation * FEX: open the host status file with a direct system call so preloads cannot rewrite it * FEX: hand a traced program's ptrace state across exec * Credit StonkGuy in the FEX anti-cheat patches and README Co-authored-by: StonkGuy <68372320+StonkGuy@users.noreply.github.com> * FEX: open guest paths with the raw openat system call so host preloads cannot replace the file * FEX: serve emulated proc files by the requested path when the host returns a memfd * FEX: map fixed guest memory above a small host address space Co-authored-by: StonkGuy <StonkGuy@users.noreply.github.com> * FEX: serve decoder reads from fixed guest memory above the host limit * Run games with anti-cheat files on an x86-64 DroidDeck-Proton under FEX The Proton launchers look for Easy Anti-Cheat or BattlEye bridge files in the game folder and, when an x86-64 DroidDeck-Proton and the matching Proton runtime are installed, hand the launch to that Proton under FEX with the game's own prefix. Picking the x86-64 tool directly also runs it under FEX. DROIDDECK_ANTICHEAT=off keeps a game on ARM64. * Keep x86-64 DroidDeck-Proton builds out of the ARM64 tool list * droiddeck-fex: take the runtime from an adopted tool's original manifest * FEX: show the guest command line when the argument area cannot be remapped * FEX: describe the container's procfs in emulated mount tables * FEX: order the anti-cheat series after the guest stack patch from main * Test the container procfs view of FEX's emulated mount tables * Docs: describe the anti-cheat signal mask fix and the container procfs view * README: match the StonkGuy credit to the renumbered FEX patches * Keep anti-cheat games on a tool the user chose instead of moving them to x86-64 * test(game-env): build the adopted-tool wrapper through extra_wrapper_sh * Check anti-cheat runtime bridges, apply component choices under FEX and honour MAP_FIXED_NOREPLACE above the host limit * Check the driver query is answered before each wrapper's call sites * Keep x86-64 Proton builds out of the automatic default tool * Keep high guest mappings intact when a fixed map or unmap fails Check room in the region table, splits included, before a fixed map or unmap removes anything, return the host munmap error without touching the table entry, and keep write-protecting low shared aliases of executable ranges that sit above the host address limit. * Keep a requested x86-64 default and accept linked anti-cheat runtimes A request for the current automatic x86-64 default now marks it as the app's choice, so the next settle no longer moves it back to ARM64. Anti-cheat runtime discovery follows a symlinked runtime directory. * Route anti-cheat games to x86-64 Proton only on a capable FEX The FEX build now lists its patches in share/fex-emu/.droiddeck-patches. Anti-cheat routing needs the fixed guest memory patch in that list and otherwise keeps the launch on ARM64, as an older FEX cannot map the anti-cheat helper buffer above the host address limit. Installing a FEX build without the list removes a list left by an earlier build. * Update FEX before deciding anti-cheat routing A device on an older FEX build never went through droiddeck-fex on the ARM64 path, so the catalog FEX was never installed and the gate kept anti-cheat games on ARM64 forever. dd_anticheat now runs the new droiddeck-fex update action first, which installs the catalog build under the same lock and retry window as other FEX launches. * Leave MAP_FIXED_NOREPLACE above the host limit to the host Wine finds the top of the address space with MAP_FIXED_NOREPLACE probes. Claiming those probes above a 39-bit host limit made Wine place its stacks in relocated memory, and every wineserver request then failed with EFAULT because the iovec buffers it passes to writev are nested pointers that are not translated. Only MAP_FIXED requests are relocated again, so the probes see the real host limit while fixed mappings above it keep working. * Translate only pointer syscall arguments into high guest memory Pointer arguments are now picked from a per-syscall layout table, so scalar values such as a truncate length are never rewritten. Sized buffers must map to one contiguous host range or the call fails with EFAULT, and new host backings are placed next to their guest neighbours so adjacent mappings stay contiguous. readv, writev and the preadv/pwritev family, sendmsg and recvmsg get a host-side copy of their iovec and msghdr with translated bases, leaving the guest copies untouched. Code invalidation for kernel writes maps the host buffer back to its guest address, and an unmap checks the table before it changes any host mapping. * Claim high guest memory only with LSE atomics and invalidate every code alias High guest mappings are claimed only when the JIT emits LSE atomics, and exclusive load/store instructions are never single-stepped, so an atomic on high memory cannot spin. A store into high code invalidates every mirror of the written page through the tracked mapping. madvise and mprotect on high memory apply to each region at its own host address. * Reject wrapping lengths and drop stale code on discarded high memory A nonzero length that wraps when page-aligned now fails madvise with EINVAL and mprotect with ENOMEM, as on Linux. Discarding advice on high memory invalidates translated code for the range whenever advice reached any region. * Add an end-to-end probe for guest memory above the host address limit * Emulate exclusive pairs on high guest memory and release failed host unmaps later * Size counted guest buffers by element and keep exclusive access within guest protection poll, ppoll, epoll waits, mmsg calls and select bitmaps now translate the whole array their count describes, so a buffer that crosses into an unrelated host range fails with EFAULT and oversized counts cannot wrap. High regions remember their protection through mprotect, splitting at the range edges, and exclusive stores to read-only pages or loads from inaccessible pages reach the guest as a fault instead of being emulated. * Refuse a high unmap when failed host unmaps could not all be retained UnmapLocked counts the overlapping regions before it changes anything and returns ENOMEM when the retired list could not hold all of them, so a host range is never dropped from tracking while still mapped. * Serve memory trim requests while syscall user dispatch blocks A thread that runs with syscall user dispatch on and its selector set to block (as x86-64 Wine does while in Windows code) took the trim signal with the selector still blocking. Every raw syscall the handler made was then dispatched to the program's SIGSYS handler, which either deadlocked the thread or killed the process when SIGSYS was blocked, so the session saw it as a deaf process and the game stalled during loading. Track the selector each thread registers through prctl, allow syscalls for the length of the handler and restore the selector before returning. * Allow syscalls for a forwarded prctl while dispatch blocks The prctl wrapper issues its syscall from the preload's own text, so a thread whose selector blocks got SIGSYS where the plain libc call would have been dispatched the same way by the caller's own rules. Allow syscalls for the forwarded call and restore the selector afterwards. The dispatch test now waits until the selector blocks before it sends the trim request, and checks a prctl call made while it blocks. * Merge high regions after protection changes and translate message batches Protect now merges neighbouring high regions whose guest and host ranges touch and whose protection and code state match, so toggling page protections no longer fills the region table. Exclusive loads on high memory accept write-only pages and exclusive stores need only PROT_WRITE, matching x86-64 where writable pages are readable. sendmmsg and recvmmsg translate the name, control and io vectors of every message in the batch, return msg_len for each processed message and the received header fields for recvmmsg. Counted arrays passed to getgroups, setgroups, semop, semtimedop, io_submit, io_getevents, io_pgetevents, move_pages, futex_waitv and listmount are now checked to stay within one host range. The unused ToHost helper is removed. * Translate fixed-size, string and in-array guest pointers in high memory Give every syscall pointer without a length a fixed x86-64 size, a length read through another argument, or a terminator scan for strings, so spans crossing separately backed regions are refused before the kernel sees them. Size message queue buffers as the type word plus msgsz. Translate io_submit control blocks and their buffers, including vectored reads and writes, through bounded host copies, restore the guest words afterwards, and report guest iocb addresses back from io_getevents. Translate move_pages page lists for the calling process and futex_waitv addresses. Merge new mappings with matching neighbours. * Size high-memory syscall spans by kernel widths and embedded sizes Read counts with the width the kernel uses for each argument, so int and unsigned int counts ignore the upper register bits and negative counts reach the handler. Size capability data by its header version, perf and scheduler attributes, file handles and mount requests by their own size fields, and landlock rules by rule type. Keep the translated prefix of a message batch, read headers that span separate backings one by one, write results back through the current guest mapping, and stop counting messages whose length cannot be stored. Revisit an entry moved into an earlier slot while merging regions. Give newer syscalls fallback numbers in the test harness. * Send translated message batches one message at a time Submit sendmmsg batches that need scratch headers one message per call, storing each length before the next message goes out, so a length that cannot be stored stops the batch where Linux would. Skip the name length when no name was given and store flags before the control length. Check the whole fixed file-handle header even when its size is invalid. Hand capget and capset a private header so the checked data size matches the version the kernel reads, and return a rewritten version to the guest. Patch and restore AIO control blocks under the mapping lock and restore only the block that was patched. * Harden high-memory aio, capability and message batch write-backs Restore patched aio buffers through /proc/self/mem when the control block became read-only and keep the scratch vectors alive if that fails too, fault capability calls whose header write-back fails, stop send batches after a short message, and pin the batch socket with a private dup. * Pin batch sockets, fall back to whole batches and reconcile pending aio restores Follow-up message sends and the first dispatch share one duplicated socket. When it cannot be duplicated, the whole translated batch goes to the kernel in one call and lengths are written back up to the first one that cannot be stored. Short sends compare against the iovec lengths given to the kernel. Unrestorable aio_buf edits, including unreadable control blocks, keep their storage in a bounded list that later submissions reconcile. * Stop message batches at unreadable vectors, send singly without a spare descriptor and reserve aio restore slots A message whose iovec snapshot cannot be taken ends the prepared batch instead of being sent with an unknown length; when it is the first message the kernel handles the original array natively. When the batch socket cannot be duplicated, messages still go one at a time on the original descriptor with each length written before the next send. Pending aio restore slots are reserved under the pending mutex before the first guest edit and released or handed to the pending record, so concurrent submissions cannot exceed the bound. Tests use a real socket pair, injected descriptor exhaustion and concurrent reservations. * Send only the first message of a batch when the socket cannot be pinned * Replay high-memory faults over the whole access and reconcile aio restores on unmap * Keep high-memory traps ordered, fault-exact and locked against unmap Protect, Map and low mmap/munmap/mremap/mprotect reconcile pending aio restores at once, and io_submit reconciles them even when no high region is mapped. Ordered loads and stores split across backings are emulated between full fences instead of being byte-copied through the trampoline; atomics and exclusives are still refused. Gather and scatter use fault-safe copies, and a failing piece is re-faulted at the guest instruction through a probe load, with SIGBUS redelivered the same way. The VMA lock is held from planning until the scatter finishes, so unmap and protect cannot race a resumed access. Sign-extending loads are no longer classified as writes. * Defer user signals while guest high memory mappings are held Only the trampoline breakpoint completes a replay, user-sent SIGSEGV, SIGBUS and SIGTRAP raised while the mapping lock is held are requeued after it is released, and stranded control block words are restored when their page turns readable again. The harness now runs under a timeout. * Rebase the FEX patch series onto FEX-2612 * FEX: restore stranded aio words before readable protection, report failures Restore every pending aio word in the range before a readable guest protection is applied, on both the high and low paths, and fail the guest mprotect with the old protection kept when a word cannot be restored or its window cannot be closed. Ignore user-sent SIGSEGV/SIGBUS after deferral, read the cleared syscall info when resuming with guest GPRs and on restore, and check exclusive acquisition from a separate thread in the harness. * FEX: submit aio control blocks through private host copies Stop editing guest IOCBs in place when aio_buf needs translation. io_submit now hands the kernel a host copy of each such control block, maps io_event.obj back to the guest pointer when the completion is reaped, redirects io_cancel by guest pointer and context to the copy, and frees copies on reap, on io_destroy, or when the kernel did not accept them. The guest control block is never patched and its protection is never touched, so the pending restore records, the protection windows and the restore hooks in mmap, munmap, mremap and mprotect are removed with their tests. * fex: keep aio keys, cancels and reaped events native for copied control blocks Guest aio_key is no longer cleared before dispatch: the slot is probed with a same-value write and only the first n accepted copies get key 0 after the host io_submit returns n. io_cancel redirects to a copy only when the guest block is readable and its key is 0, so unreadable blocks fault in the kernel as before. io_getevents and io_pgetevents reap into emulator storage, translate and release copies there, then copy the events out, returning -EFAULT if that fails. A successful io_setup clears the ring header magic so userspace ring reapers fall back to io_getevents, where copies are translated and released. * fex: leave aio rejections, keys and unwritable event buffers to the kernel A copied control block whose key slot is read-only is now passed to the kernel as the guest's own block at the end of the list, so the kernel reports its native fd, eventfd or key error. After io_submit, guest keys follow the private copies through the first rejected position, and they are stored through a fresh translation of the guest address, skipped when it no longer maps. io_getevents and io_pgetevents probe the guest event buffer and reap at most its writable prefix, handing an unwritable buffer to the kernel so completions are not consumed. * Kept AIO completions and key stores stable against sibling remaps Wrapped event buffers go to the kernel unchanged. Direct reaps report guest control blocks and release copies only after the store lands. Guest stores and reads hold the mapping lock across translation and copy. Completions whose copy-out fails are stashed per context and delivered first on the next reap, and dropped on io_destroy. * fex: stage every AIO reap and keep stashed completions recoverable Hold the guest mapping for every high address, restore the caller's signal mask after thread-context holds, replace the fixed event stash with a per-context table that reserves space before dispatch, stage all reaps so control block identities are translated before copy-out, keep collecting ready completions once the stash meets min_nr, and restash events on every error except an interrupted delivery or a destroyed context. * fex: own AIO recovery storage before dispatch and bind it to the context lifetime Allocate the recovery node with the event buffer before the kernel consumes completions and hand the buffer itself to the stash when copy-out fails, so settling never allocates. Track each context by a generation that io_setup advances, so a destroy that finishes after a replacement context reuses the ring address only releases the old context's copies and stash. Drop the reservation cap so blocking reaps keep their min_nr. * fex: publish AIO contexts from private storage, keep their generation, wake blocked reapers for stashed completions * fex: wait for AIO events in bounded slices instead of wake markers, roll back setup by its own generation, fault unreadable io_setup output Blocked reapers wait in the kernel for at most 20 ms at a time and take stashed completions between waits until the guest minimum or timeout is met, so no eventfd or io_submit notification is needed. Deferred signals end the wait like EINTR. io_setup rollback uses the generation BeginContext installed, and an unreadable context output returns -EFAULT before dispatch. --------- Co-authored-by: StonkGuy <68372320+StonkGuy@users.noreply.github.com> Co-authored-by: StonkGuy <StonkGuy@users.noreply.github.com>
4173 lines
249 KiB
Python
4173 lines
249 KiB
Python
import contextlib
|
|
import fcntl
|
|
import hashlib
|
|
import io
|
|
import json
|
|
import os
|
|
import shutil
|
|
from pathlib import Path
|
|
import runpy
|
|
import shlex
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import threading
|
|
from unittest import mock
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
|
MODULE = runpy.run_path(str(BIN / "droiddeck-game-env"))
|
|
COMPAT = runpy.run_path(str(BIN / "steam-compatibility"))
|
|
STATE = tempfile.TemporaryDirectory()
|
|
COMPAT["main"].__globals__["COMPAT_DIR"] = STATE.name
|
|
|
|
|
|
class ProducerAcquireGameEnvironmentTest(unittest.TestCase):
|
|
def test_prefixed_opt_in_enters_only_the_game_environment(self):
|
|
key = "DROIDDECK_GAME_FRAME_ACQUIRE"
|
|
scope = MODULE["GAME_PREFIX"] + key
|
|
self.assertEqual({}, MODULE["game_gpu"]({scope: "1"}, keep=True))
|
|
self.assertEqual({key: "1"}, MODULE["game_gpu"]({scope: "1"}))
|
|
self.assertEqual({}, MODULE["game_gpu"]({key: "1", scope: ""}))
|
|
self.assertEqual({}, MODULE["game_gpu"]({}))
|
|
|
|
|
|
class SupergiantDotnetReporterTest(unittest.TestCase):
|
|
def test_allows_the_builtin_mscoree_for_supergiant_reporter(self):
|
|
game = mock.Mock(files={"basecampbugreporter.native.dll"})
|
|
self.assertEqual(
|
|
({"WINEDLLOVERRIDES": "mscoree=n,b"}, [], "Supergiant: allow the builtin mscoree"),
|
|
MODULE["supergiant_dotnet_reporter"](game),
|
|
)
|
|
|
|
def test_ignores_games_without_the_supergiant_reporter(self):
|
|
game = mock.Mock(files={"enginewin64s.dll"})
|
|
self.assertIsNone(MODULE["supergiant_dotnet_reporter"](game))
|
|
|
|
|
|
class DeathStrandingAllocatorTest(unittest.TestCase):
|
|
def make_exe(self, name="ds.exe", size=None, window=None, tail=None):
|
|
folder = tempfile.mkdtemp()
|
|
self.addCleanup(shutil.rmtree, folder, True)
|
|
path = os.path.join(folder, name)
|
|
with open(path, "wb") as game:
|
|
game.truncate(MODULE["DS_SIZE"] if size is None else size)
|
|
game.seek(MODULE["DS_WINDOW_OFFSET"] - 1)
|
|
game.write(b"<" + (MODULE["DS_WINDOW"] if window is None else window) + (MODULE["DS_ORIGINAL"] if tail is None else tail) + b">")
|
|
return path
|
|
|
|
def read_tail(self, path):
|
|
with open(path, "rb") as game:
|
|
game.seek(MODULE["DS_WINDOW_OFFSET"] - 1)
|
|
return game.read(len(MODULE["DS_WINDOW"]) + len(MODULE["DS_ORIGINAL"]) + 2)
|
|
|
|
def run_fix(self, path, app_id="1850570"):
|
|
errors = io.StringIO()
|
|
with mock.patch("sys.stderr", errors):
|
|
return MODULE["death_stranding_allocator"](app_id, path), errors.getvalue()
|
|
|
|
def test_window_and_patch_have_the_measured_shape(self):
|
|
self.assertEqual(41, len(MODULE["DS_WINDOW"]))
|
|
self.assertEqual(6, len(MODULE["DS_ORIGINAL"]))
|
|
self.assertEqual(6, len(MODULE["DS_FIXED"]))
|
|
self.assertEqual(0x38FE1B9, MODULE["DS_WINDOW_OFFSET"] + len(MODULE["DS_WINDOW"]))
|
|
|
|
def test_replaces_only_the_jump_in_the_original_build(self):
|
|
path = self.make_exe()
|
|
patched, message = self.run_fix(path)
|
|
self.assertTrue(patched)
|
|
self.assertIn("Death Stranding", message)
|
|
self.assertEqual(b"<" + MODULE["DS_WINDOW"] + MODULE["DS_FIXED"] + b">", self.read_tail(path))
|
|
self.assertEqual(MODULE["DS_SIZE"], os.path.getsize(path))
|
|
|
|
def test_an_already_patched_game_is_left_alone(self):
|
|
path = self.make_exe(tail=MODULE["DS_FIXED"])
|
|
before = os.stat(path).st_mtime_ns
|
|
self.assertEqual((False, ""), self.run_fix(path))
|
|
self.assertEqual(before, os.stat(path).st_mtime_ns)
|
|
self.assertEqual(b"<" + MODULE["DS_WINDOW"] + MODULE["DS_FIXED"] + b">", self.read_tail(path))
|
|
|
|
def test_a_second_run_changes_nothing(self):
|
|
path = self.make_exe()
|
|
self.assertTrue(self.run_fix(path)[0])
|
|
after_first = self.read_tail(path)
|
|
self.assertEqual((False, ""), self.run_fix(path))
|
|
self.assertEqual(after_first, self.read_tail(path))
|
|
|
|
def test_other_builds_of_the_game_are_not_touched(self):
|
|
for size, window in ((MODULE["DS_SIZE"] + 1, None), (None, bytes(len(MODULE["DS_WINDOW"])))):
|
|
path = self.make_exe(size=size, window=window)
|
|
before = self.read_tail(path)
|
|
self.assertEqual((False, ""), self.run_fix(path))
|
|
self.assertEqual(before, self.read_tail(path))
|
|
|
|
def test_an_unknown_instruction_at_the_patch_site_is_not_touched(self):
|
|
path = self.make_exe(tail=bytes.fromhex("0f85a6000000"))
|
|
before = self.read_tail(path)
|
|
self.assertEqual((False, ""), self.run_fix(path))
|
|
self.assertEqual(before, self.read_tail(path))
|
|
|
|
def test_other_executables_are_ignored(self):
|
|
path = self.make_exe(name="game.exe")
|
|
before = self.read_tail(path)
|
|
self.assertEqual((False, ""), self.run_fix(path))
|
|
self.assertEqual(before, self.read_tail(path))
|
|
|
|
def test_other_games_are_not_touched_even_with_a_matching_file(self):
|
|
for app_id in ("440", "", None):
|
|
path = self.make_exe()
|
|
before = self.read_tail(path)
|
|
self.assertEqual((False, ""), self.run_fix(path, app_id))
|
|
self.assertEqual(before, self.read_tail(path))
|
|
|
|
def test_both_death_stranding_app_ids_are_patched(self):
|
|
for app_id in ("1850570", "1190460"):
|
|
self.assertTrue(self.run_fix(self.make_exe(), app_id)[0])
|
|
|
|
def test_the_file_name_check_ignores_case(self):
|
|
self.assertTrue(self.run_fix(self.make_exe(name="DS.EXE"))[0])
|
|
|
|
def test_a_missing_game_file_is_reported_without_raising(self):
|
|
patched, message = self.run_fix(os.path.join(tempfile.gettempdir(), "droiddeck-no-such-folder", "ds.exe"))
|
|
self.assertFalse(patched)
|
|
self.assertIn("not applied", message)
|
|
|
|
|
|
def mapping_of(text):
|
|
tokens = COMPAT["tokenize"](text)
|
|
return COMPAT["read_mapping"](tokens, COMPAT["mapping_block"](tokens))
|
|
|
|
|
|
def config_text(entries):
|
|
mapping = "".join('"%s" { "name" "%s" "config" "" "priority" "%s" }' % (app, name, "75" if app == "0" else "250") for app, name in entries)
|
|
return '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }' % mapping
|
|
|
|
|
|
class RenderPathDefaultsTest(unittest.TestCase):
|
|
DRIVER = "/drivers/DD-Turnip_v0.4.0/icd.json"
|
|
COMMAND = ["proton", "waitforexitandrun", "/games/Spintires/SpinTires.exe"]
|
|
|
|
def apply(self, env=None, command=None, model="Adreno722", library="libvulkan_freedreno.so"):
|
|
env = dict({"VK_DRIVER_FILES": self.DRIVER} if env is None else env)
|
|
manifest = json.dumps({"ICD": {"library_path": library}})
|
|
with mock.patch.object(Path, "read_text", return_value=model), \
|
|
mock.patch.object(Path, "is_file", return_value=False), \
|
|
mock.patch("builtins.open", mock.mock_open(read_data=manifest)):
|
|
note = MODULE["render_path_defaults"](command or self.COMMAND, env)
|
|
return env, note
|
|
|
|
def test_tested_render_path_keeps_other_options(self):
|
|
env, note = self.apply({"VK_DRIVER_FILES": self.DRIVER, "DXVK_CONFIG": "d3d9.maxFrameLatency = 2; ", "CUSTOM": "kept"})
|
|
self.assertEqual(env["DXVK_CONFIG"], "d3d9.maxFrameLatency = 2; dxvk.tilerMode = False")
|
|
self.assertEqual(env["CUSTOM"], "kept")
|
|
self.assertIsNotNone(note)
|
|
self.assertEqual(self.apply()[0]["DXVK_CONFIG"], "dxvk.tilerMode = False")
|
|
self.assertIsNotNone(self.apply({"VK_ICD_FILENAMES": self.DRIVER})[1])
|
|
|
|
def test_other_games_devices_and_drivers_keep_their_environment(self):
|
|
for changes in (
|
|
{"command": ["proton", "waitforexitandrun", "/games/MudRunner.exe"]},
|
|
{"command": ["proton", "run", self.COMMAND[2]]},
|
|
{"command": ["proton"]},
|
|
{"model": "Adreno740"},
|
|
{"model": "Mali-G715"},
|
|
{"library": "libvulkan.so"},
|
|
{"env": {}},
|
|
{"env": {"VK_DRIVER_FILES": "/drivers/new-turnip/icd.json"}},
|
|
{"env": {"VK_DRIVER_FILES": "", "VK_ICD_FILENAMES": self.DRIVER}},
|
|
):
|
|
with self.subTest(changes=changes):
|
|
env, note = self.apply(**changes)
|
|
self.assertIsNone(note)
|
|
self.assertNotIn("DXVK_CONFIG", env)
|
|
|
|
def test_explicit_environment_and_config_files_take_precedence(self):
|
|
for value in ("dxvk.tilerMode = Auto", "d3d9.maxFrameLatency = 1; dxvk.tilerMode=True", "dxvk.tilerMode = False"):
|
|
env, note = self.apply({"VK_DRIVER_FILES": self.DRIVER, "DXVK_CONFIG": value})
|
|
self.assertIsNone(note)
|
|
self.assertEqual(env["DXVK_CONFIG"], value)
|
|
env, note = self.apply({"VK_DRIVER_FILES": self.DRIVER, "DXVK_CONFIG_FILE": "/games/custom.conf"})
|
|
self.assertIsNone(note)
|
|
self.assertNotIn("DXVK_CONFIG", env)
|
|
with mock.patch.object(Path, "is_file", return_value=True):
|
|
env = {"VK_DRIVER_FILES": self.DRIVER}
|
|
self.assertIsNone(MODULE["render_path_defaults"](self.COMMAND, env))
|
|
self.assertNotIn("DXVK_CONFIG", env)
|
|
|
|
def test_unreadable_or_invalid_driver_metadata_leaves_launch_unchanged(self):
|
|
for data in ("not-json", "{}", '{"ICD":{"library_path":null}}'):
|
|
with mock.patch.object(Path, "read_text", return_value="Adreno722"), \
|
|
mock.patch.object(Path, "is_file", return_value=False), \
|
|
mock.patch("builtins.open", mock.mock_open(read_data=data)):
|
|
env = {"VK_DRIVER_FILES": self.DRIVER}
|
|
self.assertIsNone(MODULE["render_path_defaults"](self.COMMAND, env))
|
|
self.assertNotIn("DXVK_CONFIG", env)
|
|
with mock.patch.object(Path, "read_text", side_effect=PermissionError), \
|
|
mock.patch.object(Path, "is_file", return_value=False):
|
|
self.assertIsNone(MODULE["render_path_defaults"](self.COMMAND, {"VK_DRIVER_FILES": self.DRIVER}))
|
|
|
|
|
|
class DirtTelemetryFixTest(unittest.TestCase):
|
|
SHOWDOWN_ON = '<x><motion enabled="true" ip="127.0.0.1" port="20777" delay="1" extradata="3" /></x>'
|
|
SHOWDOWN_DEFAULT = '<x><motion enabled="true" ip="dbox" port="20777" delay="1" extradata="0" /></x>'
|
|
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
root = Path(self.tmp.name)
|
|
self.prefix = root / "compatdata/2848447563"
|
|
self.proton = root / "Proton/proton"
|
|
self.own = root / "Proton/files/lib/wine/i386-windows/ws2_32.dll"
|
|
self.own.parent.mkdir(parents=True)
|
|
self.own.write_bytes(b"MZ wine ws2_32")
|
|
self.proton.write_text("")
|
|
self.target = self.prefix / "pfx/drive_c/windows/syswow64/ws2_32.dll"
|
|
self.target.parent.mkdir(parents=True)
|
|
self.target.symlink_to(self.own)
|
|
self.stand_in = root / "droiddeck-dirt/ws2_32.dll"
|
|
self.stand_in.parent.mkdir()
|
|
self.stand_in.write_bytes(b"MZ droiddeck-dirt-ws2_32 stand-in")
|
|
self.patch = mock.patch.dict(MODULE["dirt_ws2_wanted"].__globals__, {"DIRT_WS2": str(self.stand_in)})
|
|
self.patch.start()
|
|
|
|
def tearDown(self):
|
|
self.patch.stop()
|
|
self.tmp.cleanup()
|
|
|
|
def config(self, folder, text):
|
|
path = self.prefix / "pfx/drive_c/users/steamuser/Documents/My Games" / folder / "hardwaresettings/hardware_settings_config.xml"
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(text)
|
|
|
|
def command(self, exe="showdown.exe"):
|
|
return [str(self.proton), "waitforexitandrun", "/root/Storage/games/DiRT Showdown/" + exe]
|
|
|
|
def env(self):
|
|
return {"STEAM_COMPAT_DATA_PATH": str(self.prefix)}
|
|
|
|
def test_telemetry_counts_as_on_when_the_game_sends_somewhere(self):
|
|
self.config("DiRT Showdown", self.SHOWDOWN_DEFAULT)
|
|
self.assertFalse(MODULE["dirt_telemetry_on"](self.prefix, "dirtshowdown"))
|
|
self.config("DiRT Showdown", self.SHOWDOWN_ON)
|
|
self.assertTrue(MODULE["dirt_telemetry_on"](self.prefix, "dirtshowdown"))
|
|
self.config("DiRT Showdown", self.SHOWDOWN_ON.replace('enabled="true"', 'enabled="false"'))
|
|
self.assertFalse(MODULE["dirt_telemetry_on"](self.prefix, "dirtshowdown"))
|
|
self.config("DiRT3", '<x><motion enabled="true" ip="192.168.1.20" port="20777" /></x>')
|
|
self.assertTrue(MODULE["dirt_telemetry_on"](self.prefix, "dirt3"))
|
|
|
|
def test_stand_in_is_wanted_only_for_the_dirt_games_with_telemetry_on_and_a_proton_without_the_fix(self):
|
|
wanted = MODULE["dirt_ws2_wanted"]
|
|
self.config("DiRT Showdown", self.SHOWDOWN_DEFAULT)
|
|
self.assertIsNone(wanted(self.command(), self.env()))
|
|
self.config("DiRT Showdown", self.SHOWDOWN_ON)
|
|
self.assertEqual(wanted(self.command(), self.env()), str(self.prefix))
|
|
self.assertEqual(wanted(self.command("Showdown_AVX.exe"), self.env()), str(self.prefix))
|
|
self.assertIsNone(wanted(self.command("DiRTRally2.exe"), self.env()))
|
|
self.own.write_bytes(b"MZ wine ws2_32 " + "showdown_avx.exe".encode("utf-16-le"))
|
|
self.assertIsNone(wanted(self.command(), self.env()))
|
|
|
|
def test_swap_keeps_the_prefix_link_and_restore_puts_it_back(self):
|
|
MODULE["swap_dirt_ws2"](self.prefix)
|
|
saved = self.target.with_name("ws2_32.dll.droiddeck-original")
|
|
self.assertFalse(self.target.is_symlink())
|
|
self.assertEqual(self.target.read_bytes(), self.stand_in.read_bytes())
|
|
self.assertEqual(os.readlink(saved), str(self.own))
|
|
self.assertEqual(self.own.read_bytes(), b"MZ wine ws2_32")
|
|
MODULE["swap_dirt_ws2"](self.prefix)
|
|
self.assertEqual(os.readlink(saved), str(self.own))
|
|
self.assertTrue(MODULE["restore_dirt_ws2"](self.prefix, self.proton))
|
|
self.assertEqual(os.readlink(self.target), str(self.own))
|
|
self.assertFalse(os.path.lexists(saved))
|
|
self.assertFalse(MODULE["restore_dirt_ws2"](self.prefix, self.proton))
|
|
|
|
def test_restore_keeps_a_file_proton_put_back_meanwhile(self):
|
|
MODULE["swap_dirt_ws2"](self.prefix)
|
|
newer = self.own.with_name("ws2_32-newer.dll")
|
|
newer.write_bytes(b"MZ newer wine ws2_32")
|
|
self.target.unlink()
|
|
self.target.symlink_to(newer)
|
|
self.assertFalse(MODULE["restore_dirt_ws2"](self.prefix, self.proton))
|
|
self.assertEqual(os.readlink(self.target), str(newer))
|
|
self.assertFalse(os.path.lexists(self.target.with_name("ws2_32.dll.droiddeck-original")))
|
|
|
|
def test_after_a_proton_switch_the_running_protons_file_goes_back(self):
|
|
MODULE["swap_dirt_ws2"](self.prefix)
|
|
other = Path(self.tmp.name) / "GE-Proton/proton"
|
|
other_own = other.parent / "files/lib/wine/i386-windows/ws2_32.dll"
|
|
other_own.parent.mkdir(parents=True)
|
|
other_own.write_bytes(b"MZ GE wine ws2_32")
|
|
other.write_text("")
|
|
self.assertTrue(MODULE["restore_dirt_ws2"](self.prefix, other))
|
|
self.assertEqual(os.readlink(self.target), str(other_own))
|
|
self.assertFalse(os.path.lexists(self.target.with_name("ws2_32.dll.droiddeck-original")))
|
|
|
|
def test_restore_follows_a_proton_reached_through_a_linked_folder(self):
|
|
MODULE["swap_dirt_ws2"](self.prefix)
|
|
pack = Path(self.tmp.name) / "pack"
|
|
(pack / "files/lib/wine").mkdir(parents=True)
|
|
(pack / "files/lib/wine/i386-windows").symlink_to(self.own.parent)
|
|
(pack / "proton").write_text("")
|
|
self.assertTrue(MODULE["restore_dirt_ws2"](self.prefix, pack / "proton"))
|
|
self.assertEqual(os.readlink(self.target), str(self.own))
|
|
|
|
def test_a_stand_in_left_without_the_saved_link_is_replaced_by_protons_own_file(self):
|
|
self.target.unlink()
|
|
self.target.write_bytes(self.stand_in.read_bytes())
|
|
self.assertTrue(MODULE["restore_dirt_ws2"](self.prefix, self.proton))
|
|
self.assertEqual(os.readlink(self.target), str(self.own))
|
|
|
|
def test_launch_swaps_the_stand_in_in_for_the_game_and_back_afterwards(self):
|
|
self.config("DiRT Showdown", self.SHOWDOWN_ON)
|
|
self.proton.write_text("#!" + sys.executable + "\nimport os, sys\n"
|
|
"target = os.path.join(os.environ['STEAM_COMPAT_DATA_PATH'], 'pfx/drive_c/windows/syswow64/ws2_32.dll')\n"
|
|
"print(os.environ.get('WINEDLLOVERRIDES', ''))\n"
|
|
"print(os.path.islink(target), b'droiddeck-dirt-ws2_32' in open(target, 'rb').read())\n")
|
|
self.proton.chmod(0o755)
|
|
runner = Path(self.tmp.name) / "run.py"
|
|
runner.write_text("import runpy, sys\nmain = runpy.run_path(sys.argv[1])['main']\nmain.__globals__['DIRT_WS2'] = sys.argv[2]\n"
|
|
"sys.argv = [sys.argv[1]] + sys.argv[3:]\nsys.exit(main())\n")
|
|
home = Path(self.tmp.name) / "home"
|
|
home.mkdir()
|
|
result = subprocess.run([sys.executable, str(runner), str(BIN / "droiddeck-game-env"), str(self.stand_in), *self.command()],
|
|
env={**os.environ, "HOME": str(home), "STEAM_COMPAT_DATA_PATH": str(self.prefix)}, text=True, capture_output=True)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
overrides, state = result.stdout.splitlines()[-2:]
|
|
self.assertIn("ws2_32=n,b", overrides.split(";"))
|
|
self.assertEqual(state, "False True")
|
|
self.assertIn("DiRT telemetry fix: ws2_32 stand-in", result.stderr)
|
|
self.assertEqual(os.readlink(self.target), str(self.own))
|
|
self.assertFalse(os.path.lexists(self.target.with_name("ws2_32.dll.droiddeck-original")))
|
|
|
|
def test_a_proton_that_cannot_start_leaves_the_prefix_as_it_was(self):
|
|
self.config("DiRT Showdown", self.SHOWDOWN_ON)
|
|
self.proton.write_text("not a program")
|
|
self.proton.chmod(0o644)
|
|
runner = Path(self.tmp.name) / "run.py"
|
|
runner.write_text("import runpy, sys\nmain = runpy.run_path(sys.argv[1])['main']\nmain.__globals__['DIRT_WS2'] = sys.argv[2]\n"
|
|
"sys.argv = [sys.argv[1]] + sys.argv[3:]\nsys.exit(main())\n")
|
|
home = Path(self.tmp.name) / "home"
|
|
home.mkdir()
|
|
result = subprocess.run([sys.executable, str(runner), str(BIN / "droiddeck-game-env"), str(self.stand_in), *self.command()],
|
|
env={**os.environ, "HOME": str(home), "STEAM_COMPAT_DATA_PATH": str(self.prefix)}, text=True, capture_output=True)
|
|
self.assertNotEqual(result.returncode, 0)
|
|
self.assertIn("DiRT telemetry fix: ws2_32 stand-in", result.stderr)
|
|
self.assertEqual(os.readlink(self.target), str(self.own))
|
|
self.assertFalse(os.path.lexists(self.target.with_name("ws2_32.dll.droiddeck-original")))
|
|
|
|
def test_launch_with_telemetry_off_leaves_the_prefix_alone(self):
|
|
self.config("DiRT Showdown", self.SHOWDOWN_DEFAULT)
|
|
self.proton.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ.get('WINEDLLOVERRIDES', ''))\n")
|
|
self.proton.chmod(0o755)
|
|
home = Path(self.tmp.name) / "home"
|
|
home.mkdir()
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), *self.command()],
|
|
env={**os.environ, "HOME": str(home), "STEAM_COMPAT_DATA_PATH": str(self.prefix)}, text=True, capture_output=True)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
self.assertNotIn("ws2_32=n,b", result.stdout)
|
|
self.assertEqual(os.readlink(self.target), str(self.own))
|
|
|
|
def test_a_failed_put_back_does_not_end_the_launch_with_an_error(self):
|
|
def fail():
|
|
raise OSError(28, "No space left on device")
|
|
stderr = io.StringIO()
|
|
with mock.patch("sys.stderr", stderr):
|
|
code = MODULE["start"]([sys.executable, "-c", "raise SystemExit(0)"], dict(os.environ), None, fail)
|
|
self.assertEqual(code, 0)
|
|
self.assertIn("not put back", stderr.getvalue())
|
|
|
|
def test_a_half_done_swap_is_put_back(self):
|
|
saved = self.target.with_name("ws2_32.dll.droiddeck-original")
|
|
os.replace(self.target, saved)
|
|
self.assertTrue(MODULE["restore_dirt_ws2"](self.prefix, self.proton))
|
|
self.assertEqual(os.readlink(self.target), str(self.own))
|
|
self.assertFalse(os.path.lexists(saved))
|
|
|
|
def test_a_native_ws2_32_goes_back_as_it_was_after_a_proton_switch(self):
|
|
self.target.unlink()
|
|
self.target.write_bytes(b"MZ a mod's own ws2_32")
|
|
MODULE["swap_dirt_ws2"](self.prefix)
|
|
other = Path(self.tmp.name) / "GE-Proton/proton"
|
|
(other.parent / "files/lib/wine/i386-windows").mkdir(parents=True)
|
|
(other.parent / "files/lib/wine/i386-windows/ws2_32.dll").write_bytes(b"MZ GE wine ws2_32")
|
|
other.write_text("")
|
|
self.assertTrue(MODULE["restore_dirt_ws2"](self.prefix, other))
|
|
self.assertFalse(self.target.is_symlink())
|
|
self.assertEqual(self.target.read_bytes(), b"MZ a mod's own ws2_32")
|
|
|
|
def test_a_link_to_a_mods_ws2_32_goes_back_as_it_was(self):
|
|
mod = Path(self.tmp.name) / "mods/ws2_32.dll"
|
|
mod.parent.mkdir()
|
|
mod.write_bytes(b"MZ a mod's ws2_32")
|
|
self.target.unlink()
|
|
self.target.symlink_to(mod)
|
|
MODULE["swap_dirt_ws2"](self.prefix)
|
|
other = Path(self.tmp.name) / "GE-Proton/proton"
|
|
(other.parent / "files/lib/wine/i386-windows").mkdir(parents=True)
|
|
(other.parent / "files/lib/wine/i386-windows/ws2_32.dll").write_bytes(b"MZ GE wine ws2_32")
|
|
other.write_text("")
|
|
self.assertTrue(MODULE["restore_dirt_ws2"](self.prefix, other))
|
|
self.assertEqual(os.readlink(self.target), str(mod))
|
|
|
|
def test_start_gives_the_signal_handlers_back(self):
|
|
import signal
|
|
before = {s: signal.getsignal(s) for s in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP)}
|
|
MODULE["start"]([sys.executable, "-c", "pass"], dict(os.environ), None, lambda: None)
|
|
self.assertEqual(before, {s: signal.getsignal(s) for s in before})
|
|
|
|
def test_start_puts_the_file_back_after_the_game_exits(self):
|
|
calls = []
|
|
code = MODULE["start"]([sys.executable, "-c", "raise SystemExit(3)"], dict(os.environ), None, lambda: calls.append("restored"))
|
|
self.assertEqual(code, 3)
|
|
self.assertEqual(calls, ["restored"])
|
|
with self.assertRaises(OSError):
|
|
MODULE["start"]([str(Path(self.tmp.name) / "missing")], dict(os.environ), None, lambda: calls.append("again"))
|
|
self.assertEqual(calls, ["restored"])
|
|
|
|
|
|
class EgoCorePlanTest(unittest.TestCase):
|
|
|
|
@staticmethod
|
|
def rule(op, value, worker_map):
|
|
return (' <restrict_if name="cores" op="%s" value="%d">\r\n <restrict_add>\r\n'
|
|
' <threadStrategy parallelUpdateRender="true" workerMapFile="system/%s" updateProcessor="2" />\r\n'
|
|
' </restrict_add>\r\n </restrict_if>\r\n' % (op, value, worker_map))
|
|
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.system = Path(self.tmp.name) / "DiRT 3/system"
|
|
self.system.mkdir(parents=True)
|
|
cpu = "".join(self.rule("int_eq", n, "workerMap%dCore.xml" % n) for n in (2, 3, 4, 6)) + self.rule("int_ge", 8, "workerMap8Core.xml")
|
|
self.shipped = ('<?xml version="1.0" encoding="UTF-8" ?>\r\n<hardware_settings_restrictions>\r\n <cpu>\r\n'
|
|
' <restrict_info>\r\n' + cpu +
|
|
' <restrict_else>\r\n <restrict_add>\r\n'
|
|
' <threadStrategy parallelUpdateRender="false" workerMapFile="system/workerMap.xml" />\r\n'
|
|
' </restrict_add>\r\n </restrict_else>\r\n </restrict_info>\r\n </cpu>\r\n'
|
|
' <audio_card>\r\n' + self.rule("int_eq", 5, "audio.xml") + ' </audio_card>\r\n'
|
|
'</hardware_settings_restrictions>').encode("latin-1")
|
|
self.path = self.system / "hardware_settings_restrictions.xml"
|
|
self.path.write_bytes(self.shipped)
|
|
for name in ("workerMap.xml", "workerMap2Core.xml", "workerMap3Core.xml", "workerMap4Core.xml", "workerMap6Core.xml", "workerMap8Core.xml"):
|
|
(self.system / name).write_text("<workerMap />")
|
|
self.command = ["/proton", "waitforexitandrun", str(self.system.parent / "dirt3_game.exe")]
|
|
self.saved = self.path.with_name(self.path.name + ".droiddeck-original")
|
|
|
|
def plan(self, topology, command=None):
|
|
env = {} if topology is None else {"WINE_CPU_TOPOLOGY": topology}
|
|
return MODULE["ego_core_plan"](command or self.command, env)
|
|
|
|
def test_five_cores_get_a_copy_of_the_four_core_plan(self):
|
|
note = self.plan("5:7,3,4,5,6")
|
|
self.assertIn("5 cores", note)
|
|
self.assertIn("4-core plan", note)
|
|
text = self.path.read_bytes()
|
|
four = self.rule("int_eq", 4, "workerMap4Core.xml").encode("latin-1")
|
|
five = self.rule("int_eq", 5, "workerMap4Core.xml").encode("latin-1")
|
|
self.assertEqual(text, self.shipped.replace(four, four + five))
|
|
self.assertNotIn(b"\n", text.replace(b"\r\n", b""))
|
|
self.assertEqual(self.saved.read_bytes(), self.shipped)
|
|
self.assertEqual(sorted(p.name for p in self.system.glob("*droiddeck-tmp*")), [])
|
|
self.assertIsNone(self.plan("5:7,3,4,5,6"))
|
|
self.assertEqual(self.path.read_bytes(), text)
|
|
self.assertEqual(self.saved.read_bytes(), self.shipped)
|
|
|
|
def test_seven_cores_get_the_six_core_plan(self):
|
|
self.assertIn("6-core plan", self.plan("7:7,1,2,3,4,5,6"))
|
|
self.assertIn(b'value="7">\r\n <restrict_add>\r\n <threadStrategy parallelUpdateRender="true" '
|
|
b'workerMapFile="system/workerMap6Core.xml"', self.path.read_bytes())
|
|
|
|
def test_counts_with_a_plan_are_left_alone(self):
|
|
for topology in ("2:7,6", "4:7,3,4,5", "6:7,3,4,5,6,2", "8:7,2,3,4,5,6,0,1", "12:0,1,2,3,4,5,6,7,8,9,10,11"):
|
|
self.assertIsNone(self.plan(topology), topology)
|
|
self.assertEqual(self.path.read_bytes(), self.shipped)
|
|
self.assertFalse(os.path.lexists(self.saved))
|
|
|
|
def test_nothing_changes_without_a_core_count_a_restrictions_file_a_smaller_plan_or_its_worker_map(self):
|
|
self.assertIsNone(self.plan(None))
|
|
self.assertIsNone(self.plan(""))
|
|
self.assertIsNone(self.plan("x:1"))
|
|
self.assertIsNone(self.plan("\u00b2:7"))
|
|
self.assertIsNone(self.plan("1:7"))
|
|
self.assertIsNone(self.plan("5:7,3,4,5,6", ["/proton", "waitforexitandrun"]))
|
|
self.assertIsNone(self.plan("5:7,3,4,5,6", ["/proton", "waitforexitandrun", "/elsewhere/game.exe"]))
|
|
(self.system / "workerMap4Core.xml").unlink()
|
|
self.assertIsNone(self.plan("5:7,3,4,5,6"))
|
|
self.assertEqual(self.path.read_bytes(), self.shipped)
|
|
self.assertFalse(os.path.lexists(self.saved))
|
|
|
|
def test_an_unknown_comparison_counts_as_a_plan(self):
|
|
self.path.write_bytes(self.shipped.replace(b'op="int_ge" value="8"', b'op="int_between" value="8"'))
|
|
self.assertIsNone(self.plan("5:7,3,4,5,6"))
|
|
|
|
def test_main_adds_the_plan_before_the_game_starts(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
probe = Path(tmp) / "probe"
|
|
probe.write_text('#!/bin/sh\ngrep -c \'value="5"\' "%s"\n' % self.path)
|
|
probe.chmod(0o755)
|
|
env = {k: v for k, v in os.environ.items() if not k.startswith(("WINE", "PROTON", "DROIDDECK", "DD_", "STEAM"))}
|
|
env.update(HOME=tmp, STEAM_COMPAT_DATA_PATH="/compatdata/3791535942", WINE_CPU_TOPOLOGY="5:7,3,4,5,6")
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun", self.command[2]],
|
|
env=env, text=True, capture_output=True, check=True)
|
|
self.assertEqual(result.stdout.strip(), "2", result.stderr)
|
|
self.assertIn("added a copy of its 4-core plan", result.stderr)
|
|
|
|
|
|
class SystemGraphicsLaunchTest(unittest.TestCase):
|
|
def test_start_configures_ubisoft_with_proton_before_wrapping_the_game(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
runtime, _ = self.runtime(root)
|
|
prefix = root / "42" / "pfx"
|
|
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
|
(prefix / "user.reg").write_text("WINE REGISTRY Version 2\n")
|
|
env = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": str(prefix.parent)}
|
|
command = ["/selected/proton", "waitforexitandrun", "game.exe"]
|
|
with mock.patch("subprocess.run") as run, mock.patch("os.execvpe") as execute:
|
|
MODULE["start"](command, env, None)
|
|
self.assertEqual(run.call_count, 2)
|
|
for call in run.call_args_list:
|
|
self.assertEqual(call.args[0][:3], ["/selected/proton", "runinprefix", "reg.exe"])
|
|
self.assertEqual(execute.call_args.args[:2], (str(runtime / "run-proton.py"),
|
|
[str(runtime / "run-proton.py"), *command]))
|
|
|
|
def runtime(self, root):
|
|
runtime = root / "system_vulkan" / ("a" * 64)
|
|
files = ["run-proton.py", "lib/libVkLayer_hybris_compat.so",
|
|
"wsi/libVkLayer_window_system_integration.so",
|
|
"wsi/VkLayer_window_system_integration.json"]
|
|
files += ["dxvk/%s/%s.dll" % (arch, name) for arch in ("x32", "x64")
|
|
for name in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi")]
|
|
for name in files:
|
|
target = runtime / name
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_bytes(b"component")
|
|
(runtime / "run-proton.py").chmod(0o755)
|
|
return runtime, files
|
|
|
|
def test_other_gpus_and_non_game_calls_keep_the_original_launch(self):
|
|
command = ["/proton", "waitforexitandrun", "game.exe"]
|
|
base = {"STEAM_COMPAT_DATA_PATH": "/compatdata/42", "VK_LAYER_PATH": "original"}
|
|
selected = dict(base, DROIDDECK_POWERVR_RUNTIME="/not-installed")
|
|
cases = [(command, base), (command, dict(selected, STEAM_COMPAT_DATA_PATH="/compatdata/0")),
|
|
(command, dict(selected, STEAM_COMPAT_DATA_PATH="/compatdata/invalid")),
|
|
(["/proton", "run", "iscriptevaluator.exe"], selected),
|
|
(["/proton", "getcompatpath", "x"], selected), (command[:2], selected)]
|
|
for args, env in cases:
|
|
with self.subTest(args=args, env=env):
|
|
actual, inherited = MODULE["system_graphics_launch"](args, env)
|
|
self.assertIs(actual, args)
|
|
self.assertIs(inherited, env)
|
|
|
|
def test_system_graphics_follow_game_configuration_and_preserve_other_keys(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
runtime, _ = self.runtime(Path(tmp))
|
|
base = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": "/compatdata/42"}
|
|
config = {"version": 1, "games": {"42": {
|
|
"PROTON_USE_WINED3D": "1", "DISABLE_WSI_LAYER": "1",
|
|
"ENABLE_VK_LAYER_VALVE_steam_fossilize_1": "1", "HYBRIS_BC_TEXTURES": "0",
|
|
"VK_LAYER_PATH": "old", "VK_INSTANCE_LAYERS": "old", "ENABLE_GAMESCOPE_WSI": "1",
|
|
"FEX_TSOENABLED": "1", "WINESERVER": "/selected/wineserver", "CUSTOM": "literal $value",
|
|
}}}
|
|
env = MODULE["apply_config"](base, config, "42")
|
|
command = ["/selected/proton", "waitforexitandrun", "game with spaces.exe"]
|
|
launch, result = MODULE["system_graphics_launch"](command, env)
|
|
self.assertEqual(launch, [str(runtime / "run-proton.py"), *command])
|
|
self.assertEqual(result["HYBRIS_BC_TEXTURES"], "dxvk")
|
|
self.assertEqual(result["VK_LAYER_PATH"], f"{runtime}/wsi:{runtime}/lib")
|
|
self.assertEqual(result["VK_INSTANCE_LAYERS"], "VK_LAYER_window_system_integration:VK_LAYER_HYBRIS_compat")
|
|
self.assertEqual(result["VK_LOADER_LAYERS_DISABLE"], "*gamescope*")
|
|
self.assertEqual(result["ENABLE_GAMESCOPE_WSI"], "0")
|
|
self.assertEqual(result["DISABLE_VK_LAYER_VALVE_steam_fossilize_1"], "1")
|
|
for key in ("PROTON_USE_WINED3D", "DISABLE_WSI_LAYER", "ENABLE_VK_LAYER_VALVE_steam_fossilize_1"):
|
|
self.assertNotIn(key, result)
|
|
self.assertIn(key, env)
|
|
for key in ("FEX_TSOENABLED", "WINESERVER", "CUSTOM"):
|
|
self.assertEqual(result[key], env[key])
|
|
|
|
def test_xclipse_selection_adds_its_layers_layer_path_and_dxvk_payload(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
runtime, _ = self.runtime(Path(tmp))
|
|
env = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": "/compatdata/42",
|
|
"DROIDDECK_HYBRIS_LAYERS": "VK_LAYER_DROIDDECK_xclipse:VK_LAYER_HYBRIS_compat",
|
|
"DROIDDECK_HYBRIS_LAYER_PATH": "/usr/local/lib/droiddeck-xclipse",
|
|
"DROIDDECK_HYBRIS_DXVK": "dxvk-2.6.2"}
|
|
command = ["/proton", "waitforexitandrun", "game.exe"]
|
|
# The selected payload is required like the default one.
|
|
with self.assertRaises(MODULE["SystemGraphicsError"]):
|
|
MODULE["system_graphics_launch"](command, env)
|
|
for arch in ("x32", "x64"):
|
|
for name in ("d3d8", "d3d9", "d3d10core", "d3d11", "dxgi"):
|
|
target = runtime / "dxvk-2.6.2" / arch / (name + ".dll")
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_bytes(b"component")
|
|
launch, result = MODULE["system_graphics_launch"](command, env)
|
|
self.assertEqual(launch, [str(runtime / "run-proton.py"), *command])
|
|
self.assertEqual(result["VK_INSTANCE_LAYERS"],
|
|
"VK_LAYER_window_system_integration:VK_LAYER_DROIDDECK_xclipse:VK_LAYER_HYBRIS_compat")
|
|
self.assertEqual(result["VK_LAYER_PATH"], f"{runtime}/wsi:{runtime}/lib:/usr/local/lib/droiddeck-xclipse")
|
|
self.assertEqual(result["DROIDDECK_HYBRIS_DXVK"], "dxvk-2.6.2")
|
|
for name in ("../dxvk", "other", "dxvk/x"):
|
|
with self.subTest(name=name), self.assertRaises(MODULE["SystemGraphicsError"]):
|
|
MODULE["system_graphics_launch"](command, dict(env, DROIDDECK_HYBRIS_DXVK=name))
|
|
|
|
def test_incomplete_runtime_fails_before_any_proton_exec(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
runtime, files = self.runtime(Path(tmp))
|
|
env = {"DROIDDECK_POWERVR_RUNTIME": str(runtime), "STEAM_COMPAT_DATA_PATH": "/compatdata/42"}
|
|
command = ["/proton", "waitforexitandrun", "game.exe"]
|
|
for name in files:
|
|
target = runtime / name
|
|
original = target.read_bytes()
|
|
for missing in (False, True):
|
|
with self.subTest(name=name, missing=missing):
|
|
target.unlink() if missing else target.write_bytes(b"")
|
|
with patch.object(os, "execvpe") as execute:
|
|
with self.assertRaises(MODULE["SystemGraphicsError"]):
|
|
MODULE["exec_proton"](command, env)
|
|
execute.assert_not_called()
|
|
target.write_bytes(original)
|
|
if name == "run-proton.py":
|
|
target.chmod(0o755)
|
|
(runtime / "run-proton.py").chmod(0o644)
|
|
with self.assertRaises(MODULE["SystemGraphicsError"]):
|
|
MODULE["system_graphics_launch"](command, env)
|
|
with self.assertRaises(MODULE["SystemGraphicsError"]):
|
|
MODULE["system_graphics_launch"](command, dict(env, DROIDDECK_POWERVR_RUNTIME="relative"))
|
|
|
|
def test_wrapper_receives_the_sync_selected_proton(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
runtime, _ = self.runtime(root)
|
|
env = {"HOME": tmp, "DROIDDECK_POWERVR_RUNTIME": str(runtime),
|
|
"STEAM_COMPAT_DATA_PATH": "/compatdata/42"}
|
|
command = ["/stock/proton", "waitforexitandrun", "game.exe"]
|
|
selected = ["/sync-pack/proton", *command[1:]]
|
|
selected_env = dict(env, WINESERVER="/sync-pack/wineserver", DD_SYNC_PACK="selected")
|
|
main = MODULE["main"]
|
|
with patch.dict(os.environ, env, clear=True), patch.object(sys, "argv", ["game-env", *command]), \
|
|
patch.dict(main.__globals__, {"load_sync": lambda: {},
|
|
"select_sync": lambda *args: (selected, selected_env),
|
|
"win_components": lambda *args: ""}), \
|
|
patch.object(os, "execvpe", side_effect=SystemExit(23)) as execute:
|
|
with self.assertRaises(SystemExit) as stopped:
|
|
main()
|
|
self.assertEqual(stopped.exception.code, 23)
|
|
execute.assert_called_once()
|
|
path, args, actual_env = execute.call_args.args
|
|
self.assertEqual(path, str(runtime / "run-proton.py"))
|
|
self.assertEqual(args, [path, *selected])
|
|
self.assertEqual(actual_env["WINESERVER"], "/sync-pack/wineserver")
|
|
self.assertEqual(actual_env["DD_SYNC_PACK"], "selected")
|
|
|
|
|
|
class GameDebugLoggingTest(unittest.TestCase):
|
|
def test_maintenance_precision_survives_run_with_performance_game_settings(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": {"FEX_X87REDUCEDPRECISION": "1"},
|
|
"games": {"42": {"FEX_X87REDUCEDPRECISION": "1"}}}))
|
|
probe = home / "proton"
|
|
probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ['FEX_X87REDUCEDPRECISION'])\n")
|
|
probe.chmod(0o755)
|
|
base = {**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42")}
|
|
maintenance = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "run"],
|
|
env={**base, "DROIDDECK_GOG_MAINTENANCE": "1", "FEX_X87REDUCEDPRECISION": "0"}, text=True, capture_output=True, check=True)
|
|
game = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun"],
|
|
env={**base, "FEX_X87REDUCEDPRECISION": "1"}, text=True, capture_output=True, check=True)
|
|
self.assertEqual("0", maintenance.stdout.strip())
|
|
self.assertEqual("1", game.stdout.strip())
|
|
|
|
def test_real_game_launch_without_config_file_keeps_the_base_environment(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
probe = home / "proton"
|
|
probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ['PROTON_LOG'])\n")
|
|
probe.chmod(0o755)
|
|
result = subprocess.run(
|
|
[sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun"],
|
|
env={**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42"),
|
|
"DD_DEBUG_DIR": tmp, "PROTON_LOG": "0"},
|
|
text=True, capture_output=True, check=True,
|
|
)
|
|
self.assertEqual(result.stdout.strip(), "0")
|
|
|
|
def test_game_debug_logs_override_only_diagnostic_values_and_keep_raw_settings(self):
|
|
with tempfile.TemporaryDirectory(prefix="game logs '") as debug_dir:
|
|
inherited = {"DD_DEBUG_DIR": debug_dir, "PROTON_LOG": "0", "WINEDEBUG": "-all,+relay",
|
|
"PROTON_LOG_DIR": "/old", "PROTON_CRASH_REPORT_DIR": "/old-crashes",
|
|
"DXVK_LOG_PATH": "/old-dxvk", "DXVK_LOG_LEVEL": "none", "VKD3D_DEBUG": "none",
|
|
"CUSTOM": "$(touch never); 'quoted' = literal", "DXVK_CONFIG": "dxvk.tearFree = True"}
|
|
config = {"version": 1, "gameDebugLogs": True,
|
|
"shared": {"PROTON_LOG": "0", "DD_DEBUG_DIR": "/profile-redirect"},
|
|
"games": {"42": {"PROTON_LOG_DIR": None, "DXVK_LOG_PATH": "/game-redirect"}}}
|
|
normal = MODULE["apply_config"](inherited, config, "42")
|
|
debug = MODULE["apply_game_debug_logs"](normal, config, inherited["DD_DEBUG_DIR"])
|
|
self.assertEqual(debug["PROTON_LOG"], "1")
|
|
for key in ("PROTON_LOG_DIR", "PROTON_CRASH_REPORT_DIR", "DXVK_LOG_PATH"):
|
|
self.assertEqual(debug[key], debug_dir)
|
|
self.assertEqual(debug["DXVK_LOG_LEVEL"], "debug")
|
|
self.assertEqual(debug["VKD3D_DEBUG"], "info")
|
|
self.assertIn("+relay", debug["WINEDEBUG"].split(","))
|
|
self.assertTrue(debug["WINEDEBUG"].endswith("+loaddll,+mscoree"))
|
|
for key in ("CUSTOM", "DXVK_CONFIG", "DD_DEBUG_DIR"):
|
|
self.assertEqual(debug[key], normal[key])
|
|
self.assertEqual(normal["PROTON_LOG"], "0")
|
|
self.assertEqual(inherited["PROTON_LOG_DIR"], "/old")
|
|
self.assertIs(MODULE["apply_game_debug_logs"](normal, {**config, "gameDebugLogs": False}, debug_dir), normal)
|
|
self.assertEqual(MODULE["apply_game_debug_logs"](debug, config, debug_dir), debug)
|
|
|
|
def test_wine_debug_channels_are_formatted_deduplicated_and_diagnostics_win(self):
|
|
formatted = MODULE["game_debug_channels"](
|
|
" +relay, trace-vulkan, -all, -seh, +relay, trace+vulkan, garbage, $(touch never) ",
|
|
"+seh,warn-foo,warn+foo,+relay",
|
|
)
|
|
self.assertEqual(formatted, "-all,trace+vulkan,warn+foo,+relay," +
|
|
"+timestamp,+pid,+tid,+seh,+unwind,+threadname,+debugstr,+loaddll,+mscoree")
|
|
self.assertEqual(MODULE["game_debug_channels"](formatted, "1"), formatted)
|
|
self.assertNotIn("-seh", formatted)
|
|
for value in ("x\0,+relay", "+" + "x" * 8192, 1, None):
|
|
self.assertEqual(MODULE["game_debug_channels"](value), MODULE["game_debug_channels"]())
|
|
oversized = ",".join("+channel_" + str(i) for i in range(550))
|
|
other = ",".join("+other_" + str(i) for i in range(550))
|
|
self.assertLessEqual(len(MODULE["game_debug_channels"](oversized, other)), 8192)
|
|
self.assertTrue(MODULE["game_debug_channels"](oversized, other).endswith("+loaddll,+mscoree"))
|
|
|
|
def test_game_debug_logs_require_opt_in_and_a_real_session_log_directory(self):
|
|
env = {"PROTON_LOG": "user", "CUSTOM": "keep"}
|
|
for config in ({}, {"version": 1}, {"version": 1, "gameDebugLogs": False},
|
|
{"version": 1, "gameDebugLogs": "true"}, {"version": 2, "gameDebugLogs": True}):
|
|
self.assertIs(MODULE["apply_game_debug_logs"](env, config, "/"), env)
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
not_a_directory = Path(tmp) / "file"
|
|
not_a_directory.write_text("file")
|
|
for path in (None, "", "relative", "bad\0path", str(not_a_directory), str(Path(tmp) / "missing")):
|
|
with self.subTest(path=path):
|
|
self.assertIs(MODULE["apply_game_debug_logs"](env, {"version": 1, "gameDebugLogs": True}, path), env)
|
|
|
|
def test_game_debug_toggle_is_live_preserves_command_and_excludes_probes(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
config_path = home / ".config/droiddeck/game-environment.json"
|
|
config_path.parent.mkdir(parents=True)
|
|
debug_dir = home / "session logs '$literal; directory'"
|
|
debug_dir.mkdir()
|
|
probe = home / "fake proton"
|
|
probe.write_text("#!" + sys.executable + "\nimport json, os, sys\n"
|
|
"print(json.dumps({'env': dict(os.environ), 'argv': sys.argv[1:]}))\n")
|
|
probe.chmod(0o755)
|
|
literal = "$(touch " + str(home / "never-created") + "); 'literal'=value"
|
|
config = {"version": 1, "gameDebugLogs": True,
|
|
"shared": {"PROTON_LOG": "0", "WINEDEBUG": "-all,+relay", "CUSTOM": literal,
|
|
"DD_DEBUG_DIR": "/profile-must-not-redirect"}}
|
|
env = {**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42"),
|
|
"DD_DEBUG_DIR": str(debug_dir), "PROTON_LOG": "0", "WINEDEBUG": "-all"}
|
|
command = [str(probe), "waitforexitandrun", "game 'with quotes'.exe", "argument with spaces", "$(literal)", "%command%"]
|
|
|
|
def launch(arguments, environment):
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), *arguments],
|
|
env=environment, text=True, capture_output=True, check=True)
|
|
return json.loads(result.stdout)
|
|
|
|
for enabled in (True, False, True):
|
|
config_path.write_text(json.dumps({**config, "gameDebugLogs": enabled}))
|
|
result = launch(command, env)
|
|
self.assertEqual(result["argv"], command[1:])
|
|
self.assertEqual(result["env"]["CUSTOM"], literal)
|
|
self.assertEqual(result["env"]["PROTON_LOG"], "1" if enabled else "0")
|
|
if enabled:
|
|
self.assertEqual(result["env"]["PROTON_LOG_DIR"], str(debug_dir))
|
|
self.assertIn("+relay", result["env"]["WINEDEBUG"].split(","))
|
|
self.assertIn("+seh", result["env"]["WINEDEBUG"].split(","))
|
|
else:
|
|
self.assertEqual(result["env"]["WINEDEBUG"], "-all,+relay")
|
|
for verb, prefix in (("run", "42"), ("waitforexitandrun", "0"), ("waitforexitandrun", "not-a-game")):
|
|
result = launch([str(probe), verb], {**env, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata" / prefix)})
|
|
self.assertEqual(result["env"]["PROTON_LOG"], "0")
|
|
self.assertEqual(result["env"]["WINEDEBUG"], "-all")
|
|
result = launch(command, {**env, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/-1")})
|
|
self.assertEqual(result["env"]["PROTON_LOG"], "1")
|
|
self.assertFalse((home / "never-created").exists())
|
|
self.assertEqual(json.loads(config_path.read_text())["shared"], config["shared"])
|
|
|
|
|
|
class ReadConfigMappingTest(unittest.TestCase):
|
|
def test_missing_parent_or_unbalanced_vdf_is_not_treated_as_absent_choices(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
config = Path(tmp) / "config.vdf"
|
|
config.write_text('"InstallConfigStore" { "Software" { "Other" {} } }')
|
|
self.assertIsNone(COMPAT["read_config_mapping"](str(config)))
|
|
config.write_text('"InstallConfigStore" { "Software" { "Valve" { "Steam" {} }')
|
|
self.assertIsNone(COMPAT["read_config_mapping"](str(config)))
|
|
|
|
def test_valid_steam_parent_without_compat_mapping_has_no_per_app_choices(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
config = Path(tmp) / "config.vdf"
|
|
config.write_text('"InstallConfigStore" { "Software" { "Valve" { "Steam" {} } } }')
|
|
self.assertEqual(COMPAT["read_config_mapping"](str(config)), {})
|
|
|
|
|
|
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, seen_mark = [], [], [], []
|
|
globals = MODULE["main"].__globals__
|
|
stubs = {
|
|
"game_gpu": lambda env: env,
|
|
"mark_install_scripts": lambda command, env: seen_mark.append(env.copy()) or [],
|
|
"install_scripts_done": lambda scripts, env: False,
|
|
"scripts_digest": lambda scripts: None,
|
|
"win_components": lambda *args: seen_components.append(args[3]) or "",
|
|
"restore_compatible_system_dlls": lambda *args: [],
|
|
"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,
|
|
"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])
|
|
self.assertEqual(["0"], [env["PROTON_USE_ARM64"] for env in seen_mark])
|
|
seen_mark.clear()
|
|
seen_start.clear()
|
|
command[1] = "run"
|
|
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(["1"], [env["PROTON_USE_ARM64"] for env in seen_mark])
|
|
self.assertEqual(["1"], [env["PROTON_USE_ARM64"] for env in seen_start])
|
|
|
|
def test_keyboard_helper_is_off_unless_steam_keyboard_or_the_user_wants_it(self):
|
|
cases = (
|
|
({}, "tabtip.exe=d"),
|
|
({"WINEDLLOVERRIDES": "dxgi=n"}, "dxgi=n;tabtip.exe=d"),
|
|
({"WINEDLLOVERRIDES": "tabtipx=d"}, "tabtipx=d;tabtip.exe=d"),
|
|
({"SteamDeck": "0"}, "tabtip.exe=d"),
|
|
({"SteamDeck": "1"}, None),
|
|
({"SteamDeck": "1", "WINEDLLOVERRIDES": "dxgi=n"}, "dxgi=n"),
|
|
({"WINEDLLOVERRIDES": "tabtip.exe=b"}, "tabtip.exe=b"),
|
|
({"WINEDLLOVERRIDES": "dxgi=n; TabTip.EXE=n,b"}, "dxgi=n; TabTip.EXE=n,b"),
|
|
({"WINEDLLOVERRIDES": "dxgi=n; TabTip=n,b"}, "dxgi=n; TabTip=n,b;tabtip.exe=d"),
|
|
({"WINEDLLOVERRIDES": "d3d11 tabtip.exe"}, "d3d11 tabtip.exe;tabtip.exe=d"),
|
|
({"WINEDLLOVERRIDES": "tabtip.exe;dxgi=n"}, "tabtip.exe;dxgi=n;tabtip.exe=d"),
|
|
({"WINEDLLOVERRIDES": "d3d11,tabtip.exe=b"}, "d3d11,tabtip.exe=b"),
|
|
({"WINEDLLOVERRIDES": "d3d11 tabtip.exe=b"}, "d3d11 tabtip.exe=b"),
|
|
({"WINEDLLOVERRIDES": "d3d11\ttabtip.exe=b"}, "d3d11\ttabtip.exe=b"),
|
|
({"WINEDLLOVERRIDES": "d3d11\ttabtip=b"}, "d3d11\ttabtip=b;tabtip.exe=d"),
|
|
({"WINEDLLOVERRIDES": "d3d11 dxgi=n"}, "d3d11 dxgi=n;tabtip.exe=d"),
|
|
({"WINEDLLOVERRIDES": "*tabtip.exe=b"}, "*tabtip.exe=b"),
|
|
({"WINEDLLOVERRIDES": "TabTip.exe.DLL=b"}, "TabTip.exe.DLL=b"),
|
|
({"WINEDLLOVERRIDES": "d3d11,*tabtip.exe.dll=n"}, "d3d11,*tabtip.exe.dll=n"),
|
|
({"WINEDLLOVERRIDES": "*tabtip=b"}, "*tabtip=b;tabtip.exe=d"),
|
|
({"WINEDLLOVERRIDES": "tabtip.dll=b"}, "tabtip.dll=b;tabtip.exe=d"),
|
|
)
|
|
for before, overrides in cases:
|
|
with self.subTest(env=before):
|
|
env = dict(before)
|
|
note = MODULE["keyboard_helper_off"](env)
|
|
self.assertEqual(env.get("WINEDLLOVERRIDES"), overrides)
|
|
self.assertEqual(note is not None, overrides != before.get("WINEDLLOVERRIDES"))
|
|
|
|
def test_game_launch_turns_the_keyboard_helper_off_and_keeps_user_choices(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
probe = home / "probe"
|
|
probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ.get('WINEDLLOVERRIDES', 'unset'))\n")
|
|
probe.chmod(0o755)
|
|
config = home / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
cases = (
|
|
("waitforexitandrun", {}, "tabtip.exe=d"),
|
|
("waitforexitandrun", {"WINEDLLOVERRIDES": "dxgi=n"}, "dxgi=n;tabtip.exe=d"),
|
|
("waitforexitandrun", {"SteamDeck": "1"}, "unset"),
|
|
("waitforexitandrun", {"WINEDLLOVERRIDES": "tabtip.exe=b"}, "tabtip.exe=b"),
|
|
("run", {}, "unset"),
|
|
)
|
|
for verb, profile, expected in cases:
|
|
with self.subTest(verb=verb, profile=profile):
|
|
config.write_text(json.dumps({"version": 1, "games": {"42": profile}}))
|
|
env = {k: v for k, v in os.environ.items() if k not in ("SteamDeck", "WINEDLLOVERRIDES")}
|
|
env.update(HOME=tmp, STEAM_COMPAT_DATA_PATH="/compatdata/42")
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), verb],
|
|
env=env, text=True, capture_output=True, check=True)
|
|
self.assertEqual(result.stdout.strip().splitlines()[-1], expected)
|
|
|
|
def test_optional_xbox_loader_failure_keeps_stock_launch(self):
|
|
from unittest.mock import patch
|
|
for error in (FileNotFoundError('missing'), RuntimeError('module initialization failed')):
|
|
calls = []
|
|
with patch.dict(os.environ, {}, clear=True), patch('sys.argv', ['droiddeck-game-env', '/stock', 'run']), \
|
|
patch('runpy.run_path', side_effect=error), patch('os.execvpe', side_effect=lambda *args: calls.append(args)), \
|
|
patch.dict(MODULE['main'].__globals__, load_sync=lambda: None, select_sync=lambda command, env, sync: (command, env)):
|
|
MODULE['main']()
|
|
self.assertEqual(calls[0][0:2], ('/stock', ['/stock', 'run']))
|
|
|
|
|
|
def test_directaudio_capture_follows_the_session_microphone_setting(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
probe = home / "probe"
|
|
probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ.get('AUDIO_DIRECT_MIC', 'unset'))\n")
|
|
probe.chmod(0o755)
|
|
config = home / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
for enabled, override, expected in (("1", None, "1"), ("0", "1", "0"), ("1", "0", "0")):
|
|
with self.subTest(enabled=enabled, override=override):
|
|
profile = {} if override is None else {
|
|
"AUDIO_DIRECT_MIC": override, "DD_MIC_ENABLED": override,
|
|
}
|
|
config.write_text(json.dumps({"version": 1, "games": {"42": profile}}))
|
|
env = dict(os.environ, HOME=tmp, DD_MIC_ENABLED=enabled,
|
|
AUDIO_DIRECT_MIC="1", STEAM_COMPAT_DATA_PATH="/compatdata/42")
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"),
|
|
str(probe), "waitforexitandrun"],
|
|
env=env, text=True, capture_output=True, check=True)
|
|
self.assertEqual(result.stdout.strip(), expected)
|
|
|
|
def test_game_profile_directaudio_settings_reach_the_driver(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
probe = home / "probe"
|
|
probe.write_text("#!" + sys.executable + "\nimport os\nprint(' '.join(sorted(k + '=' + v for k, v in os.environ.items() if k.startswith('BANNER_AUDIO_DIRECT_'))))\n")
|
|
probe.chmod(0o755)
|
|
config = home / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
config.write_text(json.dumps({"version": 1, "games": {"42": {"AUDIO_DIRECT_MS": "80"}}}))
|
|
base = {key: value for key, value in os.environ.items() if "AUDIO_DIRECT_" not in key}
|
|
base.update(HOME=tmp, DD_MIC_ENABLED="0", STEAM_COMPAT_DATA_PATH="/compatdata/42",
|
|
AUDIO_DIRECT_MS="60", AUDIO_DIRECT_PERIOD_MS="20", AUDIO_DIRECT_MIC="1",
|
|
BANNER_AUDIO_DIRECT_MS="60", BANNER_AUDIO_DIRECT_MIC="1")
|
|
for driver, expected in (("directaudio,pulse", "BANNER_AUDIO_DIRECT_MIC=0 BANNER_AUDIO_DIRECT_MS=80 BANNER_AUDIO_DIRECT_PERIOD_MS=20"),
|
|
("pulse", "BANNER_AUDIO_DIRECT_MIC=1 BANNER_AUDIO_DIRECT_MS=60")):
|
|
with self.subTest(driver=driver):
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun"],
|
|
env=dict(base, WINE_AUDIO_DRIVER=driver), text=True, capture_output=True, check=True)
|
|
self.assertEqual(result.stdout.strip(), expected)
|
|
|
|
def test_desktop_games_restart_on_the_gpu_with_steams_preloads_handed_back(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
gpu = home / "gpu"
|
|
gpu.write_text("#!/bin/bash\necho \"gpu LD_PRELOAD=${LD_PRELOAD-unset}\"\nexport DD_DESKTOP_GPU_CHILD=1\nexec \"$@\"\n")
|
|
gpu.chmod(0o755)
|
|
launcher = home / "launcher"
|
|
setup = COMPAT["DD_DESKTOP_GPU_SETUP"].replace("/usr/local/bin/droiddeck-gpu", str(gpu))
|
|
launcher.write_text("#!/bin/bash\nverb=$1; shift\n" + setup + "echo \"game $verb $* LD_PRELOAD=${LD_PRELOAD-unset} saved=${DD_GPU_SAVED_LD_PRELOAD-unset}\"\n")
|
|
launcher.chmod(0o755)
|
|
base = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
|
|
base["LD_PRELOAD"] = "overlay.so"
|
|
for extra, args, expected in (
|
|
({"DD_DESKTOP": "1"}, ["waitforexitandrun", "game.exe"],
|
|
["gpu LD_PRELOAD=unset", "game waitforexitandrun game.exe LD_PRELOAD=overlay.so saved=unset"]),
|
|
({"DD_DESKTOP": "1", "DD_DESKTOP_GPU": "Off"}, ["waitforexitandrun", "game.exe"],
|
|
["game waitforexitandrun game.exe LD_PRELOAD=overlay.so saved=unset"]),
|
|
({"DD_DESKTOP": "1"}, ["run", "setup.exe"],
|
|
["game run setup.exe LD_PRELOAD=overlay.so saved=unset"]),
|
|
({"DD_DESKTOP": "1"}, ["waitforexitandrun", "iscriptevaluator.exe"],
|
|
["game waitforexitandrun iscriptevaluator.exe LD_PRELOAD=overlay.so saved=unset"]),
|
|
({}, ["waitforexitandrun", "game.exe"],
|
|
["game waitforexitandrun game.exe LD_PRELOAD=overlay.so saved=unset"]),
|
|
):
|
|
with self.subTest(extra=extra, args=args):
|
|
result = subprocess.run([str(launcher)] + args, env=dict(base, **extra),
|
|
text=True, capture_output=True, check=True)
|
|
self.assertEqual(result.stdout.splitlines(), expected)
|
|
|
|
def test_the_install_script_evaluator_gets_its_scripts_marked_first(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
(root / "files/bin-arm64").mkdir(parents=True)
|
|
(root / "files/bin-arm64/wineserver").write_text("")
|
|
(root / "files/bin-arm64/wineserver").chmod(0o755)
|
|
script = root / "legacycompat/evaluatorscript_409710.vdf"
|
|
script.parent.mkdir(parents=True)
|
|
script.write_text("{}")
|
|
calls = []
|
|
run = MODULE["mark_install_scripts"].__globals__["subprocess"].run
|
|
MODULE["mark_install_scripts"].__globals__["subprocess"].run = lambda args, **kw: calls.append((args, kw["env"]))
|
|
try:
|
|
env = {"STEAM_COMPAT_CLIENT_INSTALL_PATH": str(root), "STEAM_COMPAT_DATA_PATH": str(root / "compatdata/409710")}
|
|
evaluator = [str(root / "proton"), "run", str(root / "legacycompat/iscriptevaluator.exe"), "legacycompat\\evaluatorscript_409710.vdf"]
|
|
MODULE["mark_install_scripts"](evaluator, env)
|
|
MODULE["mark_install_scripts"](["/proton", "waitforexitandrun", "/game/Game.exe"], env)
|
|
self.assertEqual(len(calls), 3)
|
|
self.assertEqual(calls[0][0], [str(root / "proton"), "run", "cmd.exe", "/c", "exit", "0"])
|
|
self.assertEqual(calls[0][1], env)
|
|
self.assertEqual(calls[1][0], [str(root / "files/bin-arm64/wineserver"), "-w"])
|
|
self.assertEqual(calls[1][1]["WINEPREFIX"], str(root / "compatdata/409710/pfx"))
|
|
self.assertEqual(calls[1][1].get("DROIDDECK_SEED_SCRIPTS"), None)
|
|
self.assertEqual(calls[2][0][1], str(root))
|
|
self.assertEqual(calls[2][1]["DROIDDECK_SEED_SCRIPTS"], str(script))
|
|
(root / "compatdata/409710/pfx").mkdir(parents=True)
|
|
(root / "compatdata/409710/pfx/system.reg").write_text("")
|
|
calls.clear()
|
|
MODULE["mark_install_scripts"](evaluator, env)
|
|
self.assertEqual([args[0] for args, _ in calls], [MODULE["SEED_REDISTS"]])
|
|
finally:
|
|
MODULE["mark_install_scripts"].__globals__["subprocess"].run = run
|
|
|
|
def test_the_install_script_seeder_runs_when_prefix_probe_times_out(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
(root / "files/bin-arm64").mkdir(parents=True)
|
|
(root / "files/bin-arm64/wineserver").write_text("")
|
|
(root / "files/bin-arm64/wineserver").chmod(0o755)
|
|
script = root / "legacycompat/evaluatorscript_409710.vdf"
|
|
script.parent.mkdir(parents=True)
|
|
script.write_text("{}")
|
|
calls = []
|
|
run = MODULE["mark_install_scripts"].__globals__["subprocess"].run
|
|
|
|
def fake_run(args, **kwargs):
|
|
calls.append((args, kwargs["env"]))
|
|
if len(calls) == 1:
|
|
raise subprocess.TimeoutExpired(args, 120)
|
|
|
|
MODULE["mark_install_scripts"].__globals__["subprocess"].run = fake_run
|
|
try:
|
|
env = {"STEAM_COMPAT_CLIENT_INSTALL_PATH": str(root), "STEAM_COMPAT_DATA_PATH": str(root / "compatdata/409710")}
|
|
MODULE["mark_install_scripts"]([str(root / "proton"), "run", str(root / "legacycompat/iscriptevaluator.exe"), "legacycompat\\evaluatorscript_409710.vdf"], env)
|
|
self.assertEqual(calls[1][0], [str(root / "files/bin-arm64/wineserver"), "-w"])
|
|
self.assertEqual(calls[2][0][0], MODULE["SEED_REDISTS"])
|
|
finally:
|
|
MODULE["mark_install_scripts"].__globals__["subprocess"].run = run
|
|
|
|
def test_the_install_script_seeder_skips_failed_wineserver_waits(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
script = root / "legacycompat/evaluatorscript_409710.vdf"
|
|
script.parent.mkdir(parents=True)
|
|
script.write_text("{}")
|
|
env = {"STEAM_COMPAT_CLIENT_INSTALL_PATH": str(root), "STEAM_COMPAT_DATA_PATH": str(root / "compatdata/409710")}
|
|
evaluator = [str(root / "proton"), "run", str(root / "legacycompat/iscriptevaluator.exe"), "legacycompat\\evaluatorscript_409710.vdf"]
|
|
wineserver = str(root / "files/bin-arm64/wineserver")
|
|
run = MODULE["mark_install_scripts"].__globals__["subprocess"].run
|
|
for failure in (subprocess.TimeoutExpired([wineserver, "-w"], 120), OSError("cannot start"),
|
|
subprocess.CalledProcessError(1, [wineserver, "-w"])):
|
|
with self.subTest(failure=type(failure).__name__):
|
|
calls = []
|
|
|
|
def fake_run(args, **kwargs):
|
|
calls.append((args, kwargs))
|
|
if len(calls) == 2:
|
|
self.assertTrue(kwargs["check"])
|
|
raise failure
|
|
|
|
MODULE["mark_install_scripts"].__globals__["subprocess"].run = fake_run
|
|
try:
|
|
self.assertEqual(MODULE["mark_install_scripts"](evaluator, env), [str(script)])
|
|
self.assertEqual(len(calls), 2)
|
|
self.assertEqual(calls[1][0], [wineserver, "-w"])
|
|
self.assertEqual(calls[1][1]["env"]["WINEPREFIX"], str(root / "compatdata/409710/pfx"))
|
|
finally:
|
|
MODULE["mark_install_scripts"].__globals__["subprocess"].run = run
|
|
|
|
def run_install_marker(self, root, env):
|
|
script = root / "legacycompat/evaluatorscript_409710.vdf"
|
|
script.parent.mkdir(parents=True, exist_ok=True)
|
|
script.write_text("{}")
|
|
calls = []
|
|
module = MODULE["mark_install_scripts"].__globals__["subprocess"]
|
|
run = module.run
|
|
module.run = lambda args, **kw: calls.append((args, kw["env"]))
|
|
try:
|
|
evaluator = [str(root / "proton"), "run", str(root / "legacycompat/iscriptevaluator.exe"), "legacycompat\\evaluatorscript_409710.vdf"]
|
|
self.assertEqual(MODULE["mark_install_scripts"](evaluator, env), [str(script)])
|
|
finally:
|
|
module.run = run
|
|
return calls
|
|
|
|
def test_the_install_script_wait_finds_wineserver_in_files_bin(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
(root / "files/bin").mkdir(parents=True)
|
|
(root / "files/bin/wineserver").write_text("")
|
|
(root / "files/bin/wineserver").chmod(0o755)
|
|
calls = self.run_install_marker(root, {"STEAM_COMPAT_CLIENT_INSTALL_PATH": str(root),
|
|
"STEAM_COMPAT_DATA_PATH": str(root / "compatdata/409710")})
|
|
self.assertEqual(calls[1][0], [str(root / "files/bin/wineserver"), "-w"])
|
|
self.assertEqual(calls[2][0][0], MODULE["SEED_REDISTS"])
|
|
|
|
def test_the_install_script_seeder_skips_the_probe_without_compat_data(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
calls = self.run_install_marker(root, {"STEAM_COMPAT_CLIENT_INSTALL_PATH": str(root)})
|
|
self.assertEqual([args[0] for args, _ in calls], [MODULE["SEED_REDISTS"]])
|
|
|
|
def test_the_install_script_seeder_checks_only_the_selected_template(self):
|
|
for machine in ("aarch64", "x86_64"):
|
|
for setting in (None, "1", "0", ""):
|
|
for arm64_bin in (False, True):
|
|
for template in ("default_pfx", "default_pfx_arm64"):
|
|
with self.subTest(machine=machine, setting=setting, arm64_bin=arm64_bin, template=template):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
if arm64_bin:
|
|
(root / "files/bin-arm64").mkdir(parents=True)
|
|
reg = root / "files/share" / template / "system.reg"
|
|
reg.parent.mkdir(parents=True)
|
|
reg.write_text("")
|
|
env = {"STEAM_COMPAT_CLIENT_INSTALL_PATH": str(root),
|
|
"STEAM_COMPAT_DATA_PATH": str(root / "compatdata/409710")}
|
|
if setting is not None:
|
|
env["PROTON_USE_ARM64"] = setting
|
|
before = dict(env)
|
|
with patch("platform.machine", return_value=machine):
|
|
calls = self.run_install_marker(root, env)
|
|
selected = "default_pfx_arm64" if machine == "aarch64" and arm64_bin and setting in (None, "1") else "default_pfx"
|
|
expected = [MODULE["SEED_REDISTS"]]
|
|
if template != selected:
|
|
expected = [str(root / "proton"), str(root / ("files/bin-arm64/wineserver")), *expected]
|
|
self.assertEqual([args[0] for args, _ in calls], expected)
|
|
self.assertEqual(env, before)
|
|
|
|
SCRIPT = ('"evaluatorscript" { "0" { "appid" "228980" "compat_installscript" { "run process" { '
|
|
'"x64 14.28.29334.0" { "hasrunkey" "HKEY_LOCAL_MACHINE\\\\Software\\\\Valve\\\\Steam\\\\Apps\\\\CommonRedist\\\\vcredist\\\\2019" '
|
|
'"process 1" "%INSTALLDIR%\\\\x64.cmd" "requirement_os" { "Is64BitWindows" "1" } } '
|
|
'"Setup" { "process 1" "%INSTALLDIR%\\\\setup.exe" } } } } }')
|
|
REDIST = "[Software\\\\Wow6432Node\\\\Valve\\\\Steam\\\\Apps\\\\CommonRedist\\\\vcredist\\\\2019] 1\n\"x64 14.28.29334.0\"=dword:00000001\n"
|
|
SETUP = "[Software\\\\Valve\\\\Steam\\\\Apps\\\\228980] 1\n\"Setup\"=dword:00000001\n"
|
|
|
|
def test_install_script_run_keys_default_to_the_app_key(self):
|
|
keys = MODULE["run_keys"](MODULE["read_vdf"](self.SCRIPT))
|
|
self.assertEqual(keys, {
|
|
("hkey_local_machine\\software\\valve\\steam\\apps\\commonredist\\vcredist\\2019", "x64 14.28.29334.0", 1),
|
|
("hkey_local_machine\\software\\valve\\steam\\apps\\228980", "setup", 1),
|
|
})
|
|
with_minimum = self.SCRIPT.replace('"Setup" { "process 1"', '"Setup" { "MinimumHasRunValue" "3" "process 1"')
|
|
self.assertIn(("hkey_local_machine\\software\\valve\\steam\\apps\\228980", "setup", 3),
|
|
MODULE["run_keys"](MODULE["read_vdf"](with_minimum)))
|
|
with self.assertRaises(ValueError):
|
|
MODULE["read_vdf"]('"a" { "b" }')
|
|
|
|
def test_install_scripts_count_as_done_only_when_recorded_and_still_marked(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
script = Path(tmp) / "evaluatorscript_1.vdf"
|
|
script.write_text(self.SCRIPT)
|
|
prefix = Path(tmp) / "compat/pfx"
|
|
env = {"STEAM_COMPAT_DATA_PATH": str(prefix.parent)}
|
|
done = MODULE["install_scripts_done"]
|
|
self.assertFalse(done([str(script)], env))
|
|
prefix.mkdir(parents=True)
|
|
MODULE["record_install_scripts"](MODULE["scripts_digest"]([str(script)]), env)
|
|
self.assertFalse(done([str(script)], env))
|
|
(prefix / "system.reg").write_text(self.REDIST)
|
|
self.assertFalse(done([str(script)], env))
|
|
(prefix / "system.reg").write_text(self.REDIST + self.SETUP)
|
|
self.assertTrue(done([str(script)], env))
|
|
# Steam rewrote the file: only marked "run process" entries, so its evaluator would run nothing either
|
|
script.write_text(self.SCRIPT.replace("x64.cmd", "x64-update.cmd"))
|
|
self.assertTrue(done([str(script)], env))
|
|
script.write_text(self.SCRIPT.replace('"Setup"', '"Setup 2"'))
|
|
self.assertFalse(done([str(script)], env))
|
|
script.write_text('"InstallScript" { "Registry" { "HKEY_LOCAL_MACHINE\\\\Software\\\\Game" { "string" { "Path" "%INSTALLDIR%" } } } }')
|
|
MODULE["record_install_scripts"](MODULE["scripts_digest"]([str(script)]), env)
|
|
self.assertFalse(done([str(script)], env))
|
|
|
|
def test_marked_run_process_scripts_count_as_done_without_a_record(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
script = Path(tmp) / "evaluatorscript_291550.vdf"
|
|
script.write_text(self.SCRIPT.replace('"0" { "appid" "228980"',
|
|
'"0" { "appid" "228980" "mode" "1" "language" "english" '
|
|
'"install_path" "/root/x" "SteamID" "7656"'))
|
|
prefix = Path(tmp) / "compat/pfx"
|
|
prefix.mkdir(parents=True)
|
|
env = {"STEAM_COMPAT_DATA_PATH": str(prefix.parent)}
|
|
done = MODULE["install_scripts_done"]
|
|
(prefix / "system.reg").write_text(self.REDIST)
|
|
self.assertFalse(done([str(script)], env))
|
|
(prefix / "system.reg").write_text(self.REDIST + self.SETUP)
|
|
self.assertTrue(done([str(script)], env))
|
|
(prefix / MODULE["INSTALL_STAMP"]).write_text("an older digest\n")
|
|
self.assertTrue(done([str(script)], env))
|
|
script.write_text(self.SCRIPT.replace('"run process" {',
|
|
'"registry" { "HKEY_LOCAL_MACHINE\\\\Software\\\\Game" { "string" { "Path" "x" } } } "run process" {'))
|
|
self.assertFalse(done([str(script)], env))
|
|
|
|
def test_install_scripts_need_their_dword_guards_satisfied(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
script = Path(tmp) / "evaluatorscript_1.vdf"
|
|
script.write_text(self.SCRIPT)
|
|
prefix = Path(tmp) / "compat/pfx"
|
|
prefix.mkdir(parents=True)
|
|
env = {"STEAM_COMPAT_DATA_PATH": str(prefix.parent)}
|
|
done = MODULE["install_scripts_done"]
|
|
MODULE["record_install_scripts"](MODULE["scripts_digest"]([str(script)]), env)
|
|
# a guard DWORD of 0 means Steam still runs the process, recorded or not
|
|
(prefix / "system.reg").write_text(self.REDIST + self.SETUP.replace("dword:00000001", "dword:00000000"))
|
|
self.assertFalse(done([str(script)], env))
|
|
(prefix / MODULE["INSTALL_STAMP"]).unlink()
|
|
self.assertFalse(done([str(script)], env))
|
|
# a value that is not a DWORD does not count either
|
|
(prefix / "system.reg").write_text(self.REDIST + self.SETUP.replace("dword:00000001", '"1"'))
|
|
self.assertFalse(done([str(script)], env))
|
|
# MinimumHasRunValue: below it the process runs again, at or above it the scripts are done
|
|
script.write_text(self.SCRIPT.replace('"Setup" { "process 1"', '"Setup" { "MinimumHasRunValue" "2" "process 1"'))
|
|
(prefix / "system.reg").write_text(self.REDIST + self.SETUP)
|
|
self.assertFalse(done([str(script)], env))
|
|
(prefix / "system.reg").write_text(self.REDIST + self.SETUP.replace("dword:00000001", "dword:00000002"))
|
|
self.assertTrue(done([str(script)], env))
|
|
|
|
def test_the_evaluator_is_skipped_once_it_finished_the_same_scripts(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
(root / "legacycompat").mkdir()
|
|
evaluator = root / "legacycompat/iscriptevaluator.exe"
|
|
evaluator.write_bytes(b"evaluator")
|
|
script = root / "legacycompat/evaluatorscript_1.vdf"
|
|
prefix = root / "compatdata/1/pfx"
|
|
prefix.mkdir(parents=True)
|
|
(prefix / "system.reg").write_text(self.REDIST + self.SETUP)
|
|
runs = root / "runs"
|
|
proton = root / "proton"
|
|
proton.write_text("#!/bin/sh\necho run >> %s\nexit ${EXIT_CODE:-0}\n" % shlex.quote(str(runs)))
|
|
proton.chmod(0o755)
|
|
|
|
# a registry action besides the marked runs: Steam's evaluator has work to do, so it runs once
|
|
with_registry = self.SCRIPT.replace(
|
|
'"run process" {', '"registry" { "HKEY_LOCAL_MACHINE\\\\Software\\\\Game" { "string" { "Path" "x" } } } "run process" {')
|
|
|
|
def evaluate(exit_code="0", text=None):
|
|
script.write_text(text or (with_registry if exit_code != "changed" else with_registry.replace("setup.exe", "setup-update.exe")))
|
|
env = dict(os.environ, HOME=tmp, STEAM_COMPAT_CLIENT_INSTALL_PATH=str(root),
|
|
STEAM_COMPAT_DATA_PATH=str(prefix.parent), EXIT_CODE="0" if exit_code == "changed" else exit_code)
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(proton), "run",
|
|
str(evaluator), "legacycompat\\evaluatorscript_1.vdf"],
|
|
env=env, text=True, capture_output=True)
|
|
return result.returncode, len(runs.read_text().splitlines()) if runs.exists() else 0
|
|
|
|
self.assertEqual(evaluate("3"), (3, 1))
|
|
self.assertFalse((prefix / ".droiddeck-install-scripts").exists())
|
|
self.assertEqual(evaluate(), (0, 2))
|
|
self.assertEqual(evaluate(), (0, 2))
|
|
self.assertEqual(evaluate("changed"), (0, 3))
|
|
# only marked "run process" entries, all set: skipped even though the file differs from the recorded one
|
|
self.assertEqual(evaluate(text=self.SCRIPT.replace("x64.cmd", "x64-update.cmd")), (0, 3))
|
|
|
|
def test_the_mali_bridge_caps_the_vkd3d_feature_level(self):
|
|
bridge = {"DD_VKBRIDGE": "1", "VKD3D_FEATURE_LEVEL": "12_2"}
|
|
self.assertIn("capped", MODULE["bridge_feature_level"](bridge))
|
|
self.assertEqual(bridge["VKD3D_FEATURE_LEVEL"], "12_0")
|
|
for env in ({"DD_VKBRIDGE": "1", "VKD3D_FEATURE_LEVEL": "11_1"}, {"VKD3D_FEATURE_LEVEL": "12_2"}, {"DD_VKBRIDGE": "1"}):
|
|
before = dict(env)
|
|
self.assertIsNone(MODULE["bridge_feature_level"](env))
|
|
self.assertEqual(env, before)
|
|
|
|
def test_profile_precedence_and_unset(self):
|
|
env = {"KEEP": "inherited", "REMOVE": "inherited", "CUSTOM": "launch option"}
|
|
config = {"version": 1, "shared": {"CUSTOM": "shared"}, "games": {"42": {"REMOVE": None, "CUSTOM": "game", "EMPTY": ""}}}
|
|
self.assertEqual(MODULE["apply_config"](env, config, "42"), {"KEEP": "inherited", "CUSTOM": "game", "EMPTY": ""})
|
|
self.assertEqual(env["REMOVE"], "inherited")
|
|
self.assertEqual(MODULE["apply_config"](env, config, "43")["CUSTOM"], "shared")
|
|
|
|
def test_games_get_their_own_turnip_debug_and_a_game_profile_still_wins(self):
|
|
gpu = MODULE["game_gpu"]
|
|
self.assertEqual(gpu({"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "", "KEEP": "1"}), {"KEEP": "1"})
|
|
self.assertEqual(gpu({"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "sysmem"}), {"TU_DEBUG": "sysmem"})
|
|
self.assertEqual(gpu({"DROIDDECK_GAME_TU_DEBUG": "nolrz"}), {"TU_DEBUG": "nolrz"})
|
|
self.assertEqual(gpu({"TU_DEBUG": "sysmem"}), {"TU_DEBUG": "sysmem"})
|
|
config = {"version": 1, "games": {"42": {"TU_DEBUG": "sysmem"}}}
|
|
env = gpu({"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": ""})
|
|
self.assertEqual(MODULE["apply_config"](env, config, "42")["TU_DEBUG"], "sysmem")
|
|
self.assertNotIn("TU_DEBUG", MODULE["apply_config"](env, config, "43"))
|
|
def applied(config, app_id="42", env=None):
|
|
return MODULE["apply_config"](env or {"TU_DEBUG": "sysmem"}, config, app_id)
|
|
prefixed = "DROIDDECK_GAME_TU_DEBUG"
|
|
config = {"version": 1, "games": {"42": {prefixed: "gmem"}, "43": {prefixed: ""}}}
|
|
self.assertEqual(applied(config)["TU_DEBUG"], "gmem")
|
|
self.assertNotIn("TU_DEBUG", applied(config, "43"))
|
|
self.assertNotIn(prefixed, applied(config))
|
|
shared = {"version": 1, "shared": {prefixed: "gmem"}, "games": {"42": {"TU_DEBUG": "nolrz"}, "43": {"TU_DEBUG": None}}}
|
|
self.assertEqual(applied(shared)["TU_DEBUG"], "nolrz")
|
|
self.assertNotIn("TU_DEBUG", applied(shared, "43"))
|
|
self.assertEqual(applied(shared, "44")["TU_DEBUG"], "gmem")
|
|
self.assertNotIn(prefixed, applied(shared, "44"))
|
|
both = {"version": 1, "games": {"42": {"TU_DEBUG": "sysmem", prefixed: ""}, "43": {"TU_DEBUG": None, prefixed: "gmem"}}}
|
|
self.assertEqual(applied(both)["TU_DEBUG"], "sysmem")
|
|
self.assertNotIn("TU_DEBUG", applied(both, "43", {"TU_DEBUG": "nolrz"}))
|
|
self.assertNotIn(prefixed, applied(both))
|
|
|
|
def test_games_run_with_gl_error_checks_unless_the_user_turns_them_off(self):
|
|
gpu = MODULE["game_gpu"]
|
|
session = {"MESA_NO_ERROR": "1", "DROIDDECK_GAME_MESA_NO_ERROR": "", "KEEP": "1"}
|
|
self.assertEqual(gpu(session), {"KEEP": "1"})
|
|
self.assertEqual(gpu(session, True), {"MESA_NO_ERROR": "1", "KEEP": "1"})
|
|
self.assertEqual(gpu({"MESA_NO_ERROR": "1"}), {"MESA_NO_ERROR": "1"})
|
|
self.assertEqual(gpu({"MESA_NO_ERROR": "1", "DROIDDECK_GAME_MESA_NO_ERROR": "1"}), {"MESA_NO_ERROR": "1"})
|
|
both = gpu({"MESA_NO_ERROR": "1", "DROIDDECK_GAME_MESA_NO_ERROR": "", "TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "nolrz"})
|
|
self.assertEqual(both, {"TU_DEBUG": "nolrz"})
|
|
self.assertEqual(gpu({"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "", "MESA_NO_ERROR": "1"}),
|
|
{"MESA_NO_ERROR": "1"})
|
|
config = {"version": 1, "games": {"42": {"MESA_NO_ERROR": "1"}}}
|
|
env = gpu(session)
|
|
self.assertEqual(MODULE["apply_config"](env, config, "42")["MESA_NO_ERROR"], "1")
|
|
self.assertNotIn("MESA_NO_ERROR", MODULE["apply_config"](env, config, "43"))
|
|
|
|
def test_a_chromium_app_keeps_the_sessions_turnip_debug(self):
|
|
gpu = MODULE["game_gpu"]
|
|
self.assertEqual(gpu({"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "", "KEEP": "1"}, True),
|
|
{"TU_DEBUG": "sysmem", "KEEP": "1"})
|
|
self.assertEqual(gpu({"TU_DEBUG": "sysmem", "DROIDDECK_GAME_TU_DEBUG": "nolrz"}, True), {"TU_DEBUG": "sysmem"})
|
|
self.assertEqual(gpu({"TU_DEBUG": "sysmem"}, True), {"TU_DEBUG": "sysmem"})
|
|
|
|
def test_chromium_files_are_found_four_levels_deep_and_no_further(self):
|
|
chromium = MODULE["chromium_app"]
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp) / "app"
|
|
(root / "usr/lib/tool").mkdir(parents=True)
|
|
(root / "usr/lib/tool/libtool.so").write_bytes(b"")
|
|
self.assertFalse(chromium(str(root)))
|
|
for name in ("chrome-sandbox", "chrome_100_percent.pak", "v8_context_snapshot.bin"):
|
|
found = root / "a/b/c" / name
|
|
found.parent.mkdir(parents=True, exist_ok=True)
|
|
found.write_bytes(b"")
|
|
self.assertTrue(chromium(str(root)), name)
|
|
found.unlink()
|
|
deep = root / "a/b/c/d/chrome-sandbox"
|
|
deep.parent.mkdir(parents=True)
|
|
deep.write_bytes(b"")
|
|
self.assertFalse(chromium(str(root)))
|
|
self.assertFalse(chromium(str(Path(tmp) / "missing")))
|
|
|
|
def test_chromium_detection_does_not_follow_links_inside_the_app(self):
|
|
chromium = MODULE["chromium_app"]
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
other = Path(tmp) / "other"
|
|
other.mkdir()
|
|
(other / "chrome-sandbox").write_bytes(b"")
|
|
root = Path(tmp) / "app"
|
|
root.mkdir()
|
|
(root / "linked").symlink_to(other, target_is_directory=True)
|
|
self.assertFalse(chromium(str(root)))
|
|
link = Path(tmp) / "app-link"
|
|
link.symlink_to(other, target_is_directory=True)
|
|
self.assertTrue(chromium(str(link)))
|
|
|
|
def test_a_games_wine_sync_choice_also_reaches_its_setup_runs(self):
|
|
env = {"DD_SYNC": "1", "DD_SYNC_FALLBACK": "1", "DD_FSYNC_FIRST": "0", "OTHER": "kept"}
|
|
config = {"version": 1, "games": {"42": {"DD_SYNC": "0", "DD_FSYNC_FIRST": "1", "PROTON_NO_ESYNC": "1", "FEX_TSOENABLED": "1"}}}
|
|
chosen = MODULE["apply_config"](env, MODULE["sync_config"](config, "42"), "42")
|
|
self.assertEqual(chosen, {"DD_SYNC": "0", "DD_SYNC_FALLBACK": "1", "DD_FSYNC_FIRST": "1", "PROTON_NO_ESYNC": "1", "OTHER": "kept"})
|
|
|
|
def test_component_profiles_override_general_and_restore_it_for_the_next_game(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
home = root / "home"
|
|
component_dir = home / ".local/share/droiddeck-components"
|
|
base = root / "proton"
|
|
target = base / "files/lib/wine/dxvk/aarch64-windows/d3d11.dll"
|
|
leftover = target.with_name("d3d8.dll")
|
|
component_dir.mkdir(parents=True)
|
|
target.parent.mkdir(parents=True)
|
|
(base / "version").write_text("1 build-1\n")
|
|
general = root / "general.dll"
|
|
game = root / "game.dll"
|
|
general.write_text("general")
|
|
game.write_text("game")
|
|
target.write_text("old")
|
|
leftover.write_text("old")
|
|
digest = lambda path: hashlib.sha256(path.read_bytes()).hexdigest()
|
|
(component_dir / "desired.tsv").write_text(
|
|
"*\tproton\tbuild-1\tdxvk\tfiles/lib/wine/dxvk/aarch64-windows/d3d11.dll\t%s\t%s\n"
|
|
"42\tproton\tbuild-1\tdxvk\tfiles/lib/wine/dxvk/aarch64-windows/d3d11.dll\t%s\t%s\n"
|
|
"42\tproton\tbuild-1\tdxvk\tfiles/lib/wine/dxvk/aarch64-windows/d3d8.dll\t-\t-\n"
|
|
% (digest(general), general, digest(game), game)
|
|
)
|
|
script = COMPAT["DD_COMPONENTS_SETUP"] + '\nverb=waitforexitandrun; dd_components "$1"\n'
|
|
env = dict(os.environ, HOME=str(home), STEAM_COMPAT_DATA_PATH="/steam/compatdata/42")
|
|
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True)
|
|
self.assertEqual(target.read_text(), "game")
|
|
self.assertFalse(leftover.exists())
|
|
|
|
env["STEAM_COMPAT_DATA_PATH"] = "/steam/compatdata/43"
|
|
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True)
|
|
self.assertEqual(target.read_text(), "general")
|
|
|
|
def test_system_powervr_preserves_dxvk_profiles_without_applying_them(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
home = root / "home"
|
|
component_dir = home / ".local/share/droiddeck-components"
|
|
component_dir.mkdir(parents=True)
|
|
base = root / "proton"
|
|
paths = {
|
|
"dxvk": "files/lib/wine/dxvk/aarch64-windows/d3d11.dll",
|
|
"fex": "files/lib/wine/aarch64-windows/libarm64ecfex.dll",
|
|
"vkd3d": "files/lib/wine/vkd3d-proton/aarch64-windows/d3d12.dll",
|
|
}
|
|
rows = []
|
|
for comp, rel in paths.items():
|
|
target = base / rel
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_text("bundled " + comp)
|
|
for scope in ("*", "42"):
|
|
source = root / (comp + ("-general" if scope == "*" else "-game"))
|
|
source.write_text(source.name)
|
|
rows.append("%s\tproton\tbuild-1\t%s\t%s\t%s\t%s\n" % (
|
|
scope, comp, rel, hashlib.sha256(source.read_bytes()).hexdigest(), source,
|
|
))
|
|
leftover = (base / paths["dxvk"]).with_name("d3d8.dll")
|
|
leftover.write_text("bundled d3d8")
|
|
rows.append("42\tproton\tbuild-1\tdxvk\t%s\t-\t-\n" % leftover.relative_to(base))
|
|
(base / "version").write_text("1 build-1\n")
|
|
selection = component_dir / "desired.tsv"
|
|
selection.write_text("".join(rows))
|
|
saved = selection.read_bytes()
|
|
script = COMPAT["DD_COMPONENTS_SETUP"] + '\nverb=waitforexitandrun; dd_components "$1"\n'
|
|
env = dict(os.environ, HOME=str(home), STEAM_COMPAT_DATA_PATH="/steam/compatdata/42",
|
|
DROIDDECK_POWERVR_RUNTIME="/system_vulkan/runtime")
|
|
|
|
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True)
|
|
|
|
self.assertEqual((base / paths["dxvk"]).read_text(), "bundled dxvk")
|
|
self.assertEqual(leftover.read_text(), "bundled d3d8")
|
|
for comp in ("fex", "vkd3d"):
|
|
self.assertEqual((base / paths[comp]).read_text(), comp + "-game")
|
|
self.assertEqual(selection.read_bytes(), saved)
|
|
|
|
# A subsequent manual-driver session still applies the saved per-game DXVK choice.
|
|
env.pop("DROIDDECK_POWERVR_RUNTIME")
|
|
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True)
|
|
self.assertEqual((base / paths["dxvk"]).read_text(), "dxvk-game")
|
|
self.assertFalse(leftover.exists())
|
|
self.assertEqual(selection.read_bytes(), saved)
|
|
|
|
def test_droiddeck_bionic_takes_only_android_fex_rows(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
home = root / "home"
|
|
component_dir = home / ".local/share/droiddeck-components"
|
|
store = component_dir / "store"
|
|
component_dir.mkdir(parents=True)
|
|
unix = "files/lib/wine/aarch64-unix/libwow64fex.so"
|
|
other = "files/lib/wine/aarch64-unix/libarm64ecfex.so"
|
|
dll = "files/lib/wine/aarch64-windows/libwow64fex.dll"
|
|
digest = lambda path: hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
def source(key, rel, text):
|
|
path = store / key / rel
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(text)
|
|
return path
|
|
|
|
def row(scope, tool, rel, path):
|
|
return "%s\t%s\tbuild-1\tfex\t%s\t%s\t%s\n" % (scope, tool, rel, digest(path), path)
|
|
|
|
bionic, glibc_tool = "DroidDeck-Bionic-12.8-r24", "DroidDeck-Proton-11-12.8"
|
|
for tool in (bionic, glibc_tool):
|
|
for rel in (unix, other, dll):
|
|
(root / tool / rel).parent.mkdir(parents=True, exist_ok=True)
|
|
(root / tool / rel).write_text("bundled " + rel)
|
|
(root / tool / "version").write_text("1 build-1\n")
|
|
glibc = source("FEXCore-2611-linux", unix, "glibc so")
|
|
android = source("FEXCore-2611-bionic", unix, "android so")
|
|
android_dll = source("FEXCore-2611-Bionic", dll, "android dll")
|
|
saved = source("original-%s-%s-fex" % (bionic, bionic), unix, "saved android so")
|
|
rows = []
|
|
for tool in (bionic, glibc_tool):
|
|
rows += [row("42", tool, unix, glibc), "42\t%s\tbuild-1\tfex\t%s\t-\t-\n" % (tool, other)]
|
|
rows += [row("43", tool, unix, android), row("43", tool, dll, android_dll)]
|
|
rows += [row("*", tool, unix, saved)]
|
|
(component_dir / "desired.tsv").write_text("".join(rows))
|
|
script = COMPAT["DD_COMPONENTS_SETUP"] + '\nverb=waitforexitandrun; dd_components "$1"\n'
|
|
run = lambda tool, app: subprocess.run(
|
|
["bash", "-c", script, "test", str(root / tool)], check=True, capture_output=True,
|
|
env=dict(os.environ, HOME=str(home), STEAM_COMPAT_DATA_PATH="/steam/compatdata/" + app))
|
|
|
|
run(bionic, "42")
|
|
self.assertEqual((root / bionic / unix).read_text(), "bundled " + unix)
|
|
self.assertEqual((root / bionic / other).read_text(), "bundled " + other)
|
|
run(bionic, "43")
|
|
self.assertEqual((root / bionic / unix).read_text(), "android so")
|
|
self.assertEqual((root / bionic / dll).read_text(), "android dll")
|
|
run(bionic, "44")
|
|
self.assertEqual((root / bionic / unix).read_text(), "saved android so")
|
|
|
|
run(glibc_tool, "42")
|
|
self.assertEqual((root / glibc_tool / unix).read_text(), "glibc so")
|
|
self.assertFalse((root / glibc_tool / other).exists())
|
|
|
|
def test_component_scope_matches_environment_scope_for_shortcut_ids(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
component_dir = root / ".local/share/droiddeck-components"
|
|
base = root / "proton"
|
|
target = base / "files/lib/wine/dxvk/aarch64-windows/d3d11.dll"
|
|
component_dir.mkdir(parents=True)
|
|
target.parent.mkdir(parents=True)
|
|
(base / "version").write_text("1 build-1\n")
|
|
rows = []
|
|
for scope in ("*", "42", "4294967295", "2147483648"):
|
|
source = root / ("default" if scope == "*" else scope)
|
|
source.write_text(scope)
|
|
rows.append("%s\tproton\tbuild-1\tdxvk\t%s\t%s\t%s\n" % (
|
|
scope, target.relative_to(base),
|
|
hashlib.sha256(source.read_bytes()).hexdigest(), source,
|
|
))
|
|
(component_dir / "desired.tsv").write_text("".join(rows))
|
|
script = COMPAT["DD_COMPONENTS_SETUP"] + '\nverb=waitforexitandrun; dd_components "$1"\n'
|
|
for value in (
|
|
"42", "00042", "43", "-1", "-0001", "4294967295", "-2147483648",
|
|
"2147483648", "-1///", "0", "-0", "000", "-2147483649", "4294967296",
|
|
"999999999999999999999999999", "not-an-id", "1+1", "",
|
|
):
|
|
with self.subTest(prefix=value):
|
|
env = dict(os.environ, HOME=str(root), STEAM_COMPAT_DATA_PATH="/steam/compatdata/" + value)
|
|
target.write_text("untouched")
|
|
subprocess.run(["bash", "-c", script, "test", str(base)], env=env, check=True, capture_output=True)
|
|
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:
|
|
game = Path(tmp) / "Godot Game"
|
|
(game / "data_game_windows_x86_64").mkdir(parents=True)
|
|
for name in ("Game.exe", "Game.pck", "libsentry.windows.release.x86_64.dll", "data_game_windows_x86_64/coreclr.dll"):
|
|
(game / name).touch()
|
|
env, extra, notes = MODULE["engine_fixes"](str(game / "Game.exe"), [])
|
|
self.assertEqual(env["FEX_TSOENABLED"], "1")
|
|
self.assertNotIn("FEX_MULTIBLOCK", env)
|
|
self.assertEqual(env["WINEDLLOVERRIDES"], "libsentry.windows.release.x86_64=d")
|
|
self.assertEqual(extra, ["--rendering-driver", "vulkan"])
|
|
self.assertEqual(MODULE["engine_fixes"](str(game / "Game.exe"), ["--rendering-driver", "opengl3"])[1], [])
|
|
(game / "data_game_windows_x86_64/Sentry.Godot.dll").touch()
|
|
self.assertNotIn("WINEDLLOVERRIDES", MODULE["engine_fixes"](str(game / "Game.exe"), [])[0])
|
|
script = Path(tmp) / "GDScript Game"
|
|
script.mkdir()
|
|
for name in ("Game.exe", "Game.pck", "libsentry.windows.release.x86_64.dll"):
|
|
(script / name).touch()
|
|
env, extra, notes = MODULE["engine_fixes"](str(script / "Game.exe"), [])
|
|
self.assertNotIn("WINEDLLOVERRIDES", env)
|
|
self.assertEqual(extra, ["--rendering-driver", "vulkan"])
|
|
other = Path(tmp) / "Other"
|
|
other.mkdir()
|
|
(other / "Other.exe").touch()
|
|
self.assertEqual(MODULE["engine_fixes"](str(other / "Other.exe"), []), ({}, [], []))
|
|
|
|
def test_original_xbox_games_get_the_emulator_fixes_instead_of_the_dotnet_preset(self):
|
|
expected = {"FEX_TSOENABLED": "1", "FEX_VECTORTSOENABLED": "0", "FEX_MEMCPYSETTSOENABLED": "0",
|
|
"FEX_HALFBARRIERTSOENABLED": "1", "FEX_X87REDUCEDPRECISION": "1", "WINE_SPECIAL_APC_INTERRUPT": "1",
|
|
"FEX_SYNCX87CONTEXT": "1", "FEX_LOOPSUSPENDCHECK": "1", "FEX_SAFEIMAGEMAP": "1",
|
|
"WINE_MF_DISPLAY_APERTURE": "1", "WINE_PRECISE_SLEEP": "1", "VKD3D_INTEROP_PRESENT": "1",
|
|
"VKD3D_PACKED_422": "1"}
|
|
|
|
def package(folder, identity):
|
|
(folder / "EmuMenu").mkdir(parents=True)
|
|
for name in ("Emu.exe", "EmuMenu/EmuMenu.exe", "EmuMenu/coreclr.dll"):
|
|
(folder / name).touch()
|
|
(folder / "MicrosoftGame.config").write_text(
|
|
'<?xml version="1.0" encoding="utf-8"?><Game configVersion="1"><Identity Name="%s" '
|
|
'Publisher="CN=Microsoft" Version="1.0.0.0"/><ExecutableList><Executable Name="EmuMenu\\EmuMenu.exe"/>'
|
|
'</ExecutableList></Game>' % identity)
|
|
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
game = Path(tmp) / "Fuzion Frenzy"
|
|
package(game, "Xbox360BackwardCompatibil.PrimaryFuzionFrenzyFuzio")
|
|
for exe in (game / "Emu.exe", game / "EmuMenu/EmuMenu.exe"):
|
|
env, extra, notes = MODULE["engine_fixes"](str(exe), [], "2773102903")
|
|
self.assertEqual((env, extra), (expected, []))
|
|
self.assertEqual(len(notes), 1)
|
|
self.assertTrue(notes[0].startswith("Original Xbox game"))
|
|
config = {"version": 1, "games": {"2773102903": {"FEX_X87REDUCEDPRECISION": "0", "VKD3D_PACKED_422": None}}}
|
|
result = MODULE["apply_config"]({}, config, "2773102903", env)
|
|
self.assertEqual(result["FEX_X87REDUCEDPRECISION"], "0")
|
|
self.assertNotIn("VKD3D_PACKED_422", result)
|
|
self.assertEqual(result["WINE_SPECIAL_APC_INTERRUPT"], "1")
|
|
store = Path(tmp) / "Psychonauts"
|
|
package(store, "Microsoft.PsychonautsforWindows10")
|
|
env, extra, notes = MODULE["engine_fixes"](str(store / "Emu.exe"), [])
|
|
self.assertEqual(env, MODULE["DOTNET_FEX"])
|
|
self.assertEqual(notes, [".NET runtime: FEX with full TSO"])
|
|
(store / "MicrosoftGame.config").write_text("<Game><Identity Name=")
|
|
self.assertEqual(MODULE["engine_fixes"](str(store / "Emu.exe"), [])[0], MODULE["DOTNET_FEX"])
|
|
self.assertEqual(MODULE["xbox_identity"](str(Path(tmp) / "Other/Game.exe")), "")
|
|
# The Xbox store accepts the file name in any case.
|
|
(game / "MicrosoftGame.config").rename(game / "microsoftgame.config")
|
|
self.assertEqual(MODULE["xbox_identity"](str(game / "EmuMenu/EmuMenu.exe")),
|
|
"Xbox360BackwardCompatibil.PrimaryFuzionFrenzyFuzio")
|
|
|
|
def test_easy_anti_cheat_games_start_offline_only_when_opted_in(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
game = Path(tmp) / "ELDEN RING/Game"
|
|
(game / "EasyAntiCheat").mkdir(parents=True)
|
|
for name in ("start_protected_game.exe", "eldenring.exe"):
|
|
(game / name).touch()
|
|
(game / "EasyAntiCheat/settings.json").write_text('\ufeff{ "executable" : "eldenring.exe" }', encoding="utf-8")
|
|
command = ["proton", "waitforexitandrun", str(game / "start_protected_game.exe"), "-arg"]
|
|
offline = MODULE["offline_without_anticheat"]
|
|
self.assertEqual(offline(command, {}), command)
|
|
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "0"}), command)
|
|
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}),
|
|
["proton", "waitforexitandrun", str(game / "eldenring.exe"), "-arg"])
|
|
(game / "EasyAntiCheat/settings.json").write_text('{ "executable" : "../../escape.exe" }')
|
|
(Path(tmp) / "escape.exe").touch()
|
|
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}), command)
|
|
(game / "EasyAntiCheat/settings.json").write_text('{ "executable" : "missing.exe" }')
|
|
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}), command)
|
|
(game / "EasyAntiCheat/settings.json").write_text('{ "executable" : "link/escape.exe" }')
|
|
outside = Path(tmp) / "outside"
|
|
outside.mkdir()
|
|
(outside / "escape.exe").touch()
|
|
(game / "link").symlink_to(outside, target_is_directory=True)
|
|
self.assertEqual(offline(command, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}), command)
|
|
(game / "EasyAntiCheat/settings.json").write_text('{ "executable" : "eldenring.exe" }')
|
|
plain = ["proton", "waitforexitandrun", str(game / "eldenring.exe")]
|
|
self.assertEqual(offline(plain, {"DROIDDECK_ANTICHEAT_OFFLINE": "1"}), plain)
|
|
self.assertEqual(offline(["proton", "run", command[2]],
|
|
{"DROIDDECK_ANTICHEAT_OFFLINE": "1"}),
|
|
["proton", "run", command[2]])
|
|
|
|
def test_easy_anti_cheat_forwarding_through_entrypoint(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
game = home / "ELDEN RING/Game"
|
|
(game / "EasyAntiCheat").mkdir(parents=True)
|
|
bootstrapper = game / "start_protected_game.exe"
|
|
target = game / "eldenring.exe"
|
|
bootstrapper.touch()
|
|
target.touch()
|
|
(game / "EasyAntiCheat/settings.json").write_text(json.dumps({"executable": "eldenring.exe"}))
|
|
proton = home / "fake-proton"
|
|
proton.write_text("#!" + sys.executable + "\nimport json, sys\nprint(json.dumps(sys.argv[1:]))\n")
|
|
proton.chmod(0o755)
|
|
config = home / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
env = dict(os.environ, HOME=tmp, STEAM_COMPAT_DATA_PATH="/compatdata/42")
|
|
env.pop("DROIDDECK_ANTICHEAT_OFFLINE", None)
|
|
for setting, expected in (("1", target), ("0", bootstrapper), (None, bootstrapper)):
|
|
with self.subTest(setting=setting):
|
|
values = {} if setting is None else {"DROIDDECK_ANTICHEAT_OFFLINE": setting}
|
|
config.write_text(json.dumps({"version": 1, "games": {"42": values}}))
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"),
|
|
str(proton), "waitforexitandrun", str(bootstrapper), "-arg"],
|
|
env=env, text=True, capture_output=True, check=True)
|
|
self.assertEqual(json.loads(result.stdout.strip()),
|
|
["waitforexitandrun", str(expected), "-arg"])
|
|
|
|
def test_deep_rock_gdk_avoids_the_raytracing_pipeline_crash(self):
|
|
game = "/game/FSD/Binaries/WinGDK/FSD-WinGDK-Shipping.exe"
|
|
env, extra, notes = MODULE["engine_fixes"](game, [])
|
|
self.assertEqual(extra, ["-noraytracing", "-ini:Engine:[/Script/Engine.RendererSettings]:r.RayTracing=False"])
|
|
self.assertEqual(env, {})
|
|
self.assertTrue(notes)
|
|
for choice in ("-raytracing", "-noraytracing"):
|
|
self.assertEqual(MODULE["engine_fixes"](game, [choice]), ({}, [], []))
|
|
self.assertEqual(MODULE["engine_fixes"]("/game/FSD-Win64-Shipping.exe", []), ({}, [], []))
|
|
self.assertEqual(MODULE["engine_fixes"]("/game/Other-WinGDK-Shipping.exe", []), ({}, [], []))
|
|
|
|
def test_dragons_dogma_2_turns_its_wine_detection_off_unless_the_user_sets_it(self):
|
|
game = "/game/Dragons Dogma 2/DD2.exe"
|
|
env, extra, notes = MODULE["engine_fixes"](game, [], "2054970")
|
|
self.assertEqual(extra, ["/WineDetectionEnabled:False"])
|
|
self.assertEqual(env, {})
|
|
self.assertTrue(notes)
|
|
self.assertEqual(MODULE["engine_fixes"](game, ["-dx12"], "2054970")[1], ["/WineDetectionEnabled:False"])
|
|
for own in ("/WineDetectionEnabled:False", "/WineDetectionEnabled:True", "/winedetectionenabled:false"):
|
|
self.assertEqual(MODULE["engine_fixes"](game, [own], "2054970"), ({}, [], []))
|
|
self.assertEqual(MODULE["engine_fixes"](game, [], "42"), ({}, [], []))
|
|
self.assertEqual(MODULE["engine_fixes"](game, []), ({}, [], []))
|
|
|
|
def test_dragon_quest_monsters_4_writes_full_detail_mesh_settings(self):
|
|
apply = MODULE["dragon_quest_monsters_4_mesh_detail"]
|
|
wanted = "r.SkeletalMeshLODBias=-4\nr.SkeletalMeshLODRadiusScale=0.25\n"
|
|
for exe, project in (("DragonQuestMonsters4Demo.exe", "DragonQuestMonsters4Demo"),
|
|
("DragonQuestMonsters4-Win64-Shipping.exe", "DragonQuestMonsters4")):
|
|
with self.subTest(exe=exe), tempfile.TemporaryDirectory() as tmp:
|
|
(Path(tmp) / "pfx").mkdir()
|
|
config = Path(tmp) / "pfx/drive_c/users/steamuser/AppData/Local" / project / "Saved/Config/Windows/Engine.ini"
|
|
with contextlib.redirect_stderr(io.StringIO()):
|
|
apply("/game/" + exe, {"STEAM_COMPAT_DATA_PATH": tmp})
|
|
self.assertEqual(config.read_text(), "[SystemSettings]\n" + wanted)
|
|
|
|
def test_dragon_quest_monsters_4_keeps_other_engine_settings(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
(Path(tmp) / "pfx").mkdir()
|
|
config = Path(tmp) / "pfx/drive_c/users/steamuser/AppData/Local/DragonQuestMonsters4Demo/Saved/Config/Windows/Engine.ini"
|
|
config.parent.mkdir(parents=True)
|
|
config.write_text("[Core.Log]\nLogTemp=Log\n\n[SystemSettings]\nr.Fog=0\nr.SkeletalMeshLODBias=0\n\n[Other]\nKey=1\n")
|
|
config.chmod(0o444)
|
|
with contextlib.redirect_stderr(io.StringIO()):
|
|
MODULE["dragon_quest_monsters_4_mesh_detail"]("/game/DragonQuestMonsters4Demo.exe", {"STEAM_COMPAT_DATA_PATH": tmp})
|
|
self.assertEqual(config.read_text(), "[Core.Log]\nLogTemp=Log\n\n[SystemSettings]\nr.Fog=0\n"
|
|
"r.SkeletalMeshLODBias=-4\nr.SkeletalMeshLODRadiusScale=0.25\n\n[Other]\nKey=1\n")
|
|
self.assertEqual(config.stat().st_mode & 0o777, 0o444)
|
|
|
|
def test_dragon_quest_monsters_4_settings_use_the_game_profile_prefix(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
exe = home / "game/DragonQuestMonsters4Demo.exe"
|
|
exe.parent.mkdir()
|
|
exe.touch()
|
|
proton = home / "fake-proton"
|
|
proton.write_text("#!" + sys.executable + "\nimport json, sys\nprint(json.dumps(sys.argv[1:]))\n")
|
|
proton.chmod(0o755)
|
|
inherited, chosen = home / "compatdata/42", home / "profile/42"
|
|
for data in (inherited, chosen):
|
|
(data / "pfx").mkdir(parents=True)
|
|
config = home / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
config.write_text(json.dumps({"version": 1, "games": {"42": {"STEAM_COMPAT_DATA_PATH": str(chosen)}}}))
|
|
subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(proton), "waitforexitandrun", str(exe)],
|
|
env=dict(os.environ, HOME=tmp, STEAM_COMPAT_DATA_PATH=str(inherited)),
|
|
text=True, capture_output=True, check=True)
|
|
engine = "pfx/drive_c/users/steamuser/AppData/Local/DragonQuestMonsters4Demo/Saved/Config/Windows/Engine.ini"
|
|
self.assertIn("r.SkeletalMeshLODBias=-4", (chosen / engine).read_text())
|
|
self.assertFalse((inherited / engine).exists())
|
|
|
|
def test_dragon_quest_monsters_4_prefix_errors_do_not_stop_the_launch(self):
|
|
errors = io.StringIO()
|
|
with mock.patch.object(Path, "is_dir", side_effect=PermissionError("denied")), contextlib.redirect_stderr(errors):
|
|
MODULE["dragon_quest_monsters_4_mesh_detail"]("/game/DragonQuestMonsters4Demo.exe", {"STEAM_COMPAT_DATA_PATH": "/compatdata/42"})
|
|
self.assertIn("left as is", errors.getvalue())
|
|
|
|
def test_other_games_do_not_get_the_dragon_quest_monsters_4_settings(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
(Path(tmp) / "pfx").mkdir()
|
|
MODULE["dragon_quest_monsters_4_mesh_detail"]("/game/DragonQuestMonsters3.exe", {"STEAM_COMPAT_DATA_PATH": tmp})
|
|
self.assertEqual(list((Path(tmp) / "pfx").iterdir()), [])
|
|
|
|
def test_arkham_city_gets_full_x87_precision_over_the_preset(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
city = Path(tmp) / "Batman Arkham City GOTY/Binaries/Win32"
|
|
city.mkdir(parents=True)
|
|
for name in ("BatmanAC.exe", "BmLauncher.exe"):
|
|
(city / name).touch()
|
|
for exe in ("BatmanAC.exe", "BmLauncher.exe"):
|
|
env, extra, notes = MODULE["engine_fixes"](str(city / exe), [])
|
|
self.assertEqual((env, extra), ({"FEX_X87REDUCEDPRECISION": "0"}, []))
|
|
config = {"version": 1, "shared": {"FEX_X87REDUCEDPRECISION": "1"}}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "200260", env)["FEX_X87REDUCEDPRECISION"], "0")
|
|
config["games"] = {"200260": {"FEX_X87REDUCEDPRECISION": "1"}}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "200260", env)["FEX_X87REDUCEDPRECISION"], "1")
|
|
asylum = Path(tmp) / "Batman Arkham Asylum GOTY/Binaries"
|
|
asylum.mkdir(parents=True)
|
|
for name in ("ShippingPC-BmGame.exe", "BmLauncher.exe"):
|
|
(asylum / name).touch()
|
|
self.assertEqual(MODULE["engine_fixes"](str(asylum / "BmLauncher.exe"), []), ({}, [], []))
|
|
|
|
def test_store_launcher_resolves_the_game_executable_from_the_sidecar(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp) / "BatmanArkhamCity"
|
|
bin_dir = root / "Binaries/Win32"
|
|
bin_dir.mkdir(parents=True)
|
|
for name in ("Batman2.exe", "BatmanAC.exe"):
|
|
(bin_dir / name).touch()
|
|
launcher = root / ".droiddeck-launch.bat"
|
|
launcher.touch()
|
|
(root / ".droiddeck-store.json").write_text(json.dumps({
|
|
"store": "epic", "id": "Egret", "title": "Batman Arkham City",
|
|
"exe": "Binaries/Win32/Batman2.exe", "launcher": ".droiddeck-launch.bat",
|
|
}))
|
|
env, extra, notes = MODULE["engine_fixes"](str(launcher), [])
|
|
self.assertEqual((env, extra), ({"FEX_X87REDUCEDPRECISION": "0"}, []))
|
|
self.assertTrue(notes)
|
|
|
|
home = Path(tmp) / "home"
|
|
config = home / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
config.write_text(json.dumps({"version": 1, "shared": {"FEX_X87REDUCEDPRECISION": "1"}}))
|
|
probe = home / "proton"
|
|
probe.write_text("#!" + sys.executable + "\nimport os, sys\n"
|
|
"print(os.environ.get('FEX_X87REDUCEDPRECISION', ''))\n"
|
|
"print(sys.argv[2])\n")
|
|
probe.chmod(0o755)
|
|
base = {k: v for k, v in os.environ.items() if not k.startswith(("FEX_", "WINE", "PROTON", "DROIDDECK", "DD_", "STEAM"))}
|
|
base.update(HOME=str(home), STEAM_COMPAT_DATA_PATH=str(home / "compatdata/3648205350"))
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun", str(launcher)],
|
|
env=base, text=True, capture_output=True, check=True)
|
|
self.assertEqual(result.stdout.splitlines(), ["0", str(launcher)])
|
|
self.assertIn("Batman: Arkham City: FEX with full x87 precision", result.stderr)
|
|
|
|
rebirth = Path(tmp) / "FF7Rebirth"
|
|
rebirth_exe = rebirth / "End/Binaries/Win64/ff7rebirth_.exe"
|
|
rebirth_exe.parent.mkdir(parents=True)
|
|
rebirth_exe.touch()
|
|
rebirth_launcher = rebirth / ".droiddeck-launch.bat"
|
|
rebirth_launcher.touch()
|
|
(rebirth / ".droiddeck-store.json").write_text(json.dumps({
|
|
"store": "epic", "id": "ff7", "title": "FF7 Rebirth",
|
|
"exe": r"End\Binaries\Win64\ff7rebirth_.exe", "launcher": ".droiddeck-launch.bat",
|
|
}))
|
|
self.assertEqual(MODULE["engine_fixes"](str(rebirth_launcher), [])[0], {"VKD3D_FEATURE_LEVEL": "12_2"})
|
|
|
|
def test_store_launcher_ignores_missing_invalid_or_escaping_sidecar_paths(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
outside = Path(tmp) / "Outside"
|
|
outside.mkdir()
|
|
outside_exe = outside / "BatmanAC.exe"
|
|
outside_exe.touch()
|
|
|
|
root = Path(tmp) / "Game"
|
|
sub = root / "sub"
|
|
sub.mkdir(parents=True)
|
|
(root / "real.exe").touch()
|
|
(sub / "nested.exe").touch()
|
|
(root / "escape.exe").symlink_to(outside_exe)
|
|
(root / "linkdir").symlink_to(outside)
|
|
launcher = root / ".droiddeck-launch.bat"
|
|
launcher.touch()
|
|
sidecar = root / ".droiddeck-store.json"
|
|
|
|
resolve = MODULE["store_game_exe"]
|
|
self.assertEqual(resolve(str(launcher)), str(launcher))
|
|
|
|
for payload in ("not-json", "[]", json.dumps({"exe": ""}), json.dumps({"exe": 123}),
|
|
json.dumps({"exe": "missing.exe"}), json.dumps({"exe": "sub"}),
|
|
json.dumps({"exe": "../Outside/BatmanAC.exe"}),
|
|
json.dumps({"exe": "sub/../real.exe"}),
|
|
json.dumps({"exe": r"sub\..\real.exe"}),
|
|
json.dumps({"exe": "linkdir/../real.exe"}),
|
|
json.dumps({"exe": "sub/../../Outside/BatmanAC.exe"}),
|
|
json.dumps({"exe": str(outside_exe)}),
|
|
json.dumps({"exe": r"C:\Windows\notepad.exe"}),
|
|
json.dumps({"exe": "escape.exe"})):
|
|
with self.subTest(payload=payload):
|
|
sidecar.write_text(payload)
|
|
self.assertEqual(resolve(str(launcher)), str(launcher))
|
|
|
|
sidecar.write_text(json.dumps({"exe": "real.exe"}))
|
|
self.assertEqual(resolve(str(launcher)), str(root / "real.exe"))
|
|
sidecar.write_text(json.dumps({"exe": "sub/nested.exe"}))
|
|
self.assertEqual(resolve(str(launcher)), str(sub / "nested.exe"))
|
|
other_bat = root / "custom.bat"
|
|
other_bat.touch()
|
|
self.assertEqual(resolve(str(other_bat)), str(other_bat))
|
|
|
|
def test_split_second_gets_x87_fip_unless_the_game_sets_jit_features(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
game = Path(tmp) / "SplitSecond"
|
|
game.mkdir()
|
|
exe = game / "SplitSecond.exe"
|
|
exe.touch()
|
|
for app_id in ("297860", ""):
|
|
env, extra, notes = MODULE["engine_fixes"](str(exe), [], app_id)
|
|
self.assertEqual((env, extra), ({"FEX_JITFEATURES": "enablex87fip"}, []))
|
|
self.assertTrue(notes)
|
|
other = Path(tmp) / "Other/Game.exe"
|
|
other.parent.mkdir()
|
|
other.touch()
|
|
self.assertEqual(MODULE["engine_fixes"](str(other), [], "297860")[0], {"FEX_JITFEATURES": "enablex87fip"})
|
|
self.assertEqual(MODULE["engine_fixes"](str(other), [], "42"), ({}, [], []))
|
|
config = {"version": 1, "shared": {"FEX_X87REDUCEDPRECISION": "1"}}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "297860", env),
|
|
{"FEX_X87REDUCEDPRECISION": "1", "FEX_JITFEATURES": "enablex87fip"})
|
|
config["games"] = {"297860": {"FEX_JITFEATURES": "off"}}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "297860", env)["FEX_JITFEATURES"], "off")
|
|
|
|
def test_inno_setup_installers_get_the_stability_preset_over_the_default(self):
|
|
stability = {"FEX_TSOENABLED": "1", "FEX_VECTORTSOENABLED": "1", "FEX_MEMCPYSETTSOENABLED": "1",
|
|
"FEX_HALFBARRIERTSOENABLED": "1", "FEX_X87REDUCEDPRECISION": "0", "FEX_MULTIBLOCK": "0"}
|
|
performance_tso = {"FEX_TSOENABLED": "1", "FEX_VECTORTSOENABLED": "0", "FEX_MEMCPYSETTSOENABLED": "0",
|
|
"FEX_HALFBARRIERTSOENABLED": "0", "FEX_X87REDUCEDPRECISION": "1", "FEX_MULTIBLOCK": "1"}
|
|
|
|
def loader(path, resources=b"", machine=0x14C, section=b".rsrc", legacy=False):
|
|
dos = bytearray(0x80)
|
|
dos[:2] = b"MZ"
|
|
dos[0x3C:0x40] = (0x80).to_bytes(4, "little")
|
|
if legacy:
|
|
dos[0x30:0x34] = b"Inno"
|
|
header = b"PE\0\0" + machine.to_bytes(2, "little") + (1).to_bytes(2, "little") + bytes(12) \
|
|
+ (0xE0).to_bytes(2, "little") + bytes(2)
|
|
entry = section.ljust(8, b"\0") + bytes(8) + len(resources).to_bytes(4, "little") \
|
|
+ (0x400).to_bytes(4, "little") + bytes(16)
|
|
path.write_bytes((bytes(dos) + header + bytes(0xE0) + entry).ljust(0x400, b"\0") + resources)
|
|
return str(path)
|
|
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
folder = Path(tmp)
|
|
table = bytes(64) + b"rDlPtS\xcd\xe6\xd7{\x0b*" + bytes(64)
|
|
installers = [
|
|
loader(folder / "setup.exe", table),
|
|
loader(folder / "setup_game_1.0.exe", bytes(64) + b"nS5W7dT\x83\xaa\x1b\x0fj"),
|
|
loader(folder / "old_setup.exe", legacy=True),
|
|
]
|
|
for installer in installers:
|
|
env, extra, notes = MODULE["engine_fixes"](installer, [])
|
|
self.assertEqual((env, extra), (stability, []), installer)
|
|
self.assertTrue(notes)
|
|
config = {"version": 1, "shared": performance_tso}
|
|
self.assertEqual({k: v for k, v in MODULE["apply_config"]({}, config, "42", env).items() if k in stability},
|
|
stability)
|
|
config["games"] = {"42": {"FEX_MULTIBLOCK": "1"}}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "42", env)["FEX_MULTIBLOCK"], "1")
|
|
|
|
not_installers = [
|
|
loader(folder / "Game.exe", bytes(256)),
|
|
loader(folder / "Game64.exe", table, machine=0x8664),
|
|
loader(folder / "Data.exe", table, section=b".data"),
|
|
folder / "missing.exe",
|
|
]
|
|
(folder / "notes.exe").write_bytes(b"rDlPtS\xcd\xe6\xd7{\x0b*")
|
|
not_installers.append(folder / "notes.exe")
|
|
for other in not_installers:
|
|
self.assertEqual(MODULE["engine_fixes"](str(other), []), ({}, [], []), other)
|
|
|
|
# The run verb skips engine_fixes; an installer started that way still gets Stability.
|
|
probe = folder / "proton"
|
|
probe.write_text("#!" + sys.executable + "\nimport json, os\nprint(json.dumps(dict(os.environ)))\n")
|
|
probe.chmod(0o755)
|
|
base = {**os.environ, **performance_tso, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(folder / "compatdata/42")}
|
|
|
|
def run_verb(program):
|
|
out = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "run", program],
|
|
env=base, text=True, capture_output=True, check=True).stdout
|
|
return {name: value for name, value in json.loads(out).items() if name in stability}
|
|
|
|
self.assertEqual(run_verb(installers[0]), stability)
|
|
self.assertEqual(run_verb(str(folder / "Game.exe")), performance_tso)
|
|
config_path = folder / ".config/droiddeck/game-environment.json"
|
|
config_path.parent.mkdir(parents=True)
|
|
config_path.write_text(json.dumps({"version": 1, "shared": {"WINEESYNC": "1"}}))
|
|
self.assertEqual(run_verb(installers[0]), stability)
|
|
config_path.write_text(json.dumps({"version": 1, "games": {"42": {"FEX_MULTIBLOCK": "1"}}}))
|
|
self.assertEqual(run_verb(installers[0]), {**stability, "FEX_MULTIBLOCK": "1"})
|
|
config_path.write_text(json.dumps({"version": 1, "games": {"42": {"FEX_MULTIBLOCK": None}}}))
|
|
self.assertNotIn("FEX_MULTIBLOCK", run_verb(installers[0]))
|
|
|
|
def test_d3dgear_capture_hook_beside_the_game_is_turned_off(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
game = Path(tmp) / "The Crew 2"
|
|
game.mkdir()
|
|
for name in ("TheCrew2.exe", "TheCrew2_BE.exe", "d3dgear64.dll"):
|
|
(game / name).touch()
|
|
env, extra, notes = MODULE["engine_fixes"](str(game / "TheCrew2.exe"), [])
|
|
self.assertEqual((env, extra), ({"WINEDLLOVERRIDES": "d3dgear64=d"}, []))
|
|
self.assertTrue(notes)
|
|
(game / "d3dgear64.dll").rename(game / "D3DGear64.DLL")
|
|
self.assertEqual(MODULE["engine_fixes"](str(game / "TheCrew2.exe"), [])[0], {"WINEDLLOVERRIDES": "d3dgear64=d"})
|
|
(game / "D3DGear64.DLL").unlink()
|
|
self.assertEqual(MODULE["engine_fixes"](str(game / "TheCrew2.exe"), []), ({}, [], []))
|
|
|
|
def test_doom_2016_keeps_the_swapchain_image_count_it_asks_for(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
game = Path(tmp) / "DOOM (2016)"
|
|
game.mkdir()
|
|
for name in ("DOOMx64.exe", "DOOMx64vk.exe", "Galaxy64.dll"):
|
|
(game / name).touch()
|
|
images = {
|
|
"GAMESCOPE_WSI_MIN_IMAGE_COUNT": None,
|
|
"GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT": None,
|
|
"vk_x11_strict_image_count": "true",
|
|
}
|
|
for exe in ("DOOMx64.exe", "DOOMx64vk.exe"):
|
|
env, extra, notes = MODULE["engine_fixes"](str(game / exe), [])
|
|
self.assertEqual((env, extra), (images, []))
|
|
self.assertTrue(notes)
|
|
launched = {"GAMESCOPE_WSI_MIN_IMAGE_COUNT": "8", "GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT": "1"}
|
|
result = MODULE["apply_config"](launched, {"version": 1}, "3566086475", env)
|
|
self.assertNotIn("GAMESCOPE_WSI_MIN_IMAGE_COUNT", result)
|
|
self.assertNotIn("GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT", result)
|
|
self.assertEqual(result["vk_x11_strict_image_count"], "true")
|
|
config = {"version": 1, "games": {"3566086475": {"GAMESCOPE_WSI_MIN_IMAGE_COUNT": "3"}}}
|
|
self.assertEqual(MODULE["apply_config"](launched, config, "3566086475", env)["GAMESCOPE_WSI_MIN_IMAGE_COUNT"], "3")
|
|
eternal = Path(tmp) / "DOOMEternal"
|
|
eternal.mkdir()
|
|
(eternal / "DOOMEternalx64vk.exe").touch()
|
|
self.assertEqual(MODULE["engine_fixes"](str(eternal / "DOOMEternalx64vk.exe"), []), ({}, [], []))
|
|
other = Path(tmp) / "Other"
|
|
other.mkdir()
|
|
for name in ("Other.exe", "DOOMx64vk.exe"):
|
|
(other / name).touch()
|
|
self.assertEqual(MODULE["engine_fixes"](str(other / "Other.exe"), []), ({}, [], []))
|
|
|
|
def test_dll_overrides_from_several_fixes_are_all_kept(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
for name in ("Game.exe", "Game.pck", "GodotSharp.dll", "libsentry.windows.release.x86_64.dll", "d3dgear64.dll"):
|
|
(Path(tmp) / name).touch()
|
|
env = MODULE["engine_fixes"](str(Path(tmp) / "Game.exe"), [])[0]
|
|
self.assertEqual(env["WINEDLLOVERRIDES"], "libsentry.windows.release.x86_64=d;d3dgear64=d")
|
|
|
|
def test_black_ops_iii_and_dark_souls_remastered_skip_protonfixes(self):
|
|
for exe in ("/game/Call of Duty Black Ops III/BlackOps3.exe", "/game/DARK SOULS REMASTERED/DarkSoulsRemastered.exe"):
|
|
env, extra, notes = MODULE["engine_fixes"](exe, [])
|
|
self.assertEqual((env, extra), ({"PROTONFIXES_DISABLE": "1"}, []))
|
|
self.assertTrue(notes)
|
|
self.assertEqual(MODULE["engine_fixes"]("/game/Game/DarkSoulsII.exe", []), ({}, [], []))
|
|
|
|
def test_black_ops_ii_starts_with_steam_exec_handling(self):
|
|
for exe in ("/game/Call of Duty Black Ops II/t6zm.exe", "/game/Call of Duty Black Ops II/t6mp.exe", "/game/Call of Duty Black Ops II/t6sp.exe"):
|
|
env, extra, notes = MODULE["engine_fixes"](exe, [])
|
|
self.assertEqual((env, extra), ({"WINESTEAMNOEXEC": "0"}, []))
|
|
self.assertTrue(notes)
|
|
self.assertEqual(MODULE["engine_fixes"]("/game/Game/Other.exe", [], "202990")[0], {"WINESTEAMNOEXEC": "0"})
|
|
self.assertEqual(MODULE["engine_fixes"]("/game/Game/Other.exe", []), ({}, [], []))
|
|
|
|
def test_little_nightmares_keeps_its_render_thread(self):
|
|
env, extra, notes = MODULE["engine_fixes"]("/game/Little Nightmares/Atlas/Binaries/Win64/LittleNightmares.exe", [])
|
|
self.assertEqual((env, extra), ({"PROTONFIXES_DISABLE": "1"}, []))
|
|
self.assertTrue(notes)
|
|
self.assertEqual(MODULE["engine_fixes"]("/game/Little Nightmares II/Moonlight/Binaries/Win64/LittleNightmaresII.exe", []), ({}, [], []))
|
|
|
|
def test_game_cores_are_parsed_from_lists_and_ranges(self):
|
|
parse = MODULE["parse_cores"]
|
|
self.assertEqual(parse("0-3,6"), {0, 1, 2, 3, 6})
|
|
self.assertEqual(parse(" 4, 5 "), {4, 5})
|
|
for bad in ("", "a", "3-1", "1,,2", "-1", "1-"):
|
|
self.assertIsNone(parse(bad), bad)
|
|
|
|
def test_a_profiles_game_cores_pin_the_game_within_the_online_cores(self):
|
|
calls = []
|
|
os_mod = MODULE["os"]
|
|
with mock.patch.dict(MODULE["game_cores"].__globals__, {"online_cores": lambda: {0, 1, 2, 3, 4, 5, 6, 7}}), \
|
|
mock.patch.object(os_mod, "sched_setaffinity", side_effect=lambda pid, cores: calls.append(set(cores)), create=True):
|
|
MODULE["game_cores"]({"DROIDDECK_GAME_CORES": "0-2,9"})
|
|
MODULE["game_cores"]({"DROIDDECK_GAME_CORES": "junk"})
|
|
MODULE["game_cores"]({"DROIDDECK_GAME_CORES": "12-13"})
|
|
MODULE["game_cores"]({})
|
|
self.assertEqual(calls, [{0, 1, 2}])
|
|
self.assertEqual(MODULE["parse_cores"]("0,2-7"), {0, 2, 3, 4, 5, 6, 7})
|
|
|
|
def test_windows_games_see_only_the_cores_they_are_pinned_to(self):
|
|
os_mod = MODULE["os"]
|
|
online = {"online_cores": lambda: {0, 1, 2, 3, 4, 5, 6, 7}}
|
|
cases = [
|
|
({"DD_GAME_CPUS": "6,7"}, {6, 7}, "2:6,7", "2:6,7"),
|
|
({"DROIDDECK_GAME_CORES": "0-2"}, {0, 1, 2}, "3:0,1,2", "3:0,1,2"),
|
|
({"DD_GAME_CPUS": "0-7"}, set(range(8)), None, None),
|
|
({}, {6, 7}, None, None),
|
|
({"DD_GAME_CPUS": "6,7", "WINE_CPU_TOPOLOGY": "4:0,1,2,3"}, {6, 7}, "4:0,1,2,3", "4:0,1,2,3"),
|
|
({"WINE_CPU_TOPOLOGY": "2:0,1"}, set(range(8)), "2:0,1", "2:0,1"),
|
|
({"DD_GAME_CPUS": "6,7", "WINE_CPU_TOPOLOGY": ""}, {6, 7}, "", None),
|
|
({"DD_GAME_CPUS": "6,7", "PROTON_CPU_TOPOLOGY": "1:7"}, {6, 7}, None, "1:7"),
|
|
({"DD_GAME_CPUS": "9"}, {9}, None, None),
|
|
]
|
|
for env, affinity, expected, proton in cases:
|
|
env["DROIDDECK_FASTEST_CORES"] = "0"
|
|
with mock.patch.dict(MODULE["cpu_topology"].__globals__, online), \
|
|
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
|
|
MODULE["cpu_topology"](env)
|
|
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
|
|
self.assertEqual(env.get("PROTON_CPU_TOPOLOGY"), proton, env)
|
|
|
|
def test_only_games_get_the_larger_swapchain(self):
|
|
game = {"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/945360"}
|
|
self.assertTrue(MODULE["game_images"](game))
|
|
self.assertEqual(game["GAMESCOPE_WSI_MIN_IMAGE_COUNT"], "8")
|
|
self.assertEqual(game["GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT"], "1")
|
|
own = {"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/945360", "GAMESCOPE_WSI_MIN_IMAGE_COUNT": "3"}
|
|
MODULE["game_images"](own)
|
|
self.assertEqual(own["GAMESCOPE_WSI_MIN_IMAGE_COUNT"], "3")
|
|
for env in ({}, {"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0"}):
|
|
self.assertFalse(MODULE["game_images"](env))
|
|
self.assertNotIn("GAMESCOPE_WSI_MIN_IMAGE_COUNT", env)
|
|
|
|
def test_opengl_games_do_not_wait_for_the_screen_refresh(self):
|
|
cases = [
|
|
({}, "0"),
|
|
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/-686078602"}, "0"),
|
|
({"vblank_mode": "2"}, "2"),
|
|
({"vblank_mode": ""}, ""),
|
|
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0"}, None),
|
|
({"STEAM_COMPAT_DATA_PATH": ""}, None),
|
|
]
|
|
for env, expected in cases:
|
|
env.setdefault("STEAM_COMPAT_DATA_PATH", "/steam/compatdata/3608888694")
|
|
added = expected == "0" and "vblank_mode" not in env
|
|
self.assertEqual(MODULE["gl_vsync"](env), added, env)
|
|
self.assertEqual(env.get("vblank_mode"), expected, env)
|
|
said = "OpenGL does not wait for the screen refresh"
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
probe = Path(tmp) / "probe"
|
|
probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ.get('vblank_mode', 'unset'))\n")
|
|
probe.chmod(0o755)
|
|
config = Path(tmp) / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
for inherited, edits, expected in (({}, None, "0"), ({"vblank_mode": "3"}, None, "3"),
|
|
({}, {"vblank_mode": None}, "unset"), ({}, {"vblank_mode": "2"}, "2"),
|
|
({"vblank_mode": "3"}, {"vblank_mode": None}, "unset")):
|
|
with self.subTest(inherited=inherited, edits=edits):
|
|
config.write_text(json.dumps({"version": 1, "games": {"42": edits or {}}}))
|
|
env = {name: value for name, value in os.environ.items() if name != "vblank_mode"}
|
|
env.update(HOME=tmp, STEAM_COMPAT_DATA_PATH="/compatdata/42", **inherited)
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun"],
|
|
env=env, text=True, capture_output=True, check=True)
|
|
self.assertEqual(result.stdout.strip(), expected)
|
|
self.assertEqual(said in result.stderr, expected == "0" and not inherited, result.stderr)
|
|
|
|
def test_teardown_keeps_its_own_vsync_unless_the_player_chose(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
probe = Path(tmp) / "probe"
|
|
probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ.get('vblank_mode', 'unset'))\n")
|
|
probe.chmod(0o755)
|
|
game = Path(tmp) / "Teardown/teardown.exe"
|
|
game.parent.mkdir()
|
|
game.write_bytes(b"MZ")
|
|
config = Path(tmp) / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
for inherited, edits, shared, expected in (({}, None, None, "2"), ({"vblank_mode": "0"}, None, None, "0"),
|
|
({}, {"vblank_mode": "1"}, None, "1"),
|
|
({}, None, {"vblank_mode": "1"}, "1")):
|
|
with self.subTest(inherited=inherited, edits=edits, shared=shared):
|
|
config.write_text(json.dumps({"version": 1, "shared": shared or {}, "games": {"1167630": edits or {}}}))
|
|
env = {name: value for name, value in os.environ.items() if name != "vblank_mode"}
|
|
env.update(HOME=tmp, STEAM_COMPAT_DATA_PATH="/compatdata/1167630", **inherited)
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun", str(game)],
|
|
env=env, text=True, capture_output=True, check=True)
|
|
self.assertEqual(result.stdout.strip(), expected, result.stderr)
|
|
|
|
def test_windows_cpu_0_is_the_fastest_core(self):
|
|
os_mod = MODULE["os"]
|
|
pocket_fit = {0: 379, 1: 379, 2: 923, 3: 923, 4: 923, 5: 867, 6: 867, 7: 1024}
|
|
every = set(range(8))
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton = Path(tmp) / "proton"
|
|
proton.write_text('default_cpu_limit = {\n "19900" : "16", # Far Cry 2\n'
|
|
' "2229830" : "1", # Command & Conquer\n "11440" : "4", # DiRT\n'
|
|
' "1038250" : "P", # DIRT 5\n "618970" : 4, # Outcast, written as Proton 10 does\n'
|
|
'}\n\nother = {\n "620" : "2",\n}\n')
|
|
command = [str(proton), "waitforexitandrun", "/game/game.exe"]
|
|
cases = [
|
|
({}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
|
|
({"DD_GAME_CPUS": "6,7"}, {6, 7}, pocket_fit, "2:7,6", "2:7,6"),
|
|
({"DROIDDECK_GAME_CORES": "0-2"}, {0, 1, 2}, pocket_fit, "3:2,0,1", "3:2,0,1"),
|
|
({"DD_GAME_CPUS": "0-7"}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
|
|
({"WINE_CPU_TOPOLOGY": "2:0,1"}, every, pocket_fit, "2:0,1", "2:0,1"),
|
|
({"WINE_CPU_TOPOLOGY": ""}, every, pocket_fit, "", None),
|
|
({"PROTON_CPU_TOPOLOGY": "1:0"}, every, pocket_fit, None, "1:0"),
|
|
({"DROIDDECK_FASTEST_CORES": "0"}, every, pocket_fit, None, None),
|
|
({"SteamGameId": "2229830"}, every, pocket_fit, "1:7", "1:7"),
|
|
({"SteamGameId": "11440"}, every, pocket_fit, "4:7,2,3,4", "4:7,2,3,4"),
|
|
({"SteamGameId": "19900"}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
|
|
({"SteamGameId": "1038250"}, every, pocket_fit, None, None),
|
|
({"SteamGameId": "618970"}, every, pocket_fit, "4:7,2,3,4", "4:7,2,3,4"),
|
|
({"SteamGameId": "620"}, every, pocket_fit, "8:7,2,3,4,5,6,0,1", "8:7,2,3,4,5,6,0,1"),
|
|
({"SteamGameId": "2229830", "DD_GAME_CPUS": "0,1"}, {0, 1}, pocket_fit, "2:0,1", "2:0,1"),
|
|
({"SteamGameId": "2229830", "DROIDDECK_GAME_CORES": "12-13"}, every, pocket_fit, "1:7", "1:7"),
|
|
({"SteamGameId": "11440", "DD_GAME_CPUS": "0-7"}, every, pocket_fit, "4:7,2,3,4", "4:7,2,3,4"),
|
|
({}, every, {core: 100 for core in every}, None, None),
|
|
({}, every, None, None, None),
|
|
({"SteamGameId": "11440"}, every, None, "4:0,1,2,3", "4:0,1,2,3"),
|
|
({"DD_GAME_CPUS": "9"}, {9}, pocket_fit, None, None),
|
|
]
|
|
cases += [
|
|
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0"}, every, pocket_fit, None, None),
|
|
({"STEAM_COMPAT_DATA_PATH": ""}, every, pocket_fit, None, None),
|
|
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0", "DD_GAME_CPUS": "6,7"}, {6, 7}, pocket_fit, "2:6,7", "2:6,7"),
|
|
]
|
|
for env, affinity, speeds, expected, proton_topology in cases:
|
|
env.setdefault("STEAM_COMPAT_DATA_PATH", "/steam/compatdata/3608888694")
|
|
with mock.patch.dict(MODULE["cpu_topology"].__globals__, {"online_cores": lambda: every}), \
|
|
mock.patch.dict(MODULE["fastest_first"].__globals__, {"core_speeds": lambda cores, speeds=speeds: speeds}), \
|
|
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
|
|
MODULE["cpu_topology"](env, command)
|
|
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
|
|
self.assertEqual(env.get("PROTON_CPU_TOPOLOGY"), proton_topology, env)
|
|
self.assertIsNone(MODULE["proton_cpu_limit"](["/missing/proton"], {"SteamGameId": "11440"}))
|
|
self.assertIsNone(MODULE["proton_cpu_limit"](command, {}))
|
|
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "1038250"}), "P")
|
|
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "618970"}), 4)
|
|
|
|
def test_core_speeds_read_capacity_then_top_clock(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
for core, capacity, clock in ((0, "379", "2265600"), (1, None, "3302400")):
|
|
folder = Path(tmp) / ("cpu%d" % core) / "cpufreq"
|
|
folder.mkdir(parents=True)
|
|
(folder / "cpuinfo_max_freq").write_text(clock + "\n")
|
|
if capacity:
|
|
(folder.parent / "cpu_capacity").write_text(capacity + "\n")
|
|
speeds = MODULE["core_speeds"]
|
|
self.assertEqual(speeds([0], tmp), {0: 379})
|
|
self.assertEqual(speeds([0, 1], tmp), {0: 2265600, 1: 3302400})
|
|
self.assertIsNone(speeds([0, 2], tmp))
|
|
|
|
def test_titles_with_former_feature_level_workarounds_keep_detected_capabilities(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
names = (
|
|
"StellarBlade/SB.exe", "StellarBlade/.droiddeck-launch.bat",
|
|
"StellarBlade/SB/Binaries/Win64/SB-Win64-Shipping.exe",
|
|
"Caravan/CaravanSandWitch.exe", "Caravan/.droiddeck-launch.bat",
|
|
"Caravan/CaravanSandWitch/Binaries/Win64/CaravanSandWitch-Win64-Shipping.exe",
|
|
"RoboCop/RoboCop.exe", "RoboCop/RoboCop/Binaries/Win64/RoboCop-Win64-Shipping.exe",
|
|
"ReSkate/Skate.exe", "ReSkate/ReSkate.dll", "ReSkate/ReSkateLauncher.exe",
|
|
"Cyberpunk/REDprelauncher.exe", "Cyberpunk/bin/x64/Cyberpunk2077.exe",
|
|
)
|
|
for name in names:
|
|
p = root / name
|
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
p.touch()
|
|
for name in names:
|
|
if name.endswith(".dll"):
|
|
continue
|
|
env, extra, notes = MODULE["engine_fixes"](str(root / name), [])
|
|
self.assertNotIn("VKD3D_FEATURE_LEVEL", env, name)
|
|
self.assertNotIn("VKD3D_SHADER_MODEL", env, name)
|
|
for values in ({}, {"VKD3D_FEATURE_LEVEL": "12_2", "VKD3D_SHADER_MODEL": "6_9"}):
|
|
config = {"version": 1, "shared": values}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "42", env), values, name)
|
|
config = {"version": 1, "shared": {}, "games": {"42": values}}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "42", env), values, name)
|
|
|
|
def test_ff7_rebirth_runs_at_feature_level_12_2_unless_the_game_overrides_it(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp) / "FINAL FANTASY VII REBIRTH"
|
|
game = root / "End/Binaries/Win64/ff7rebirth_.exe"
|
|
game.parent.mkdir(parents=True)
|
|
for exe in (root / "ff7rebirth.exe", game):
|
|
exe.touch()
|
|
env, extra, notes = MODULE["engine_fixes"](str(exe), [])
|
|
self.assertEqual(env, {"VKD3D_FEATURE_LEVEL": "12_2"}, exe.name)
|
|
self.assertTrue(notes)
|
|
config = {"version": 1, "shared": {}, "games": {"42": {"VKD3D_FEATURE_LEVEL": "12_1"}}}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "42", env), {"VKD3D_FEATURE_LEVEL": "12_1"})
|
|
|
|
def test_kcd2_runs_at_feature_level_12_2_by_app_id_unless_the_game_overrides_it(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
exe = Path(tmp) / "Bin/Win64MasterMasterSteamPGO/KingdomCome.exe"
|
|
exe.parent.mkdir(parents=True)
|
|
exe.touch()
|
|
env, extra, notes = MODULE["engine_fixes"](str(exe), [], "1771300")
|
|
self.assertEqual(env, {"VKD3D_FEATURE_LEVEL": "12_2", "VKD3D_SHADER_MODEL": "6_9"})
|
|
self.assertTrue(notes)
|
|
config = {"version": 1, "shared": {}, "games": {"1771300": {"VKD3D_FEATURE_LEVEL": "12_1"}}}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "1771300", env), {"VKD3D_FEATURE_LEVEL": "12_1", "VKD3D_SHADER_MODEL": "6_9"})
|
|
self.assertEqual(MODULE["engine_fixes"](str(exe), [], "42")[0], {})
|
|
|
|
def test_hades_ii_runs_at_feature_level_12_2_from_steam_and_xbox_unless_the_game_overrides_it(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
for exe in (Path(tmp) / "Hades II/Ship/Hades2.exe", Path(tmp) / "Xbox/Hades II/Hades2.exe"):
|
|
exe.parent.mkdir(parents=True)
|
|
exe.touch()
|
|
env, extra, notes = MODULE["engine_fixes"](str(exe), [])
|
|
self.assertEqual(env, {"VKD3D_FEATURE_LEVEL": "12_2"}, str(exe))
|
|
self.assertTrue(notes)
|
|
config = {"version": 1, "shared": {}, "games": {"42": {"VKD3D_FEATURE_LEVEL": "12_1"}}}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "42", env), {"VKD3D_FEATURE_LEVEL": "12_1"})
|
|
self.assertEqual(MODULE["engine_fixes"]("/game/Hades/x64/Hades.exe", [])[0], {})
|
|
|
|
def test_unity_players_keep_tso_over_the_preset(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
def game(*names):
|
|
for name in names:
|
|
(Path(tmp) / name).parent.mkdir(parents=True, exist_ok=True)
|
|
(Path(tmp) / name).touch()
|
|
return str(Path(tmp) / names[0])
|
|
|
|
il2cpp = game("Megabonk/Megabonk.x86_64", "Megabonk/UnityPlayer.so", "Megabonk/GameAssembly.so")
|
|
mono = game("Mono/Game.x86_64", "Mono/UnityPlayer.so")
|
|
windows = game("Crab Game/Crab Game.exe", "Crab Game/UnityPlayer.dll", "Crab Game/GameAssembly.dll")
|
|
windows_mono = game("RoR2/Risk of Rain 2.exe", "RoR2/UnityPlayer.dll", "RoR2/MonoBleedingEdge/mono-2.0-bdwgc.dll")
|
|
for exe in (il2cpp, mono, windows, windows_mono):
|
|
env, extra, notes = MODULE["engine_fixes"](exe, [])
|
|
self.assertEqual((env, extra, notes), ({"FEX_TSOENABLED": "1"}, [], ["Unity: FEX with TSO"]))
|
|
performance = {"version": 1, "shared": {"FEX_TSOENABLED": "0", "FEX_VECTORTSOENABLED": "0"}}
|
|
result = MODULE["apply_config"]({}, performance, "3405340", env)
|
|
self.assertEqual((result["FEX_TSOENABLED"], result["FEX_VECTORTSOENABLED"]), ("1", "0"))
|
|
performance["games"] = {"3405340": {"FEX_TSOENABLED": "0"}}
|
|
self.assertEqual(MODULE["apply_config"]({}, performance, "3405340", env)["FEX_TSOENABLED"], "0")
|
|
|
|
def test_a_new_fix_only_needs_registering(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
(Path(tmp) / "Game.exe").touch()
|
|
(Path(tmp) / "engine.dll").touch()
|
|
check = lambda game: ({"ENGINE": "1"}, ["--flag"], "engine") if "engine.dll" in game.files else None
|
|
MODULE["FIXES"].append(check)
|
|
try:
|
|
self.assertEqual(MODULE["engine_fixes"](str(Path(tmp) / "Game.exe"), []), ({"ENGINE": "1"}, ["--flag"], ["engine"]))
|
|
finally:
|
|
MODULE["FIXES"].remove(check)
|
|
|
|
def test_engine_fixes_sit_between_shared_and_game_profiles(self):
|
|
env = {"WINEDLLOVERRIDES": "dxgi=n"}
|
|
fixes = {"FEX_MULTIBLOCK": "0", "WINEDLLOVERRIDES": "libsentry=d"}
|
|
config = {"version": 1, "shared": {"FEX_MULTIBLOCK": "1"}, "games": {"42": {"FEX_TSOENABLED": "0"}}}
|
|
result = MODULE["apply_config"](env, config, "42", {**fixes, "FEX_TSOENABLED": "1"})
|
|
self.assertEqual(result["FEX_MULTIBLOCK"], "0")
|
|
self.assertEqual(result["FEX_TSOENABLED"], "0")
|
|
self.assertEqual(result["WINEDLLOVERRIDES"], "dxgi=n;libsentry=d")
|
|
|
|
def test_game_dll_overrides_follow_droiddecks_own(self):
|
|
fixes = {"WINEDLLOVERRIDES": "msvcp100=n,b"}
|
|
config = {"version": 1, "shared": {}, "games": {"42": {"WINEDLLOVERRIDES": "windowscodecs,windowscodecsext=n"}}}
|
|
result = MODULE["apply_config"]({}, config, "42", fixes)
|
|
self.assertEqual(result["WINEDLLOVERRIDES"], "msvcp100=n,b;windowscodecs,windowscodecsext=n")
|
|
|
|
def test_game_dll_overrides_edge_cases(self):
|
|
fixes = {"WINEDLLOVERRIDES": "msvcp100=n,b"}
|
|
env = {"WINEDLLOVERRIDES": "dxgi=n"}
|
|
for game, shared, expected in (
|
|
({"WINEDLLOVERRIDES": "msvcp100=b"}, {}, "msvcp100=n,b;msvcp100=b"),
|
|
({"WINEDLLOVERRIDES": ""}, {}, "msvcp100=n,b"),
|
|
({"WINEDLLOVERRIDES": None}, {}, None),
|
|
({"WINEDLLOVERRIDES": "d3d9=n"}, {"WINEDLLOVERRIDES": "xinput1_3=n"}, "msvcp100=n,b;d3d9=n"),
|
|
({}, {}, "dxgi=n;msvcp100=n,b"),
|
|
({"WINEDLLOVERRIDES": "x" * 8179}, {}, "msvcp100=n,b;" + "x" * 8179),
|
|
):
|
|
with self.subTest(game=game, shared=shared):
|
|
config = {"version": 1, "shared": shared, "games": {"42": game, "43": {"WINEDLLOVERRIDES": "d3d11=n"}}}
|
|
result = MODULE["apply_config"](env, config, "42", fixes)
|
|
self.assertEqual(result.get("WINEDLLOVERRIDES"), expected)
|
|
self.assertEqual(MODULE["apply_config"](env, config, "43")["WINEDLLOVERRIDES"], "d3d11=n")
|
|
stderr = io.StringIO()
|
|
config = {"version": 1, "shared": {}, "games": {"42": {"WINEDLLOVERRIDES": "x" * 8192}}}
|
|
with mock.patch("sys.stderr", stderr):
|
|
result = MODULE["apply_config"](env, config, "42", fixes)
|
|
self.assertEqual(result["WINEDLLOVERRIDES"], "x" * 8192)
|
|
self.assertIn("too long", stderr.getvalue())
|
|
|
|
def test_invalid_configuration_is_atomic(self):
|
|
env = {"ORIGINAL": "unchanged"}
|
|
for entries in ({"A": "ok", "BAD=KEY": "x"}, {"A": "bad\0value"}, {"A": 1}):
|
|
with self.assertRaises(ValueError):
|
|
MODULE["apply_config"](env, {"version": 1, "shared": entries}, "42")
|
|
self.assertEqual(env, {"ORIGINAL": "unchanged"})
|
|
|
|
def test_texture_filtering_is_appended_to_dxvk_config(self):
|
|
options = "d3d9.samplerAnisotropy = 16; d3d11.samplerAnisotropy = 16"
|
|
config = {"version": 1, "shared": {}, "games": {}, "dxvkConfig": options}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "42")["DXVK_CONFIG"], options)
|
|
own = {"DXVK_CONFIG": "dxvk.maxFrameRate = 60; "}
|
|
self.assertEqual(MODULE["apply_config"](own, config, "42")["DXVK_CONFIG"], "dxvk.maxFrameRate = 60; " + options)
|
|
shared = {"version": 1, "shared": {"DXVK_CONFIG": "dxvk.tearFree = True"}, "games": {}, "dxvkConfig": options}
|
|
self.assertEqual(MODULE["apply_config"]({}, shared, "42")["DXVK_CONFIG"], "dxvk.tearFree = True; " + options)
|
|
self.assertNotIn("DXVK_CONFIG", MODULE["apply_config"]({}, {**config, "dxvkConfig": ""}, "42"))
|
|
for bad in (1, "a\0b", "x" * 8193):
|
|
with self.assertRaises(ValueError):
|
|
MODULE["apply_config"]({}, {**config, "dxvkConfig": bad}, "42")
|
|
|
|
def test_game_texture_filtering_overrides_default_without_leaking(self):
|
|
default = "d3d9.samplerAnisotropy = 16"
|
|
game = "d3d9.samplerAnisotropy = 4"
|
|
config = {
|
|
"version": 1,
|
|
"shared": {},
|
|
"games": {},
|
|
"dxvkConfig": default,
|
|
"dxvkConfigGames": {"42": game, "43": ""},
|
|
}
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "42")["DXVK_CONFIG"], game)
|
|
self.assertNotIn("DXVK_CONFIG", MODULE["apply_config"]({}, config, "43"))
|
|
self.assertEqual(MODULE["apply_config"]({}, config, "44")["DXVK_CONFIG"], default)
|
|
with self.assertRaises(ValueError):
|
|
MODULE["apply_config"]({}, {**config, "dxvkConfigGames": []}, "42")
|
|
|
|
def test_game_logs_only_when_asked_and_only_for_game_launches(self):
|
|
game_logs = MODULE["game_logs"]
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
command = ["/proton", "waitforexitandrun", "/games/Hades/Hades.exe"]
|
|
env = {"DD_DEBUG_DIR": tmp, "VK_DRIVER_FILES": "/icd.json"}
|
|
self.assertEqual(game_logs(command, env, "1145360", now=0), env)
|
|
on = dict(env, DD_GAME_LOGS="1")
|
|
self.assertEqual(game_logs(["/proton", "run", "x.exe"], on, "1145360", now=0), on)
|
|
result = game_logs(command, on, "1145360", now=0)
|
|
folder = Path(result["PROTON_LOG_DIR"])
|
|
self.assertEqual(folder.parent, Path(tmp) / "games")
|
|
self.assertTrue(folder.name.endswith("-1145360"))
|
|
self.assertEqual(result["DXVK_LOG_PATH"], str(folder))
|
|
self.assertEqual(result["PROTON_LOG"], "1")
|
|
launch = (folder / "launch.txt").read_text()
|
|
self.assertIn("VK_DRIVER_FILES=/icd.json", launch)
|
|
self.assertNotIn("PROTON_LOG", env)
|
|
named = game_logs(command, on, None, now=0)
|
|
self.assertTrue(Path(named["PROTON_LOG_DIR"]).name.endswith("-Hades"))
|
|
|
|
def test_graphics_logs_trace_wine_only_when_asked(self):
|
|
game_logs = MODULE["game_logs"]
|
|
command = ["/proton", "waitforexitandrun", "/games/Hades/Hades.exe"]
|
|
with tempfile.TemporaryDirectory() as tmp, mock.patch("subprocess.Popen"):
|
|
on = {"DD_GAME_LOGS": "1", "DD_DEBUG_DIR": tmp}
|
|
for given in ({}, {"PROTON_LOG": "0"}, {"PROTON_LOG": ""}):
|
|
with self.subTest(given=given):
|
|
result = game_logs(command, {**on, **given}, "42", now=0)
|
|
self.assertEqual(result["PROTON_LOG"], "1")
|
|
self.assertEqual(result["WINEDEBUG"], "-all,err+all")
|
|
own = game_logs(command, {**on, "WINEDEBUG": "+relay"}, "42", now=0)
|
|
self.assertEqual(own["WINEDEBUG"], "+relay")
|
|
for value in ("1", "+relay"):
|
|
with self.subTest(proton_log=value):
|
|
user = game_logs(command, {**on, "PROTON_LOG": value}, "42", now=0)
|
|
self.assertEqual(user["PROTON_LOG"], value)
|
|
self.assertNotIn("WINEDEBUG", user)
|
|
config = {"version": 1, "gameDebugLogs": True}
|
|
debug = game_logs(command, MODULE["apply_game_debug_logs"](on, config, tmp), "42", now=0)
|
|
self.assertEqual(debug["PROTON_LOG"], "1")
|
|
self.assertEqual(debug["WINEDEBUG"], MODULE["game_debug_channels"]())
|
|
|
|
def test_game_debug_switch_controls_wine_traces_with_graphics_logs_on(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
config_path = home / ".config/droiddeck/game-environment.json"
|
|
config_path.parent.mkdir(parents=True)
|
|
probe = home / "proton"
|
|
probe.write_text("#!" + sys.executable + "\nimport json, os\n"
|
|
"print(json.dumps({k: os.environ.get(k) for k in ('PROTON_LOG', 'WINEDEBUG')}))\n")
|
|
probe.chmod(0o755)
|
|
env = {**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/599140"),
|
|
"DD_DEBUG_DIR": tmp, "DD_GAME_LOGS": "1"}
|
|
for name in ("PROTON_LOG", "WINEDEBUG"):
|
|
env.pop(name, None)
|
|
for enabled in (True, False, True):
|
|
with self.subTest(enabled=enabled):
|
|
config_path.write_text(json.dumps({"version": 1, "gameDebugLogs": enabled}))
|
|
result = json.loads(subprocess.run(
|
|
[sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun", "game.exe"],
|
|
env=env, text=True, capture_output=True, check=True).stdout)
|
|
self.assertEqual(result["PROTON_LOG"], "1")
|
|
if enabled:
|
|
self.assertIn("+seh", result["WINEDEBUG"].split(","))
|
|
else:
|
|
self.assertEqual(result["WINEDEBUG"], "-all,err+all")
|
|
|
|
def test_rapid_game_launches_keep_separate_diagnostics(self):
|
|
with tempfile.TemporaryDirectory() as tmp, mock.patch("subprocess.Popen"):
|
|
env = {"DD_GAME_LOGS": "1", "DD_DEBUG_DIR": tmp}
|
|
first = MODULE["game_logs"](["/proton", "waitforexitandrun", "first.exe"], env, "42", now=0)
|
|
second = MODULE["game_logs"](["/proton", "waitforexitandrun", "second.exe"], env, "42", now=0)
|
|
self.assertNotEqual(first["PROTON_LOG_DIR"], second["PROTON_LOG_DIR"])
|
|
self.assertIn("exe: first.exe", (Path(first["PROTON_LOG_DIR"]) / "launch.txt").read_text())
|
|
self.assertIn("exe: second.exe", (Path(second["PROTON_LOG_DIR"]) / "launch.txt").read_text())
|
|
|
|
def test_open_driver_pairs_report_the_drivers_own_vkd3d_caps(self):
|
|
apply = MODULE["apply_config"]
|
|
config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2", "VKD3D_SHADER_MODEL": "6_9"},
|
|
"games": {"42": {"VKD3D_SHADER_MODEL": "6_6"}}}
|
|
adreno = apply({}, config, "1")
|
|
self.assertEqual(adreno["VKD3D_FEATURE_LEVEL"], "12_2")
|
|
pair = apply({"DD_OPEN_DRIVER": "1"}, config, "1")
|
|
self.assertNotIn("VKD3D_FEATURE_LEVEL", pair)
|
|
self.assertNotIn("VKD3D_SHADER_MODEL", pair)
|
|
self.assertEqual(pair["DROIDDECK_VKD3D_CAPS"], "driver")
|
|
own = apply({"DD_OPEN_DRIVER": "1"}, config, "42")
|
|
self.assertEqual(own["VKD3D_SHADER_MODEL"], "6_6")
|
|
self.assertNotIn("VKD3D_FEATURE_LEVEL", own)
|
|
|
|
def test_game_ids_and_probes(self):
|
|
for prefix in ("", "/compatdata/0", "/compatdata/0-123", "/compatdata/nope", "/compatdata/4294967296"):
|
|
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:
|
|
home = Path(tmp)
|
|
config = home / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
probe = home / "fake-proton"
|
|
probe.write_text("#!/usr/bin/python3\nimport json, os, sys\nprint(json.dumps([os.environ.get('CUSTOM'), sys.argv[1:]]))\n")
|
|
probe.chmod(0o755)
|
|
env = {**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": "/compatdata/42"}
|
|
for value in ("first value", "$(touch " + str(home / "injected") + "); 'literal'=value"):
|
|
config.write_text(json.dumps({"version": 1, "shared": {"CUSTOM": value}}))
|
|
result = subprocess.check_output([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun", "path with spaces", "a=b"], env=env, text=True)
|
|
self.assertEqual(json.loads(result), [value, ["waitforexitandrun", "path with spaces", "a=b"]])
|
|
self.assertFalse((home / "injected").exists())
|
|
for verb, prefix in (("run", "/compatdata/42"), ("waitforexitandrun", "/compatdata/0")):
|
|
output = subprocess.check_output([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), verb], env={**env, "STEAM_COMPAT_DATA_PATH": prefix, "CUSTOM": "original"}, text=True)
|
|
self.assertEqual(json.loads(output)[0], "original")
|
|
config.write_text("{broken")
|
|
result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun"], env={**env, "CUSTOM": "original"}, text=True, capture_output=True, check=True)
|
|
self.assertEqual(json.loads(result.stdout)[0], "original")
|
|
|
|
def test_generated_valve_and_third_party_launchers_apply_configuration(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
steam = home / "Steam"
|
|
tools = steam / "compatibilitytools.d"
|
|
depot = steam / "steamapps/common" / COMPAT["SOURCES"][0]
|
|
(depot / "files/bin-arm64").mkdir(parents=True)
|
|
extra = tools / "custom-proton"
|
|
extra.mkdir(parents=True)
|
|
for base in (depot, extra):
|
|
proton = base / "proton"
|
|
proton.write_text("#!/usr/bin/python3\nimport json, os, sys\nprint(json.dumps([os.environ['CUSTOM'], sys.argv[1:]]))\nsys.exit(7)\n")
|
|
proton.chmod(0o755)
|
|
(extra / "toolmanifest.vdf").write_text('"manifest" { "commandline" "/proton %verb%" }')
|
|
COMPAT["build_tool"](str(tools / COMPAT["TOOL"]), str(depot))
|
|
COMPAT["adopt_extras"](str(tools))
|
|
config = home / ".config/droiddeck/game-environment.json"
|
|
config.parent.mkdir(parents=True)
|
|
config.write_text(json.dumps({"version": 1, "shared": {"CUSTOM": "shared"}, "games": {"42": {"CUSTOM": "specific"}}}))
|
|
wrappers = (tools / COMPAT["TOOL"] / COMPAT["LAUNCHER"], extra / COMPAT["EXTRA_WRAPPER"])
|
|
for wrapper in wrappers:
|
|
wrapper.write_text(wrapper.read_text().replace("/usr/local/bin/droiddeck-game-env", str(BIN / "droiddeck-game-env")))
|
|
result = subprocess.run([str(wrapper), "waitforexitandrun", "game with spaces.exe"],
|
|
env={"PATH": os.defpath, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": "/compatdata/42", "STEAM_COMPAT_CLIENT_INSTALL_PATH": str(steam)},
|
|
text=True, capture_output=True)
|
|
self.assertEqual(result.returncode, 7, result.stderr)
|
|
self.assertEqual(json.loads(result.stdout), ["specific", ["waitforexitandrun", "game with spaces.exe"]])
|
|
|
|
def test_default_is_compatible_tool_and_labels_mark_it(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
label = home / "label"
|
|
label.write_text("Compatible\n")
|
|
COMPAT["display_name"].__globals__["LABEL_FILE"] = str(label)
|
|
tools = home / "compatibilitytools.d"
|
|
extra = tools / "proton-cachyos-11"
|
|
extra.mkdir(parents=True)
|
|
(extra / "proton").write_text("")
|
|
(extra / "toolmanifest.vdf").write_text('"manifest" { "commandline" "/proton %verb%" }')
|
|
vdf = tools / COMPAT["TOOL"] / "compatibilitytool.vdf"
|
|
COMPAT["build_tool"](str(tools / COMPAT["TOOL"]), None)
|
|
self.assertIn('"display_name" "Proton ARM64 (Compatible)"', vdf.read_text())
|
|
for source in COMPAT["SOURCES"]:
|
|
COMPAT["build_tool"](str(tools / COMPAT["TOOL"]), str(home / "steamapps/common" / source))
|
|
self.assertIn('"display_name" "%s ARM64 (Compatible)"' % source.replace(" (ARM64)", ""), vdf.read_text())
|
|
protect = COMPAT["adopt_extras"](str(tools))
|
|
self.assertIn('"display_name" "proton-cachyos-11 (Compatible)"', (extra / "compatibilitytool.vdf").read_text())
|
|
config = home / "config.vdf"
|
|
mapping = "".join('"%s" { "name" "%s" "config" "" "priority" "%s" }' % entry for entry in (
|
|
("0", "GE-Proton10-25", "75"), ("42", "proton_experimental_arm64", "250"), ("43", "proton-cachyos-11", "250")))
|
|
config.write_text('"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }' % mapping)
|
|
COMPAT["register_default"](str(config), ["44"], protect=protect)
|
|
tokens = COMPAT["tokenize"](config.read_text())
|
|
names = {tokens[i - 1].strip('"'): tokens[i + 2].strip('"') for i in range(1, len(tokens) - 2) if tokens[i] == "{" and tokens[i + 1] == '"name"'}
|
|
self.assertEqual(names, {"0": COMPAT["TOOL"], "42": COMPAT["TOOL"], "43": "proton-cachyos-11", "44": COMPAT["TOOL"]})
|
|
|
|
def test_existing_install_moves_to_new_tool_name(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
(home / "label").write_text("Compatible\n")
|
|
COMPAT["main"].__globals__["LABEL_FILE"] = str(home / "label")
|
|
steam = home / "Steam"
|
|
depot = steam / "steamapps/common" / COMPAT["SOURCES"][0]
|
|
(depot / "files/bin-arm64").mkdir(parents=True)
|
|
(steam / "steamapps/appmanifest_42.acf").write_text("")
|
|
legacy = steam / "compatibilitytools.d" / COMPAT["LEGACY_TOOL"]
|
|
legacy.mkdir(parents=True)
|
|
for name in COMPAT["OWN_FILES"]:
|
|
(legacy / name).write_text("old")
|
|
(steam / "config").mkdir()
|
|
config = steam / "config/config.vdf"
|
|
mapping = "".join('"%s" { "name" "%s" "config" "" "priority" "%s" }' % (app, COMPAT["LEGACY_TOOL"], priority)
|
|
for app, priority in (("0", "75"), ("42", "250")))
|
|
config.write_text('"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }' % mapping)
|
|
argv = sys.argv
|
|
try:
|
|
sys.argv = ["steam-compatibility", str(steam)]
|
|
COMPAT["main"]()
|
|
migrated = config.read_text()
|
|
COMPAT["main"]()
|
|
finally:
|
|
sys.argv = argv
|
|
self.assertFalse(legacy.exists())
|
|
self.assertIn('"display_name" "Proton Experimental ARM64 (Compatible)"',
|
|
(steam / "compatibilitytools.d" / COMPAT["TOOL"] / "compatibilitytool.vdf").read_text())
|
|
self.assertNotIn(COMPAT["LEGACY_TOOL"], migrated)
|
|
self.assertEqual(migrated.count('"%s"' % COMPAT["TOOL"]), 2)
|
|
self.assertEqual(config.read_text(), migrated)
|
|
|
|
def test_launchers_and_adopted_protons_from_before_the_rename_move_over(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
(home / "label").write_text("Compatible\n")
|
|
COMPAT["main"].__globals__["LABEL_FILE"] = str(home / "label")
|
|
tools = home / "compatibilitytools.d"
|
|
own = tools / COMPAT["TOOL"]
|
|
own.mkdir(parents=True)
|
|
for name in ("toolmanifest.vdf", "compatibilitytool.vdf", COMPAT["LEGACY_LAUNCHER"]):
|
|
(own / name).write_text("old")
|
|
spare = tools / COMPAT["TOOL_11"]
|
|
spare.mkdir()
|
|
for name in ("toolmanifest.vdf", "compatibilitytool.vdf", COMPAT["LEGACY_LAUNCHER"]):
|
|
(spare / name).write_text("old")
|
|
extra = tools / "GE-Proton11-7"
|
|
extra.mkdir()
|
|
(extra / "proton").write_text("")
|
|
(extra / "toolmanifest.vdf").write_text('"manifest" { "commandline" "/%s %%verb%%" }' % COMPAT["LEGACY_EXTRA_WRAPPER"])
|
|
(extra / ("toolmanifest.vdf" + COMPAT["LEGACY_ORIGINAL_SUFFIX"])).write_text('"manifest" { "commandline" "/proton %verb%" }')
|
|
(extra / COMPAT["LEGACY_EXTRA_WRAPPER"]).write_text("old")
|
|
COMPAT["build_tool"](str(own), None)
|
|
COMPAT["remove_tool"](str(spare))
|
|
self.assertEqual(COMPAT["adopt_extras"](str(tools)), {"GE-Proton11-7": "GE-Proton11-7"})
|
|
self.assertEqual(sorted(os.listdir(own)), sorted(COMPAT["OWN_FILES"]))
|
|
self.assertFalse(spare.exists())
|
|
self.assertEqual(sorted(os.listdir(extra)), sorted(["proton", "toolmanifest.vdf", "compatibilitytool.vdf",
|
|
COMPAT["EXTRA_WRAPPER"], "toolmanifest.vdf" + COMPAT["ORIGINAL_SUFFIX"]]))
|
|
self.assertIn("/%s %%verb%%" % COMPAT["EXTRA_WRAPPER"], (extra / "toolmanifest.vdf").read_text())
|
|
self.assertIn('"/proton %verb%"', (extra / ("toolmanifest.vdf" + COMPAT["ORIGINAL_SUFFIX"])).read_text())
|
|
self.assertIn('"$here/proton"', (extra / COMPAT["EXTRA_WRAPPER"]).read_text())
|
|
self.assertIn("GE-Proton11-7", [entry["name"] for entry in COMPAT["tool_catalog"](str(home), None)])
|
|
|
|
def test_droiddeck_proton_is_adopted_and_labelled_like_any_other_extra(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
home = Path(tmp)
|
|
(home / "label").write_text("Compatible\n")
|
|
COMPAT["display_name"].__globals__["LABEL_FILE"] = str(home / "label")
|
|
tools = home / "compatibilitytools.d"
|
|
extra = tools / "DroidDeck-Proton 11-7.5"
|
|
extra.mkdir(parents=True)
|
|
(extra / "proton").write_text("")
|
|
(extra / "toolmanifest.vdf").write_text('"manifest" { "version" "2" "commandline" "/proton %verb%" "require_tool_appid" "4185400" }')
|
|
(extra / "compatibilitytool.vdf").write_text(
|
|
'"compatibilitytools" { "compat_tools" { "DroidDeck-Proton-11-7.5" { "install_path" "." '
|
|
'"display_name" "DroidDeck-Proton 11-7.5" "from_oslist" "windows" "to_oslist" "linux" } } }')
|
|
COMPAT["build_tool"](str(tools / COMPAT["TOOL"]), None)
|
|
protect = COMPAT["adopt_extras"](str(tools))
|
|
self.assertEqual(protect, {"DroidDeck-Proton-11-7.5": "DroidDeck-Proton 11-7.5"})
|
|
compat = (extra / "compatibilitytool.vdf").read_text()
|
|
self.assertIn('"DroidDeck-Proton-11-7.5"', compat)
|
|
self.assertIn('"display_name" "DroidDeck-Proton 11-7.5 (Compatible)"', compat)
|
|
self.assertNotIn("require_tool_appid", (extra / "toolmanifest.vdf").read_text())
|
|
self.assertIn('"$here/proton"', (extra / COMPAT["EXTRA_WRAPPER"]).read_text())
|
|
catalog = COMPAT["tool_catalog"](str(home), None)
|
|
self.assertIn({"name": "DroidDeck-Proton-11-7.5", "display": "DroidDeck-Proton 11-7.5 (Compatible)",
|
|
"dir": "DroidDeck-Proton 11-7.5", "valve": False}, catalog)
|
|
config = home / "config.vdf"
|
|
config.write_text(config_text([("0", COMPAT["TOOL"]), ("42", "DroidDeck-Proton-11-7.5")]))
|
|
COMPAT["register_default"](str(config), ["42", "43"], protect=protect)
|
|
self.assertEqual(mapping_of(config.read_text()), {"0": COMPAT["TOOL"], "42": "DroidDeck-Proton-11-7.5", "43": COMPAT["TOOL"]})
|
|
changes, _ = COMPAT["plan_mapping"]({"0": COMPAT["TOOL"], "42": "DroidDeck-Proton-11-7.5"}, ["42"], [COMPAT["TOOL"]], COMPAT["TOOL"], {})
|
|
self.assertEqual(changes, {"42": COMPAT["TOOL"]})
|
|
|
|
def test_both_proton_wrappers_call_environment_launcher(self):
|
|
self.assertIn('dd_directaudio "$depot" "$@"', COMPAT["LAUNCHER_SH"])
|
|
self.assertIn('dd_directaudio "$here" "$@"', COMPAT["extra_wrapper_sh"]("proton"))
|
|
for script in (COMPAT["LAUNCHER_SH"], COMPAT["extra_wrapper_sh"]("proton")):
|
|
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
|
|
self.assertIn('dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', script)
|
|
|
|
def test_both_proton_wrappers_answer_steams_driver_query_without_wine(self):
|
|
scripts = (COMPAT["launcher_sh"](), COMPAT["extra_wrapper_sh"]("proton"))
|
|
query = "/root/.local/share/Steam/steamrtarm64/../bin/d3ddriverquery64.exe"
|
|
probe = "/root/.local/share/Steam/steamapps/compatdata/0"
|
|
for script, here in zip(scripts, ("$depot", "$here")):
|
|
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
|
|
answered = script.index('case "$verb:${1##*/}:')
|
|
self.assertLess(answered, script.index('dd_components "%s"' % here))
|
|
self.assertLess(answered, script.index('dd_anticheat "$@"'))
|
|
for args, prefix in (([query, "-d3d12"], probe), ([query], probe + "/"),
|
|
([query.replace("64.exe", ".exe")], probe)):
|
|
result = subprocess.run(["bash", "-s", "run"] + args, input=script, text=True, capture_output=True,
|
|
env={"PATH": os.defpath, "HOME": "/nonexistent", "STEAM_COMPAT_DATA_PATH": prefix},
|
|
timeout=10)
|
|
self.assertEqual(result.returncode, 1, result.stderr)
|
|
self.assertEqual(result.stdout, "")
|
|
self.assertIn("D3D driver query is not run", result.stderr)
|
|
skip = COMPAT["DD_DRIVER_QUERY_SKIP"]
|
|
for verb, args, prefix in (
|
|
("getcompatpath", [query], probe),
|
|
("run", [query], "/root/.local/share/Steam/steamapps/compatdata/2276548447"),
|
|
("run", [query], None),
|
|
("waitforexitandrun", ["/games/AIO/AIO-Graphics-Test-64bit.exe", "--cube", "dx11"], probe),
|
|
("run", ["/games/Tool/tool.exe", query], probe),
|
|
("run", ["/games/d3ddriverquery64.exe.bak"], probe)):
|
|
env = {"PATH": os.defpath}
|
|
if prefix is not None:
|
|
env["STEAM_COMPAT_DATA_PATH"] = prefix
|
|
out = subprocess.run(["bash", "-c", "verb=" + verb + "\n" + skip + "echo continued", "_"] + args,
|
|
env=env, capture_output=True, text=True, check=True).stdout
|
|
self.assertEqual(out, "continued\n", (verb, args, prefix))
|
|
|
|
def test_bionic_tool_starts_droiddeck_proton_when_proot_is_on(self):
|
|
script = COMPAT["extra_wrapper_sh"]("proton")
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
tools = Path(tmp) / "compatibilitytools.d"
|
|
|
|
def tool(name, bionic=False):
|
|
d = tools / name
|
|
(d / "bionic").mkdir(parents=True)
|
|
if bionic:
|
|
(d / "bionic" / "launch.sh").write_text("")
|
|
wrapper = d / "droiddeck-proton-wrap"
|
|
wrapper.write_text(script if bionic else '#!/bin/sh\necho "ran ${0%/*}" "$@"\n')
|
|
wrapper.chmod(0o755)
|
|
return wrapper
|
|
|
|
bionic = tool("DroidDeck-Bionic-12.8-r37", bionic=True)
|
|
tool("DroidDeck-Proton 11-12.8")
|
|
tool("DroidDeck-Proton-11-12.10")
|
|
tool("DroidDeck-Proton-12.8-bionic-test", bionic=True)
|
|
tool("GE-Proton10-25")
|
|
base = {"PATH": os.defpath, "HOME": "/nonexistent"}
|
|
|
|
def launch(extra=()):
|
|
env = dict(base, **dict(extra))
|
|
return subprocess.run([str(bionic), "waitforexitandrun", "/games/A B/game.exe", "-x"], env=env,
|
|
capture_output=True, text=True, timeout=10)
|
|
|
|
result = launch()
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
self.assertEqual(result.stdout, "ran %s waitforexitandrun /games/A B/game.exe -x\n"
|
|
% os.path.realpath(tools / "DroidDeck-Proton-11-12.10"))
|
|
self.assertIn("this launch uses DroidDeck-Proton-11-12.10", result.stderr)
|
|
|
|
shutil.rmtree(tools / "DroidDeck-Proton-11-12.10")
|
|
self.assertIn("ran %s " % os.path.realpath(tools / "DroidDeck-Proton 11-12.8"), launch().stdout)
|
|
|
|
self.assertNotIn("ran ", launch({"DDNATV_ROOT": "/data/rootfs"}).stdout)
|
|
shutil.rmtree(tools / "DroidDeck-Proton 11-12.8")
|
|
self.assertNotIn("this launch uses", launch().stderr)
|
|
|
|
def test_wrappers_preload_the_session_library_before_the_input_shim(self):
|
|
overlay = "/root/.local/share/Steam/ubuntu12_64/gameoverlayrenderer.so"
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
for name in ("libddsession.so", "libfakeinput.so"):
|
|
(Path(tmp) / name).write_bytes(b"")
|
|
for script in (COMPAT["LAUNCHER_SH"], COMPAT["extra_wrapper_sh"]("proton")):
|
|
start = script.index("for fake in ")
|
|
block = script[start:script.index("\ndone\n", start) + 6].replace("/usr/local/lib/", tmp + "/")
|
|
for inherited, expected in (
|
|
(None, ["libddsession.so", "libfakeinput.so"]),
|
|
(overlay, ["libddsession.so", "libfakeinput.so", overlay]),
|
|
(tmp + "/libfakeinput.so:" + overlay, ["libddsession.so", "libfakeinput.so", overlay]),
|
|
(tmp + "/libddsession.so:" + tmp + "/libfakeinput.so", ["libddsession.so", "libfakeinput.so"])):
|
|
env = {"PATH": os.defpath}
|
|
if inherited is not None:
|
|
env["LD_PRELOAD"] = inherited
|
|
out = subprocess.run(["bash", "-c", block + 'printf %s "$LD_PRELOAD"'], env=env,
|
|
capture_output=True, text=True, check=True).stdout
|
|
self.assertEqual([entry.replace(tmp + "/", "") for entry in out.split(":")], expected, inherited)
|
|
|
|
|
|
class ProtonDefaultTest(unittest.TestCase):
|
|
TOOL = COMPAT["TOOL"]
|
|
CATALOG = [
|
|
{"name": COMPAT["TOOL"], "display": "Proton Experimental ARM64", "dir": "Proton Experimental (ARM64)", "valve": True},
|
|
{"name": COMPAT["TOOL_11"], "display": "Proton 11.0 ARM64", "dir": "Proton 11.0 (ARM64)", "valve": True},
|
|
{"name": "GE-Proton11-7", "display": "GE-Proton11-7", "dir": "GE-Proton11-7", "valve": False},
|
|
]
|
|
NAMES = [t["name"] for t in CATALOG]
|
|
|
|
def plan(self, current, installed, default, auto):
|
|
return COMPAT["plan_mapping"](current, installed, self.NAMES, default, auto)
|
|
|
|
def test_new_installs_and_valve_picks_follow_the_default(self):
|
|
changes, auto = self.plan({"0": self.TOOL, "10": "proton_experimental", "11": "proton_11_arm64", "12": "GE-Proton11-7", "13": "steamlinuxruntime"},
|
|
["10", "11", "12", "13", "14"], "GE-Proton11-7", {})
|
|
self.assertEqual(changes, {"0": "GE-Proton11-7", "10": "GE-Proton11-7", "11": "GE-Proton11-7", "14": "GE-Proton11-7"})
|
|
self.assertEqual(auto, {"10": "GE-Proton11-7", "11": "GE-Proton11-7", "14": "GE-Proton11-7"})
|
|
|
|
def test_games_on_a_removed_custom_proton_go_back_to_the_default(self):
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
{"0": self.TOOL, "311210": "bo3fix-proton", "42": "GE-Proton11-7"}, ["311210", "42"], self.NAMES, self.TOOL, {},
|
|
removed={"bo3fix-proton"})
|
|
self.assertEqual(changes, {"311210": self.TOOL})
|
|
self.assertEqual(auto, {"311210": self.TOOL})
|
|
|
|
def test_removed_tools_are_custom_builds_missing_from_the_catalog(self):
|
|
state = {"tools": [
|
|
{"name": self.TOOL, "valve": True},
|
|
{"name": "bo3fix-proton", "valve": False},
|
|
{"name": "GE-Proton11-7", "valve": False},
|
|
]}
|
|
self.assertEqual(COMPAT["removed_tools"](state, self.CATALOG), {"bo3fix-proton"})
|
|
self.assertEqual(COMPAT["removed_tools"]({}, self.CATALOG), set())
|
|
|
|
def test_a_failed_extra_adoption_is_not_classified_as_removed(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
tools = Path(tmp) / "compatibilitytools.d"
|
|
tools.mkdir()
|
|
state = {"tools": [{"name": "GE-Proton11-7", "dir": "GE-Proton11-7", "valve": False}]}
|
|
(tools / "GE-Proton11-7").mkdir()
|
|
catalog = [tool for tool in self.CATALOG if tool["name"] != "GE-Proton11-7"]
|
|
self.assertEqual(COMPAT["removed_tools"](state, catalog, str(tools)), set())
|
|
(tools / "GE-Proton11-7").rmdir()
|
|
self.assertEqual(COMPAT["removed_tools"](state, catalog, str(tools)), {"GE-Proton11-7"})
|
|
|
|
def test_a_build_being_replaced_is_not_classified_as_removed(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
tools = Path(tmp) / "compatibilitytools.d"
|
|
state = {"tools": [{"name": "GE-Proton11-7", "dir": "GE-Proton11-7", "valve": False}]}
|
|
catalog = [tool for tool in self.CATALOG if tool["name"] != "GE-Proton11-7"]
|
|
aside = tools / COMPAT["REPLACING"] / "GE-Proton11-7"
|
|
aside.mkdir(parents=True)
|
|
self.assertEqual(COMPAT["removed_tools"](state, catalog, str(tools)), set())
|
|
aside.rmdir()
|
|
self.assertEqual(COMPAT["removed_tools"](state, catalog, str(tools)), {"GE-Proton11-7"})
|
|
|
|
def test_a_request_for_a_removed_tool_is_dropped_and_others_are_kept(self):
|
|
state = {"tools": self.CATALOG, "games_applied": {}}
|
|
requests = {"10": {"valve": False, "dir": "GE-Proton11-7"}, "11": {"valve": False, "dir": "Never-Installed"},
|
|
"12": {"valve": True, "dir": "GE-Proton11-7"}}
|
|
catalog = [tool for tool in self.CATALOG if tool["name"] != "GE-Proton11-7"]
|
|
settled, moved = COMPAT["settle_game_requests"](requests, state, {}, catalog, removed={"GE-Proton11-7"})
|
|
self.assertTrue(moved)
|
|
self.assertEqual(settled, {"11": requests["11"], "12": requests["12"]})
|
|
self.assertEqual(COMPAT["settle_game_requests"](requests, state, {}, catalog), (requests, False))
|
|
malformed = {"10": {"valve": False, "dir": []}}
|
|
self.assertEqual(COMPAT["settle_game_requests"](malformed, state, {}, catalog, removed={"GE-Proton11-7"}), (malformed, False))
|
|
|
|
def test_a_game_on_a_removed_tool_follows_the_default_across_registrations(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
config = Path(tmp) / "config.vdf"
|
|
config.write_text(config_text([("0", self.TOOL), ("10", "GE-Proton11-7"), ("11", "GE-Proton11-7")]))
|
|
request = {"valve": False, "dir": "GE-Proton11-7"}
|
|
available = [tool for tool in self.CATALOG if tool["name"] != "GE-Proton11-7"]
|
|
(Path(tmp) / "games.json").write_text(json.dumps({"version": 1, "games": {"10": request}}))
|
|
(Path(tmp) / "state.json").write_text(json.dumps({
|
|
"default": self.TOOL,
|
|
"tools": self.CATALOG,
|
|
}))
|
|
for default in (self.TOOL, self.TOOL, COMPAT["TOOL_11"]):
|
|
COMPAT["register_default"](
|
|
str(config), ["10", "11"], default=default, catalog=available,
|
|
directory=tmp,
|
|
)
|
|
self.assertEqual(mapping_of(config.read_text()),
|
|
{"0": COMPAT["TOOL_11"], "10": COMPAT["TOOL_11"], "11": COMPAT["TOOL_11"]})
|
|
self.assertEqual(json.loads((Path(tmp) / "games.json").read_text())["games"], {})
|
|
|
|
def test_a_steam_pick_survives_the_removal_of_another_tool(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
config = Path(tmp) / "config.vdf"
|
|
config.write_text(config_text([("0", self.TOOL), ("10", COMPAT["TOOL_11"])]))
|
|
available = [tool for tool in self.CATALOG if tool["name"] != "GE-Proton11-7"]
|
|
(Path(tmp) / "games.json").write_text(json.dumps(
|
|
{"version": 1, "games": {"10": {"valve": False, "dir": "GE-Proton11-7"}}}))
|
|
(Path(tmp) / "state.json").write_text(json.dumps({"default": self.TOOL, "tools": self.CATALOG, "auto": {}}))
|
|
COMPAT["register_default"](str(config), ["10"], default=self.TOOL, catalog=available, directory=tmp)
|
|
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, "10": COMPAT["TOOL_11"]})
|
|
|
|
def test_windows_only_titles_still_follow_the_default(self):
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
{"0": self.TOOL}, ["42"], self.NAMES, self.TOOL, {})
|
|
self.assertEqual(changes, {"42": self.TOOL})
|
|
self.assertEqual(auto, {"42": self.TOOL})
|
|
|
|
def test_native_arm64_default_clears_only_our_auto_mapping(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
config = Path(tmp) / "config.vdf"
|
|
config.write_text(config_text([("0", self.TOOL), ("42", self.TOOL)]))
|
|
(Path(tmp) / "state.json").write_text(json.dumps({
|
|
"default": self.TOOL,
|
|
"auto": {"42": self.TOOL},
|
|
}))
|
|
globals_ = COMPAT["register_default"].__globals__
|
|
original_native_targets = globals_["native_targets"]
|
|
globals_["native_targets"] = lambda _root, _apps: {"42": None}
|
|
try:
|
|
COMPAT["register_default"](
|
|
str(config), ["42"], catalog=self.CATALOG, directory=tmp)
|
|
first = config.read_bytes()
|
|
self.assertEqual(mapping_of(first.decode()), {"0": self.TOOL})
|
|
self.assertEqual(COMPAT["tokenize"](first.decode()),
|
|
COMPAT["tokenize"](config_text([("0", self.TOOL)])))
|
|
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["auto"], {})
|
|
|
|
COMPAT["register_default"](
|
|
str(config), ["42"], catalog=self.CATALOG, directory=tmp)
|
|
self.assertEqual(config.read_bytes(), first)
|
|
finally:
|
|
globals_["native_targets"] = original_native_targets
|
|
|
|
def test_saved_native_choice_survives_valve_pick_without_appinfo(self):
|
|
app = "452280"
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
steam = root / "Steam"
|
|
config = steam / "config/config.vdf"
|
|
config.parent.mkdir(parents=True)
|
|
(steam / "steamapps").mkdir()
|
|
(steam / "steamapps" / ("appmanifest_%s.acf" % app)).write_text("")
|
|
config.write_text(config_text([("0", self.TOOL)]))
|
|
(root / "state.json").write_text(json.dumps({
|
|
"default": self.TOOL,
|
|
"auto": {},
|
|
"native_choices": [app],
|
|
}))
|
|
|
|
globals_ = COMPAT["register_default"].__globals__
|
|
original_native_targets = globals_["native_targets"]
|
|
globals_["native_targets"] = lambda _root, _apps: {}
|
|
try:
|
|
COMPAT["register_default"](
|
|
str(config), [], catalog=self.CATALOG, directory=tmp, picks=[app])
|
|
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_choices"], [app])
|
|
finally:
|
|
globals_["native_targets"] = original_native_targets
|
|
|
|
def test_shortcuts_scanner_keeps_native_choice_for_unrelated_app_list(self):
|
|
app, added_shortcut = "452280", "3537741571"
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
steam = root / "Steam"
|
|
config = steam / "config/config.vdf"
|
|
config.parent.mkdir(parents=True)
|
|
(steam / "steamapps").mkdir()
|
|
(steam / "steamapps" / ("appmanifest_%s.acf" % app)).write_text("")
|
|
config.write_text(config_text([("0", self.TOOL)]))
|
|
(root / "state.json").write_text(json.dumps({
|
|
"default": self.TOOL,
|
|
"auto": {},
|
|
"native_choices": [app],
|
|
}))
|
|
|
|
globals_ = COMPAT["register_default"].__globals__
|
|
original_native_targets = globals_["native_targets"]
|
|
globals_["native_targets"] = lambda _root, wanted: {
|
|
app: COMPAT["NATIVE_CHOICE"]
|
|
} if app in wanted else {}
|
|
try:
|
|
COMPAT["register_default"](
|
|
str(config), [app], catalog=self.CATALOG, directory=tmp)
|
|
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_choices"], [app])
|
|
self.assertEqual(state["auto"], {added_shortcut: self.TOOL})
|
|
self.assertEqual(mapping_of(config.read_text()), {
|
|
"0": self.TOOL,
|
|
added_shortcut: self.TOOL,
|
|
})
|
|
finally:
|
|
globals_["native_targets"] = original_native_targets
|
|
|
|
def test_a_listed_title_with_a_bundled_arm64_linux_build_defaults_to_fex(self):
|
|
globals_ = COMPAT["native_targets"].__globals__
|
|
original_platforms = globals_["appinfo_platforms"]
|
|
globals_["appinfo_platforms"] = lambda _path, wanted: {
|
|
app: ({"linux", "windows"}, "64", "game") for app in ("4385780", "42") if app in wanted
|
|
}
|
|
try:
|
|
native = COMPAT["native_targets"]("/nonexistent", ["4385780", "42"])
|
|
finally:
|
|
globals_["appinfo_platforms"] = original_platforms
|
|
self.assertEqual(native["4385780"], COMPAT["FEX_TOOL"])
|
|
self.assertIs(native["42"], COMPAT["NATIVE_CHOICE"])
|
|
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
{"0": self.TOOL}, ["4385780"], self.NAMES, self.TOOL, {}, native)
|
|
self.assertEqual(changes, {"4385780": COMPAT["FEX_TOOL"]})
|
|
self.assertEqual(auto, {"4385780": COMPAT["FEX_TOOL"]})
|
|
|
|
for choice in (self.TOOL, "GE-Proton11-7"):
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
{"0": self.TOOL, "4385780": choice}, ["4385780"], self.NAMES, self.TOOL, {}, native)
|
|
self.assertEqual(changes, {})
|
|
self.assertEqual(auto, {})
|
|
|
|
def test_a_cleared_fex_default_for_a_listed_title_is_kept_as_a_native_choice(self):
|
|
app = "4385780"
|
|
fex = COMPAT["FEX_TOOL"]
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
steam = Path(tmp) / "Steam"
|
|
config = steam / "config/config.vdf"
|
|
config.parent.mkdir(parents=True)
|
|
config.write_text(config_text([("0", self.TOOL)]))
|
|
(Path(tmp) / "state.json").write_text(json.dumps({"default": self.TOOL, "auto": {}}))
|
|
|
|
globals_ = COMPAT["native_targets"].__globals__
|
|
original_platforms = globals_["appinfo_platforms"]
|
|
globals_["appinfo_platforms"] = lambda _path, wanted: {
|
|
app: ({"linux", "windows"}, "64", "game")
|
|
} if app in wanted else {}
|
|
try:
|
|
def run():
|
|
COMPAT["register_default"](str(config), [app], catalog=self.CATALOG, directory=tmp)
|
|
return json.loads((Path(tmp) / "state.json").read_text())
|
|
|
|
state = run()
|
|
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, app: fex})
|
|
self.assertEqual(state["auto"], {app: fex})
|
|
|
|
config.write_text(config_text([("0", self.TOOL), (app, "")]))
|
|
state = run()
|
|
cleared = config.read_bytes()
|
|
self.assertEqual(mapping_of(cleared.decode()), {"0": self.TOOL, app: ""})
|
|
self.assertEqual(state["auto"], {})
|
|
self.assertEqual(state["native_choices"], [app])
|
|
run()
|
|
self.assertEqual(config.read_bytes(), cleared)
|
|
|
|
config.write_text(config_text([("0", self.TOOL), (app, fex)]))
|
|
state = run()
|
|
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, app: fex})
|
|
self.assertEqual(state["native_choices"], [])
|
|
finally:
|
|
globals_["appinfo_platforms"] = original_platforms
|
|
|
|
def test_factorio_preserves_an_observed_native_choice_despite_ambiguous_metadata(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
steam = Path(tmp) / "Steam"
|
|
config = steam / "config/config.vdf"
|
|
config.parent.mkdir(parents=True)
|
|
config.write_text(config_text([("0", self.TOOL)]))
|
|
state = {"default": self.TOOL, "auto": {}}
|
|
(Path(tmp) / "state.json").write_text(json.dumps(state))
|
|
|
|
globals_ = COMPAT["native_targets"].__globals__
|
|
original_platforms = globals_["appinfo_platforms"]
|
|
globals_["appinfo_platforms"] = lambda _path, wanted: {
|
|
"427520": ({"linux", "macos", "windows"}, "", "game")
|
|
} if "427520" in wanted else {}
|
|
try:
|
|
native = COMPAT["native_targets"](str(steam), ["427520"])
|
|
self.assertIs(native["427520"], COMPAT["NATIVE_CHOICE"])
|
|
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
{"0": self.TOOL}, ["427520"], self.NAMES, self.TOOL, {}, native)
|
|
self.assertEqual(changes, {"427520": self.TOOL})
|
|
self.assertEqual(auto, {"427520": self.TOOL})
|
|
|
|
COMPAT["register_default"](
|
|
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
|
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, "427520": self.TOOL})
|
|
|
|
state["auto"] = {"427520": self.TOOL}
|
|
(Path(tmp) / "state.json").write_text(json.dumps(state))
|
|
config.write_text(config_text([("0", self.TOOL)]))
|
|
COMPAT["register_default"](
|
|
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
|
first = config.read_bytes()
|
|
self.assertEqual(mapping_of(first.decode()), {"0": self.TOOL})
|
|
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_choices"], ["427520"])
|
|
|
|
COMPAT["register_default"](
|
|
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
|
self.assertEqual(config.read_bytes(), first)
|
|
|
|
config.write_text(config_text([("0", self.TOOL), ("427520", "")]))
|
|
COMPAT["register_default"](
|
|
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
|
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_choices"], ["427520"])
|
|
COMPAT["register_default"](
|
|
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
|
self.assertEqual(config.read_bytes(), native_choice)
|
|
|
|
for choice in (COMPAT["FEX_TOOL"], COMPAT["TOOL_11"], "GE-Proton11-7"):
|
|
config.write_text(config_text([("0", self.TOOL), ("427520", choice)]))
|
|
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_choices"], [])
|
|
|
|
state = json.loads((Path(tmp) / "state.json").read_text())
|
|
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")]))
|
|
COMPAT["register_default"](
|
|
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_choices"], [])
|
|
self.assertEqual(saved["auto"], {})
|
|
finally:
|
|
globals_["appinfo_platforms"] = original_platforms
|
|
|
|
def test_native_arm64_preserves_a_proton_mapping_without_managed_state(self):
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
{"0": self.TOOL, "42": self.TOOL}, ["42"], self.NAMES, self.TOOL,
|
|
{"42": self.TOOL}, {"42": None}, managed=())
|
|
self.assertEqual(changes, {})
|
|
self.assertEqual(auto, {})
|
|
|
|
def test_native_arm64_keeps_a_chosen_valve_proton_through_its_wrapper(self):
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
{"0": self.TOOL, "42": "proton_experimental"}, ["42"], self.NAMES,
|
|
self.TOOL, {}, {"42": None})
|
|
self.assertEqual(changes, {"42": self.TOOL})
|
|
self.assertEqual(auto, {})
|
|
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
{"0": self.TOOL, "42": self.TOOL}, ["42"], self.NAMES,
|
|
self.TOOL, {}, {"42": None})
|
|
self.assertEqual(changes, {})
|
|
self.assertEqual(auto, {})
|
|
|
|
def test_native_arm64_keeps_explicit_runtime_fex_and_proton_profiles(self):
|
|
fex = COMPAT["FEX_TOOL"]
|
|
current = {
|
|
"0": self.TOOL,
|
|
"42": COMPAT["TOOL_11"],
|
|
"43": "GE-Proton11-7",
|
|
"44": "steamlinuxruntime_arm64",
|
|
"45": fex,
|
|
"46": "",
|
|
}
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
current, ["42", "43", "44", "45", "46"], self.NAMES, self.TOOL, {},
|
|
{app: None for app in ("42", "43", "44", "45", "46")},
|
|
overrides={"46": "GE-Proton11-7"},
|
|
)
|
|
self.assertEqual(changes, {"46": "GE-Proton11-7"})
|
|
self.assertEqual(auto, {})
|
|
|
|
def test_titles_following_the_default_move_with_it_and_picks_stay(self):
|
|
current = {"0": self.TOOL, "10": self.TOOL, "11": "GE-Proton11-7", "12": self.TOOL}
|
|
auto = {"10": self.TOOL, "11": self.TOOL, "12": self.TOOL}
|
|
changes, auto = self.plan(current, ["10", "11", "12"], COMPAT["TOOL_11"], auto)
|
|
self.assertEqual(changes, {"0": COMPAT["TOOL_11"], "10": COMPAT["TOOL_11"], "12": COMPAT["TOOL_11"]})
|
|
self.assertEqual(auto, {"10": COMPAT["TOOL_11"], "12": COMPAT["TOOL_11"]})
|
|
|
|
def test_a_removed_tool_falls_back_to_the_default(self):
|
|
changes, auto = self.plan({"0": self.TOOL, "10": "GE-Proton10-1", "11": "droiddeck-proton-12-arm64"}, ["10", "11"], self.TOOL, {"10": "GE-Proton10-1"})
|
|
self.assertEqual(changes, {"10": self.TOOL, "11": self.TOOL})
|
|
self.assertEqual(auto, {"10": self.TOOL, "11": self.TOOL})
|
|
|
|
def test_uninstalled_titles_are_forgotten(self):
|
|
changes, auto = self.plan({"0": self.TOOL}, [], self.TOOL, {"10": self.TOOL})
|
|
self.assertEqual((changes, auto), ({}, {}))
|
|
|
|
def test_per_game_proton_override_and_inherit_follow_steam_mappings(self):
|
|
current = {"0": self.TOOL, "10": self.TOOL, "11": "GE-Proton11-7", "12": self.TOOL}
|
|
overrides = {"10": "GE-Proton11-7", "11": None}
|
|
changes, auto = COMPAT["plan_mapping"](
|
|
current, ["10", "11", "12"], self.NAMES, COMPAT["TOOL_11"],
|
|
{"10": self.TOOL, "12": self.TOOL}, overrides=overrides)
|
|
self.assertEqual(changes, {"0": COMPAT["TOOL_11"], "10": "GE-Proton11-7", "11": COMPAT["TOOL_11"], "12": COMPAT["TOOL_11"]})
|
|
self.assertEqual(auto, {"11": COMPAT["TOOL_11"], "12": COMPAT["TOOL_11"]})
|
|
|
|
def test_per_game_requests_resolve_identity_and_defer_a_new_live_tool(self):
|
|
requests = {
|
|
"10": {"valve": False, "dir": "GE-Proton11-7"},
|
|
"11": None,
|
|
"12": {"valve": True, "dir": "Proton 11.0 (ARM64)"},
|
|
"0": None,
|
|
}
|
|
self.assertEqual(
|
|
COMPAT["requested_games"](requests, self.CATALOG),
|
|
{"10": "GE-Proton11-7", "11": None, "12": COMPAT["TOOL_11"]},
|
|
)
|
|
self.assertEqual(
|
|
COMPAT["requested_games"](requests, self.CATALOG, [self.TOOL, COMPAT["TOOL_11"]]),
|
|
{"10": COMPAT["DEFERRED_GAME_TOOL"], "11": None, "12": COMPAT["TOOL_11"]},
|
|
)
|
|
|
|
def test_missing_per_game_proton_is_preserved_during_default_registration(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
config = Path(tmp) / "config.vdf"
|
|
config.write_text(config_text([
|
|
("0", self.TOOL),
|
|
("10", "GE-Proton9-1"),
|
|
("11", self.TOOL),
|
|
]))
|
|
(Path(tmp) / "games.json").write_text(json.dumps({
|
|
"version": 1,
|
|
"games": {
|
|
"10": {"valve": False, "dir": "GE-Proton9-1"},
|
|
},
|
|
}))
|
|
|
|
COMPAT["register_default"](
|
|
str(config), ["10", "11"], default=COMPAT["TOOL_11"],
|
|
catalog=self.CATALOG, directory=tmp,
|
|
)
|
|
|
|
self.assertEqual(mapping_of(config.read_text()), {
|
|
"0": COMPAT["TOOL_11"],
|
|
"10": "GE-Proton9-1",
|
|
"11": COMPAT["TOOL_11"],
|
|
})
|
|
|
|
def test_per_game_proton_that_was_removed_goes_back_to_the_default(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
config = Path(tmp) / "config.vdf"
|
|
config.write_text(config_text([
|
|
("0", self.TOOL),
|
|
("10", "Experimental-DroidDeck-Proton-11-12.8-pr34-build"),
|
|
("12", "GE-Proton9-1"),
|
|
]))
|
|
(Path(tmp) / "games.json").write_text(json.dumps({
|
|
"version": 1,
|
|
"games": {
|
|
"10": {"valve": False, "dir": "Experimental-DroidDeck-Proton-11-12.8-pr34-build"},
|
|
"12": {"valve": False, "dir": "GE-Proton9-1"},
|
|
},
|
|
}))
|
|
(Path(tmp) / "state.json").write_text(json.dumps({
|
|
"default": self.TOOL,
|
|
"tools": self.CATALOG + [{
|
|
"name": "Experimental-DroidDeck-Proton-11-12.8-pr34-build",
|
|
"display": "Experimental-DroidDeck-Proton-11-12.8-pr34-build",
|
|
"dir": "Experimental-DroidDeck-Proton-11-12.8-pr34-build", "valve": False,
|
|
}],
|
|
}))
|
|
|
|
COMPAT["register_default"](
|
|
str(config), ["10", "12"], default=self.TOOL,
|
|
catalog=self.CATALOG, directory=tmp,
|
|
)
|
|
|
|
self.assertEqual(mapping_of(config.read_text()), {
|
|
"0": self.TOOL,
|
|
"10": self.TOOL,
|
|
"12": "GE-Proton9-1",
|
|
})
|
|
|
|
def test_the_last_side_to_change_wins(self):
|
|
state = {"default": self.TOOL, "applied": 5}
|
|
default, state = COMPAT["choose_default"]("GE-Proton11-7", state, {"seq": 5, "dir": "Proton 11.0 (ARM64)", "valve": True}, self.CATALOG, now=100)
|
|
self.assertEqual((default, state["source"], state["seq"]), ("GE-Proton11-7", "steam", 100))
|
|
default, state = COMPAT["choose_default"]("GE-Proton11-7", state, {"seq": 6, "dir": "Proton 11.0 (ARM64)", "valve": True}, self.CATALOG, now=200)
|
|
self.assertEqual((default, state["source"], state["seq"], state["applied"]), (COMPAT["TOOL_11"], "app", 200, 6))
|
|
default, state = COMPAT["choose_default"]("GE-Proton11-7", state, {"seq": 6}, self.CATALOG, adopt_steam=False, now=300)
|
|
self.assertEqual((default, state["seq"]), (COMPAT["TOOL_11"], 200))
|
|
default, state = COMPAT["choose_default"]("proton_experimental", state, {"seq": 6}, self.CATALOG, now=300)
|
|
self.assertEqual(default, COMPAT["TOOL_11"])
|
|
|
|
def test_a_request_for_a_missing_tool_is_dropped(self):
|
|
default, state = COMPAT["choose_default"](self.TOOL, {"default": self.TOOL}, {"seq": 9, "dir": "GE-Proton9-1", "valve": False}, self.CATALOG, now=1)
|
|
self.assertEqual((default, state["applied"]), (self.TOOL, 9))
|
|
default, state = COMPAT["choose_default"]("GE-Proton11-7", state, {"seq": 9, "dir": "GE-Proton9-1", "valve": False}, self.CATALOG, now=2)
|
|
self.assertEqual(default, "GE-Proton11-7")
|
|
|
|
def test_settle_before_the_client_starts(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
config = Path(tmp) / "config.vdf"
|
|
config.write_text(config_text([("0", self.TOOL), ("10", "proton_experimental"), ("11", "GE-Proton11-7")]))
|
|
(Path(tmp) / "request.json").write_text(json.dumps({"seq": 3, "dir": "Proton 11.0 (ARM64)", "valve": True}))
|
|
default = COMPAT["register_default"](str(config), ["10", "11", "12"], catalog=self.CATALOG, directory=tmp, settle=True)
|
|
self.assertEqual(default, COMPAT["TOOL_11"])
|
|
self.assertEqual(mapping_of(config.read_text()), {"0": COMPAT["TOOL_11"], "10": COMPAT["TOOL_11"], "11": "GE-Proton11-7", "12": COMPAT["TOOL_11"]})
|
|
state = json.loads((Path(tmp) / "state.json").read_text())
|
|
self.assertEqual((state["applied"], state["source"], state["tools"]), (3, "app", self.CATALOG))
|
|
config.write_text(config_text([("0", "GE-Proton11-7"), ("10", COMPAT["TOOL_11"]), ("11", "GE-Proton11-7"), ("12", COMPAT["TOOL_11"])]))
|
|
default = COMPAT["register_default"](str(config), ["10", "11", "12"], catalog=self.CATALOG, directory=tmp, settle=True)
|
|
self.assertEqual(default, "GE-Proton11-7")
|
|
self.assertEqual(mapping_of(config.read_text())["10"], "GE-Proton11-7")
|
|
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["source"], "steam")
|
|
config.write_text(config_text([("0", "proton_experimental")]))
|
|
default = COMPAT["register_default"](str(config), ["10"], catalog=self.CATALOG, directory=tmp)
|
|
self.assertEqual(mapping_of(config.read_text()), {"0": "GE-Proton11-7", "10": "GE-Proton11-7"})
|
|
|
|
def test_the_shortcut_writer_keeps_the_chosen_default(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
steam = Path(tmp) / "Steam"
|
|
for name in COMPAT["SOURCES"]:
|
|
(steam / "steamapps/common" / name / "files/bin-arm64").mkdir(parents=True)
|
|
(steam / "config").mkdir()
|
|
config = steam / "config/config.vdf"
|
|
config.write_text(config_text([("0", COMPAT["TOOL_11"]), ("10", COMPAT["TOOL_11"]), ("3044416433", COMPAT["TOOL_11"])]))
|
|
(Path(tmp) / "state.json").write_text(json.dumps({"default": COMPAT["TOOL_11"], "auto": {"10": COMPAT["TOOL_11"], "3044416433": COMPAT["TOOL_11"]}}))
|
|
COMPAT["register_default"](str(config), apps=["3044416433", "3212965118"], protect={}, directory=tmp)
|
|
self.assertEqual(mapping_of(config.read_text()), {"0": COMPAT["TOOL_11"], "10": COMPAT["TOOL_11"], "3044416433": COMPAT["TOOL_11"], "3212965118": COMPAT["TOOL_11"]})
|
|
|
|
def test_each_valve_depot_gets_its_own_tool(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
steam = Path(tmp) / "Steam"
|
|
for name in COMPAT["SOURCES"]:
|
|
(steam / "steamapps/common" / name / "files/bin-arm64").mkdir(parents=True)
|
|
self.assertEqual(COMPAT["find_source"](str(steam), COMPAT["OWN_TOOLS"][1][1]), str(steam / "steamapps/common/Proton 11.0 (ARM64)"))
|
|
self.assertEqual(COMPAT["find_source"](str(steam)), str(steam / "steamapps/common/Proton Experimental (ARM64)"))
|
|
self.assertEqual([(t["name"], t["dir"]) for t in COMPAT["tool_catalog"](str(steam), {})],
|
|
[(COMPAT["TOOL"], "Proton Experimental (ARM64)"), (COMPAT["TOOL_11"], "Proton 11.0 (ARM64)")])
|
|
for name, sources in COMPAT["OWN_TOOLS"]:
|
|
COMPAT["build_tool"](str(steam / "compatibilitytools.d" / name), COMPAT["find_source"](str(steam), sources), sources, name)
|
|
self.assertEqual(COMPAT["adopt_extras"](str(steam / "compatibilitytools.d")), {})
|
|
self.assertEqual(sorted(os.listdir(steam / "compatibilitytools.d" / COMPAT["TOOL_11"])), sorted(COMPAT["OWN_FILES"]))
|
|
launcher = COMPAT["launcher_sh"](COMPAT["OWN_TOOLS"][1][1])
|
|
self.assertIn('for name in "Proton 11.0 (ARM64)"; do', launcher)
|
|
self.assertIn("${major%%.*}", launcher)
|
|
|
|
|
|
|
|
class DirectAudioPrefixTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
base = Path(self.tmp.name)
|
|
self.tool = base / "tool"
|
|
(self.tool / "files/bin-arm64").mkdir(parents=True)
|
|
wine = self.tool / "files/bin-arm64/wine"
|
|
wine.write_text("#!/bin/sh\necho wine-11.0-4c8f2e1 '(Staging)'\n")
|
|
wine.chmod(0o755)
|
|
(self.tool / "files/lib/wine/aarch64-unix").mkdir(parents=True)
|
|
self.winepulse = self.tool / "files/lib/wine/aarch64-unix/winepulse.so"
|
|
self.winepulse.write_bytes(b"\x7fELF classic wine 11 pulse driver")
|
|
self.sets = base / "directaudio"
|
|
for set_name in ("linux-wine11", "linux-wine11-systhread"):
|
|
for arch in ("aarch64-windows", "i386-windows", "aarch64-unix"):
|
|
(self.sets / set_name / "lib/wine" / arch).mkdir(parents=True)
|
|
(self.sets / set_name / "lib/wine/aarch64-windows/winedirectaudio.drv").write_bytes(b"arm64x-" + set_name.encode())
|
|
(self.sets / set_name / "lib/wine/i386-windows/winedirectaudio.drv").write_bytes(b"i386")
|
|
self.audio = self.sets / "linux-wine11"
|
|
self.compat = base / "compat"
|
|
self.windows = self.compat / "pfx/drive_c/windows"
|
|
for folder in ("system32", "syswow64"):
|
|
(self.windows / folder).mkdir(parents=True)
|
|
self.reg = self.compat / "pfx/user.reg"
|
|
|
|
def run_setup(self, verb="waitforexitandrun", target="game.exe", cwd=None, extra=None):
|
|
script = COMPAT["DD_DIRECTAUDIO_SETUP"] + '\nverb=$2\ndd_directaudio "$1" "$3"\necho "WINEDLLPATH=$WINEDLLPATH"\necho "WINE_AUDIO_DRIVER=${WINE_AUDIO_DRIVER:-}"\nenv | grep "^BANNER_AUDIO_DIRECT_" | sort\n'
|
|
steam = self.compat.parent / "Steam"
|
|
env = dict(os.environ, DD_DIRECTAUDIO=str(self.sets), STEAM_COMPAT_DATA_PATH=str(self.compat),
|
|
STEAM_COMPAT_CLIENT_INSTALL_PATH=str(steam), **(extra or {}))
|
|
env.pop("WINEDLLPATH", None)
|
|
env.pop("WINE_AUDIO_DRIVER", None)
|
|
return subprocess.run(["bash", "-c", script, "bash", str(self.tool), verb, target], cwd=cwd, env=env,
|
|
capture_output=True, text=True, check=True)
|
|
|
|
def audio_values(self):
|
|
found, current = [], None
|
|
for line in self.reg.read_text().splitlines():
|
|
if line.startswith("["):
|
|
current = line.rsplit("] ", 1)[0] + "]"
|
|
elif line.startswith('"Audio"='):
|
|
found.append((current, line))
|
|
return found
|
|
|
|
def link(self, folder):
|
|
path = self.windows / folder / "winedirectaudio.drv"
|
|
return os.readlink(path) if path.is_symlink() else None
|
|
|
|
def test_steam_installscript_evaluator_does_not_change_prefix_audio(self):
|
|
legacycompat = self.compat.parent / "Steam/legacycompat"
|
|
legacycompat.mkdir(parents=True)
|
|
(legacycompat / "iscriptevaluator.exe").write_bytes(b"Steam install-script evaluator")
|
|
self.reg.write_text("WINE REGISTRY Version 2\n\n#arch=win64\n")
|
|
|
|
result = self.run_setup(target="iscriptevaluator.exe", cwd=legacycompat)
|
|
|
|
self.assertIn("DirectAudio skipped for Steam's install-script evaluator", result.stderr)
|
|
self.assertIn("WINEDLLPATH=\n", result.stdout)
|
|
self.assertIn("WINE_AUDIO_DRIVER=\n", result.stdout)
|
|
self.assertEqual(self.reg.read_text(), "WINE REGISTRY Version 2\n\n#arch=win64\n")
|
|
self.assertIsNone(self.link("system32"))
|
|
self.assertIsNone(self.link("syswow64"))
|
|
|
|
def test_same_basename_outside_steam_legacycompat_keeps_normal_setup(self):
|
|
legacycompat = self.compat.parent / "Steam/legacycompat"
|
|
legacycompat.mkdir(parents=True)
|
|
(legacycompat / "iscriptevaluator.exe").write_bytes(b"Steam install-script evaluator")
|
|
other = self.compat.parent / "other"
|
|
other.mkdir()
|
|
(other / "iscriptevaluator.exe").write_bytes(b"unrelated executable")
|
|
self.reg.write_text("WINE REGISTRY Version 2\n\n#arch=win64\n")
|
|
|
|
result = self.run_setup(target="iscriptevaluator.exe", cwd=other)
|
|
|
|
self.assertIn("DirectAudio selected", result.stderr)
|
|
self.assertEqual(self.link("system32"), str(self.audio / "lib/wine/aarch64-windows/winedirectaudio.drv"))
|
|
self.assertEqual(self.audio_values(), [("[Software\\\\Wine\\\\Drivers]", '"Audio"="directaudio,pulse"')])
|
|
def test_audio_direct_settings_reach_the_driver_under_its_own_names(self):
|
|
self.reg.write_text("WINE REGISTRY Version 2\n\n#arch=win64\n")
|
|
result = self.run_setup(extra={"AUDIO_DIRECT_MS": "60", "AUDIO_DIRECT_PERIOD_MS": "20",
|
|
"AUDIO_DIRECT_RELAY": "/run/relay.sock", "OTHER_AUDIO_DIRECT_MS": "5"})
|
|
lines = [line for line in result.stdout.splitlines() if line.startswith("BANNER_")]
|
|
self.assertEqual(lines, ["BANNER_AUDIO_DIRECT_MS=60", "BANNER_AUDIO_DIRECT_PERIOD_MS=20",
|
|
"BANNER_AUDIO_DIRECT_RELAY=/run/relay.sock"])
|
|
|
|
def test_audio_direct_settings_are_not_handed_on_when_directaudio_stays_off(self):
|
|
legacycompat = self.compat.parent / "Steam/legacycompat"
|
|
legacycompat.mkdir(parents=True)
|
|
(legacycompat / "iscriptevaluator.exe").write_bytes(b"Steam install-script evaluator")
|
|
result = self.run_setup(target="iscriptevaluator.exe", cwd=legacycompat, extra={"AUDIO_DIRECT_MS": "60"})
|
|
self.assertNotIn("BANNER_AUDIO_DIRECT_MS", result.stdout)
|
|
|
|
def test_non_launch_verbs_preserve_audio_configuration(self):
|
|
for verb in ("getcompatpath", "getnativepath", "destroyprefix"):
|
|
with self.subTest(verb=verb):
|
|
self.reg.write_text('WINE REGISTRY Version 2\n\n[Software\\\\Wine\\\\Drivers] 1\n"Audio"="pulse"\n')
|
|
before = self.reg.read_bytes()
|
|
result = self.run_setup(verb)
|
|
self.assertEqual(self.reg.read_bytes(), before)
|
|
self.assertIsNone(self.link("system32"))
|
|
self.assertIsNone(self.link("syswow64"))
|
|
self.assertIn("WINEDLLPATH=\n", result.stdout)
|
|
self.assertIn("WINE_AUDIO_DRIVER=\n", result.stdout)
|
|
|
|
def test_other_windows_launch_verbs_still_set_up_audio(self):
|
|
self.reg.write_text("WINE REGISTRY Version 2\n")
|
|
for verb in ("run", "runinprefix"):
|
|
with self.subTest(verb=verb):
|
|
result = self.run_setup(verb)
|
|
self.assertIn("DirectAudio ready", result.stderr)
|
|
self.assertIn("WINE_AUDIO_DRIVER=directaudio,pulse\n", result.stdout)
|
|
self.assertEqual(self.link("system32"), str(self.audio / "lib/wine/aarch64-windows/winedirectaudio.drv"))
|
|
|
|
def test_the_driver_is_placed_and_selected_the_way_wine_reads_it(self):
|
|
self.reg.write_text("WINE REGISTRY Version 2\n;; All keys relative to \\\\User\\\\S-1-5-21-0-0-0-1000\n\n#arch=win64\n")
|
|
result = self.run_setup()
|
|
self.assertIn("DirectAudio selected", result.stderr)
|
|
self.assertIn("WINEDLLPATH=%s/lib/wine" % self.audio, result.stdout)
|
|
self.assertIn("WINE_AUDIO_DRIVER=directaudio,pulse\n", result.stdout)
|
|
self.assertEqual(self.link("system32"), str(self.audio / "lib/wine/aarch64-windows/winedirectaudio.drv"))
|
|
self.assertEqual(self.link("syswow64"), str(self.audio / "lib/wine/i386-windows/winedirectaudio.drv"))
|
|
self.assertEqual((self.windows / "system32/winedirectaudio.drv").read_bytes(), b"arm64x-linux-wine11")
|
|
self.assertEqual(self.audio_values(), [("[Software\\\\Wine\\\\Drivers]", '"Audio"="directaudio,pulse"')])
|
|
before = self.reg.read_text()
|
|
self.assertNotIn("DirectAudio selected", self.run_setup().stderr)
|
|
self.assertEqual(self.reg.read_text(), before)
|
|
self.assertEqual(sorted(os.listdir(self.windows / "system32")), ["winedirectaudio.drv"])
|
|
|
|
def test_without_a_prefix_it_waits_for_the_next_launch(self):
|
|
result = self.run_setup()
|
|
self.assertIn("takes effect the next time this game starts", result.stderr)
|
|
self.assertEqual(self.link("system32"), None)
|
|
|
|
def test_the_system_thread_set_is_picked_from_winepulse_not_the_version(self):
|
|
self.reg.write_text("WINE REGISTRY Version 2\n\n#arch=win64\n")
|
|
self.winepulse.write_bytes(b"\x7fELF cachyos pulse driver PsCreateSystemThread NtSetInformationThread")
|
|
result = self.run_setup()
|
|
systhread = self.sets / "linux-wine11-systhread"
|
|
self.assertIn("DirectAudio ready (Wine 11, linux-wine11-systhread)", result.stderr)
|
|
self.assertIn("WINEDLLPATH=%s/lib/wine" % systhread, result.stdout)
|
|
self.assertEqual(self.link("system32"), str(systhread / "lib/wine/aarch64-windows/winedirectaudio.drv"))
|
|
self.assertEqual((self.windows / "system32/winedirectaudio.drv").read_bytes(), b"arm64x-linux-wine11-systhread")
|
|
|
|
def test_no_set_for_the_interface_leaves_protons_own_audio(self):
|
|
self.reg.write_text("WINE REGISTRY Version 2\n\n#arch=win64\n")
|
|
self.winepulse.write_bytes(b"\x7fELF PsCreateSystemThread")
|
|
shutil.rmtree(self.sets / "linux-wine11-systhread")
|
|
result = self.run_setup()
|
|
self.assertIn("no driver set for the linux-wine11-systhread interface", result.stderr)
|
|
self.assertIn("WINEDLLPATH=\n", result.stdout)
|
|
self.assertIn("WINE_AUDIO_DRIVER=\n", result.stdout)
|
|
self.assertFalse((self.windows / "system32/winedirectaudio.drv").exists())
|
|
|
|
def test_older_selections_are_upgraded(self):
|
|
self.reg.write_text('WINE REGISTRY Version 2\n\n[SoftwareWineDrivers] 1790995967\n#time=1dd52e24550e980\n"Audio"="directaudio"\n'
|
|
'\n[Software\\\\Wine\\\\Drivers] 1790995986\n#time=1dd52e250b31ec4\n"Audio"="directaudio"\n')
|
|
self.assertIn("DirectAudio selected", self.run_setup().stderr)
|
|
self.assertEqual(self.audio_values(), [("[SoftwareWineDrivers]", '"Audio"="directaudio"'),
|
|
("[Software\\\\Wine\\\\Drivers]", '"Audio"="directaudio"'),
|
|
("[Software\\\\Wine\\\\Drivers]", '"Audio"="directaudio,pulse"')])
|
|
self.assertNotIn("DirectAudio selected", self.run_setup().stderr)
|
|
|
|
def test_a_copied_driver_is_replaced_by_the_staged_one(self):
|
|
self.reg.write_text("WINE REGISTRY Version 2\n")
|
|
(self.windows / "system32/winedirectaudio.drv").write_bytes(b"stale copy")
|
|
self.run_setup()
|
|
self.assertEqual(self.link("system32"), str(self.audio / "lib/wine/aarch64-windows/winedirectaudio.drv"))
|
|
|
|
def test_nothing_is_selected_without_the_driver_in_the_prefix(self):
|
|
self.reg.write_text("WINE REGISTRY Version 2\n")
|
|
shutil.rmtree(self.windows)
|
|
self.assertIn("could not be placed", self.run_setup().stderr)
|
|
self.assertEqual(self.audio_values(), [])
|
|
(self.windows / "system32").mkdir(parents=True)
|
|
(self.audio / "lib/wine/aarch64-windows/winedirectaudio.drv").unlink()
|
|
self.assertIn("could not be placed", self.run_setup().stderr)
|
|
self.assertEqual(self.audio_values(), [])
|
|
|
|
def test_a_new_prefix_waits_for_the_next_launch(self):
|
|
shutil.rmtree(self.compat / "pfx")
|
|
self.assertIn("no prefix yet", self.run_setup().stderr)
|
|
self.assertFalse(self.reg.exists())
|
|
|
|
def test_another_wine_major_is_left_alone(self):
|
|
(self.tool / "files/bin-arm64/wine").write_text("#!/bin/sh\necho wine-10.0\n")
|
|
self.reg.write_text("WINE REGISTRY Version 2\n")
|
|
result = self.run_setup()
|
|
self.assertIn("left off", result.stderr)
|
|
self.assertIn("WINEDLLPATH=\n", result.stdout)
|
|
self.assertEqual(self.audio_values(), [])
|
|
self.assertIsNone(self.link("system32"))
|
|
|
|
|
|
class ProjectZomboidJvmTest(unittest.TestCase):
|
|
ARGS = ["-Djava.awt.headless=true", "-Xmx3072m", "-XX:+UseZGC", "-XX:-CreateCoredumpOnCrash"]
|
|
|
|
def launch(self, tmp, args=None, stem="ProjectZomboid64"):
|
|
settings = Path(tmp) / (stem + ".json")
|
|
settings.write_text(json.dumps({"mainClass": "zombie/gameStates/MainScreenState", "vmArgs": args or self.ARGS}))
|
|
command = ["proton", "waitforexitandrun", str(Path(tmp) / (stem + ".exe"))]
|
|
return settings, command
|
|
|
|
def test_zgc_becomes_g1_and_the_c1_jit_flag_is_added_once(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
settings, command = self.launch(tmp)
|
|
MODULE["project_zomboid_jvm"](command)
|
|
data = json.loads(settings.read_text())
|
|
self.assertEqual(data["vmArgs"], ["-Djava.awt.headless=true", "-Xmx3072m", "-XX:-CreateCoredumpOnCrash",
|
|
"-XX:+UseG1GC", "-XX:TieredStopAtLevel=1"])
|
|
self.assertEqual(data["mainClass"], "zombie/gameStates/MainScreenState")
|
|
before = settings.read_text()
|
|
MODULE["project_zomboid_jvm"](command)
|
|
self.assertEqual(settings.read_text(), before)
|
|
|
|
def test_other_collectors_and_windows_specific_lists_are_rewritten(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
settings, command = self.launch(tmp)
|
|
settings.write_text(json.dumps({"vmArgs": ["-XX:+UseParallelGC", "-Xmx1g"],
|
|
"windows": {"10.0.17134": {"vmArgs": ["-XX:+UseZGC", "-XX:+UseG1GC"]}}}))
|
|
MODULE["project_zomboid_jvm"](command)
|
|
data = json.loads(settings.read_text())
|
|
flags = ["-XX:+UseG1GC", "-XX:TieredStopAtLevel=1"]
|
|
self.assertEqual(data["vmArgs"], ["-Xmx1g"] + flags)
|
|
self.assertEqual(data["windows"]["10.0.17134"]["vmArgs"], flags)
|
|
|
|
def test_other_games_and_unreadable_files_are_left_alone(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
settings, command = self.launch(tmp, stem="Other")
|
|
before = settings.read_text()
|
|
MODULE["project_zomboid_jvm"](command)
|
|
self.assertEqual(settings.read_text(), before)
|
|
settings.write_text("{")
|
|
MODULE["project_zomboid_jvm"](command[:2] + [str(Path(tmp) / "Other.exe")])
|
|
(Path(tmp) / "ProjectZomboid64.json").write_text("{")
|
|
MODULE["project_zomboid_jvm"](command[:2] + [str(Path(tmp) / "ProjectZomboid64.exe")])
|
|
self.assertEqual((Path(tmp) / "ProjectZomboid64.json").read_text(), "{")
|
|
|
|
|
|
class UbisoftOverlayTest(unittest.TestCase):
|
|
SETTINGS = (
|
|
"language:\n code: en-US\n"
|
|
"overlay:\n enabled: true\n forceunhookgame: false\n fps_enabled: false\n warning_enabled: true\n"
|
|
"patchTrigger:\n source: USER_RESTART\n"
|
|
)
|
|
|
|
def test_the_overlay_and_its_prompt_are_turned_off_and_the_rest_is_kept(self):
|
|
got = MODULE["overlay_off"](self.SETTINGS)
|
|
self.assertEqual(got, self.SETTINGS.replace("enabled: true", "enabled: false"))
|
|
self.assertEqual(MODULE["overlay_off"](got), got)
|
|
|
|
def test_missing_keys_or_section_are_added(self):
|
|
self.assertEqual(MODULE["overlay_off"]("overlay:\n fps_enabled: true\nmisc:\n a: 1\n"),
|
|
"overlay:\n fps_enabled: true\n enabled: false\n warning_enabled: false\nmisc:\n a: 1\n")
|
|
self.assertEqual(MODULE["overlay_off"](""), "overlay:\n enabled: false\n warning_enabled: false\n")
|
|
|
|
def test_blank_lines_inside_the_overlay_section_do_not_end_it(self):
|
|
text = "overlay:\n enabled: true\n\n warning_enabled: true\n\nmisc:\n a: 1\n"
|
|
self.assertEqual(MODULE["overlay_off"](text), text.replace("true", "false"))
|
|
self.assertEqual(MODULE["overlay_off"]("overlay:\n fps_enabled: true\n\nmisc:\n a: 1\n"),
|
|
"overlay:\n fps_enabled: true\n enabled: false\n warning_enabled: false\n\nmisc:\n a: 1\n")
|
|
|
|
def test_an_annotated_overlay_header_is_the_same_section(self):
|
|
self.assertEqual(MODULE["overlay_off"]("overlay: # in-game\n enabled: true\n"),
|
|
"overlay: # in-game\n enabled: false\n warning_enabled: false\n")
|
|
|
|
def test_only_prefixes_with_ubisoft_connect_are_touched(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
prefix = Path(tmp) / "447040/pfx"
|
|
env = {"STEAM_COMPAT_DATA_PATH": str(prefix.parent)}
|
|
settings = prefix / MODULE["UBISOFT_SETTINGS"]
|
|
prefix.mkdir(parents=True)
|
|
MODULE["ubisoft_overlay_off"](env)
|
|
self.assertFalse(settings.exists())
|
|
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
|
MODULE["ubisoft_overlay_off"](env)
|
|
self.assertEqual(settings.read_text(), "overlay:\n enabled: false\n warning_enabled: false\n")
|
|
settings.write_text(self.SETTINGS)
|
|
settings.chmod(0o644)
|
|
MODULE["ubisoft_overlay_off"](env)
|
|
self.assertEqual(settings.read_text(), self.SETTINGS.replace("enabled: true", "enabled: false"))
|
|
self.assertEqual(settings.stat().st_mode & 0o777, 0o644)
|
|
self.assertEqual(sorted(p.name for p in settings.parent.iterdir()), ["settings.yaml"])
|
|
|
|
|
|
class UbisoftCompositionTest(unittest.TestCase):
|
|
def test_writes_through_wine_without_replacing_a_live_servers_registry(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
prefix = Path(tmp) / "pfx"
|
|
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
|
registry = prefix / "user.reg"
|
|
registry.write_text("registry last saved by Wine\n")
|
|
env = {"STEAM_COMPAT_DATA_PATH": tmp, "WINESERVER": "/selected/wineserver"}
|
|
keys = []
|
|
|
|
def write_registry(argv, **kwargs):
|
|
self.assertEqual(argv[:4], ["/selected/proton", "runinprefix", "reg.exe", "add"])
|
|
self.assertEqual(argv[5:], ["/v", "dcomp", "/t", "REG_SZ", "/d", "", "/f"])
|
|
self.assertIs(kwargs["env"], env)
|
|
self.assertTrue(kwargs["check"])
|
|
keys.append(argv[4])
|
|
registry.write_text("newer state saved by the active Wine server\n")
|
|
return subprocess.CompletedProcess(argv, 0)
|
|
|
|
with mock.patch("subprocess.run", side_effect=write_registry) as run:
|
|
MODULE["ubisoft_composition_off"]("/selected/proton", env)
|
|
self.assertEqual(run.call_count, 2)
|
|
self.assertEqual(registry.read_text(), "newer state saved by the active Wine server\n")
|
|
self.assertEqual(keys, [r"HKCU\Software\Wine\AppDefaults\%s\DllOverrides" % program
|
|
for program in ("upc.exe", "UplayWebCore.exe")])
|
|
self.assertEqual(list(prefix.glob(".ubisoft-*.reg")), [])
|
|
|
|
def test_other_prefixes_and_uninitialized_registries_are_untouched(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
prefix = Path(tmp) / "pfx"
|
|
prefix.mkdir()
|
|
registry = prefix / "user.reg"
|
|
registry.write_text("WINE REGISTRY Version 2\n")
|
|
env = {"STEAM_COMPAT_DATA_PATH": tmp}
|
|
with mock.patch("subprocess.run") as run:
|
|
MODULE["ubisoft_composition_off"]("proton", env)
|
|
self.assertEqual(registry.read_text(), "WINE REGISTRY Version 2\n")
|
|
registry.unlink()
|
|
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
|
MODULE["ubisoft_composition_off"]("proton", env)
|
|
self.assertFalse(registry.exists())
|
|
run.assert_not_called()
|
|
|
|
def test_failed_registry_write_keeps_the_game_launch_available(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
prefix = Path(tmp) / "pfx"
|
|
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
|
(prefix / "user.reg").write_text("WINE REGISTRY Version 2\n")
|
|
for failed_write in (0, 1):
|
|
stderr = io.StringIO()
|
|
results = [subprocess.CompletedProcess([], 0)] * failed_write
|
|
results.append(subprocess.CalledProcessError(1, "proton"))
|
|
with mock.patch("subprocess.run", side_effect=results) as run, mock.patch("sys.stderr", stderr):
|
|
MODULE["ubisoft_composition_off"]("proton", {"STEAM_COMPAT_DATA_PATH": tmp})
|
|
self.assertEqual(run.call_count, failed_write + 1)
|
|
self.assertIn("configuration failed", stderr.getvalue())
|
|
self.assertNotIn("uses CEF", stderr.getvalue())
|
|
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)
|
|
|
|
|
|
def program_image(machine, imports):
|
|
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] = machine.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")
|
|
image[optional + 120:optional + 124] = (0x1000).to_bytes(4, "little")
|
|
image[optional + 124:optional + 128] = (20 * (len(imports) + 1)).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")
|
|
name = 20 * (len(imports) + 1)
|
|
for index, dll in enumerate(imports):
|
|
image[0x200 + index * 20 + 12:0x200 + index * 20 + 16] = (0x1000 + name).to_bytes(4, "little")
|
|
image[0x200 + name:0x200 + name + len(dll)] = dll.encode()
|
|
name += len(dll) + 1
|
|
return bytes(image)
|
|
|
|
|
|
def bytes_path(folder, data):
|
|
path = folder / "image.exe"
|
|
path.write_bytes(data)
|
|
return path
|
|
|
|
|
|
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(program_image(machine, []))
|
|
(dist / "aarch64-windows/wineboot.exe").write_bytes(program_image(0xAA64, ["UCRTBASE.dll", "rpcrt4.dll"]))
|
|
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_x64_dlls_proton_programs_do_not_import_are_kept_in_arm64_system32(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton, compat, windows = self.prefix(tmp)
|
|
builtins = proton.parent / "files/lib/wine/aarch64-windows"
|
|
(builtins / "explorer.exe").write_bytes(program_image(0xAA64, ["shell32.dll"]))
|
|
(builtins / "shell32.dll").write_bytes(program_image(0xAA64, ["msvcp_win.dll"]))
|
|
names = ("vulkan-1.dll", "msvcp140.dll", "VCRUNTIME140.dll", "concrt140.dll", "d3dcompiler_43.dll",
|
|
"winhttp.dll", "msvcp_win.dll")
|
|
for name in names:
|
|
(builtins / name.lower()).write_bytes(program_image(0xAA64, []))
|
|
(windows / "system32" / name).write_bytes(pe_image(0x8664))
|
|
self.assertEqual(["system32/msvcp_win.dll (machine 0x8664)"], self.run_repair(compat, proton))
|
|
for name in names[:-1]:
|
|
self.assertFalse((windows / "system32" / name).is_symlink())
|
|
self.assertEqual(0x8664, MODULE["pe_machine"](windows / "system32" / name))
|
|
|
|
def test_repaired_dll_proton_programs_do_not_import_gets_its_native_copy_back(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton, compat, windows = self.prefix(tmp)
|
|
builtins = proton.parent / "files/lib/wine/aarch64-windows"
|
|
(builtins / "vulkan-1.dll").write_bytes(pe_image(0xAA64))
|
|
system32 = windows / "system32"
|
|
for name in ("vulkan-1.dll", "ucrtbase.dll"):
|
|
(system32 / name).symlink_to(os.path.relpath(builtins / name, system32))
|
|
(system32 / (name + ".foreign-arch")).write_bytes(pe_image(0x8664))
|
|
(system32 / "vulkan-1.dll.foreign-arch.1").write_bytes(pe_image(0x8664) + b"newest")
|
|
restore = MODULE["restore_compatible_system_dlls"]
|
|
self.assertEqual(["system32/vulkan-1.dll (machine 0x8664)"], restore(str(compat), str(proton)))
|
|
self.assertFalse((system32 / "vulkan-1.dll").is_symlink())
|
|
self.assertTrue((system32 / "vulkan-1.dll").read_bytes().endswith(b"newest"))
|
|
self.assertFalse((system32 / "vulkan-1.dll.foreign-arch.1").exists())
|
|
self.assertTrue((system32 / "ucrtbase.dll").is_symlink())
|
|
self.assertEqual([], restore(str(compat), str(proton)))
|
|
self.assertEqual([], self.run_repair(compat, proton))
|
|
|
|
def test_prefix_backup_directory_is_listed_once_per_pass(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton, compat, windows = self.prefix(tmp)
|
|
builtins = proton.parent / "files/lib/wine/aarch64-windows"
|
|
system32 = windows / "system32"
|
|
for index in range(12):
|
|
name = "native_%02d.dll" % index
|
|
(builtins / name).write_bytes(pe_image(0xAA64))
|
|
(system32 / name).symlink_to(os.path.relpath(builtins / name, system32))
|
|
(system32 / (name + ".foreign-arch")).write_bytes(pe_image(0x8664))
|
|
(system32 / "ucrtbase.dll").write_bytes(pe_image(0x8664))
|
|
original_listdir = os.listdir
|
|
visited = []
|
|
|
|
def counted_listdir(folder):
|
|
if Path(folder) == system32:
|
|
visited.append(folder)
|
|
return original_listdir(folder)
|
|
|
|
with mock.patch("os.listdir", side_effect=counted_listdir):
|
|
restored = MODULE["restore_compatible_system_dlls"](str(compat), str(proton))
|
|
fixed = self.run_repair(compat, proton)
|
|
self.assertEqual(12, len(restored))
|
|
self.assertEqual(["system32/ucrtbase.dll (machine 0x8664)"], fixed)
|
|
# One system32 listing for restore and one for repair, regardless
|
|
# of the number of DLLs and backup files in the prefix.
|
|
self.assertEqual(2, len(visited))
|
|
|
|
def test_restore_takes_the_highest_backup_serial_across_gaps(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton, compat, windows = self.prefix(tmp)
|
|
builtins = proton.parent / "files/lib/wine/aarch64-windows"
|
|
(builtins / "vulkan-1.dll").write_bytes(pe_image(0xAA64))
|
|
system32 = windows / "system32"
|
|
(system32 / "vulkan-1.dll").symlink_to(os.path.relpath(builtins / "vulkan-1.dll", system32))
|
|
(system32 / "vulkan-1.dll.foreign-arch.2").write_bytes(pe_image(0x8664) + b"two")
|
|
(system32 / "vulkan-1.dll.foreign-arch.10").write_bytes(pe_image(0x8664) + b"ten")
|
|
self.assertEqual(["system32/vulkan-1.dll (machine 0x8664)"],
|
|
MODULE["restore_compatible_system_dlls"](str(compat), str(proton)))
|
|
self.assertTrue((system32 / "vulkan-1.dll").read_bytes().endswith(b"ten"))
|
|
|
|
def test_unreadable_proton_program_keeps_the_conservative_rule(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton, compat, windows = self.prefix(tmp)
|
|
builtins = proton.parent / "files/lib/wine/aarch64-windows"
|
|
(builtins / "broken.exe").mkdir()
|
|
(builtins / "vulkan-1.dll").write_bytes(pe_image(0xAA64))
|
|
system32 = windows / "system32"
|
|
(system32 / "concrt140.dll").write_bytes(pe_image(0x8664))
|
|
(builtins / "concrt140.dll").write_bytes(pe_image(0xAA64))
|
|
(system32 / "vulkan-1.dll").symlink_to(os.path.relpath(builtins / "vulkan-1.dll", system32))
|
|
(system32 / "vulkan-1.dll.foreign-arch").write_bytes(pe_image(0x8664))
|
|
self.assertEqual([], MODULE["restore_compatible_system_dlls"](str(compat), str(proton)))
|
|
self.assertTrue((system32 / "vulkan-1.dll").is_symlink())
|
|
self.assertEqual(["system32/concrt140.dll (machine 0x8664)"], self.run_repair(compat, proton))
|
|
|
|
def test_new_backup_goes_above_the_highest_existing_serial(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton, compat, windows = self.prefix(tmp)
|
|
system32 = windows / "system32"
|
|
(system32 / "ucrtbase.dll").write_bytes(pe_image(0x8664) + b"newest")
|
|
(system32 / "ucrtbase.dll.foreign-arch").write_bytes(pe_image(0x8664))
|
|
(system32 / "ucrtbase.dll.foreign-arch.2").write_bytes(pe_image(0x8664))
|
|
self.assertEqual(["system32/ucrtbase.dll (machine 0x8664)"], self.run_repair(compat, proton))
|
|
self.assertTrue((system32 / "ucrtbase.dll.foreign-arch.3").read_bytes().endswith(b"newest"))
|
|
self.assertFalse((system32 / "ucrtbase.dll.foreign-arch.1").exists())
|
|
|
|
def test_truncated_import_table_keeps_the_conservative_rule(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton, compat, windows = self.prefix(tmp)
|
|
builtins = proton.parent / "files/lib/wine/aarch64-windows"
|
|
(builtins / "cut.exe").write_bytes(program_image(0xAA64, ["concrt140.dll"])[:0x20A])
|
|
self.assertIsNone(MODULE["PE"]["pe_imports"](builtins / "cut.exe"))
|
|
self.assertIsNone(MODULE["PE"]["pe_imports"](bytes_path(Path(tmp), program_image(0xAA64, ["a.dll"])[:200])))
|
|
self.assertEqual(set(), MODULE["PE"]["pe_imports"](bytes_path(Path(tmp), program_image(0xAA64, []))))
|
|
moved = bytearray(program_image(0xAA64, ["concrt140.dll"]))
|
|
moved[208:212] = (0x3000).to_bytes(4, "little")
|
|
self.assertIsNone(MODULE["PE"]["pe_imports"](bytes_path(Path(tmp), moved)))
|
|
(builtins / "concrt140.dll").write_bytes(pe_image(0xAA64))
|
|
(windows / "system32/concrt140.dll").write_bytes(pe_image(0x8664))
|
|
self.assertEqual(["system32/concrt140.dll (machine 0x8664)"], self.run_repair(compat, proton))
|
|
|
|
def test_restore_leaves_other_links_and_x64_proton_alone(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton, compat, windows = self.prefix(tmp)
|
|
builtins = proton.parent / "files/lib/wine/aarch64-windows"
|
|
(builtins / "vulkan-1.dll").write_bytes(pe_image(0xAA64))
|
|
other = Path(tmp) / "other-vulkan-1.dll"
|
|
other.write_bytes(pe_image(0xAA64))
|
|
system32 = windows / "system32"
|
|
(system32 / "vulkan-1.dll").symlink_to(other)
|
|
(system32 / "vulkan-1.dll.foreign-arch").write_bytes(pe_image(0x8664))
|
|
(system32 / "rpcrt4.dll").symlink_to(os.path.relpath(builtins / "rpcrt4.dll", system32))
|
|
(system32 / "rpcrt4.dll.foreign-arch").write_bytes(pe_image(0x14C))
|
|
self.assertEqual([], MODULE["restore_compatible_system_dlls"](str(compat), str(proton)))
|
|
self.assertTrue((system32 / "vulkan-1.dll").is_symlink())
|
|
self.assertTrue((system32 / "rpcrt4.dll").is_symlink())
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
proton, compat, windows = self.prefix(tmp, arm=False)
|
|
dist = proton.parent / "files/lib/wine/x86_64-windows"
|
|
dist.mkdir(parents=True)
|
|
(dist / "vulkan-1.dll").write_bytes(pe_image(0x8664))
|
|
system32 = windows / "system32"
|
|
(system32 / "vulkan-1.dll").symlink_to(os.path.relpath(dist / "vulkan-1.dll", system32))
|
|
(system32 / "vulkan-1.dll.foreign-arch").write_bytes(pe_image(0xAA64))
|
|
self.assertEqual([], MODULE["restore_compatible_system_dlls"](str(compat), str(proton)))
|
|
self.assertTrue((system32 / "vulkan-1.dll").is_symlink())
|
|
|
|
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(".dd-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(".dd-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.dd-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))
|
|
|
|
|
|
class SharedDataHealTest(unittest.TestCase):
|
|
CURRENT = (21, 0x1234abcd, 0x5678ef01, os.getuid(), 1000)
|
|
STALE = (21, 0x0badf00d, 0x0ddba11, 10122, 1000)
|
|
|
|
def setUp(self):
|
|
self.globals = MODULE["heal_shared_data"].__globals__
|
|
self.old_machine_id = self.globals["MACHINE_ID"]
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.cleanup)
|
|
machine_id = Path(self.tmp.name) / "machine-id"
|
|
machine_id.write_text("1234abcd5678ef01%s\n" % ("0" * 16))
|
|
self.globals["MACHINE_ID"] = str(machine_id)
|
|
self.compat = Path(self.tmp.name) / "compat"
|
|
self.root = self.compat / "pfx/drive_c/ProgramData"
|
|
self.root.mkdir(parents=True)
|
|
probe = self.root / "probe"
|
|
probe.write_text("")
|
|
try:
|
|
os.setxattr(probe, "user.wine.sd", b"x")
|
|
except OSError:
|
|
self.skipTest("needs user xattrs")
|
|
probe.unlink()
|
|
|
|
def cleanup(self):
|
|
self.globals["MACHINE_ID"] = self.old_machine_id
|
|
for folder, dirs, files in os.walk(self.tmp.name):
|
|
for name in dirs + files:
|
|
path = os.path.join(folder, name)
|
|
if not os.path.islink(path):
|
|
os.chmod(path, 0o700)
|
|
self.tmp.cleanup()
|
|
|
|
def own(self, path, subs, authority=5):
|
|
sid = bytes([1, len(subs)]) + authority.to_bytes(6, "big") + struct.pack("<%dI" % len(subs), *subs)
|
|
header = struct.pack("<BBHIIII", 1, 0, 0x8004, len(sid), 0, 0, 0)
|
|
os.setxattr(path, "user.wine.sd", b"\x01\x00" + header + sid, follow_symlinks=False)
|
|
|
|
def heal(self):
|
|
return MODULE["heal_shared_data"](str(self.compat))
|
|
|
|
def mode(self, path):
|
|
return path.stat().st_mode & 0o777
|
|
|
|
def test_entries_a_stale_owner_locked_are_unlocked_and_every_stale_owner_is_cleared(self):
|
|
agent = self.root / "Vendor/Agent"
|
|
(agent / "Logs").mkdir(parents=True)
|
|
(agent / "Agent.dat").write_text("1")
|
|
(agent / "Tools.exe").write_text("x")
|
|
(agent / "Icons").mkdir()
|
|
for path in (agent.parent, agent, agent / "Logs", agent / "Agent.dat", agent / "Tools.exe", agent / "Icons"):
|
|
self.own(path, self.STALE)
|
|
(agent / "Tools.exe").chmod(0o550)
|
|
(agent / "Icons").chmod(0o500)
|
|
(agent / "Agent.dat").chmod(0)
|
|
(agent / "Logs").chmod(0)
|
|
agent.chmod(0)
|
|
self.assertEqual((["Vendor/Agent", "Vendor/Agent/Agent.dat", "Vendor/Agent/Logs"],
|
|
["Vendor", "Vendor/Agent", "Vendor/Agent/Agent.dat", "Vendor/Agent/Icons",
|
|
"Vendor/Agent/Logs", "Vendor/Agent/Tools.exe"]), self.heal())
|
|
self.assertEqual(0o500, self.mode(agent / "Icons"))
|
|
self.assertEqual(0o700, self.mode(agent))
|
|
self.assertEqual(0o700, self.mode(agent / "Logs"))
|
|
self.assertEqual(0o600, self.mode(agent / "Agent.dat"))
|
|
self.assertEqual(0o550, self.mode(agent / "Tools.exe"))
|
|
self.assertEqual("1", (agent / "Agent.dat").read_text())
|
|
(agent / "Logs/new").mkdir()
|
|
for path in (agent.parent, agent, agent / "Logs", agent / "Agent.dat", agent / "Tools.exe", agent / "Icons"):
|
|
self.assertNotIn("user.wine.sd", os.listxattr(path))
|
|
self.assertEqual(([], []), self.heal())
|
|
|
|
def test_current_and_well_known_owners_untagged_entries_and_links_are_left_alone(self):
|
|
mine = self.root / "Mine"
|
|
mine.mkdir(mode=0o755)
|
|
self.own(mine, self.CURRENT)
|
|
(mine / "settings.ini").write_text("x")
|
|
self.own(mine / "settings.ini", self.CURRENT)
|
|
(mine / "settings.ini").chmod(0o444)
|
|
denied = self.root / "Denied"
|
|
denied.mkdir()
|
|
self.own(denied, self.CURRENT)
|
|
denied.chmod(0)
|
|
admins = self.root / "Admins"
|
|
admins.mkdir()
|
|
self.own(admins, (32, 544))
|
|
admins.chmod(0o500)
|
|
plain = self.root / "Plain"
|
|
plain.mkdir()
|
|
plain.chmod(0)
|
|
outside = Path(self.tmp.name) / "outside"
|
|
outside.mkdir()
|
|
self.own(outside, self.STALE)
|
|
outside.chmod(0o500)
|
|
(self.root / "Link").symlink_to(outside)
|
|
self.assertEqual(([], []), self.heal())
|
|
self.assertEqual(0o755, self.mode(mine))
|
|
self.assertEqual(0o444, self.mode(mine / "settings.ini"))
|
|
self.assertEqual(0, self.mode(denied))
|
|
self.assertEqual(0o500, self.mode(admins))
|
|
self.assertEqual(0, self.mode(plain))
|
|
self.assertEqual(0o500, self.mode(outside))
|
|
for path in (mine, mine / "settings.ini", admins, outside):
|
|
self.assertIn("user.wine.sd", os.listxattr(path))
|
|
|
|
def test_a_locked_program_data_folder_is_healed_before_its_entries(self):
|
|
(self.root / "Vendor").mkdir()
|
|
self.own(self.root / "Vendor", self.STALE)
|
|
(self.root / "Vendor").chmod(0)
|
|
self.own(self.root, self.STALE)
|
|
self.root.chmod(0)
|
|
self.assertEqual(([".", "Vendor"], [".", "Vendor"]), self.heal())
|
|
self.assertEqual(0o700, self.mode(self.root))
|
|
self.assertEqual(0o700, self.mode(self.root / "Vendor"))
|
|
|
|
def test_a_heal_waits_while_another_launch_heals_the_same_prefix(self):
|
|
(self.root / "Vendor").mkdir()
|
|
self.own(self.root / "Vendor", self.STALE)
|
|
(self.root / "Vendor").chmod(0)
|
|
results = []
|
|
lock = os.open(self.compat / "pfx", os.O_RDONLY | os.O_DIRECTORY)
|
|
try:
|
|
fcntl.flock(lock, fcntl.LOCK_EX)
|
|
worker = threading.Thread(target=lambda: results.append(self.heal()))
|
|
worker.start()
|
|
worker.join(0.3)
|
|
self.assertTrue(worker.is_alive())
|
|
self.assertEqual(0, self.mode(self.root / "Vendor"))
|
|
finally:
|
|
os.close(lock)
|
|
worker.join(10)
|
|
self.assertEqual([(["Vendor"], ["Vendor"])], results)
|
|
|
|
def test_user_sid_follows_wine_for_a_missing_or_short_machine_id(self):
|
|
sid = MODULE["wine_user_sid"]
|
|
self.assertEqual(self.CURRENT, sid())
|
|
self.globals["MACHINE_ID"] = str(Path(self.tmp.name) / "missing")
|
|
self.assertEqual((21, 0, 0, 0, 1000), sid())
|
|
short = Path(self.tmp.name) / "short"
|
|
short.write_text("1234\n")
|
|
self.globals["MACHINE_ID"] = str(short)
|
|
self.assertEqual((21, 0, 0, 0, 1000), sid())
|
|
binary = Path(self.tmp.name) / "binary"
|
|
binary.write_bytes(b"\xff\xfe" + b"0" * 15)
|
|
self.globals["MACHINE_ID"] = str(binary)
|
|
self.assertEqual((21, 0, 0, os.getuid(), 1000), sid())
|
|
signed = Path(self.tmp.name) / "signed"
|
|
signed.write_text("+234abcd5678ef01\n")
|
|
self.globals["MACHINE_ID"] = str(signed)
|
|
self.assertEqual((21, 0x234abcd, 0x5678ef01, os.getuid(), 1000), sid())
|
|
signed.write_text("-000000000000001\n")
|
|
self.assertEqual((21, 0xffffffff, 0xffffffff, os.getuid(), 1000), sid())
|
|
|
|
def test_prefix_without_shared_data_is_skipped(self):
|
|
self.assertEqual(([], []), MODULE["heal_shared_data"](str(Path(self.tmp.name) / "missing")))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|
|
|
|
|
|
class ForceSsbsTest(unittest.TestCase):
|
|
def test_libssbs_is_preloaded_only_when_asked_and_only_into_arm64_proton(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
arm = Path(tmp) / "arm"
|
|
(arm / "files/lib/wine/aarch64-unix").mkdir(parents=True)
|
|
x86 = Path(tmp) / "x86"
|
|
(x86 / "files/lib/wine/x86_64-unix").mkdir(parents=True)
|
|
lib = Path(tmp) / "libssbs.so"
|
|
lib.write_bytes(b"\x7fELF")
|
|
g = MODULE["force_ssbs"].__globals__
|
|
old = g["SSBS_LIB"]
|
|
g["SSBS_LIB"] = str(lib)
|
|
try:
|
|
env = {"LD_PRELOAD": "/usr/local/lib/libddsession.so"}
|
|
self.assertEqual(MODULE["force_ssbs"]([str(arm / "proton"), "waitforexitandrun"], env), env)
|
|
on = dict(env, DROIDDECK_FORCE_SSBS="1")
|
|
got = MODULE["force_ssbs"]([str(arm / "proton"), "waitforexitandrun"], on)
|
|
self.assertEqual(got["LD_PRELOAD"], "/usr/local/lib/libddsession.so:" + str(lib))
|
|
self.assertEqual(MODULE["force_ssbs"]([str(arm / "proton")], got)["LD_PRELOAD"], got["LD_PRELOAD"])
|
|
self.assertEqual(MODULE["force_ssbs"]([str(x86 / "proton")], on), on)
|
|
finally:
|
|
g["SSBS_LIB"] = old
|