mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
Merge DroidDeck 0.5.0 into the non-Adreno test branch
Conflicts kept both sides: the 0.5.0 GPU drivers redesign (Auto / pair / mix modes, rollback of a pair that never starts a session) with the test branch's Mali, PowerVR and Xclipse rules (Mali display on the phone's own driver, bridge and system-Vulkan fallbacks, 1-hour list refresh for the open drivers); the test branch's Update button for rebuilt open pairs moved into 0.5.0's new GPU drivers panel; Venus GL probing, the Mali compatibility layer and oom_score_adj redirect kept with 0.5.0's x86-64 Steam client, VAC diagnostics and caller-aware preload hooks.
This commit is contained in:
commit
bab999038f
616 files changed
+83918
-2233
No files matched your search
@@ -0,0 +1,69 @@
|
||||
"""Build the pinned lite-palm/lite-landmark MediaPipe bundle (mediapipe==0.10.21)."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
from pathlib import Path
|
||||
import zipfile
|
||||
|
||||
FULL_SHA = 'fbc2a30080c3c557093b5ddfc334698132eb341044ccee322ccf8bcf3607cde1'
|
||||
LITE_SHA = 'd7fde8ac11f8ce03f8663775bfc323f4fc9f2a38062b4f4efa142874ef5b2a48'
|
||||
PALM_SHA = 'e9a4aaddf90dda56a87235303cf00e4c2d3fb28725f68fd88772997dac905c18'
|
||||
|
||||
def write_entry(archive, name, data):
|
||||
entry = zipfile.ZipInfo(name, (1980, 1, 1, 0, 0, 0))
|
||||
entry.create_system = 3
|
||||
entry.external_attr = 0o100644 << 16
|
||||
archive.writestr(entry, data)
|
||||
|
||||
def canonicalize_associated_files(data):
|
||||
with zipfile.ZipFile(io.BytesIO(data)) as archive:
|
||||
entries = archive.infolist()
|
||||
if not entries:
|
||||
return data
|
||||
prefix = data[:min(entry.header_offset for entry in entries)]
|
||||
files = {entry.filename: archive.read(entry) for entry in entries}
|
||||
output = io.BytesIO(prefix)
|
||||
with zipfile.ZipFile(output, 'a', compression=zipfile.ZIP_STORED) as archive:
|
||||
for name in sorted(files):
|
||||
write_entry(archive, name, files[name])
|
||||
return output.getvalue()
|
||||
|
||||
def build(full, lite, palm, output):
|
||||
import mediapipe
|
||||
from mediapipe.tasks.python.metadata import metadata
|
||||
from mediapipe.tasks.metadata import schema_py_generated as schema
|
||||
if mediapipe.__version__ != '0.10.21':
|
||||
raise ValueError('Use mediapipe==0.10.21 for reproducible metadata')
|
||||
for path, expected in [(full, FULL_SHA), (lite, LITE_SHA), (palm, PALM_SHA)]:
|
||||
if hashlib.sha256(path.read_bytes()).hexdigest() != expected:
|
||||
raise ValueError(f'Model source checksum mismatch: {path}')
|
||||
with zipfile.ZipFile(full) as task:
|
||||
references = {name: task.read(name) for name in ['hand_detector.tflite', 'hand_landmarks_detector.tflite']}
|
||||
def contract(data):
|
||||
graph = schema.Model.GetRootAsModel(data, 0).Subgraphs(0)
|
||||
return [[(graph.Tensors(int(i)).Name(), graph.Tensors(int(i)).ShapeAsNumpy().tolist(), graph.Tensors(int(i)).Type())
|
||||
for i in indices] for indices in (graph.InputsAsNumpy(), graph.OutputsAsNumpy())]
|
||||
models = {}
|
||||
for name, path in [('hand_detector.tflite', palm), ('hand_landmarks_detector.tflite', lite)]:
|
||||
data = path.read_bytes()
|
||||
reference = references[name]
|
||||
if contract(data) != contract(reference):
|
||||
raise ValueError(f'Lite tensor contract differs: {name}')
|
||||
populator = metadata.MetadataPopulator.with_model_buffer(data)
|
||||
populator.load_metadata_and_associated_files(reference)
|
||||
populator.populate()
|
||||
models[name] = canonicalize_associated_files(populator.get_model_buffer())
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
with zipfile.ZipFile(output, 'w', compression=zipfile.ZIP_STORED) as task:
|
||||
for name, data in models.items():
|
||||
write_entry(task, name, data)
|
||||
print(hashlib.sha256(output.read_bytes()).hexdigest())
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--full', type=Path, default=Path('app/src/main/assets/models/hand_landmarker.task'))
|
||||
parser.add_argument('--lite', type=Path, required=True, help='Pinned hand_landmark_lite.tflite from storage.googleapis.com/mediapipe-assets/')
|
||||
parser.add_argument('--palm', type=Path, required=True, help='Pinned palm_detection_lite.tflite from storage.googleapis.com/mediapipe-assets/')
|
||||
parser.add_argument('--output', type=Path, default=Path('app/src/main/assets/models/hand_landmarker_lite.task'))
|
||||
args = parser.parse_args()
|
||||
build(args.full, args.lite, args.palm, args.output)
|
||||
@@ -0,0 +1,179 @@
|
||||
"""Build checksum-pinned Android RGB UVC libraries and their fault-injection test."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tarfile
|
||||
import urllib.request
|
||||
import zipfile
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
RECIPES = ROOT / 'tools/uvc'
|
||||
PACKAGES = (
|
||||
{'name': 'libusb', 'version': '1.0.30', 'license': 'LGPL-2.1-or-later',
|
||||
'url': 'https://github.com/libusb/libusb/releases/download/v1.0.30/libusb-1.0.30.tar.bz2',
|
||||
'archive': 'libusb-1.0.30.tar.bz2',
|
||||
'sha256': 'fea36f34f9156400209595e300840767ab1a385ede1dc7ee893015aea9c6dbaf'},
|
||||
{'name': 'libuvc', 'version': '0.0.8', 'license': 'BSD-3-Clause',
|
||||
'url': 'https://github.com/libuvc/libuvc/archive/refs/tags/v0.0.8.zip',
|
||||
'archive': 'libuvc-0.0.8.zip',
|
||||
'sha256': '67922938ad81eb82b8ce14576f15a68ac75e30af738728a1f3070b6bbc938bce'},
|
||||
)
|
||||
|
||||
|
||||
def sha256(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def download(package, cache):
|
||||
archive = cache / package['archive']
|
||||
if not archive.exists():
|
||||
request = urllib.request.Request(package['url'], headers={'User-Agent': 'DroidDeckXR-UVC-Build'})
|
||||
with urllib.request.urlopen(request, timeout=60) as response:
|
||||
payload = response.read()
|
||||
if hashlib.sha256(payload).hexdigest() != package['sha256']:
|
||||
raise ValueError(f"Downloaded checksum mismatch: {package['archive']}")
|
||||
archive.write_bytes(payload)
|
||||
if sha256(archive) != package['sha256']:
|
||||
raise ValueError(f'Cached checksum mismatch: {archive}')
|
||||
return archive
|
||||
|
||||
|
||||
def extract(archive, destination):
|
||||
if archive.suffix == '.zip':
|
||||
with zipfile.ZipFile(archive) as bundle:
|
||||
for item in bundle.infolist():
|
||||
(destination / item.filename).resolve().relative_to(destination.resolve())
|
||||
if (item.external_attr >> 16) & 0o170000 == 0o120000:
|
||||
raise ValueError('Symlink in ZIP archive')
|
||||
bundle.extractall(destination)
|
||||
else:
|
||||
with tarfile.open(archive) as bundle:
|
||||
bundle.extractall(destination, filter='data')
|
||||
|
||||
|
||||
def patch_source(source, patch):
|
||||
old, new = [], []
|
||||
content = source.read_text(encoding='utf-8')
|
||||
hunks = []
|
||||
for line in patch.read_text(encoding='utf-8').splitlines(keepends=True):
|
||||
if line.startswith(('--- ', '+++ ')):
|
||||
continue
|
||||
if line.startswith('@@ '):
|
||||
if old or new:
|
||||
hunks.append((''.join(old), ''.join(new)))
|
||||
old, new = [], []
|
||||
elif line.startswith(' '):
|
||||
old.append(line[1:])
|
||||
new.append(line[1:])
|
||||
elif line.startswith('-'):
|
||||
old.append(line[1:])
|
||||
elif line.startswith('+'):
|
||||
new.append(line[1:])
|
||||
else:
|
||||
raise ValueError(f'Unsupported patch line: {line!r}')
|
||||
hunks.append((''.join(old), ''.join(new)))
|
||||
for before, after in hunks:
|
||||
if not before or content.count(before) != 1:
|
||||
raise ValueError(f'Patch context mismatch: {source}')
|
||||
content = content.replace(before, after, 1)
|
||||
source.write_text(content, encoding='utf-8', newline='\n')
|
||||
|
||||
|
||||
def run(command, log):
|
||||
result = subprocess.run([str(part) for part in command], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, text=True, encoding='utf-8')
|
||||
log.write_text(result.stdout, encoding='utf-8')
|
||||
print(result.stdout, end='')
|
||||
result.check_returncode()
|
||||
|
||||
|
||||
def build(args):
|
||||
output, cache = args.output.resolve(), args.cache.resolve()
|
||||
source, binary, dist = output / 'src', output / 'android-arm64', output / 'dist'
|
||||
for folder in (output, cache, source):
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
for package in PACKAGES:
|
||||
extract(download(package, cache), source)
|
||||
patch = RECIPES / 'libuvc-submit-failure.patch'
|
||||
stream = source / 'libuvc-0.0.8/src/stream.c'
|
||||
patch_source(stream, patch)
|
||||
|
||||
ndk, cmake = args.ndk.resolve(), args.cmake.resolve()
|
||||
ninja = args.ninja.resolve() if args.ninja else cmake.parent / ('ninja.exe' if os.name == 'nt' else 'ninja')
|
||||
configure = [cmake, '-S', RECIPES, '-B', binary, '-G', 'Ninja',
|
||||
f'-DCMAKE_MAKE_PROGRAM={ninja.as_posix()}',
|
||||
f'-DCMAKE_TOOLCHAIN_FILE={(ndk / "build/cmake/android.toolchain.cmake").as_posix()}',
|
||||
f'-DRGB_UVC_SOURCE_ROOT={source.as_posix()}', '-DANDROID_ABI=arm64-v8a',
|
||||
'-DANDROID_PLATFORM=android-26', '-DANDROID_STL=c++_static',
|
||||
'-DCMAKE_BUILD_TYPE=RelWithDebInfo']
|
||||
compile_command = [cmake, '--build', binary, '--parallel', str(args.jobs)]
|
||||
run(configure, output / 'configure.log')
|
||||
run(compile_command, output / 'build.log')
|
||||
|
||||
copies = {
|
||||
binary / 'libusb.so': dist / 'arm64-v8a/libusb.so',
|
||||
binary / 'libuvc.a': dist / 'arm64-v8a/libuvc.a',
|
||||
binary / 'uvc_submit_failure_test': dist / 'arm64-v8a/uvc_submit_failure_test',
|
||||
source / 'libusb-1.0.30/libusb/libusb.h': dist / 'include/libusb.h',
|
||||
source / 'libuvc-0.0.8/include/libuvc/libuvc.h': dist / 'include/libuvc/libuvc.h',
|
||||
binary / 'generated/libuvc/libuvc_config.h': dist / 'include/libuvc/libuvc_config.h',
|
||||
source / 'libusb-1.0.30/COPYING': dist / 'licenses/libusb-COPYING',
|
||||
source / 'libuvc-0.0.8/LICENSE.txt': dist / 'licenses/libuvc-LICENSE.txt',
|
||||
}
|
||||
for original, target in copies.items():
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(original, target)
|
||||
prebuilt = list((ndk / 'toolchains/llvm/prebuilt').iterdir())
|
||||
if len(prebuilt) != 1:
|
||||
raise ValueError(f'Expected one NDK host toolchain: {prebuilt}')
|
||||
readelf = prebuilt[0] / 'bin' / ('llvm-readelf.exe' if os.name == 'nt' else 'llvm-readelf')
|
||||
reports = []
|
||||
for name in ('libusb.so', 'uvc_submit_failure_test'):
|
||||
result = subprocess.check_output([str(readelf), '-h', '-l', '-d', str(binary / name)],
|
||||
text=True, encoding='utf-8')
|
||||
if 'AArch64' not in result or 'TEXTREL' in result:
|
||||
raise ValueError(f'Unexpected ELF ABI or text relocations: {name}')
|
||||
loads = [line for line in result.splitlines() if line.lstrip().startswith('LOAD')]
|
||||
if not loads or any(not line.rstrip().endswith('0x4000') for line in loads):
|
||||
raise ValueError(f'ELF must use 16 KiB LOAD alignment: {name}')
|
||||
if name == 'uvc_submit_failure_test' and ('[libusb.so]' not in result or 'libglasses' in result):
|
||||
raise ValueError('Fault test must depend on standalone libusb')
|
||||
reports.append(result)
|
||||
(output / 'elf-validation.txt').write_text('\n'.join(reports), encoding='utf-8')
|
||||
manifest = {
|
||||
'packages': PACKAGES,
|
||||
'patch': {'path': str(patch.relative_to(ROOT)), 'sha256': sha256(patch),
|
||||
'sourceSha256': sha256(stream),
|
||||
'reason': 'Preserve USB submission errors; remove unsubmitted transfers under cb_mutex, then cancel/drain submitted transfers and join the callback thread.'},
|
||||
'build': {'ndk': str(ndk), 'ndkSourceProperties': (ndk / 'source.properties').read_text(encoding='utf-8'),
|
||||
'configure': [str(part) for part in configure], 'compile': [str(part) for part in compile_command],
|
||||
'api': 26, 'abi': 'arm64-v8a', 'pic': True, 'queueBuffers': 8,
|
||||
'isoPacketsPerTransferMaximum': 32, 'jpegConversion': False,
|
||||
'libusbShared': True, 'libuvcStatic': True,
|
||||
'recipeHashes': {str(path.relative_to(ROOT)): sha256(path) for path in
|
||||
(Path(__file__), RECIPES / 'CMakeLists.txt', RECIPES / 'submit_failure_test.cpp')}},
|
||||
'validation': {'nativeBuild': 'passed', 'linkNoUndefined': 'passed', 'machine': 'AArch64',
|
||||
'loadAlignmentBytes': 16384, 'textRelocations': False,
|
||||
'deviceRuntimeTest': 'not run by build script'},
|
||||
'artifacts': [{'path': str(path.relative_to(output)), 'sha256': sha256(path), 'size': path.stat().st_size}
|
||||
for path in copies.values()],
|
||||
}
|
||||
(output / 'provenance.json').write_text(json.dumps(manifest, indent=2) + '\n', encoding='utf-8')
|
||||
print(f'Libraries and headers: {dist}')
|
||||
print(f'Provenance: {output / "provenance.json"}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--ndk', type=Path, required=True)
|
||||
parser.add_argument('--cmake', type=Path, required=True)
|
||||
parser.add_argument('--ninja', type=Path)
|
||||
parser.add_argument('--output', type=Path, default=ROOT / 'build/rgb-uvc')
|
||||
parser.add_argument('--cache', type=Path, default=ROOT / 'build/uvc-source-cache')
|
||||
parser.add_argument('--jobs', type=int, default=4)
|
||||
build(parser.parse_args())
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "cardboard.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int failures;
|
||||
#define CHECK(c) do { if (!(c)) { printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #c); failures++; } } while (0)
|
||||
@@ -35,9 +36,78 @@ int main(void) {
|
||||
q.source = CARDBOARD_SOURCE_SBS;
|
||||
cardboard_push_constants(&q, pose, 3840, 1080, 2400, 1080, pc);
|
||||
CHECK(near(pc[17], 1920.0f / 1080.0f) && near(pc[18], 1.0f));
|
||||
q.mono = 1;
|
||||
cardboard_push_constants(&q, pose, 3840, 1080, 1920, 1080, pc);
|
||||
CHECK(near(pc[3], 0.0f) && near(pc[19], 1920.0f / 1080.0f) && near(pc[20], 1.0f));
|
||||
q.mono = 0;
|
||||
cardboard_push_constants(&q, pose, 3840, 1080, 1920, 1080, pc);
|
||||
CHECK(near(pc[3], 0.032f) && near(pc[19], 960.0f / 1080.0f) && near(pc[20], 0.0f));
|
||||
cardboard_push_constants(&q, pose, 0, 0, 0, 0, pc);
|
||||
CHECK(isfinite(pc[17]) && isfinite(pc[19]));
|
||||
|
||||
// Narrow optical profiles and the lower SteamVR slider values must reach
|
||||
// the projection unchanged, rather than all becoming a 30-degree view.
|
||||
const float glasses_fovs[] = {22.0f, 23.3f, 24.0f, 25.8f, 29.0f};
|
||||
for (unsigned i = 0; i < sizeof(glasses_fovs) / sizeof(glasses_fovs[0]); i++) {
|
||||
q.fov_deg = glasses_fovs[i];
|
||||
cardboard_clamp(&q);
|
||||
CHECK(near(q.fov_deg, glasses_fovs[i]));
|
||||
cardboard_push_constants(&q, pose, 3840, 1080, 3840, 1080, pc);
|
||||
CHECK(near(pc[14], tanf(glasses_fovs[i] * 0.5f * (float)M_PI / 180.0f)));
|
||||
}
|
||||
|
||||
const struct cardboard_params screen = {
|
||||
.enabled = 1, .source = CARDBOARD_SOURCE_SCREEN, .ipd_m = 0.064f,
|
||||
.screen_dist_m = 3.0f, .screen_width_m = 2.0f, .fov_deg = 25.8f,
|
||||
};
|
||||
const int source_sizes[][2] = {{1280, 720}, {1600, 900}, {1920, 1080}};
|
||||
const int panel_heights[] = {1080, 1200};
|
||||
for (unsigned panel = 0; panel < sizeof(panel_heights) / sizeof(panel_heights[0]); panel++) {
|
||||
float native[24];
|
||||
const int height = panel_heights[panel];
|
||||
cardboard_push_constants(&screen, pose, 1920, 1080, 3840, height, native);
|
||||
for (unsigned size = 0; size < sizeof(source_sizes) / sizeof(source_sizes[0]); size++) {
|
||||
cardboard_push_constants(&screen, pose, source_sizes[size][0], source_sizes[size][1], 3840, height, pc);
|
||||
for (unsigned field = 0; field < 24; field++) CHECK(near(pc[field], native[field]));
|
||||
CHECK(near(pc[17], 16.0f / 9.0f));
|
||||
CHECK(near(pc[18], CARDBOARD_SOURCE_SCREEN));
|
||||
CHECK(near(pc[19], 1920.0f / height));
|
||||
CHECK(near(pc[20], 0.0f));
|
||||
}
|
||||
}
|
||||
q.source = CARDBOARD_SOURCE_FLAT;
|
||||
cardboard_clamp(&q);
|
||||
CHECK(q.source == CARDBOARD_SOURCE_FLAT);
|
||||
for (unsigned panel = 0; panel < sizeof(panel_heights) / sizeof(panel_heights[0]); panel++) {
|
||||
for (unsigned size = 0; size < sizeof(source_sizes) / sizeof(source_sizes[0]); size++) {
|
||||
cardboard_push_constants(&q, pose, source_sizes[size][0], source_sizes[size][1], 3840, panel_heights[panel], pc);
|
||||
CHECK(near(pc[17], 16.0f / 9.0f));
|
||||
CHECK(near(pc[18], CARDBOARD_SOURCE_FLAT));
|
||||
CHECK(near(pc[19], 1920.0f / panel_heights[panel]));
|
||||
CHECK(near(pc[20], 0.0f));
|
||||
}
|
||||
}
|
||||
q.fov_deg = 0.0f;
|
||||
cardboard_clamp(&q);
|
||||
CHECK(q.fov_deg > 0.0f && q.fov_deg < glasses_fovs[0]);
|
||||
|
||||
const float translation[3] = {0.25f, -0.3f, 0.5f};
|
||||
q.source = CARDBOARD_SOURCE_SCREEN;
|
||||
cardboard_push_constants(&q, pose, 1920, 1080, 3840, 1200, pc);
|
||||
float original[24]; memcpy(original, pc, sizeof(pc));
|
||||
cardboard_push_translation(&q, translation, pc);
|
||||
for (int i = 0; i < 21; ++i) CHECK(near(pc[i], original[i]));
|
||||
for (int i = 0; i < 3; ++i) CHECK(near(pc[21+i], translation[i]));
|
||||
q.source = CARDBOARD_SOURCE_SBS;
|
||||
cardboard_push_translation(&q, translation, pc);
|
||||
CHECK(near(pc[21], 0) && near(pc[22], 0) && near(pc[23], 0));
|
||||
q.source = CARDBOARD_SOURCE_FLAT;
|
||||
cardboard_push_translation(&q, translation, pc);
|
||||
CHECK(near(pc[21], 0) && near(pc[22], 0) && near(pc[23], 0));
|
||||
q.source = CARDBOARD_SOURCE_SCREEN;
|
||||
const float zero[3] = {0};
|
||||
cardboard_push_translation(&q, zero, pc);
|
||||
for (int i = 0; i < 24; ++i) CHECK(near(pc[i], original[i]));
|
||||
if (failures) return 1;
|
||||
printf("PASS: cardboard params\n");
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile and render the tracked-menu GLES shaders with headless Mesa (opt-in)."""
|
||||
|
||||
import argparse
|
||||
import ctypes as c
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import struct
|
||||
import zlib
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault('EGL_PLATFORM', 'surfaceless')
|
||||
os.environ.setdefault('LIBGL_ALWAYS_SOFTWARE', '1')
|
||||
os.environ.setdefault('MESA_GLES_VERSION_OVERRIDE', '2.0')
|
||||
root = pathlib.Path(__file__).resolve().parents[1]
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--output-dir', type=pathlib.Path, default=root / 'build/glasses-menu-shader')
|
||||
args = parser.parse_args()
|
||||
out = args.output_dir.resolve()
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
source_path = root / 'app/src/main/java/com/droiddeck/launcher/glasses/GlassesMenuSurface.kt'
|
||||
source = source_path.read_text()
|
||||
shaders = {name: re.search(r'private const val '+name+r' = """(.*?)"""', source, re.S).group(1).encode()
|
||||
for name in ('VERTEX', 'FRAGMENT')}
|
||||
try:
|
||||
egl = c.CDLL('libEGL.so.1')
|
||||
gl = c.CDLL('libGLESv2.so.2')
|
||||
except OSError as error:
|
||||
raise SystemExit('This opt-in check needs Linux EGL/GLES and Mesa software rendering. '
|
||||
'On Debian/Ubuntu install libegl1 libegl-mesa0 libgles2 libgl1-mesa-dri. '
|
||||
f'Library load failed: {error}') from error
|
||||
|
||||
def bind(lib, name, result, *args):
|
||||
fn = getattr(lib, name)
|
||||
fn.restype, fn.argtypes = result, args
|
||||
return fn
|
||||
|
||||
P, I, U, F = c.c_void_p, c.c_int, c.c_uint, c.c_float
|
||||
eglGetDisplay = bind(egl, 'eglGetDisplay', P, P)
|
||||
eglInitialize = bind(egl, 'eglInitialize', U, P, c.POINTER(I), c.POINTER(I))
|
||||
eglChooseConfig = bind(egl, 'eglChooseConfig', U, P, c.POINTER(I), c.POINTER(P), I, c.POINTER(I))
|
||||
eglCreatePbufferSurface = bind(egl, 'eglCreatePbufferSurface', P, P, P, c.POINTER(I))
|
||||
eglCreateContext = bind(egl, 'eglCreateContext', P, P, P, P, c.POINTER(I))
|
||||
eglMakeCurrent = bind(egl, 'eglMakeCurrent', U, P, P, P, P)
|
||||
eglQueryString = bind(egl, 'eglQueryString', c.c_char_p, P, I)
|
||||
eglGetProcAddress = bind(egl, 'eglGetProcAddress', P, c.c_char_p)
|
||||
display = eglGetDisplay(None)
|
||||
major, minor = I(), I()
|
||||
assert eglInitialize(display, c.byref(major), c.byref(minor))
|
||||
attrs = (I * 15)(0x3033, 1, 0x3040, 4, 0x3024, 8, 0x3023, 8, 0x3022, 8, 0x3021, 8, 0x3025, 0, 0x3038)
|
||||
config, count = P(), I()
|
||||
assert eglChooseConfig(display, attrs, c.byref(config), 1, c.byref(count)) and count.value
|
||||
surface = eglCreatePbufferSurface(display, config, (I * 5)(0x3057, 512, 0x3056, 256, 0x3038))
|
||||
context = eglCreateContext(display, config, None, (I * 3)(0x3098, 2, 0x3038))
|
||||
assert surface and context and eglMakeCurrent(display, surface, surface, context)
|
||||
getString = bind(gl, 'glGetString', c.c_char_p, U)
|
||||
getError = bind(gl, 'glGetError', U)
|
||||
metadata = {'source_sha256': hashlib.sha256(source.encode()).hexdigest(),
|
||||
'shader_sha256': {key: hashlib.sha256(value).hexdigest() for key, value in shaders.items()},
|
||||
'egl': eglQueryString(display, 0x3054).decode(),
|
||||
'gles': getString(0x1F02).decode(), 'renderer': getString(0x1F01).decode(),
|
||||
'assumption': 'External texture contains top-row-first Canvas buffer pixels; consumer transform flips Y, as Android GLConsumer does. Device SurfaceTexture/Canvas integration still needs validation.'}
|
||||
assert b'GL_OES_EGL_image_external' in getString(0x1F03)
|
||||
createShader = bind(gl, 'glCreateShader', U, U)
|
||||
shaderSource = bind(gl, 'glShaderSource', None, U, I, c.POINTER(c.c_char_p), c.POINTER(I))
|
||||
compileShader = bind(gl, 'glCompileShader', None, U)
|
||||
getShaderiv = bind(gl, 'glGetShaderiv', None, U, U, c.POINTER(I))
|
||||
getShaderLog = bind(gl, 'glGetShaderInfoLog', None, U, I, c.POINTER(I), c.c_char_p)
|
||||
compiled = []
|
||||
for name, kind in [('VERTEX', 0x8B31), ('FRAGMENT', 0x8B30)]:
|
||||
shader = createShader(kind)
|
||||
text = c.c_char_p(shaders[name])
|
||||
shaderSource(shader, 1, c.byref(text), None)
|
||||
compileShader(shader)
|
||||
status, log = I(), c.create_string_buffer(8192)
|
||||
getShaderiv(shader, 0x8B81, c.byref(status))
|
||||
getShaderLog(shader, len(log), None, log)
|
||||
assert status.value, name + ': ' + log.value.decode()
|
||||
compiled.append(shader)
|
||||
createProgram = bind(gl, 'glCreateProgram', U)
|
||||
attachShader = bind(gl, 'glAttachShader', None, U, U)
|
||||
linkProgram = bind(gl, 'glLinkProgram', None, U)
|
||||
getProgramiv = bind(gl, 'glGetProgramiv', None, U, U, c.POINTER(I))
|
||||
getProgramLog = bind(gl, 'glGetProgramInfoLog', None, U, I, c.POINTER(I), c.c_char_p)
|
||||
program = createProgram()
|
||||
for shader in compiled:
|
||||
attachShader(program, shader)
|
||||
linkProgram(program)
|
||||
status, log = I(), c.create_string_buffer(8192)
|
||||
getProgramiv(program, 0x8B82, c.byref(status))
|
||||
getProgramLog(program, len(log), None, log)
|
||||
assert status.value, log.value.decode()
|
||||
useProgram = bind(gl, 'glUseProgram', None, U)
|
||||
useProgram(program)
|
||||
getUniform = bind(gl, 'glGetUniformLocation', I, U, c.c_char_p)
|
||||
uniform1i = bind(gl, 'glUniform1i', None, I, I)
|
||||
uniform3f = bind(gl, 'glUniform3f', None, I, F, F, F)
|
||||
uniform4f = bind(gl, 'glUniform4f', None, I, F, F, F, F)
|
||||
uniformMatrix4 = bind(gl, 'glUniformMatrix4fv', None, I, I, U, c.POINTER(F))
|
||||
loc = lambda name: getUniform(program, name.encode())
|
||||
uniform1i(loc('uTexture'), 0)
|
||||
flip = (F * 16)(1,0,0,0, 0,-1,0,0, 0,0,1,0, 0,1,0,1)
|
||||
uniformMatrix4(loc('uTextureMatrix'), 1, 0, flip)
|
||||
|
||||
genTextures = bind(gl, 'glGenTextures', None, I, c.POINTER(U))
|
||||
bindTexture = bind(gl, 'glBindTexture', None, U, U)
|
||||
texParameteri = bind(gl, 'glTexParameteri', None, U, U, I)
|
||||
texImage2D = bind(gl, 'glTexImage2D', None, U, I, I, I, I, I, U, U, P)
|
||||
names = (U * 2)()
|
||||
genTextures(2, names)
|
||||
bindTexture(0x0DE1, names[0])
|
||||
pixels = bytes(value for y in range(256) for x in range(256) for value in (x, y, 37, 255))
|
||||
pixel_data = (c.c_ubyte * len(pixels)).from_buffer_copy(pixels)
|
||||
texImage2D(0x0DE1, 0, 0x1908, 256, 256, 0, 0x1908, 0x1401, pixel_data)
|
||||
for param, value in [(0x2801,0x2601),(0x2800,0x2601),(0x2802,0x812F),(0x2803,0x812F)]:
|
||||
texParameteri(0x0DE1, param, value)
|
||||
createImage = c.CFUNCTYPE(P, P, P, U, P, c.POINTER(I))(eglGetProcAddress(b'eglCreateImageKHR'))
|
||||
imageTarget = c.CFUNCTYPE(None, U, P)(eglGetProcAddress(b'glEGLImageTargetTexture2DOES'))
|
||||
image = createImage(display, context, 0x30B1, P(names[0]), (I * 3)(0x30BC, 0, 0x3038))
|
||||
assert image
|
||||
bindTexture(0x8D65, names[1])
|
||||
imageTarget(0x8D65, image)
|
||||
for param, value in [(0x2801,0x2601),(0x2800,0x2601),(0x2802,0x812F),(0x2803,0x812F)]:
|
||||
texParameteri(0x8D65, param, value)
|
||||
assert getError() == 0
|
||||
getAttrib = bind(gl, 'glGetAttribLocation', I, U, c.c_char_p)
|
||||
enableAttrib = bind(gl, 'glEnableVertexAttribArray', None, U)
|
||||
attribPointer = bind(gl, 'glVertexAttribPointer', None, U, I, U, U, I, P)
|
||||
vertices = (F * 8)(-1,-1, 1,-1, -1,1, 1,1)
|
||||
position = getAttrib(program, b'aPosition')
|
||||
enableAttrib(position)
|
||||
attribPointer(position, 2, 0x1406, 0, 0, vertices)
|
||||
viewport = bind(gl, 'glViewport', None, I, I, I, I)
|
||||
draw = bind(gl, 'glDrawArrays', None, U, I, I)
|
||||
read = bind(gl, 'glReadPixels', None, I, I, I, I, U, U, P)
|
||||
finish = bind(gl, 'glFinish', None)
|
||||
cases = []
|
||||
|
||||
def render(name, mono=True, position=(0,0,0), yaw=0, width=512, height=256, coords=((64,32),(448,32),(64,224),(448,224)), backdrop=False):
|
||||
viewport(0, 0, width, height)
|
||||
cs, sn = math.cos(yaw), math.sin(yaw)
|
||||
for row, values in enumerate(((cs,0,sn),(0,1,0),(-sn,0,cs))):
|
||||
uniform3f(loc('uRotation'+str(row)), *values)
|
||||
uniform3f(loc('uHead'), *position)
|
||||
uniform3f(loc('uScreen'), 1, 1, 2)
|
||||
uniform4f(loc('uOptics'), .5, width/height/(1 if mono else 2), 0 if mono else .032, 1 if mono else 0)
|
||||
draw(0x0005, 0, 4)
|
||||
finish()
|
||||
assert getError() == 0
|
||||
actual = (c.c_ubyte * (width*height*4))()
|
||||
read(0,0,width,height,0x1908,0x1401,actual)
|
||||
samples = []
|
||||
for x, y in coords:
|
||||
# Readback is GL bottom-up; coordinates below are image top-left.
|
||||
offset = ((height-1-y)*width+x)*4
|
||||
rgb = list(actual[offset:offset+3])
|
||||
eye = 0 if mono or x < width/2 else 1
|
||||
ux = (x+.5)/width if mono else (x+.5)/(width/2)-eye
|
||||
vy = (y+.5)/height
|
||||
rayx = (ux-.5)*(width/height/(1 if mono else 2))
|
||||
rayy = .5-vy
|
||||
dx, dy, dz = cs*rayx-sn, rayy, -sn*rayx-cs
|
||||
eo = 0 if mono else (-.032 if eye == 0 else .032)
|
||||
ox, oy, oz = position[0]+cs*eo, position[1], position[2]-sn*eo
|
||||
t = (-1-oz)/dz if dz else -1
|
||||
uv = ((ox+dx*t)*.5+.5, -(oy+dy*t)+.5)
|
||||
valid = dz < -.0001 and t > 0 and all(0 <= v <= 1 for v in uv) and not backdrop
|
||||
expected = [round(max(0,min(255,v*256-.5))) for v in uv]+[37] if valid else [4,4,5]
|
||||
assert all(abs(a-b) <= 2 for a,b in zip(rgb,expected)), (name,x,y,rgb,expected,uv)
|
||||
samples.append({'at':[x,y],'rgb':rgb,'expected':expected})
|
||||
cases.append({'name':name,'samples':samples})
|
||||
if name == 'mono_upright':
|
||||
rows = bytearray()
|
||||
for y in range(height-1,-1,-1):
|
||||
for x in range(width):
|
||||
start=(y*width+x)*4
|
||||
rows.extend(actual[start:start+3])
|
||||
(out/'menu-shader-mono.ppm').write_bytes(f'P6\n{width} {height}\n255\n'.encode()+rows)
|
||||
def chunk(name, data):
|
||||
return struct.pack('>I',len(data))+name+data+struct.pack('>I',zlib.crc32(name+data)&0xffffffff)
|
||||
scanlines=b''.join(b'\x00'+rows[y*width*3:(y+1)*width*3] for y in range(height))
|
||||
(out/'menu-shader-mono.png').write_bytes(b'\x89PNG\r\n\x1a\n'+
|
||||
chunk(b'IHDR',struct.pack('>IIBBBBB',width,height,8,2,0,0,0))+
|
||||
chunk(b'IDAT',zlib.compress(scanlines))+chunk(b'IEND',b''))
|
||||
|
||||
render('mono_upright')
|
||||
render('sbs_both_eyes', mono=False, width=512, height=128,
|
||||
coords=((32,16),(224,16),(32,112),(224,112),(288,16),(480,16),(288,112),(480,112),(128,64),(384,64)))
|
||||
render('six_dof_translation', position=(.2,.1,.1), coords=((256,128),(200,96),(300,160)))
|
||||
render('row_major_yaw', yaw=math.radians(10), coords=((256,128),(200,96),(300,160)))
|
||||
render('behind_plane', position=(0,0,-2), coords=((256,128),), backdrop=True)
|
||||
render('back_facing', yaw=math.pi, coords=((256,128),), backdrop=True)
|
||||
metadata['cases'] = cases
|
||||
metadata['result'] = 'PASS'
|
||||
(out/'menu-shader-validation.json').write_text(json.dumps(metadata, indent=2)+'\n')
|
||||
print(json.dumps(metadata, indent=2), flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+199
-21
@@ -5,13 +5,18 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import gzip
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import uuid
|
||||
import zlib
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
@@ -21,6 +26,7 @@ from adb_device import DeviceResolutionError, resolve_serial
|
||||
# tools/release/variants.txt: the same app also ships as other packages (e.g. com.antutu.benchmark.full).
|
||||
PACKAGE = os.environ.get("DROIDDECK_PACKAGE", "com.droiddeck.launcher")
|
||||
AUTHORITY = f"content://{PACKAGE}.agent"
|
||||
PACKAGE_NAME = re.compile(r"[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)+")
|
||||
STEAM_CLIENT_APP = 769
|
||||
REQUEST_CAP = 256 * 1024
|
||||
|
||||
@@ -295,27 +301,35 @@ def pacing_summary(text: str, package: str = PACKAGE) -> dict:
|
||||
frames shown, and 60 handed over can be 48 on screen with one in four held for two refreshes.
|
||||
"""
|
||||
records = {"game": [], "surface": []}
|
||||
for part in re.split(r"^layerName = ", text, flags=re.M)[1:]:
|
||||
name, _, body = part.partition("\n")
|
||||
for part in re.split(r"^displayRefreshRate = ", text, flags=re.M)[1:]:
|
||||
rate = re.match(r"(\d+)", part)
|
||||
layer = re.search(r"^layerName = (.*)$", part, re.M)
|
||||
frames = re.search(r"^totalFrames = (\d+)", part, re.M)
|
||||
hist = re.search(r"^present2present histogram is as below:\n(.*)", part, re.M)
|
||||
if not (rate and layer and frames and hist):
|
||||
continue
|
||||
name = layer.group(1)
|
||||
kind = ("game" if "droiddeck_wayland_game" in name
|
||||
else "surface" if f"SurfaceView[{package}/" in name else None)
|
||||
frames = re.search(r"^totalFrames = (\d+)", body, re.M)
|
||||
hist = re.search(r"^present2present histogram is as below:\n(.*)", body, re.M)
|
||||
if kind and frames and hist:
|
||||
records[kind].append((re.sub(r"#\d+$", "", name.strip()), int(frames.group(1)), hist.group(1)))
|
||||
if kind and int(frames.group(1)):
|
||||
bins = {int(ms): int(n) for ms, n in re.findall(r"(\d+)ms=(\d+)", hist.group(1)) if int(n)}
|
||||
records[kind].append((re.sub(r"#\d+$", "", name.strip()), int(frames.group(1)), bins, int(rate.group(1))))
|
||||
chosen = records["game"] or records["surface"]
|
||||
histogram: dict[int, int] = {}
|
||||
for _, _, hist in chosen:
|
||||
for ms, count in re.findall(r"(\d+)ms=(\d+)", hist):
|
||||
if int(count):
|
||||
histogram[int(ms)] = histogram.get(int(ms), 0) + int(count)
|
||||
off = 0
|
||||
for _, _, bins, _ in chosen:
|
||||
for ms, count in bins.items():
|
||||
histogram[ms] = histogram.get(ms, 0) + count
|
||||
if bins:
|
||||
# SurfaceFlinger bins by whole milliseconds, so one cadence spans two buckets (16.7 ms: 16 and 17).
|
||||
mode = max(bins, key=bins.get)
|
||||
off += sum(count for ms, count in bins.items() if abs(ms - mode) > 1)
|
||||
intervals = sum(histogram.values())
|
||||
cadence = max(histogram, key=histogram.get) if histogram else None
|
||||
off = intervals - histogram.get(cadence, 0) if histogram else 0
|
||||
return {
|
||||
"layers": sorted({name for name, _, _ in chosen}),
|
||||
"frames": sum(frames for _, frames, _ in chosen),
|
||||
"refreshRates": sorted({int(r) for r in re.findall(r"^displayRefreshRate = (\d+)", text, re.M)}),
|
||||
"layers": sorted({name for name, _, _, _ in chosen}),
|
||||
"frames": sum(frames for _, frames, _, _ in chosen),
|
||||
"refreshRates": sorted({rate for _, _, _, rate in chosen}),
|
||||
"presentToPresentMs": {str(ms): histogram[ms] for ms in sorted(histogram)},
|
||||
"cadenceMs": cadence,
|
||||
"offCadence": off,
|
||||
@@ -327,17 +341,30 @@ def pacing(adb: str, serial: str, seconds: float) -> dict:
|
||||
"""Frames on screen and their intervals over `seconds`, from SurfaceFlinger's timestats."""
|
||||
seconds = max(1.0, min(600.0, seconds))
|
||||
timestats = ("shell", "dumpsys", "SurfaceFlinger", "--timestats")
|
||||
if run_adb(adb, serial, *timestats, "-clear", "-enable").returncode != 0:
|
||||
try:
|
||||
enabled = run_adb(adb, serial, *timestats, "-clear", "-enable")
|
||||
except ControlError as exc:
|
||||
raise ControlError(str(exc), "PACING_FAILED") from exc
|
||||
if enabled.returncode != 0:
|
||||
raise ControlError("could not enable SurfaceFlinger timestats", "PACING_FAILED")
|
||||
started = time.monotonic()
|
||||
time.sleep(seconds)
|
||||
dump = run_adb(adb, serial, *timestats, "-dump", timeout=60)
|
||||
elapsed = time.monotonic() - started
|
||||
run_adb(adb, serial, *timestats, "-disable")
|
||||
try:
|
||||
time.sleep(seconds)
|
||||
dump = run_adb(adb, serial, *timestats, "-dump", timeout=60)
|
||||
except ControlError as exc:
|
||||
raise ControlError(str(exc), "PACING_FAILED") from exc
|
||||
finally:
|
||||
elapsed = time.monotonic() - started
|
||||
try:
|
||||
disabled = run_adb(adb, serial, *timestats, "-disable").returncode == 0
|
||||
except ControlError:
|
||||
disabled = False
|
||||
if dump.returncode != 0:
|
||||
raise ControlError(dump.stderr.decode(errors="replace").strip() or "timestats dump failed", "PACING_FAILED")
|
||||
if not disabled:
|
||||
raise ControlError("could not turn SurfaceFlinger timestats off", "PACING_FAILED")
|
||||
summary = pacing_summary(dump.stdout.decode(errors="replace"))
|
||||
if not summary["layers"]:
|
||||
if not summary["layers"] or not summary["frames"]:
|
||||
raise ControlError("No DroidDeck layer drew during the capture: is a session on screen?", "NO_FRAMES")
|
||||
summary["fpsOnScreen"] = round(summary["frames"] / elapsed, 1)
|
||||
return {"ok": True, "command": "pacing", "seconds": round(elapsed, 1), **summary}
|
||||
@@ -382,8 +409,101 @@ def input_request(args: argparse.Namespace) -> dict:
|
||||
raise ControlError(f"Unknown input type {kind}", "INVALID_INPUT")
|
||||
|
||||
|
||||
def xr_ppm_to_png(data: bytes, linear: bool = False) -> bytes:
|
||||
header = re.match(rb"P6\n([0-9]+) ([0-9]+)\n255\n", data)
|
||||
if not header:
|
||||
raise ControlError("Invalid XR image header", "XR_CAPTURE_FAILED")
|
||||
width, height = map(int, header.groups())
|
||||
pixels = data[header.end():]
|
||||
if not (0 < width <= 16384 and 0 < height <= 16384) or len(pixels) != width * height * 3:
|
||||
raise ControlError("Invalid XR image dimensions or incomplete pixels", "XR_CAPTURE_FAILED")
|
||||
def chunk(kind: bytes, value: bytes) -> bytes:
|
||||
return struct.pack('>I', len(value)) + kind + value + struct.pack('>I', zlib.crc32(kind + value))
|
||||
stride = width * 3
|
||||
rows = b''.join(b'\0' + pixels[start:start + stride] for start in range(0, len(pixels), stride))
|
||||
transfer = chunk(b'gAMA', struct.pack('>I', 100000)) if linear else chunk(b'sRGB', b'\0')
|
||||
return (b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', width, height, 8, 2, 0, 0, 0)) + transfer +
|
||||
chunk(b'IDAT', zlib.compress(rows)) + chunk(b'IEND', b''))
|
||||
|
||||
|
||||
def xr_capture(adb: str, serial: str, destination: Path, timeout: float) -> dict:
|
||||
if not 0 < timeout <= 120:
|
||||
raise ControlError("XR capture timeout must be between 0 and 120 seconds", "INVALID_TIMEOUT")
|
||||
remote = f'/sdcard/Android/data/{PACKAGE}/files/xr-capture'
|
||||
token = uuid.uuid4().hex
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
request = Path(temporary) / 'request'
|
||||
request.write_text(token, encoding='ascii')
|
||||
pushed = run_adb(adb, serial, 'push', str(request), remote + '.request.tmp')
|
||||
if pushed.returncode:
|
||||
raise ControlError(pushed.stderr.decode(errors='replace'), 'XR_CAPTURE_FAILED')
|
||||
moved = run_adb(adb, serial, 'shell', 'mv', remote + '.request.tmp', remote + '.request')
|
||||
if moved.returncode:
|
||||
raise ControlError(moved.stderr.decode(errors='replace'), 'XR_CAPTURE_FAILED')
|
||||
deadline = time.monotonic() + timeout
|
||||
metadata = None
|
||||
while time.monotonic() < deadline:
|
||||
remaining = deadline - time.monotonic()
|
||||
if remaining <= 0:
|
||||
break
|
||||
try:
|
||||
result = run_adb(adb, serial, 'shell', 'cat', remote + '.json', timeout=remaining)
|
||||
except ControlError as error:
|
||||
if not isinstance(error.__cause__, subprocess.TimeoutExpired):
|
||||
raise
|
||||
break
|
||||
try:
|
||||
answer = json.loads(result.stdout)
|
||||
if answer.get('id') == token:
|
||||
metadata = answer
|
||||
break
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
time.sleep(0.2)
|
||||
if metadata is None:
|
||||
try:
|
||||
run_adb(adb, serial, 'shell', 'rm', '-f', remote + '.request', timeout=1)
|
||||
except ControlError:
|
||||
pass
|
||||
raise ControlError('No fresh XR capture. Enter SteamVR using a build with XR capture support.', 'TIMEOUT')
|
||||
if not metadata.get('ok'):
|
||||
detail = 'No valid XR projection layer is being submitted' if not metadata.get('validLayer') else 'GPU readback or image write failed'
|
||||
raise ControlError(detail, 'XR_CAPTURE_FAILED')
|
||||
images = {}
|
||||
for eye in (('left', 'right', 'source') if metadata.get('sourceImage') else ('left', 'right')):
|
||||
pulled = run_adb(adb, serial, 'exec-out', 'gzip', '-c', remote + '-' + eye + '.ppm', timeout=120)
|
||||
if pulled.returncode:
|
||||
raise ControlError(pulled.stderr.decode(errors='replace'), 'XR_CAPTURE_FAILED')
|
||||
try:
|
||||
pixels = gzip.decompress(pulled.stdout)
|
||||
except (OSError, EOFError, zlib.error) as error:
|
||||
raise ControlError('Incomplete compressed XR image', 'XR_CAPTURE_FAILED') from error
|
||||
images[eye] = xr_ppm_to_png(pixels, linear=eye == 'source' and metadata.get('sourceColorSpace') == 'linear')
|
||||
# Detect overlapping captures before publishing images with another request's metadata.
|
||||
check = run_adb(adb, serial, 'shell', 'cat', remote + '.json')
|
||||
try:
|
||||
unchanged = json.loads(check.stdout).get('id') == token
|
||||
except (ValueError, AttributeError):
|
||||
unchanged = False
|
||||
if not unchanged:
|
||||
raise ControlError('XR capture was replaced by another request; retry', 'XR_CAPTURE_FAILED')
|
||||
try:
|
||||
destination.mkdir(parents=True, exist_ok=True)
|
||||
for eye, image in images.items():
|
||||
(destination / (eye + '.png')).write_bytes(image)
|
||||
(destination / 'capture.json').write_text(json.dumps(metadata, indent=2), encoding='utf-8')
|
||||
except OSError as error:
|
||||
raise ControlError(str(error), 'FILE_IO') from error
|
||||
return {'ok': True, 'command': 'xr-frame', 'deviceSerial': serial, 'capture': metadata,
|
||||
'left': str((destination / 'left.png').resolve()), 'right': str((destination / 'right.png').resolve()),
|
||||
**({'source': str((destination / 'source.png').resolve())} if 'source' in images else {}),
|
||||
'scope': 'App eye textures before headset compositor reprojection; excludes Meta system overlays'}
|
||||
|
||||
|
||||
def execute(args: argparse.Namespace, adb: str, serial: str) -> dict:
|
||||
command = args.command
|
||||
if command == 'xr-frame':
|
||||
return xr_capture(adb, serial, Path(args.path), args.timeout)
|
||||
|
||||
if command == "state":
|
||||
return add_serial(get_state(adb, serial), serial)
|
||||
@@ -397,6 +517,8 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict:
|
||||
if not args.url.startswith("steam://"):
|
||||
raise ControlError("Steam URL must start with steam://", "INVALID_STEAM_URL")
|
||||
request["steamUrl"] = args.url
|
||||
if args.steamvr:
|
||||
request["steamVr"] = True
|
||||
if args.reuse:
|
||||
current = get_state(adb, serial)["session"]
|
||||
wanted = {"steam": "steam", "desktop": "lxqt"}[args.mode]
|
||||
@@ -540,6 +662,28 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict:
|
||||
if command == "access":
|
||||
return add_serial(checked(provider_call(adb, serial, "access"), "ACCESS_FAILED"), serial)
|
||||
|
||||
if command == "glasses":
|
||||
request = {"op": args.glasses_op or "status"}
|
||||
if args.glasses_op == "set":
|
||||
request.update(key=args.key, value=args.value)
|
||||
elif args.glasses_op == "simulate":
|
||||
request["seconds"] = args.seconds
|
||||
if args.yaw is not None:
|
||||
request["yaw"] = args.yaw
|
||||
if args.pitch is not None:
|
||||
request["pitch"] = args.pitch
|
||||
elif args.glasses_op == "mode":
|
||||
request["mode"] = args.mode
|
||||
elif args.glasses_op == "imu":
|
||||
request["ms"] = args.ms
|
||||
elif args.glasses_op == "spatial-diagnostics":
|
||||
request["enabled"] = not args.off
|
||||
elif args.glasses_op == "spatial-recenter":
|
||||
request["screen"] = args.screen
|
||||
elif args.glasses_op == "raw":
|
||||
request.update(msgId=args.msg_id, payload=args.payload or "")
|
||||
return add_serial(checked(provider_call(adb, serial, "glasses", request=request), "GLASSES_FAILED"), serial)
|
||||
|
||||
if command == "logs":
|
||||
state = get_state(adb, serial)
|
||||
session = state.get("session", {})
|
||||
@@ -590,6 +734,7 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
start = commands.add_parser("start", help="start Steam or the desktop")
|
||||
start.add_argument("mode", choices=["steam", "desktop"])
|
||||
start.add_argument("--ui", choices=["bigpicture", "desktop"], default="bigpicture")
|
||||
start.add_argument("--steamvr", action="store_true", help="start SteamVR with the session (VITURE glasses)")
|
||||
start.add_argument("--url", help="steam:// URL to pass to the client")
|
||||
start.add_argument("--wait", action="store_true", help="wait for READY after starting")
|
||||
start.add_argument("--reuse", action="store_true", help="keep a running session of this mode instead of failing")
|
||||
@@ -708,6 +853,33 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
|
||||
commands.add_parser("access", help="whether debugging tools are enabled on the device")
|
||||
|
||||
glasses = commands.add_parser("glasses", help="VITURE glasses: status, settings, head tracking test")
|
||||
glasses_ops = glasses.add_subparsers(dest="glasses_op")
|
||||
glasses_ops.add_parser("status")
|
||||
glasses_ops.add_parser("allow", help="ask for USB control of the glasses again")
|
||||
glasses_set = glasses_ops.add_parser("set", help="refreshHz, sbsHz, resolution2d, resolution3d, resolutionVr (auto or WIDTHxHEIGHT per eye), brightness, volume, sunblock, 3d, 3dof, gameOnGlasses, headTracking, auto3d, picture3d, screenWidthDm, screenDistanceDm, vrFovDeg")
|
||||
glasses_set.add_argument("key")
|
||||
glasses_set.add_argument("value")
|
||||
glasses_sim = glasses_ops.add_parser("simulate", help="feed a moving head pose (yaw, pitch and roll sweeps), or hold one")
|
||||
glasses_sim.add_argument("--seconds", type=int, default=20)
|
||||
glasses_sim.add_argument("--yaw", type=float, help="hold this yaw (degrees, left positive) instead of sweeping")
|
||||
glasses_sim.add_argument("--pitch", type=float, help="hold this pitch (degrees, down positive) instead of sweeping")
|
||||
glasses_ops.add_parser("stop-simulate")
|
||||
glasses_ops.add_parser("query", help="ask the glasses for their display mode, brightness, volume and IMU state")
|
||||
spatial_diagnostics = glasses_ops.add_parser("spatial-diagnostics", help="start stereo diagnostics without saving images")
|
||||
spatial_diagnostics.add_argument("--off", action="store_true")
|
||||
spatial_recenter = glasses_ops.add_parser("spatial-recenter", help="recenter the current spatial origin")
|
||||
spatial_recenter.add_argument("--screen", action="store_true")
|
||||
glasses_ops.add_parser("spatial-floor", help="set floor using configured eye height")
|
||||
glasses_ops.add_parser("spatial-restart", help="restart the provider for explicit tracking recovery")
|
||||
glasses_mode = glasses_ops.add_parser("mode", help="send a display mode byte, e.g. 0x31 (1080p60), 0x34 (1080p120), 0x32 (3D)")
|
||||
glasses_mode.add_argument("mode")
|
||||
glasses_imu = glasses_ops.add_parser("imu", help="stream the glasses' IMU for a moment and show what it reports")
|
||||
glasses_imu.add_argument("--ms", type=int, default=2000)
|
||||
glasses_raw = glasses_ops.add_parser("raw", help="send one MCU command (debugging tools)")
|
||||
glasses_raw.add_argument("msg_id", help="hex message id, e.g. 0x0007")
|
||||
glasses_raw.add_argument("payload", nargs="?", help="hex bytes")
|
||||
|
||||
logs = commands.add_parser("logs", help="pull the latest session artifact directory")
|
||||
logs.add_argument("which", choices=["latest"])
|
||||
logs.add_argument("destination", nargs="?")
|
||||
@@ -717,6 +889,10 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
shot.add_argument("path")
|
||||
shot.add_argument("--display", type=int, help="logical display id (see displays); default the default display")
|
||||
|
||||
xr = commands.add_parser('xr-frame', help='capture both submitted XR eyes and pose metadata')
|
||||
xr.add_argument('path', help='output directory for left.png, right.png and capture.json')
|
||||
xr.add_argument('--timeout', type=float, default=15)
|
||||
|
||||
rec = commands.add_parser("record", help="record the screen to an mp4")
|
||||
rec.add_argument("path")
|
||||
rec.add_argument("--seconds", type=float, default=10)
|
||||
@@ -738,7 +914,7 @@ EXIT_SESSION = {
|
||||
}
|
||||
EXIT_TIMEOUT = {"TIMEOUT", "ARTIFACT_TIMEOUT"}
|
||||
EXIT_FILE = {"NO_SESSION_LOGS", "LOG_PULL_FAILED", "SCREENSHOT_FAILED", "FILE_IO", "RECORD_FAILED", "PUSH_FAILED",
|
||||
"PACING_FAILED"}
|
||||
"PACING_FAILED", "XR_CAPTURE_FAILED"}
|
||||
EXIT_DENIED = {"AGENT_COMMANDS_DISABLED", "PROTECTED_PREFS", "PROTECTED_CONTROL"}
|
||||
|
||||
|
||||
@@ -763,6 +939,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
args = build_parser().parse_args(argv)
|
||||
serial = None
|
||||
try:
|
||||
if not PACKAGE_NAME.fullmatch(PACKAGE): # it reaches the device shell through `am start` and `content call`
|
||||
raise ControlError(f"DROIDDECK_PACKAGE is not an Android package name: {PACKAGE!r}", "INVALID_REQUEST")
|
||||
adb = adb_path(args.adb)
|
||||
serial = resolve_serial(adb, args.serial, log=True)
|
||||
result = execute(args, adb, serial)
|
||||
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/bash
|
||||
# Runs inside an Arch Linux ARM container (menci/archlinuxarm:base-devel) on an arm64 runner. Arch Linux ARM ships
|
||||
# no FEX package and FEX publishes no Linux binaries.
|
||||
set -euxo pipefail
|
||||
VERSION=${FEX_VERSION:-FEX-2610}
|
||||
WORK=/work
|
||||
cd "$WORK"
|
||||
grep -q '^DisableSandbox' /etc/pacman.conf || sed -i 's/^\[options\]/[options]\nDisableSandbox/' /etc/pacman.conf
|
||||
{ for m in https://ca.us.mirror.archlinuxarm.org https://fl.us.mirror.archlinuxarm.org https://de3.mirror.archlinuxarm.org https://nl.mirror.archlinuxarm.org; do echo "Server = $m/\$arch/\$repo"; done; cat /etc/pacman.d/mirrorlist; } > /etc/pacman.d/mirrorlist.new
|
||||
mv /etc/pacman.d/mirrorlist.new /etc/pacman.d/mirrorlist
|
||||
pacman -Syu --noconfirm --needed git zstd binutils cmake ninja clang lld llvm python squashfs-tools file patchelf xxhash
|
||||
|
||||
# The x86 sysroot is Arch x86_64 and multilib i686 packages unpacked by pacman, never run: no scriptlets or signature checks.
|
||||
THUNKS=${FEX_THUNKS:-0}
|
||||
X86ROOT=$WORK/x86root
|
||||
if [ "$THUNKS" = 1 ]; then
|
||||
pacman -S --noconfirm --needed pkgconf libx11 libxcb libxrandr libxrender libxext xorgproto \
|
||||
libglvnd mesa wayland libdrm alsa-lib libxshmfence vulkan-headers vulkan-icd-loader
|
||||
rm -rf "$X86ROOT" && mkdir -p "$X86ROOT/var/lib/pacman" "$WORK/x86-cache"
|
||||
cat > "$WORK/x86-pacman.conf" <<'CONF'
|
||||
[options]
|
||||
Architecture = x86_64
|
||||
SigLevel = Never
|
||||
DisableSandbox
|
||||
[core]
|
||||
Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch
|
||||
[extra]
|
||||
Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch
|
||||
[multilib]
|
||||
Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch
|
||||
CONF
|
||||
pacman --config "$WORK/x86-pacman.conf" --root "$X86ROOT" --dbpath "$X86ROOT/var/lib/pacman" \
|
||||
--cachedir "$WORK/x86-cache" --noscriptlet --noconfirm --overwrite '*' -Sy \
|
||||
glibc linux-api-headers gcc gcc-libs libx11 libxcb xorgproto libxrandr libxrender libxext libxau \
|
||||
libxdmcp libglvnd mesa wayland libdrm alsa-lib libxshmfence \
|
||||
lib32-glibc lib32-gcc-libs lib32-libx11 lib32-libxcb lib32-libxrandr lib32-libxrender \
|
||||
lib32-libxext lib32-libglvnd lib32-mesa lib32-wayland lib32-libdrm lib32-alsa-lib lib32-libxshmfence
|
||||
ls "$X86ROOT/usr/include" | head -5
|
||||
fi
|
||||
|
||||
rm -rf fex-src out && git clone -q --depth 1 --branch "$VERSION" --recurse-submodules --shallow-submodules https://github.com/FEX-Emu/FEX.git fex-src
|
||||
for p in tools/fex/patches/*.patch; do patch -d fex-src -p1 --no-backup-if-mismatch < "$p"; done
|
||||
# FEX's x86 toolchain files assume an x86 build machine; here the guest thunks need the x86 sysroot too.
|
||||
# Arch's clang adds stack protection; its canary load in a guest thunk's prologue clobbered r11 (the host function).
|
||||
if [ "$THUNKS" = 1 ]; then
|
||||
for t in fex-src/Data/CMake/toolchain_x86_64.cmake fex-src/Data/CMake/toolchain_x86_32.cmake; do
|
||||
printf '\nif (X86_DEV_ROOTFS AND NOT X86_DEV_ROOTFS STREQUAL "/")\n set(CMAKE_SYSROOT "${X86_DEV_ROOTFS}")\nendif()\n' >> "$t"
|
||||
printf '\nset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector")\nset(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector")\n' >> "$t"
|
||||
done
|
||||
fi
|
||||
# TUNE_CPU none: the default (native) would tune for the runner's Neoverse cores, not the device.
|
||||
cmake -S fex-src -B fex-build -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local \
|
||||
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DUSE_LINKER=lld \
|
||||
-DTUNE_CPU=none -DTUNE_ARCH=armv8-a \
|
||||
-DBUILD_TESTING=OFF -DBUILD_FEXCONFIG=OFF -DENABLE_ASSERTIONS=OFF \
|
||||
$( [ "$THUNKS" = 1 ] && echo "-DBUILD_THUNKS=ON -DX86_DEV_ROOTFS=$X86ROOT" || echo "-DBUILD_THUNKS=OFF" ) \
|
||||
-DENABLE_CCACHE=OFF -DENABLE_OFFLINE_TELEMETRY=OFF \
|
||||
${FEX_EXTRA_CXXFLAGS:+-DCMAKE_CXX_FLAGS="$FEX_EXTRA_CXXFLAGS"}
|
||||
ninja -C fex-build
|
||||
DESTDIR="$WORK/out" ninja -C fex-build install
|
||||
install -Dm755 /usr/bin/unsquashfs out/usr/local/bin/unsquashfs
|
||||
# The Linux runtime has no xxhash and no ld.so.cache: the library goes beside libFEXCore and the programs
|
||||
# that need it find it through RUNPATH.
|
||||
install -Dm644 "$(readlink -f /usr/lib/libxxhash.so.0)" out/usr/local/lib/libxxhash.so.0
|
||||
bundled=$(cd out/usr/local/lib && ls -- *.so* | sort -u)
|
||||
for f in out/usr/local/bin/*; do
|
||||
[ -L "$f" ] && continue
|
||||
file "$f" | grep -q ELF || continue
|
||||
readelf -d "$f" | awk '/NEEDED/ { gsub(/[\[\]]/, "", $5); print $5 }' | grep -qxF "$bundled" \
|
||||
&& patchelf --set-rpath '$ORIGIN/../lib' "$f"
|
||||
done
|
||||
# Every NEEDED soname must resolve in a stock guest: bundled here or provided by the runtime (runtime-libs.txt).
|
||||
for f in out/usr/local/bin/* out/usr/local/lib/*.so* out/usr/local/lib/fex-emu/HostThunks*/*.so; do
|
||||
[ -f "$f" ] && file "$f" | grep -q ELF || continue
|
||||
readelf -d "$f" | awk '/NEEDED/ { gsub(/[\[\]]/, "", $5); print $5 }'
|
||||
done | sort -u | tee fex-needed.txt
|
||||
missing=$(printf '%s\n' "$bundled" | cat - tools/fex/runtime-libs.txt | sort -u | comm -23 fex-needed.txt -)
|
||||
[ -z "$missing" ] || { echo "not in the Linux runtime or this package:" $missing >&2; exit 1; }
|
||||
for f in out/usr/local/bin/*; do
|
||||
[ -L "$f" ] || ! file "$f" | grep -q ELF && continue
|
||||
if readelf -d "$f" | awk '/NEEDED/ { gsub(/[\[\]]/, "", $5); print $5 }' | grep -qxF "$bundled"; then
|
||||
readelf -d "$f" | grep -q 'RUNPATH.*\$ORIGIN/\.\./lib' || { echo "$f needs a bundled library but has no RUNPATH" >&2; exit 1; }
|
||||
fi
|
||||
done
|
||||
(cd out && find . -type f -o -type l | sort) | tee fex-files.txt
|
||||
tar -C out -c . | zstd -19 -T0 -o fex.tzst
|
||||
sha256sum fex.tzst | tee fex.tzst.sha256
|
||||
@@ -0,0 +1,203 @@
|
||||
diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp
|
||||
index 7172460..2c80dca 100644
|
||||
--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp
|
||||
+++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/FileManagement.cpp
|
||||
@@ -29,6 +29,7 @@ $end_info$
|
||||
#include <algorithm>
|
||||
#include <errno.h>
|
||||
#include <cstring>
|
||||
+#include <linux/magic.h>
|
||||
#include <linux/openat2.h>
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
@@ -632,6 +633,163 @@ static bool ShouldSkipOpenInEmu(int flags) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+static bool IsOnProcFS(int DirFD, const char* Pathname) {
|
||||
+ int FD = ::openat(DirFD, Pathname, O_PATH | O_NOFOLLOW | O_CLOEXEC);
|
||||
+ if (FD == -1) {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ struct statfs Buffer {};
|
||||
+ const bool Result = fstatfs(FD, &Buffer) == 0 && Buffer.f_type == PROC_SUPER_MAGIC;
|
||||
+ close(FD);
|
||||
+ return Result;
|
||||
+}
|
||||
+
|
||||
+// openat2() with RESOLVE_IN_ROOT, walked one component at a time: PRoot has no openat2 and fails it with ENOSYS.
|
||||
+// DirFD is AT_FDCWD only for thunk overlays, which never resolve in the root.
|
||||
+static int OpenatWithoutOpenat2(int DirFD, const char* Pathname, int Flags, uint32_t Mode) {
|
||||
+ if (DirFD == AT_FDCWD) {
|
||||
+ return ::syscall(SYSCALL_DEF(openat), DirFD, Pathname, Flags, Mode);
|
||||
+ }
|
||||
+
|
||||
+ // The kernel's MAXSYMLINKS.
|
||||
+ constexpr uint32_t MaxSymlinks = 40;
|
||||
+ uint32_t Symlinks {};
|
||||
+ std::optional<dev_t> RootDev {};
|
||||
+
|
||||
+ // O_NOFOLLOW and O_CREAT | O_EXCL leave a final symlink alone, unless a trailing slash follows it.
|
||||
+ const bool NoFollow = (Flags & O_NOFOLLOW) || (Flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
|
||||
+
|
||||
+ char Resolved[PATH_MAX];
|
||||
+ size_t ResolvedLen {};
|
||||
+
|
||||
+ std::array<char[PATH_MAX], 2> Pending;
|
||||
+ uint32_t PendingIndex {};
|
||||
+ const char* Remaining = Pathname;
|
||||
+
|
||||
+ for (;;) {
|
||||
+ while (*Remaining == '/') {
|
||||
+ ++Remaining;
|
||||
+ }
|
||||
+
|
||||
+ if (*Remaining == 0) {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ const char* Component = Remaining;
|
||||
+ const char* ComponentEnd = Component;
|
||||
+ while (*ComponentEnd != 0 && *ComponentEnd != '/') {
|
||||
+ ++ComponentEnd;
|
||||
+ }
|
||||
+ const size_t ComponentLen = ComponentEnd - Component;
|
||||
+
|
||||
+ Remaining = ComponentEnd;
|
||||
+ while (*Remaining == '/') {
|
||||
+ ++Remaining;
|
||||
+ }
|
||||
+ const bool Last = *Remaining == 0;
|
||||
+ const bool TrailingSlash = Last && Remaining != ComponentEnd;
|
||||
+
|
||||
+ if (ComponentLen == 1 && Component[0] == '.') {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ if (ComponentLen == 2 && Component[0] == '.' && Component[1] == '.') {
|
||||
+ while (ResolvedLen > 0 && Resolved[ResolvedLen - 1] != '/') {
|
||||
+ --ResolvedLen;
|
||||
+ }
|
||||
+ if (ResolvedLen > 0) {
|
||||
+ --ResolvedLen;
|
||||
+ }
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ const size_t Separator = ResolvedLen > 0 ? 1 : 0;
|
||||
+ const size_t CandidateLen = ResolvedLen + Separator + ComponentLen;
|
||||
+ if (CandidateLen + 1 >= PATH_MAX) {
|
||||
+ errno = ENAMETOOLONG;
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (Separator) {
|
||||
+ Resolved[ResolvedLen] = '/';
|
||||
+ }
|
||||
+ memcpy(&Resolved[ResolvedLen + Separator], Component, ComponentLen);
|
||||
+ Resolved[CandidateLen] = 0;
|
||||
+
|
||||
+ struct stat Buffer {};
|
||||
+ const bool Follow = !Last || TrailingSlash || !NoFollow;
|
||||
+ const int StatResult = Follow ? fstatat(DirFD, Resolved, &Buffer, AT_SYMLINK_NOFOLLOW) : -1;
|
||||
+
|
||||
+ if (StatResult == 0 && S_ISLNK(Buffer.st_mode)) {
|
||||
+ if (++Symlinks > MaxSymlinks) {
|
||||
+ errno = ELOOP;
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (!RootDev) {
|
||||
+ struct stat Root {};
|
||||
+ if (fstat(DirFD, &Root) != 0) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+ RootDev = Root.st_dev;
|
||||
+ }
|
||||
+
|
||||
+ if (Buffer.st_dev != *RootDev && IsOnProcFS(DirFD, Resolved)) {
|
||||
+ // Only procfs has magic links. RESOLVE_IN_ROOT fails them with EXDEV and the callers then open without it.
|
||||
+ return ::syscall(SYSCALL_DEF(openat), DirFD, Pathname, Flags, Mode);
|
||||
+ }
|
||||
+
|
||||
+ char* Target = Pending[PendingIndex];
|
||||
+ const ssize_t TargetLen = readlinkat(DirFD, Resolved, Target, PATH_MAX);
|
||||
+ if (TargetLen <= 0) {
|
||||
+ if (TargetLen == 0) {
|
||||
+ errno = ENOENT;
|
||||
+ }
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ const size_t RestLen = strlen(ComponentEnd);
|
||||
+ if (static_cast<size_t>(TargetLen) + RestLen >= PATH_MAX) {
|
||||
+ errno = ENAMETOOLONG;
|
||||
+ return -1;
|
||||
+ }
|
||||
+ memcpy(&Target[TargetLen], ComponentEnd, RestLen + 1);
|
||||
+
|
||||
+ if (Target[0] == '/') {
|
||||
+ ResolvedLen = 0;
|
||||
+ }
|
||||
+ Remaining = Target;
|
||||
+ PendingIndex ^= 1;
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ if (Last) {
|
||||
+ // openat reports on the final component, which O_CREAT may create.
|
||||
+ ResolvedLen = CandidateLen;
|
||||
+ if (TrailingSlash) {
|
||||
+ Resolved[ResolvedLen++] = '/';
|
||||
+ }
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if (StatResult != 0) {
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (!S_ISDIR(Buffer.st_mode)) {
|
||||
+ errno = ENOTDIR;
|
||||
+ return -1;
|
||||
+ }
|
||||
+ ResolvedLen = CandidateLen;
|
||||
+ }
|
||||
+
|
||||
+ if (ResolvedLen == 0) {
|
||||
+ Resolved[ResolvedLen++] = '.';
|
||||
+ }
|
||||
+ Resolved[ResolvedLen] = 0;
|
||||
+ return ::syscall(SYSCALL_DEF(openat), DirFD, Resolved, Flags, Mode);
|
||||
+}
|
||||
+
|
||||
bool FileManager::ReplaceEmuFd(int fd, int flags, uint32_t mode) {
|
||||
char Tmp[PATH_MAX + 1];
|
||||
|
||||
@@ -678,6 +836,8 @@ uint64_t FileManager::Open(const char* pathname, int flags, uint32_t mode) {
|
||||
// This means a magic symlink (/proc/foo) was involved. In this case we
|
||||
// just punt and do the access without RESOLVE_IN_ROOT.
|
||||
fd = ::syscall(SYSCALL_DEF(openat), Path.FD, Path.Path, flags, mode);
|
||||
+ } else if (fd == -1 && errno == ENOSYS) {
|
||||
+ fd = OpenatWithoutOpenat2(Path.FD, Path.Path, flags, mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -931,6 +1091,8 @@ uint64_t FileManager::Openat([[maybe_unused]] int dirfs, const char* pathname, i
|
||||
// This means a magic symlink (/proc/foo) was involved. In this case we
|
||||
// just punt and do the access without RESOLVE_IN_ROOT.
|
||||
fd = ::syscall(SYSCALL_DEF(openat), Path.FD, Path.Path, flags, mode);
|
||||
+ } else if (fd == -1 && errno == ENOSYS) {
|
||||
+ fd = OpenatWithoutOpenat2(Path.FD, Path.Path, flags, mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -967,6 +1129,8 @@ uint64_t FileManager::Openat2(int dirfs, const char* pathname, FEX::HLE::open_ho
|
||||
// This means a magic symlink (/proc/foo) was involved. In this case we
|
||||
// just punt and do the access without RESOLVE_IN_ROOT.
|
||||
fd = ::syscall(SYSCALL_DEF(openat2), Path.FD, Path.Path, how, usize);
|
||||
+ } else if (fd == -1 && errno == ENOSYS && how->resolve == 0) {
|
||||
+ fd = OpenatWithoutOpenat2(Path.FD, Path.Path, how->flags, how->mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
--- a/ThunkLibs/Generator/gen.cpp
|
||||
+++ b/ThunkLibs/Generator/gen.cpp
|
||||
@@ -840,6 +840,5 @@
|
||||
|
||||
const bool Success = Compiler.ExecuteAction(Action);
|
||||
|
||||
- Files->clearStatCache();
|
||||
return Success;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp
|
||||
index 60b0ef1..4a94009 100644
|
||||
--- a/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp
|
||||
+++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/LinuxAllocator.cpp
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "LinuxSyscalls/LinuxAllocator.h"
|
||||
#include "LinuxSyscalls/Syscalls.h"
|
||||
|
||||
+#include <FEXCore/Utils/Allocator.h>
|
||||
#include <FEXCore/Utils/MathUtils.h>
|
||||
#include <FEXCore/Utils/TypeDefines.h>
|
||||
#include <FEXHeaderUtils/Syscalls.h>
|
||||
@@ -9,6 +10,7 @@
|
||||
#include <FEXCore/fextl/memory.h>
|
||||
|
||||
#include <bitset>
|
||||
+#include <fcntl.h>
|
||||
#include <linux/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/user.h>
|
||||
@@ -82,6 +84,7 @@ private:
|
||||
std::mutex AllocMutex {};
|
||||
uint64_t FindPageRange(uint64_t Start, size_t Pages) const;
|
||||
uint64_t FindPageRange_TopDown(uint64_t Start, size_t Pages) const;
|
||||
+ bool SetHostMappedPages(uint64_t PageAddr, size_t PagesLength);
|
||||
using FindHandler = uint64_t (MemAllocator32Bit::*)(uint64_t Start, size_t Pages) const;
|
||||
FindHandler FindPageRangePtr {};
|
||||
};
|
||||
@@ -132,6 +135,37 @@ uint64_t MemAllocator32Bit::FindPageRange_TopDown(uint64_t Start, size_t Pages)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+// Marks each run of host mappings that overlaps the range as used, in full. Returns false if none overlaps.
|
||||
+bool MemAllocator32Bit::SetHostMappedPages(uint64_t PageAddr, size_t PagesLength) {
|
||||
+ const int MapsFD = ::open("/proc/self/maps", O_RDONLY | O_CLOEXEC);
|
||||
+ if (MapsFD == -1) {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ const auto Gaps =
|
||||
+ FEXCore::Allocator::CollectMemoryGaps(BASE_KEY << FEXCore::Utils::FEX_PAGE_SHIFT, TOP_KEY << FEXCore::Utils::FEX_PAGE_SHIFT, MapsFD);
|
||||
+ close(MapsFD);
|
||||
+
|
||||
+ const uint64_t EndPage = PageAddr + PagesLength;
|
||||
+ uint64_t MappedBegin = BASE_KEY;
|
||||
+ bool Marked = false;
|
||||
+ auto MarkIfOverlapping = [&](uint64_t MappedEnd) {
|
||||
+ if (MappedBegin < MappedEnd && MappedBegin < EndPage && PageAddr < MappedEnd) {
|
||||
+ SetUsedPages(MappedBegin, MappedEnd - MappedBegin);
|
||||
+ Marked = true;
|
||||
+ }
|
||||
+ };
|
||||
+
|
||||
+ for (const auto& Gap : Gaps) {
|
||||
+ const uintptr_t GapBegin = reinterpret_cast<uintptr_t>(Gap.Ptr);
|
||||
+ MarkIfOverlapping(GapBegin >> FEXCore::Utils::FEX_PAGE_SHIFT);
|
||||
+ MappedBegin = (GapBegin + Gap.Size) >> FEXCore::Utils::FEX_PAGE_SHIFT;
|
||||
+ }
|
||||
+ MarkIfOverlapping(TOP_KEY);
|
||||
+
|
||||
+ return Marked;
|
||||
+}
|
||||
+
|
||||
void* MemAllocator32Bit::Mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) {
|
||||
std::scoped_lock<std::mutex> lk {AllocMutex};
|
||||
size_t PagesLength = FEXCore::AlignUp(length, FEXCore::Utils::FEX_PAGE_SIZE) >> FEXCore::Utils::FEX_PAGE_SHIFT;
|
||||
@@ -175,11 +209,17 @@ void* MemAllocator32Bit::Mmap(void* addr, size_t length, int prot, int flags, in
|
||||
|
||||
auto AllocateNoHint = [&]() -> void* {
|
||||
bool Wrapped = false;
|
||||
+ bool Restarted = false;
|
||||
uint64_t BottomPage = Map32Bit && (LastScanLocation >= LastKeyLocation32Bit) ? LastKeyLocation32Bit : LastScanLocation;
|
||||
restart: {
|
||||
// Linear range scan
|
||||
uint64_t LowerPage = (this->*FindPageRangePtr)(BottomPage, PagesLength);
|
||||
if (LowerPage == 0) {
|
||||
+ // A second scan from the start found nothing either: the range is full, as the kernel would say.
|
||||
+ if (Restarted) {
|
||||
+ return reinterpret_cast<void*>(-ENOMEM);
|
||||
+ }
|
||||
+ Restarted = true;
|
||||
// Try again but this time from the start
|
||||
BottomPage = Map32Bit ? LastKeyLocation32Bit : LastKeyLocation;
|
||||
LowerPage = (this->*FindPageRangePtr)(BottomPage, PagesLength);
|
||||
@@ -206,7 +246,17 @@ restart: {
|
||||
return (void*)(uintptr_t)-errno;
|
||||
} else {
|
||||
// Try again
|
||||
- if (SearchDown) {
|
||||
+ if (Map32Bit) {
|
||||
+ // MAP_32BIT from a 64-bit guest, whose other mappings bypass this allocator: once Counter-Strike 2 had reserved the
|
||||
+ // low 2GB, stepping one page at a time scanned for ever. Record what the host holds there and rescan the range, or
|
||||
+ // move past it if that mapping is gone.
|
||||
+ const bool Marked = SetHostMappedPages(LowerPage, PagesLength);
|
||||
+ if (SearchDown) {
|
||||
+ BottomPage = Marked ? UpperPage - 1 : LowerPage - 1;
|
||||
+ } else {
|
||||
+ BottomPage = Marked ? LowerPage : UpperPage;
|
||||
+ }
|
||||
+ } else if (SearchDown) {
|
||||
--BottomPage;
|
||||
} else {
|
||||
++BottomPage;
|
||||
@@ -0,0 +1,12 @@
|
||||
ld-linux-aarch64.so.1
|
||||
libGLX.so.0
|
||||
libOpenGL.so.0
|
||||
libc.so.6
|
||||
libgcc_s.so.1
|
||||
liblz4.so.1
|
||||
liblzma.so.5
|
||||
liblzo2.so.2
|
||||
libm.so.6
|
||||
libstdc++.so.6
|
||||
libz.so.1
|
||||
libzstd.so.1
|
||||
@@ -26,7 +26,7 @@ for arch in x86_64 i386; do
|
||||
fi
|
||||
done
|
||||
done
|
||||
for target in x86_64/faultreport i386/faultreport x86_64/thunkaudit; do
|
||||
for target in x86_64/faultreport i386/faultreport; do
|
||||
arch=${target%/*} name=${target#*/}
|
||||
case $arch in
|
||||
x86_64) bits=-m64 ;;
|
||||
@@ -41,13 +41,24 @@ for target in x86_64/faultreport i386/faultreport x86_64/thunkaudit; do
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
lib=$out/x86_64/libwebkitinput.so
|
||||
gcc -m64 -shared -fPIC -O2 -Wall -Wextra -nostdlib -fno-stack-protector -fno-builtin -fvisibility=hidden \
|
||||
-o "$lib" tools/linuxfs/fex/webkitinput.c
|
||||
strip --strip-unneeded "$lib"
|
||||
if objdump -p "$lib" | grep -q NEEDED || [ "$(nm -D --undefined-only "$lib" | awk '{print $1 $2}' | LC_ALL=C sort | tr '\n' ' ')" != "wdlsym wg_object_get_data wg_object_set wg_object_set_data wg_type_check_instance_is_a wgtk_container_forall wgtk_container_get_type wgtk_key_snooper_install wgtk_widget_get_toplevel wwebkit_user_script_new wwebkit_user_script_unref wwebkit_web_view_get_type wwebkit_web_view_get_uri wwebkit_web_view_run_javascript " ]; then
|
||||
echo "$lib must need nothing but weak GLib, GTK and WebKit calls" >&2
|
||||
exit 1
|
||||
fi
|
||||
stub=$(mktemp -d)
|
||||
gcc -m64 -shared -nostdlib -Wl,-soname,/usr/lib/x86_64-linux-gnu/libvulkan.so.1 -o "$stub/libvulkan.so.1" -x c /dev/null
|
||||
gcc -m64 -shared -nostdlib -Wl,-z,nodelete -Wl,--no-as-needed \
|
||||
-o "$out/x86_64/libvulkan-thunk.so" -x c /dev/null -x none "$stub/libvulkan.so.1"
|
||||
lib=$out/x86_64/libvulkan-thunk.so
|
||||
gcc -m64 -shared -fPIC -O2 -Wall -Wextra -fvisibility=hidden -Wl,-soname,libvulkan.so.1 -Wl,-z,nodelete -Wl,--no-as-needed \
|
||||
-o "$lib" tools/linuxfs/fex/vulkanpin.c "$stub/libvulkan.so.1" -ldl
|
||||
rm -rf "$stub"
|
||||
if ! objdump -p "$out/x86_64/libvulkan-thunk.so" | grep -q 'NEEDED *\/usr/lib/x86_64-linux-gnu/libvulkan\.so\.1$' \
|
||||
|| ! objdump -p "$out/x86_64/libvulkan-thunk.so" | grep -q 'FLAGS_1 *0x0*8$'; then
|
||||
echo "$out/x86_64/libvulkan-thunk.so must be nodelete and need only the Vulkan thunk" >&2
|
||||
strip --strip-unneeded "$lib"
|
||||
newest=$(objdump -T "$lib" | grep -o 'GLIBC_2\.[0-9]*' | sort -u -t. -k2,2n | tail -1)
|
||||
if ! objdump -p "$lib" | grep -q 'NEEDED *\/usr/lib/x86_64-linux-gnu/libvulkan\.so\.1$' \
|
||||
|| ! objdump -p "$lib" | grep -q 'FLAGS_1 *0x0*8$' || [ "${newest#GLIBC_2.}" -gt 31 ]; then
|
||||
echo "$lib must be nodelete, need the Vulkan thunk and run on glibc 2.31" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -27,6 +27,15 @@ export BL_DESKTOP=1
|
||||
ln -sf /usr/local/bin/droiddeck-steam-launch /usr/local/bin/steamdeck-steam 2>/dev/null
|
||||
ln -sf /usr/local/bin/droiddeck-steam-shim /usr/local/bin/steam 2>/dev/null
|
||||
python3 /usr/local/bin/droiddeck-desktop-games 2>&1 | sed 's/^/[games] /'
|
||||
cat > /usr/share/applications/droiddeck-steam-x64.desktop <<'ENTRY'
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Steam x86-64 (FEX, experimental)
|
||||
Comment=Valve's x86-64 Linux client under FEX, in its own home with its own login
|
||||
Exec=qterminal -e /usr/local/bin/droiddeck-steam-x64
|
||||
Icon=steam
|
||||
Categories=System;
|
||||
ENTRY
|
||||
python3 /usr/local/bin/droiddeck-pad-defaults 2>&1 | sed 's/^/[pads] /'
|
||||
( while sleep 30; do python3 /usr/local/bin/droiddeck-pad-defaults 2>&1 | sed 's/^/[pads] /'; done ) &
|
||||
python3 /usr/local/bin/droiddeck-desktop-gpu 2>&1 | sed 's/^/[gpu] /'
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#if !defined(__x86_64__)
|
||||
#error thunkaudit is built for x86_64 guests only
|
||||
#endif
|
||||
|
||||
#define LA_SER_ORIG 0x01
|
||||
|
||||
static const char vulkan_thunk[] = "/usr/lib/x86_64-linux-gnu/libvulkan.so.1";
|
||||
static const char vulkan_pin[] = "/usr/lib/x86_64-linux-gnu/droiddeck/libvulkan-thunk.so";
|
||||
|
||||
static int same(const char *a, const char *b)
|
||||
{
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
return *a == *b;
|
||||
}
|
||||
|
||||
static const char *base_name(const char *path)
|
||||
{
|
||||
const char *name = path;
|
||||
for (; *path; path++)
|
||||
if (*path == '/')
|
||||
name = path + 1;
|
||||
return name;
|
||||
}
|
||||
|
||||
__attribute__((visibility("default"))) unsigned int la_version(unsigned int version)
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
__attribute__((visibility("default"))) char *la_objsearch(const char *name, unsigned long *cookie, unsigned int flag)
|
||||
{
|
||||
const char *file = base_name(name);
|
||||
(void)cookie;
|
||||
if (flag == LA_SER_ORIG && !same(name, vulkan_thunk) && (same(file, "libvulkan.so.1") || same(file, "libvulkan.so")))
|
||||
return (char *)vulkan_pin;
|
||||
return (char *)name;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#include <dlfcn.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef VULKAN_THUNK
|
||||
#define VULKAN_THUNK "/usr/lib/x86_64-linux-gnu/libvulkan.so.1"
|
||||
#endif
|
||||
|
||||
#define VK_INCOMPLETE 5
|
||||
#define VK_ERROR_INITIALIZATION_FAILED (-3)
|
||||
#define EXTENSIONS 128
|
||||
|
||||
typedef int VkResult;
|
||||
typedef void (*Function)(void);
|
||||
typedef struct {
|
||||
char extensionName[256];
|
||||
unsigned int specVersion;
|
||||
} VkExtensionProperties;
|
||||
typedef VkResult (*Enumerate)(const char *, unsigned int *, VkExtensionProperties *);
|
||||
typedef Function (*ProcAddr)(void *, const char *);
|
||||
|
||||
/* The driver cannot enumerate devices for an instance with VK_KHR_display, and gamescope's WSI layer aborts on that. */
|
||||
static const char *const hidden_extensions[] = {
|
||||
"VK_KHR_display",
|
||||
"VK_KHR_get_display_properties2",
|
||||
"VK_EXT_direct_mode_display",
|
||||
"VK_EXT_acquire_xlib_display",
|
||||
"VK_EXT_acquire_drm_display",
|
||||
"VK_EXT_display_surface_counter",
|
||||
};
|
||||
|
||||
static void *thunk(const char *name)
|
||||
{
|
||||
void *library = dlopen(VULKAN_THUNK, RTLD_NOW | RTLD_NOLOAD);
|
||||
void *found = library ? dlsym(library, name) : NULL;
|
||||
if (library)
|
||||
dlclose(library);
|
||||
return found;
|
||||
}
|
||||
|
||||
static int hidden(const char *name)
|
||||
{
|
||||
for (size_t i = 0; i < sizeof(hidden_extensions) / sizeof(hidden_extensions[0]); i++)
|
||||
if (!strcmp(name, hidden_extensions[i]))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("default"))) VkResult vkEnumerateInstanceExtensionProperties(const char *layer, unsigned int *count,
|
||||
VkExtensionProperties *properties)
|
||||
{
|
||||
static Enumerate real;
|
||||
VkExtensionProperties all[EXTENSIONS];
|
||||
unsigned int total = EXTENSIONS, kept = 0, room = properties ? *count : 0;
|
||||
VkResult result;
|
||||
if (!real)
|
||||
real = (Enumerate)thunk("vkEnumerateInstanceExtensionProperties");
|
||||
if (!real)
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
result = real(layer, &total, all);
|
||||
if (result < 0)
|
||||
return result;
|
||||
for (unsigned int i = 0; i < total; i++) {
|
||||
if (hidden(all[i].extensionName))
|
||||
continue;
|
||||
if (properties && kept < room)
|
||||
memcpy(&properties[kept], &all[i], sizeof(all[i]));
|
||||
kept++;
|
||||
}
|
||||
if (!properties) {
|
||||
*count = kept;
|
||||
return result;
|
||||
}
|
||||
*count = kept < room ? kept : room;
|
||||
return kept > room ? VK_INCOMPLETE : result;
|
||||
}
|
||||
|
||||
__attribute__((visibility("default"))) Function vkGetInstanceProcAddr(void *instance, const char *name)
|
||||
{
|
||||
static ProcAddr real;
|
||||
if (!strcmp(name, "vkGetInstanceProcAddr"))
|
||||
return (Function)vkGetInstanceProcAddr;
|
||||
if (!strcmp(name, "vkEnumerateInstanceExtensionProperties"))
|
||||
return (Function)vkEnumerateInstanceExtensionProperties;
|
||||
if (!real)
|
||||
real = (ProcAddr)thunk("vkGetInstanceProcAddr");
|
||||
return real ? real(instance, name) : NULL;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
#if !defined(__x86_64__)
|
||||
#error webkitinput is built for x86_64 guests only
|
||||
#endif
|
||||
|
||||
typedef struct _WebKitSettings WebKitSettings;
|
||||
typedef struct _WebKitUserContentManager WebKitUserContentManager;
|
||||
typedef struct _WebKitUserScript WebKitUserScript;
|
||||
|
||||
extern void g_object_set(void *object, const char *first_property, ...) __attribute__((weak));
|
||||
extern void *g_object_get_data(void *object, const char *key) __attribute__((weak));
|
||||
extern void g_object_set_data(void *object, const char *key, void *data) __attribute__((weak));
|
||||
extern void *dlsym(void *handle, const char *symbol) __attribute__((weak));
|
||||
extern unsigned gtk_key_snooper_install(int (*snooper)(void *, void *, void *), void *data) __attribute__((weak));
|
||||
extern void *gtk_widget_get_toplevel(void *widget) __attribute__((weak));
|
||||
extern void gtk_container_forall(void *container, void (*callback)(void *, void *), void *data) __attribute__((weak));
|
||||
extern unsigned long gtk_container_get_type(void) __attribute__((weak));
|
||||
extern unsigned long webkit_web_view_get_type(void) __attribute__((weak));
|
||||
extern int g_type_check_instance_is_a(void *instance, unsigned long type) __attribute__((weak));
|
||||
extern const char *webkit_web_view_get_uri(void *view) __attribute__((weak));
|
||||
extern void webkit_web_view_run_javascript(void *view, const char *script, void *cancellable, void *callback,
|
||||
void *data) __attribute__((weak));
|
||||
extern WebKitUserScript *webkit_user_script_new(const char *source, int frames, int time,
|
||||
const char *const *allow, const char *const *block) __attribute__((weak));
|
||||
extern void webkit_user_script_unref(WebKitUserScript *script) __attribute__((weak));
|
||||
|
||||
static const char NAV_SCRIPT[] =
|
||||
"(()=>{let open=-1e9,arrowAt=-1e9,ringed=null,ringOutline='',ringOffset='',settleTimer=0,settling=false,redirecting=false;"
|
||||
"const shown=()=>[...document.querySelectorAll('[role=dialog],[role=alertdialog],[aria-modal=true],[role=menu]')]"
|
||||
".some(e=>e.getClientRects().length);"
|
||||
"const hidden=e=>{const r=e.getBoundingClientRect();if(!r.width||!r.height)return true;"
|
||||
"for(let n=e;n&&n.nodeType===1;n=n.parentElement){const s=getComputedStyle(n);"
|
||||
"if(s.visibility==='hidden'||+s.opacity<0.1)return true;}return false;};"
|
||||
"const windowButton=e=>/^(Minimize|Maximize|Restore|Close) window$/.test(e.getAttribute('aria-label')||'');"
|
||||
"const editing=e=>!!e&&e.nodeType===1&&(e.isContentEditable||"
|
||||
"e.matches('input:not([type=checkbox]):not([type=radio]):not([type=button]):not([type=submit]),textarea,select'));"
|
||||
"const mainNav=()=>[...document.querySelectorAll('nav')].filter(n=>n.querySelectorAll('a[href]').length>1&&!hidden(n))"
|
||||
".sort((a,b)=>a.getBoundingClientRect().y-b.getBoundingClientRect().y)[0];"
|
||||
"const first=nav=>{const below=nav?nav.getBoundingClientRect().bottom:0,all=[];"
|
||||
"for(const e of document.querySelectorAll('a[href],button,input,[role=button],[tabindex]')){"
|
||||
"if(e.tabIndex<0||(nav&&nav.contains(e)))continue;const r=e.getBoundingClientRect();"
|
||||
"if(r.top<below||r.bottom>innerHeight||windowButton(e)||hidden(e))continue;all.push({e,r});}"
|
||||
"const big=all.filter(c=>c.r.width*c.r.height>=12000),list=big.length?big:all;"
|
||||
"const key=c=>Math.round(c.r.top/8)*1e5+c.r.left;"
|
||||
"list.sort((a,b)=>key(a)-key(b));return list.length?list[0].e:null;};"
|
||||
"const big=e=>{const r=e.getBoundingClientRect();return r.width*r.height>=12000;};"
|
||||
"const toward=(from,key,nav,small)=>{const r=from.getBoundingClientRect(),cx=r.left+r.width/2,cy=r.top+r.height/2;let best=null,score=1e9;"
|
||||
"for(const c of document.querySelectorAll('a[href],button,[role=button],[tabindex]')){if(c===from||c.tabIndex<0||(nav&&nav.contains(c))||from.contains(c)||c.contains(from))continue;"
|
||||
"const q=c.getBoundingClientRect();if(!small&&q.width*q.height<12000)continue;const qx=q.left+q.width/2,qy=q.top+q.height/2;let along,across;"
|
||||
"if(key==='ArrowDown'){along=q.top-r.bottom;across=qx-cx;}else if(key==='ArrowUp'){along=r.top-q.bottom;across=qx-cx;}"
|
||||
"else if(key==='ArrowRight'){along=q.left-r.right;across=qy-cy;}else{along=r.left-q.right;across=qy-cy;}"
|
||||
"if(along<-4)continue;const d=Math.max(along,0)+2*Math.abs(across);if(d<score&&!windowButton(c)&&!hidden(c)){score=d;best=c;}}return best;};"
|
||||
"const settle=()=>{const a=document.activeElement;if(editing(a)||shown())return;const nav=mainNav(),list=[];"
|
||||
"for(const c of document.querySelectorAll('a[href],button,[role=button],[tabindex]')){if(c.tabIndex<0||(nav&&nav.contains(c)))continue;"
|
||||
"const r=c.getBoundingClientRect();if(r.width*r.height>=12000&&r.top>=0&&r.left>=0&&r.bottom<=innerHeight&&r.right<=innerWidth)list.push({c,r});}"
|
||||
"const key=x=>Math.round(x.r.top/8)*1e5+x.r.left;list.sort((x,y)=>key(x)-key(y));"
|
||||
"for(const {c,r} of list){const hit=document.elementFromPoint(r.left+r.width/2,r.top+8);"
|
||||
"if(hit&&(hit===c||c.contains(hit))&&!hidden(c)){arrowAt=performance.now();c.focus({preventScroll:true});return;}}};"
|
||||
"const arm=()=>{clearTimeout(settleTimer);settleTimer=setTimeout(()=>{settling=false;settle();},200);};"
|
||||
"addEventListener('scroll',()=>{if(settling)arm();},true);"
|
||||
"const unring=()=>{if(ringed){ringed.style.outline=ringOutline;ringed.style.outlineOffset=ringOffset;ringed=null;}};"
|
||||
"addEventListener('keydown',e=>{const k=e.key||'';if(k.startsWith('Arrow')){arrowAt=e.timeStamp;const a=document.activeElement;"
|
||||
"if(!editing(a)&&!shown()){const nav=mainNav();"
|
||||
"if(!a||a===document.body||hidden(a)||(k==='ArrowDown'&&nav&&nav.contains(a))){const f=first(nav);"
|
||||
"if(f){e.preventDefault();e.stopImmediatePropagation();f.focus();f.scrollIntoView({block:'nearest'});}}"
|
||||
"else if(big(a)&&!e.ctrlKey&&!e.altKey){let t=toward(a,k,nav);"
|
||||
"if(!t&&(k==='ArrowUp'||k==='ArrowDown'))t=toward(a,k,nav,true);"
|
||||
"if(t){e.preventDefault();e.stopImmediatePropagation();t.focus({preventScroll:true});t.scrollIntoView({block:'nearest',inline:'nearest'});}}}}"
|
||||
"if(k==='Escape')open=shown()?e.timeStamp:-1e9;"
|
||||
"if(e.code==='F13'){e.preventDefault();e.stopImmediatePropagation();settling=true;arm();}},true);"
|
||||
"addEventListener('keydown',e=>{if(e.key!=='BrowserBack')return;e.preventDefault();e.stopImmediatePropagation();"
|
||||
"const a=document.activeElement;if(editing(a)){a.blur();return;}"
|
||||
"if(e.timeStamp-open>500)history.back();},true);"
|
||||
"window.droiddeckTab=step=>{"
|
||||
"const nav=mainNav();if(!nav)return;"
|
||||
"const tabs=[...nav.querySelectorAll('a[href]')].filter(a=>!hidden(a)),part=p=>p.split('/')[1]||'';"
|
||||
"const at=tabs.findIndex(a=>part(new URL(a.href).pathname)===part(location.pathname));"
|
||||
"const to=tabs[Math.min(tabs.length-1,Math.max(0,at+step))];"
|
||||
"if(at>=0&&to!==tabs[at]){to.click();to.blur();}};"
|
||||
"const redirect=n=>{redirecting=true;try{n.focus();}finally{redirecting=false;}};"
|
||||
"addEventListener('focusout',unring,true);"
|
||||
"addEventListener('focusin',e=>{const t=e.target;if(!(t instanceof Element)||e.timeStamp-arrowAt>1000)return;"
|
||||
"const back=e.relatedTarget instanceof Element&&e.relatedTarget.focus?e.relatedTarget:null;"
|
||||
"if(!redirecting&&windowButton(t)){if(back)redirect(back);return;}"
|
||||
"if(!redirecting&&hidden(t)){let a=t.parentElement;"
|
||||
"while(a&&!(a.matches('a[href],button,[role=button],[tabindex]')&&!hidden(a)))a=a.parentElement;"
|
||||
"if(a)redirect(a);else if(back)redirect(back);return;}"
|
||||
"unring();ringed=(t.matches('input,textarea')&&t.closest('label'))||t;"
|
||||
"ringOutline=ringed.style.outline;ringOffset=ringed.style.outlineOffset;"
|
||||
"ringed.style.outline='3px solid #fff';ringed.style.outlineOffset='2px';},true);})();";
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
void *window;
|
||||
signed char send_event;
|
||||
unsigned time;
|
||||
unsigned state;
|
||||
unsigned keyval;
|
||||
} KeyEvent;
|
||||
|
||||
static void *launcher_view;
|
||||
|
||||
static void find_launcher_view(void *widget, void *data)
|
||||
{
|
||||
(void)data;
|
||||
if (launcher_view)
|
||||
return;
|
||||
if (g_type_check_instance_is_a(widget, webkit_web_view_get_type())) {
|
||||
const char *uri = webkit_web_view_get_uri(widget);
|
||||
const char *prefix = "tauri:";
|
||||
while (uri && *prefix && *uri == *prefix) {
|
||||
uri++;
|
||||
prefix++;
|
||||
}
|
||||
if (uri && !*prefix)
|
||||
launcher_view = widget;
|
||||
} else if (g_type_check_instance_is_a(widget, gtk_container_get_type())) {
|
||||
gtk_container_forall(widget, find_launcher_view, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static int switch_tab(void *grab, void *event_data, void *data)
|
||||
{
|
||||
KeyEvent *event = event_data;
|
||||
(void)data;
|
||||
if (!grab || event->type != 8 || !(event->state & 4) || (event->keyval != 0xff55 && event->keyval != 0xff56))
|
||||
return 0;
|
||||
launcher_view = 0;
|
||||
find_launcher_view(gtk_widget_get_toplevel(grab), 0);
|
||||
if (!launcher_view)
|
||||
return 0;
|
||||
webkit_web_view_run_javascript(launcher_view, event->keyval == 0xff56 ? "window.droiddeckTab&&droiddeckTab(1)"
|
||||
: "window.droiddeckTab&&droiddeckTab(-1)",
|
||||
0, 0, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void watch_tab_keys(void)
|
||||
{
|
||||
static int watching;
|
||||
if (watching || !gtk_key_snooper_install || !gtk_widget_get_toplevel || !gtk_container_forall ||
|
||||
!gtk_container_get_type || !webkit_web_view_get_type || !g_type_check_instance_is_a ||
|
||||
!webkit_web_view_get_uri || !webkit_web_view_run_javascript)
|
||||
return;
|
||||
watching = 1;
|
||||
gtk_key_snooper_install(switch_tab, 0);
|
||||
}
|
||||
|
||||
static void set(WebKitSettings *settings, const char *setter, const char *property, int value)
|
||||
{
|
||||
static int setting;
|
||||
if (setting) {
|
||||
void (*next)(WebKitSettings *, int) = dlsym ? (void (*)(WebKitSettings *, int))dlsym((void *)-1l, setter) : 0;
|
||||
if (next)
|
||||
next(settings, value);
|
||||
return;
|
||||
}
|
||||
if (!g_object_set)
|
||||
return;
|
||||
setting = 1;
|
||||
g_object_set(settings, property, value, "enable-smooth-scrolling", 0, "enable-spatial-navigation", 1, (const char *)0);
|
||||
setting = 0;
|
||||
}
|
||||
|
||||
#define SETTER(name, property) \
|
||||
__attribute__((visibility("default"))) void webkit_settings_set_##name(WebKitSettings *settings, int value) \
|
||||
{ \
|
||||
set(settings, "webkit_settings_set_" #name, property, value); \
|
||||
}
|
||||
|
||||
SETTER(enable_javascript, "enable-javascript")
|
||||
SETTER(enable_developer_extras, "enable-developer-extras")
|
||||
SETTER(enable_webgl, "enable-webgl")
|
||||
SETTER(enable_webaudio, "enable-webaudio")
|
||||
SETTER(enable_page_cache, "enable-page-cache")
|
||||
SETTER(javascript_can_access_clipboard, "javascript-can-access-clipboard")
|
||||
SETTER(javascript_can_open_windows_automatically, "javascript-can-open-windows-automatically")
|
||||
SETTER(enable_back_forward_navigation_gestures, "enable-back-forward-navigation-gestures")
|
||||
|
||||
__attribute__((visibility("default"))) void webkit_user_content_manager_add_script(WebKitUserContentManager *manager,
|
||||
WebKitUserScript *script)
|
||||
{
|
||||
static void (*next)(WebKitUserContentManager *, WebKitUserScript *);
|
||||
if (!next && dlsym)
|
||||
next = (void (*)(WebKitUserContentManager *, WebKitUserScript *))dlsym((void *)-1l, "webkit_user_content_manager_add_script");
|
||||
if (!next)
|
||||
return;
|
||||
watch_tab_keys();
|
||||
if (g_object_get_data && g_object_set_data && webkit_user_script_new && webkit_user_script_unref &&
|
||||
!g_object_get_data(manager, "droiddeck-nav")) {
|
||||
g_object_set_data(manager, "droiddeck-nav", (void *)1);
|
||||
WebKitUserScript *nav = webkit_user_script_new(NAV_SCRIPT, 1, 0, 0, 0);
|
||||
if (nav) {
|
||||
next(manager, nav);
|
||||
webkit_user_script_unref(nav);
|
||||
}
|
||||
}
|
||||
next(manager, script);
|
||||
}
|
||||
@@ -21,6 +21,7 @@ Requests: ping, exec, focus, cdp, quit. Each answer is {"ok": true, ...} or
|
||||
import base64
|
||||
import json
|
||||
import math
|
||||
import re
|
||||
import os
|
||||
import selectors
|
||||
import signal
|
||||
@@ -177,6 +178,11 @@ class X:
|
||||
return list(struct.unpack("<%dI" % n, data))
|
||||
return data
|
||||
|
||||
def cardinals(self, window, name, values):
|
||||
self.s.sendall(struct.pack("<BBHIIIB3xI", 18, 0, 6 + len(values), window,
|
||||
self.atom(name), self.atom("CARDINAL"), 32, len(values))
|
||||
+ struct.pack("<%dI" % len(values), *values))
|
||||
|
||||
|
||||
def windows(x):
|
||||
"""Top-level windows that are mapped or carry an app id: what gamescope picks focus from."""
|
||||
@@ -249,6 +255,67 @@ def focus_snapshot():
|
||||
return snap
|
||||
|
||||
|
||||
STEAM_APP_CLASS = re.compile(r"steam_app_(\d+)$")
|
||||
|
||||
|
||||
def tag_game_windows(snap):
|
||||
if os.environ.get("BL_STEAM_CLIENT_ARCH") != "x86_64":
|
||||
return False
|
||||
tagged = False
|
||||
for display, wins in snap.get("displays", {}).items():
|
||||
if display == os.environ.get("DISPLAY"):
|
||||
continue
|
||||
for win in wins:
|
||||
match = STEAM_APP_CLASS.match(win.get("class") or "")
|
||||
if not match or win.get("appId") or win.get("map") != "viewable" or win.get("overrideRedirect"):
|
||||
continue
|
||||
try:
|
||||
done = subprocess.run(["xprop", "-display", display, "-id", str(win["window"]), "-f", "STEAM_GAME", "32c",
|
||||
"-set", "STEAM_GAME", match.group(1)],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=5).returncode == 0
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
done = False
|
||||
log("game window %s on %s tagged STEAM_GAME=%s: %s" % (win["window"], display, match.group(1), "ok" if done else "failed"))
|
||||
tagged = tagged or done
|
||||
return tagged
|
||||
|
||||
|
||||
def vr_scene_app(path=Path('/run/droiddeck/droiddeck-steamvr/scene-focus.json'), proc=Path('/proc')):
|
||||
"""Only a live SteamVR scene with its dashboard hidden may claim game focus."""
|
||||
try:
|
||||
state = json.loads(path.read_text())
|
||||
server, scene = int(state['serverPid']), int(state['scenePid'])
|
||||
if server <= 0 or scene <= 0 or state['dashboard'] is not False:
|
||||
return None
|
||||
if (proc / str(server) / 'comm').read_text().strip() != 'vrserver':
|
||||
return None
|
||||
for entry in (proc / str(scene) / 'environ').read_bytes().split(b'\0'):
|
||||
if entry.startswith(b'SteamAppId='):
|
||||
app = int(entry.split(b'=', 1)[1])
|
||||
return app if 0 < app < 2**32 else None
|
||||
except (OSError, ValueError, TypeError, KeyError):
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
class VrSceneFocus:
|
||||
def __init__(self):
|
||||
self.original = None
|
||||
self.written = None
|
||||
|
||||
def order(self, current, focusable, app):
|
||||
if app is None or app not in focusable:
|
||||
restore = self.original if self.written == current else None
|
||||
self.original = self.written = None
|
||||
return restore
|
||||
if current and current[0] == app:
|
||||
return None
|
||||
if self.original is None:
|
||||
self.original = list(current)
|
||||
self.written = [app] + [item for item in current if item != app]
|
||||
return self.written
|
||||
|
||||
|
||||
class FocusWatcher(threading.Thread):
|
||||
"""Rewrites focus.json when gamescope's focus properties change, and every few seconds when
|
||||
the windows do (a window can change without any root property moving)."""
|
||||
@@ -259,19 +326,35 @@ class FocusWatcher(threading.Thread):
|
||||
self.changed = threading.Event()
|
||||
self.last = None
|
||||
self.seq = 0
|
||||
self.vr_focus = VrSceneFocus()
|
||||
|
||||
def run(self):
|
||||
threading.Thread(target=self.listen, daemon=True, name="focus-events").start()
|
||||
last_app, last_snapshot = None, 0
|
||||
while True:
|
||||
self.changed.wait(timeout=5)
|
||||
notified = self.changed.wait(timeout=0.5)
|
||||
self.changed.clear()
|
||||
app = vr_scene_app()
|
||||
if not notified and app == last_app and time.monotonic() - last_snapshot < 5:
|
||||
continue
|
||||
last_app, last_snapshot = app, time.monotonic()
|
||||
time.sleep(0.2)
|
||||
try:
|
||||
snap = focus_snapshot()
|
||||
order = self.vr_focus.order(snap.get('baselayerAppIds', []), snap.get('focusableApps', []), app)
|
||||
if order is not None:
|
||||
x = X(os.environ['DISPLAY'])
|
||||
try:
|
||||
x.cardinals(x.root, 'GAMESCOPECTRL_BASELAYER_APPID', order)
|
||||
finally:
|
||||
x.close()
|
||||
except (OSError, AgentError) as e:
|
||||
log("focus snapshot failed: %s" % e)
|
||||
time.sleep(2)
|
||||
continue
|
||||
if tag_game_windows(snap):
|
||||
self.changed.set()
|
||||
continue
|
||||
body = {k: v for k, v in snap.items() if k != "t"}
|
||||
if body == self.last:
|
||||
continue
|
||||
@@ -527,6 +610,31 @@ def wait_for_steam_shortcut_overview(agent_dir, game_id, timeout=45):
|
||||
raise AgentError("STEAM_OVERVIEW_TIMEOUT", "Steam did not load shortcut app overview %d" % app_id)
|
||||
|
||||
|
||||
def steam_shortcut_state(agent_dir, game_id, timeout=6):
|
||||
if steam_shortcut_app_id(game_id) is None:
|
||||
return "not-shortcut"
|
||||
timeout = request_timeout({"timeout": timeout}, 6)
|
||||
deadline = time.monotonic() + timeout
|
||||
expression = """(() => {
|
||||
const store = globalThis.appStore;
|
||||
if (typeof store?.GetAppOverviewByGameID !== 'function' || !store.m_bIsInitialized) return 'loading';
|
||||
if (store.GetAppOverviewByGameID(%s) != null) return 'ready';
|
||||
return store.allApps.some(app => app.app_type == 1073741824) ? 'missing' : 'loading';
|
||||
})()""" % json.dumps(game_id)
|
||||
state = "loading"
|
||||
while True:
|
||||
try:
|
||||
state = cdp_eval(agent_dir, expression, await_promise=False,
|
||||
timeout=min(5, max(0.25, deadline - time.monotonic()))).get("value") or "loading"
|
||||
except AgentError as error:
|
||||
if error.code not in ("NO_DEVTOOLS", "DEVTOOLS_UNREACHABLE", "NO_TARGET", "TIMEOUT"):
|
||||
raise
|
||||
state = "loading"
|
||||
if state == "ready" or time.monotonic() >= deadline:
|
||||
return state
|
||||
time.sleep(min(0.5, max(0, deadline - time.monotonic())))
|
||||
|
||||
|
||||
def game_pids(app_id):
|
||||
"""Our processes started for this Steam app (Steam sets SteamAppId / SteamGameId in their
|
||||
environment, and Proton's wine processes inherit it)."""
|
||||
@@ -804,6 +912,28 @@ def main(argv):
|
||||
return 3
|
||||
print("droiddeck-agent: Steam overview is ready for shortcut app %d" % prepared["appId"])
|
||||
return 0
|
||||
if argv and argv[0] == "--steam-asleep":
|
||||
expression = """(() => {
|
||||
const store = globalThis.SuspendResumeStore;
|
||||
return store ? (store.m_bSuspending ? 'yes' : 'no') : 'unknown';
|
||||
})()"""
|
||||
try:
|
||||
state = cdp_eval(Path(base) / "agent", expression, await_promise=False, timeout=3).get("value") or "unknown"
|
||||
except (AgentError, OSError, ValueError):
|
||||
state = "unknown"
|
||||
print(state)
|
||||
return {"yes": 0, "no": 5}.get(state, 1)
|
||||
if argv and argv[0] == "--steam-shortcut-state":
|
||||
if len(argv) not in (2, 3):
|
||||
print("usage: droiddeck-agent --steam-shortcut-state <cgameid> [timeout-seconds]", file=sys.stderr)
|
||||
return 2
|
||||
try:
|
||||
state = steam_shortcut_state(Path(base) / "agent", argv[1], argv[2] if len(argv) == 3 else 6)
|
||||
except (AgentError, OSError, ValueError) as error:
|
||||
print("droiddeck-agent: could not ask the client about the shortcut: %s" % error, file=sys.stderr)
|
||||
return 1
|
||||
print(state)
|
||||
return {"ready": 0, "missing": 4, "not-shortcut": 3}.get(state, 1)
|
||||
serve(Path(base) / "agent", focus="--no-focus" not in argv)
|
||||
return 0
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@ import re
|
||||
import sys
|
||||
|
||||
HOME = os.environ.get("HOME", "/root")
|
||||
STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HOME, ".local/share/Steam")
|
||||
LIBRARIES = ((STEAM_ROOT, "Steam Games"), ("/mnt/droiddeck-sd", "SD Games"))
|
||||
X64 = os.environ.get("BL_STEAM_CLIENT_ARCH") == "x86_64"
|
||||
CLIENT_HOME = (os.environ.get("BL_X64_HOME") or os.path.join(HOME, ".droiddeck-x64")) if X64 else HOME
|
||||
STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(CLIENT_HOME, ".local/share/Steam")
|
||||
LIBRARIES = ((STEAM_ROOT, "Steam Games"), ("/mnt/droiddeck-sd/x86-64" if X64 else "/mnt/droiddeck-sd", "SD Games"))
|
||||
NOT_GAMES = {228980, 1070560, 1391110, 1493710, 1628350, 3127680, 4183110, 4185400, 4427310, 4628740}
|
||||
APPS_DIR = os.path.join(HOME, ".local/share/applications")
|
||||
PREFIX = "droiddeck-game-"
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
[ -n "${LD_PRELOAD:-}" ] && export DROIDDECK_STEAM_PRELOAD="$LD_PRELOAD"
|
||||
unset LD_PRELOAD LD_LIBRARY_PATH
|
||||
exec /usr/bin/python3 -I /usr/local/bin/droiddeck-epic run
|
||||
@@ -28,15 +28,25 @@ URUNTIME = "/usr/local/lib/droiddeck/uruntime"
|
||||
HOST_PRELOAD = "/etc/ld.so.preload"
|
||||
FEX_APPID = "3127680"
|
||||
SNIPER_APPID = "1628350"
|
||||
INSTALL_DIRS = {FEX_APPID: "FEX-Emu", SNIPER_APPID: "SteamLinuxRuntime_sniper"}
|
||||
SLR4_APPID = "4183110"
|
||||
INSTALL_DIRS = {FEX_APPID: "FEX-Emu", SNIPER_APPID: "SteamLinuxRuntime_sniper", SLR4_APPID: "SteamLinuxRuntime_4"}
|
||||
MARKER = ".droiddeck-fex"
|
||||
LAYOUT = 1
|
||||
ROOTFS_LAYOUT = 1
|
||||
ARCH_DIRS = ("x86_64-linux-gnu", "i386-linux-gnu")
|
||||
INTERPRETERS = ("ld-linux-x86-64.so.2", "ld-linux.so.2")
|
||||
PROVIDED = frozenset((
|
||||
"ld-linux-x86-64.so.2", "ld-linux.so.2", "libc.so.6", "libm.so.6", "libmvec.so.1", "libpthread.so.0", "libdl.so.2",
|
||||
"librt.so.1", "libutil.so.1", "libresolv.so.2", "libanl.so.1", "libBrokenLocale.so.1", "libnsl.so.1",
|
||||
"libnss_compat.so.2", "libnss_dns.so.2", "libnss_files.so.2", "libnss_hesiod.so.2", "libthread_db.so.1",
|
||||
"libmemusage.so", "libpcprofile.so", "libc_malloc_debug.so.0", "gconv", "libstdc++.so.6", "libgcc_s.so.1",
|
||||
))
|
||||
GLIBC_BUILD = re.compile(r"^(?:ld|lib[A-Za-z_]+)-2\.[0-9]+\.so$|^libSegFault\.so$")
|
||||
GUEST_LIBDIRS = (("x86_64", "lib/x86_64-linux-gnu"), ("i386", "lib/i386-linux-gnu"))
|
||||
PRELOAD_NAMES = ("libblsession.so", "libfakeinput.so")
|
||||
FAULT_REPORT = "libfaultreport.so"
|
||||
THUNK_AUDIT = "libthunkaudit.so"
|
||||
THUNK_AUDIT_GUEST = "/usr/lib/x86_64-linux-gnu/droiddeck/" + THUNK_AUDIT
|
||||
VULKAN_PIN = "libvulkan-thunk.so"
|
||||
VULKAN_PIN_DIR = "lib/x86_64-linux-gnu/droiddeck/vulkan"
|
||||
VULKAN_THUNK = "libvulkan-guest.so"
|
||||
RUNTIME_LIBRARIES = (("libc.so.6", b"GLIBC_"), ("libstdc++.so.6", b"GLIBCXX_"))
|
||||
VERSION_NAME = re.compile(rb"GLIBC(?:XX)?_[0-9][0-9.]*[0-9]")
|
||||
@@ -164,15 +174,15 @@ def platform_version(path):
|
||||
return tuple(int(part) for part in re.findall(r"\d+", os.path.basename(path)))
|
||||
|
||||
|
||||
def runtime_platform():
|
||||
runtime = app_dir(SNIPER_APPID)
|
||||
def runtime_platform(appid=SNIPER_APPID, prefix="sniper_platform_"):
|
||||
runtime = app_dir(appid)
|
||||
if not runtime:
|
||||
return None
|
||||
try:
|
||||
entries = os.listdir(runtime)
|
||||
except OSError:
|
||||
return None
|
||||
platforms = [os.path.join(runtime, entry) for entry in entries if entry.startswith("sniper_platform_")]
|
||||
platforms = [os.path.join(runtime, entry) for entry in entries if entry.startswith(prefix)]
|
||||
platforms = [path for path in platforms if os.path.isdir(os.path.join(path, "files"))
|
||||
and os.path.isfile(os.path.join(path, "usr-mtree.txt.gz"))]
|
||||
return max(platforms, key=platform_version, default=None)
|
||||
@@ -234,6 +244,75 @@ def materialize(platform):
|
||||
return True
|
||||
|
||||
|
||||
def graphics_platform():
|
||||
return runtime_platform(SLR4_APPID, "steamrt4_platform_")
|
||||
|
||||
|
||||
def provides_newer(base, provider):
|
||||
for name, prefix in RUNTIME_LIBRARIES:
|
||||
ours = {v for v in version_names(os.path.join(base, "files/lib/x86_64-linux-gnu", name)) if v.startswith(prefix)}
|
||||
theirs = {v for v in version_names(os.path.join(provider, "files/lib/x86_64-linux-gnu", name)) if v.startswith(prefix)}
|
||||
if not ours or not theirs or not ours < theirs:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def mirror(source, provider, name, target):
|
||||
if provider and name in PROVIDED and os.path.lexists(os.path.join(provider, name)):
|
||||
os.symlink(os.path.realpath(os.path.join(provider, name)), os.path.join(target, name))
|
||||
return
|
||||
path = os.path.join(source, name)
|
||||
link = os.readlink(path) if os.path.islink(path) else None
|
||||
if link and GLIBC_BUILD.match(os.path.basename(link)):
|
||||
if name not in INTERPRETERS:
|
||||
return
|
||||
link = os.path.join(os.path.dirname(link), name)
|
||||
if provider and GLIBC_BUILD.match(name):
|
||||
return
|
||||
if link and not link.startswith("/"):
|
||||
os.symlink(link, os.path.join(target, name))
|
||||
else:
|
||||
os.symlink(os.path.realpath(path), os.path.join(target, name))
|
||||
|
||||
|
||||
def build_rootfs(base, provider):
|
||||
"""The runtime with glibc and libstdc++ taken from a newer one, which FEX's GL and Vulkan thunks are built against."""
|
||||
base_files, provider_files = os.path.join(base, "files"), os.path.join(provider, "files")
|
||||
rootfs = os.path.join(STATE, "rootfs")
|
||||
stamp = "%d\n%s\n%s%s\n%s" % (ROOTFS_LAYOUT, os.path.realpath(base), read_text(os.path.join(base_files, MARKER)) or "",
|
||||
os.path.realpath(provider), read_text(os.path.join(provider_files, MARKER)) or "")
|
||||
if read_text(os.path.join(rootfs, MARKER)) == stamp:
|
||||
return False
|
||||
for entry in os.listdir(STATE):
|
||||
if entry.startswith("rootfs."):
|
||||
shutil.rmtree(os.path.join(STATE, entry), ignore_errors=True)
|
||||
tmp = "%s.%d.tmp" % (rootfs, os.getpid())
|
||||
os.makedirs(tmp)
|
||||
for entry in os.listdir(base_files):
|
||||
if entry not in ("lib", "lib64", "usr", MARKER):
|
||||
os.symlink(os.path.realpath(os.path.join(base_files, entry)), os.path.join(tmp, entry))
|
||||
os.symlink(".", os.path.join(tmp, "usr"))
|
||||
for top in ("lib", "lib64"):
|
||||
source = os.path.join(base_files, top)
|
||||
os.makedirs(os.path.join(tmp, top))
|
||||
for entry in os.listdir(source) if os.path.isdir(source) else ():
|
||||
path = os.path.join(source, entry)
|
||||
if entry in ARCH_DIRS and os.path.isdir(path) and not os.path.islink(path):
|
||||
provided = os.path.join(provider_files, top, entry)
|
||||
os.makedirs(os.path.join(tmp, top, entry))
|
||||
for name in set(os.listdir(path)) | {name for name in PROVIDED if os.path.lexists(os.path.join(provided, name))}:
|
||||
mirror(path, provided, name, os.path.join(tmp, top, entry))
|
||||
else:
|
||||
mirror(source, None, entry, os.path.join(tmp, top))
|
||||
write_if_changed(os.path.join(tmp, MARKER), stamp)
|
||||
old = "%s.%d.old" % (rootfs, os.getpid())
|
||||
if os.path.lexists(rootfs):
|
||||
os.rename(rootfs, old)
|
||||
os.rename(tmp, rootfs)
|
||||
shutil.rmtree(old, ignore_errors=True)
|
||||
return True
|
||||
|
||||
|
||||
def host_preloads():
|
||||
listed = read_text(HOST_PRELOAD) or ""
|
||||
return [name for name in PRELOAD_NAMES if name in listed]
|
||||
@@ -247,10 +326,14 @@ def install_preloads(root):
|
||||
if os.path.isfile(source):
|
||||
copy_if_changed(source, os.path.join(root, libdir, "droiddeck", name))
|
||||
shipped.setdefault(name, set()).add(arch)
|
||||
for name in (THUNK_AUDIT, VULKAN_PIN):
|
||||
source = os.path.join(PRELOADS, "x86_64", name)
|
||||
if os.path.isfile(source):
|
||||
copy_if_changed(source, os.path.join(root, "lib/x86_64-linux-gnu/droiddeck", name))
|
||||
pin = os.path.join(PRELOADS, "x86_64", VULKAN_PIN)
|
||||
if os.path.isfile(pin):
|
||||
copy_if_changed(pin, os.path.join(root, VULKAN_PIN_DIR, "libvulkan.so.1"))
|
||||
alias = os.path.join(root, VULKAN_PIN_DIR, "libvulkan.so")
|
||||
if not os.path.islink(alias) or os.readlink(alias) != "libvulkan.so.1":
|
||||
if os.path.lexists(alias):
|
||||
os.unlink(alias)
|
||||
os.symlink("libvulkan.so.1", alias)
|
||||
wanted = [name for name in host_preloads() if name in shipped]
|
||||
if len(shipped.get(FAULT_REPORT, ())) == len(GUEST_LIBDIRS):
|
||||
wanted.append(FAULT_REPORT)
|
||||
@@ -270,14 +353,16 @@ def write_config(fex, root):
|
||||
def link_steam_sdk():
|
||||
for sdk, candidates in (("sdk64", ("linux64", "ubuntu12_64")), ("sdk32", ("linux32", "ubuntu12_32"))):
|
||||
link = os.path.join(HOME, ".steam", sdk)
|
||||
if os.path.lexists(link):
|
||||
continue
|
||||
want = "x86_64" if sdk == "sdk64" else "i386"
|
||||
if elf_arch(os.path.join(link, "steamclient.so")) == want:
|
||||
continue
|
||||
for candidate in candidates:
|
||||
directory = os.path.join(STEAM_ROOT, candidate)
|
||||
if elf_arch(os.path.join(directory, "steamclient.so")) == want:
|
||||
os.makedirs(os.path.dirname(link), exist_ok=True)
|
||||
os.symlink(directory, link)
|
||||
tmp = "%s.%d.tmp" % (link, os.getpid())
|
||||
os.symlink(directory, tmp)
|
||||
os.replace(tmp, link)
|
||||
break
|
||||
|
||||
|
||||
@@ -308,7 +393,7 @@ def request_install():
|
||||
return []
|
||||
|
||||
|
||||
def describe(fex, platform):
|
||||
def describe(fex, platform, graphics=None):
|
||||
return {
|
||||
"fex": fex["bin"] if fex else None,
|
||||
"server": fex["server"] if fex else None,
|
||||
@@ -317,6 +402,7 @@ def describe(fex, platform):
|
||||
"steamclient64": os.path.realpath(os.path.join(HOME, ".steam", "sdk64", "steamclient.so"))
|
||||
if elf_arch(os.path.join(HOME, ".steam", "sdk64", "steamclient.so")) == "x86_64" else None,
|
||||
"ready": bool(fex and fex["server"] and platform),
|
||||
"graphics": graphics,
|
||||
}
|
||||
|
||||
|
||||
@@ -346,13 +432,27 @@ def prepare():
|
||||
if materialize(platform):
|
||||
say("prepared %s as the x86 runtime" % os.path.basename(platform))
|
||||
install_preloads(root)
|
||||
provider = graphics_platform()
|
||||
if provider and materialize(provider):
|
||||
say("prepared %s for the x86 runtime's C and C++ libraries" % os.path.basename(provider))
|
||||
if not provider:
|
||||
say("Steam Linux Runtime 4.0 (Steam app %s) is not installed yet; x86 games may not find their graphics drivers"
|
||||
% SLR4_APPID)
|
||||
elif not provides_newer(platform, provider):
|
||||
say("%s has no newer C and C++ libraries than %s" % (os.path.basename(provider), os.path.basename(platform)))
|
||||
provider = None
|
||||
else:
|
||||
if build_rootfs(platform, provider):
|
||||
say("built the x86 runtime from %s with the C and C++ libraries of %s"
|
||||
% (os.path.basename(platform), os.path.basename(provider)))
|
||||
root = os.path.join(STATE, "rootfs")
|
||||
write_config(fex, root)
|
||||
fex["rootfs"] = root
|
||||
try:
|
||||
link_steam_sdk()
|
||||
except OSError:
|
||||
pass
|
||||
status = describe(fex, platform)
|
||||
status = describe(fex, platform, provider)
|
||||
write_if_changed(STATUS_FILE, json.dumps(status, indent=2) + "\n")
|
||||
with contextlib.suppress(OSError):
|
||||
os.unlink(WANTED)
|
||||
@@ -422,8 +522,16 @@ def guest_environment(fex, env):
|
||||
result["FEX_APP_CONFIG_LOCATION"] = CONFIG_DIR + "/"
|
||||
result["FEX_APP_DATA_LOCATION"] = data + "/"
|
||||
result["FEX_APP_CACHE_LOCATION"] = CACHE_DIR + "/"
|
||||
# Valve's FEX-Emu binds its server socket under $STEAM_COMPAT_DATA_PATH/fex-emu whatever FEX_APP_DATA_LOCATION or
|
||||
# FEX_SERVERSOCKETPATH say, and sun_path is 108 bytes: compatdata under the app's data folder is too long.
|
||||
if result.get("STEAM_COMPAT_DATA_PATH"):
|
||||
short = data if data != DATA_DIR else "/tmp/fex"
|
||||
os.makedirs(short, exist_ok=True)
|
||||
result["STEAM_COMPAT_DATA_PATH"] = short
|
||||
result.setdefault("FEX_SILENTLOG", "0")
|
||||
result.setdefault("FEX_OUTPUTLOG", "stderr")
|
||||
# Mono's incremental Boehm collector corrupts its heap under FEX, so Unity games crash at their first collections.
|
||||
result.setdefault("GC_DISABLE_INCREMENTAL", "1")
|
||||
if fex["portable"]:
|
||||
result["FEX_PORTABLE"] = "1"
|
||||
else:
|
||||
@@ -439,7 +547,7 @@ def guest_environment(fex, env):
|
||||
result["FEX_THUNKCONFIG"] = os.path.join(CONFIG_DIR, "ThunksConfig.json")
|
||||
preload = [part for part in split_paths(result.get("LD_PRELOAD")) if os.path.exists(part) and not is_arm(part)]
|
||||
library_path = [part for part in (result.get("LD_LIBRARY_PATH") or "").split(":")
|
||||
if part and "steamrtarm64" not in part and "aarch64" not in part]
|
||||
if part and "arm64" not in part and "aarch64" not in part]
|
||||
for name, parts in (("LD_PRELOAD", preload), ("LD_LIBRARY_PATH", library_path)):
|
||||
if parts:
|
||||
result[name] = ":".join(parts)
|
||||
@@ -477,6 +585,7 @@ def vulkan_thunk_loads(fex, folder):
|
||||
needed = version_names(os.path.join(fex["guest_thunks"], VULKAN_THUNK))
|
||||
if not needed:
|
||||
return False
|
||||
needed |= version_names(os.path.join(PRELOADS, "x86_64", VULKAN_PIN))
|
||||
found = bundled_libraries(folder)
|
||||
for name, prefix in RUNTIME_LIBRARIES:
|
||||
library = found.get(name) or os.path.join(fex["rootfs"], "lib/x86_64-linux-gnu", name)
|
||||
@@ -503,9 +612,10 @@ def launch(command, env, mode, decide=None):
|
||||
x86_64 = elf_arch(program) != "i386"
|
||||
thunks = "on" if "FEX_THUNKCONFIG" in guest else "off"
|
||||
folder = decide if decide and os.path.isdir(decide) else os.path.dirname(program)
|
||||
if thunks == "on" and x86_64 and all(os.path.isfile(os.path.join(PRELOADS, "x86_64", name)) for name in (THUNK_AUDIT, VULKAN_PIN)) \
|
||||
if thunks == "on" and x86_64 and os.path.isfile(os.path.join(PRELOADS, "x86_64", VULKAN_PIN)) \
|
||||
and vulkan_thunk_loads(fex, folder):
|
||||
guest["LD_AUDIT"] = ":".join([THUNK_AUDIT_GUEST] + split_paths(guest.get("LD_AUDIT")))
|
||||
# Any LD_AUDIT module makes Mono's garbage collector crash under FEX, so the Vulkan thunk is pinned by search path.
|
||||
guest["LD_LIBRARY_PATH"] = ":".join(["/usr/" + VULKAN_PIN_DIR] + split_paths(guest.get("LD_LIBRARY_PATH")))
|
||||
thunks = "on, its own Vulkan loader too"
|
||||
say("running %s with %s (runtime %s, thunks %s)" % (program, fex["bin"], guest.get("FEX_ROOTFS", "none"), thunks))
|
||||
return os.execve(fex["bin"], [fex["bin"], program] + command[1:], guest)
|
||||
@@ -557,19 +667,38 @@ def extracted():
|
||||
|
||||
def want_fex():
|
||||
with locked():
|
||||
status = describe(fex_install(), runtime_platform())
|
||||
status = describe(fex_install(), runtime_platform(), graphics_platform())
|
||||
if not status["ready"]:
|
||||
request_install()
|
||||
write_if_changed(STATUS_FILE, json.dumps(status, indent=2) + "\n")
|
||||
|
||||
|
||||
XATTR_ONLY_NOISE = re.compile(r"^(proot (error|warning)|Failed to exec memfd|Further error messages of this type are suppressed)")
|
||||
|
||||
|
||||
def only_xattrs_failed(errors):
|
||||
seen = False
|
||||
for line in errors.splitlines():
|
||||
if "write_xattr" in line:
|
||||
seen = True
|
||||
elif re.search(r"fail|could not|cannot|error", line, re.I) and not XATTR_ONLY_NOISE.match(line):
|
||||
return False
|
||||
return seen
|
||||
|
||||
|
||||
def extract(image):
|
||||
image = os.path.abspath(image)
|
||||
clear_extracted()
|
||||
x86 = elf_arch(image) in X86.values()
|
||||
if os.access(URUNTIME, os.X_OK):
|
||||
status = subprocess.call([URUNTIME, "--appimage-extract"], stdout=subprocess.DEVNULL,
|
||||
env=dict(os.environ, TARGET_APPIMAGE=image))
|
||||
run = subprocess.run([URUNTIME, "--appimage-extract"], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
|
||||
env=dict(os.environ, TARGET_APPIMAGE=image))
|
||||
errors = run.stderr.decode("utf-8", "replace")
|
||||
sys.stderr.write(errors)
|
||||
status = run.returncode
|
||||
if status == 2 and only_xattrs_failed(errors) and extracted() and os.path.lexists("squashfs-root/AppRun"):
|
||||
say("uruntime could not keep the image's extended attributes; the files are unpacked")
|
||||
status = 0
|
||||
if status == 0 and extracted():
|
||||
if x86:
|
||||
want_fex()
|
||||
@@ -586,7 +715,7 @@ def extract(image):
|
||||
unsquashfs = shutil.which("unsquashfs")
|
||||
if unsquashfs:
|
||||
clear_extracted()
|
||||
status = subprocess.call([unsquashfs, "-q", "-n", "-o", str(appimage_offset(image)), "-d", "squashfs-root", image],
|
||||
status = subprocess.call([unsquashfs, "-q", "-n", "-no-xattrs", "-o", str(appimage_offset(image)), "-d", "squashfs-root", image],
|
||||
stdout=subprocess.DEVNULL)
|
||||
if status == 0:
|
||||
if x86:
|
||||
@@ -654,7 +783,7 @@ def main(argv):
|
||||
return 0 if prepare() else 1
|
||||
if action == "status":
|
||||
with locked():
|
||||
status = describe(fex_install(), runtime_platform())
|
||||
status = describe(fex_install(), runtime_platform(), graphics_platform())
|
||||
write_if_changed(STATUS_FILE, json.dumps(status, indent=2) + "\n")
|
||||
print(json.dumps(status, indent=2))
|
||||
return 0 if status["ready"] else 1
|
||||
|
||||
@@ -25,8 +25,15 @@ WORK=/var/cache/droiddeck-flatpak
|
||||
CONF=$WORK/pacman.conf
|
||||
mkdir -p "$WORK/pkg" "$WORK/db" || fail "cannot create $WORK"
|
||||
|
||||
{ for m in https://ca.us.mirror.archlinuxarm.org https://fl.us.mirror.archlinuxarm.org \
|
||||
https://de3.mirror.archlinuxarm.org https://nl.mirror.archlinuxarm.org; do
|
||||
OVERSEAS="https://ca.us.mirror.archlinuxarm.org https://fl.us.mirror.archlinuxarm.org https://de3.mirror.archlinuxarm.org https://nl.mirror.archlinuxarm.org"
|
||||
MAINLAND=""
|
||||
for m in https://mirrors.tuna.tsinghua.edu.cn/archlinuxarm https://mirrors.ustc.edu.cn/archlinuxarm \
|
||||
https://mirrors.bfsu.edu.cn/archlinuxarm https://mirrors.sjtug.sjtu.edu.cn/archlinuxarm; do
|
||||
if curl -fsS -r 0-0 --connect-timeout 4 --max-time 8 -o /dev/null "$m/aarch64/core/core.db" 2>/dev/null; then
|
||||
MAINLAND="$MAINLAND $m"
|
||||
fi
|
||||
done
|
||||
{ for m in $MAINLAND $OVERSEAS; do
|
||||
echo "Server = $m/\$arch/\$repo"; done
|
||||
grep '^Server' /etc/pacman.d/mirrorlist 2>/dev/null; } > "$WORK/mirrorlist"
|
||||
sed -e 's/^DownloadUser/#DownloadUser/' \
|
||||
|
||||
@@ -7,7 +7,7 @@ import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
SYNC_KEYS = ("BL_SYNC_FALLBACK", "BL_FSYNC_FIRST", "BL_SYNC_MIN_NOFILE", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC", "PROTON_NO_NTSYNC", "WINEESYNC")
|
||||
SYNC_KEYS = ("BL_SYNC", "BL_SYNC_FALLBACK", "BL_FSYNC_FIRST", "BL_SYNC_MIN_NOFILE", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC", "PROTON_NO_NTSYNC", "WINEESYNC")
|
||||
SEED_REDISTS = "/usr/local/bin/droiddeck-seed-redists"
|
||||
PACK_KEYS = ("WINESERVER", "BL_SYNC_PACK", "WINEESYNC", "PROTON_NO_ESYNC", "PROTON_NO_FSYNC")
|
||||
|
||||
@@ -260,36 +260,6 @@ def force_ssbs(command, env):
|
||||
return env
|
||||
|
||||
|
||||
def umu_capable(proton):
|
||||
"""Whether this Proton's script has umu's launch without Steam: GE-Proton, Proton-CachyOS and
|
||||
DroidDeck-Proton run umu.exe in place of steam.exe when UMU_ID is set; Valve's Proton does not."""
|
||||
try:
|
||||
with open(proton, encoding="utf-8", errors="replace") as source:
|
||||
text = source.read()
|
||||
except OSError:
|
||||
return False
|
||||
return "UMU_ID" in text and "umu.exe" in text
|
||||
|
||||
|
||||
def start_without_steam(command, env, app_id):
|
||||
"""DROIDDECK_NO_STEAM=1 (a game's Start without Steam): launch the game without Proton's
|
||||
steam.exe, for games that close right away because of what it sets up. A Proton with umu's
|
||||
launch gets UMU_ID - Proton still sets up the prefix, and a Steam game keeps its protonfixes
|
||||
under its own id; any other Proton runs the game straight in the prefix (runinprefix)."""
|
||||
if env.get("DROIDDECK_NO_STEAM", "").lower() not in ("1", "on", "true", "yes"):
|
||||
return command, env
|
||||
if len(command) < 3 or command[1] != "waitforexitandrun":
|
||||
return command, env
|
||||
if umu_capable(command[0]):
|
||||
if not env.get("UMU_ID"):
|
||||
steam_game = app_id is not None and int(app_id) < 2**31
|
||||
env = dict(env, UMU_ID=app_id if steam_game else "0")
|
||||
print("droiddeck-game-env: starting without Steam (umu.exe in place of steam.exe, UMU_ID=%s)" % env["UMU_ID"], file=sys.stderr)
|
||||
return command, env
|
||||
print("droiddeck-game-env: starting without Steam (this Proton has no umu launch: runinprefix)", file=sys.stderr)
|
||||
return [command[0], "runinprefix"] + command[2:], env
|
||||
|
||||
|
||||
EVALUATOR_SCRIPT = re.compile(r"(?:^|[\\/])evaluatorscript_[0-9]+\.vdf$", re.IGNORECASE)
|
||||
|
||||
|
||||
@@ -300,7 +270,7 @@ def mark_install_scripts(command, env):
|
||||
ones stop with an error."""
|
||||
if not any(arg.lower().replace("\\", "/").endswith("iscriptevaluator.exe") for arg in command):
|
||||
return
|
||||
root = env.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or str(Path.home() / ".local/share/Steam")
|
||||
root = env.get("BL_X64_STEAM_ROOT") or env.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or str(Path.home() / ".local/share/Steam")
|
||||
scripts = [str(Path(root) / arg.replace("\\", "/")) for arg in command if EVALUATOR_SCRIPT.search(arg)]
|
||||
scripts = [path for path in scripts if os.path.isfile(path)]
|
||||
if not scripts:
|
||||
@@ -453,7 +423,6 @@ def main():
|
||||
if mic_enabled == "0":
|
||||
env["BANNER_AUDIO_DIRECT_MIC"] = "0"
|
||||
env = force_ssbs(command, env)
|
||||
command, env = start_without_steam(command, env, app_id)
|
||||
sync = load_sync()
|
||||
launch, launch_env = select_sync(command, env, sync)
|
||||
if launch[0] != command[0]:
|
||||
|
||||
@@ -10,7 +10,9 @@ import importlib.util
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import uuid
|
||||
|
||||
import gi
|
||||
@@ -24,6 +26,8 @@ INTERFACE = NAME + ".Manager"
|
||||
UPOWER = "org.freedesktop.UPower"
|
||||
UPOWER_ROOT = "/org/freedesktop/UPower"
|
||||
NATIVE_PREPARE_MS = 1500
|
||||
AGENT = Path(__file__).resolve().with_name("droiddeck-agent")
|
||||
ASLEEP_WAIT = 6
|
||||
INTROSPECTION = """
|
||||
<node>
|
||||
<interface name="org.freedesktop.login1.Manager">
|
||||
@@ -80,6 +84,7 @@ class LoginManager:
|
||||
if name == "CanSuspend":
|
||||
reply.return_value(GLib.Variant("(s)", ("yes",)))
|
||||
elif name in ("Suspend", "SuspendWithFlags"):
|
||||
print("== login1: %s.%s asked by %s" % (interface.rsplit(".", 1)[-1], name, sender), flush=True)
|
||||
if self.pending:
|
||||
reply.return_dbus_error(NAME + ".OperationInProgress", "The session is already pausing")
|
||||
return
|
||||
@@ -149,7 +154,7 @@ class LoginManager:
|
||||
if file.get_basename() == self.wake.name or (other and other.get_basename() == self.wake.name):
|
||||
if self.wake.exists():
|
||||
self.wake.unlink(missing_ok=True)
|
||||
self.resume(force=True)
|
||||
self.woken()
|
||||
if file.get_basename() == self.state.name or (other and other.get_basename() == self.state.name):
|
||||
self.check_state()
|
||||
|
||||
@@ -171,6 +176,19 @@ class LoginManager:
|
||||
self.resume()
|
||||
return False
|
||||
|
||||
def woken(self):
|
||||
if self.pending is not None:
|
||||
self.resume(force=True)
|
||||
return
|
||||
threading.Thread(target=lambda: GLib.idle_add(self.replay_unless_awake, steam_asleep()), daemon=True).start()
|
||||
|
||||
def replay_unless_awake(self, asleep):
|
||||
if asleep is False and self.pending is None:
|
||||
print("== login1: Steam is awake; no sleep/wake replay", flush=True)
|
||||
return False
|
||||
self.resume(force=True)
|
||||
return False
|
||||
|
||||
def resume(self, force=False):
|
||||
if self.pending is None:
|
||||
if force:
|
||||
@@ -195,6 +213,15 @@ class LoginManager:
|
||||
self.notify(False)
|
||||
|
||||
|
||||
def steam_asleep():
|
||||
try:
|
||||
code = subprocess.run([str(AGENT), "--steam-asleep"], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL, timeout=ASLEEP_WAIT).returncode
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
return None
|
||||
return {0: True, 5: False}.get(code)
|
||||
|
||||
|
||||
def load_netmanager():
|
||||
path = Path(__file__).resolve().with_name("droiddeck-netmanager")
|
||||
loader = importlib.machinery.SourceFileLoader("droiddeck_netmanager", str(path))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"""Runs a Windows program with the Proton the Steam client has chosen for it.
|
||||
|
||||
droiddeck-proton-run [--window] PROGRAM [ARGS...]
|
||||
droiddeck-proton-run --app ID [--dir FOLDER] [--options TEXT] [PROGRAM [ARGS...]]
|
||||
|
||||
The program belongs to an installed Steam game when it sits in one's folder, to a prefix when it
|
||||
sits in one's drive_c, or to a non-Steam shortcut that names it; any other program gets a prefix of
|
||||
@@ -10,11 +11,15 @@ config.vdf picks the tool, else the client's default for all other titles ("0").
|
||||
started as the client starts it - its toolmanifest's command line, the waitforexitandrun verb and
|
||||
the STEAM_COMPAT_* environment - so its wrapper applies the game's settings, components and audio.
|
||||
--window keeps the program in the desktop's own window, drawn with WineD3D.
|
||||
--app starts one game without the Steam client (its Start without Steam): a Steam game's default
|
||||
Windows launch option from appinfo.vdf when no program is given, else the program in that
|
||||
shortcut's own prefix, started in --dir with the shortcut's launch options (--options).
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import runpy
|
||||
import shlex
|
||||
import struct
|
||||
import sys
|
||||
import zlib
|
||||
@@ -249,6 +254,81 @@ def locate(program, root):
|
||||
os.path.dirname(program), root, "own")
|
||||
|
||||
|
||||
def split_words(text):
|
||||
try:
|
||||
return shlex.split(text or "")
|
||||
except ValueError:
|
||||
return (text or "").split()
|
||||
|
||||
|
||||
def split_options(text):
|
||||
"""A shortcut's launch options: NAME=value words before %command% go to the environment, the words
|
||||
after it - or all of them, without %command% - are the program's arguments."""
|
||||
words = split_words(text)
|
||||
if "%command%" not in words:
|
||||
return {}, words
|
||||
at = words.index("%command%")
|
||||
env = {}
|
||||
for word in words[:at]:
|
||||
name, equals, value = word.partition("=")
|
||||
if equals and re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", name):
|
||||
env[name] = value
|
||||
return env, words[at + 1:]
|
||||
|
||||
|
||||
def find_file(base, relative):
|
||||
"""base/relative, matching each part without regard to case as Windows does."""
|
||||
path = base
|
||||
for part in [p for p in relative.replace("\\", "/").split("/") if p and p != "."]:
|
||||
exact = os.path.join(path, part)
|
||||
if part == ".." or os.path.exists(exact):
|
||||
path = exact
|
||||
continue
|
||||
try:
|
||||
match = next((name for name in sorted(os.listdir(path)) if name.lower() == part.lower()), None)
|
||||
except OSError:
|
||||
return None
|
||||
if match is None:
|
||||
return None
|
||||
path = os.path.join(path, match)
|
||||
return os.path.normpath(path)
|
||||
|
||||
|
||||
def steam_install(appid, root):
|
||||
for library in libraries(root):
|
||||
found = re.search(r'"installdir"\s+"([^"]+)"',
|
||||
read_text(os.path.join(library, "steamapps", "appmanifest_%s.acf" % appid)) or "")
|
||||
if found:
|
||||
return library, os.path.join(library, "steamapps", "common", found.group(1))
|
||||
return None, None
|
||||
|
||||
|
||||
def steam_launch(appid, root):
|
||||
"""(target, program, arguments) for a Steam game's default Windows launch option, or None."""
|
||||
library, install = steam_install(appid, root)
|
||||
if not install or not os.path.isdir(install):
|
||||
return None
|
||||
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf")).get(str(appid), {})
|
||||
options = [option for option in entry.get("launch_options", ())
|
||||
if not option["betakey"] and (not option["oslist"] or "windows" in option["oslist"])]
|
||||
options.sort(key=lambda option: (option["type"] not in ("", "default", "none"),
|
||||
int(option["key"]) if option["key"].isdigit() else 0))
|
||||
for option in options:
|
||||
program = find_file(install, option["executable"])
|
||||
if not program or not os.path.isfile(program):
|
||||
continue
|
||||
start = find_file(install, option["workingdir"]) if option["workingdir"] else None
|
||||
target = Target(appid, os.path.join(library, "steamapps", "compatdata", str(appid)), install, library, "steam",
|
||||
start if start and os.path.isdir(start) else os.path.dirname(program))
|
||||
return target, program, split_words(option["arguments"])
|
||||
return None
|
||||
|
||||
|
||||
def shortcut_target(appid, program, start, root):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)), os.path.dirname(program), root,
|
||||
"shortcut", start if start and os.path.isdir(start) else None)
|
||||
|
||||
|
||||
def steam_launches(target, program, root):
|
||||
"""Whether a launch option of the Steam game starts [program]: then Steam should start it."""
|
||||
if target.kind != "steam":
|
||||
@@ -292,24 +372,52 @@ def arguments(program, args):
|
||||
|
||||
def main(argv):
|
||||
window = False
|
||||
app, start, options = None, None, ""
|
||||
while argv and argv[0].startswith("--"):
|
||||
option = argv.pop(0)
|
||||
if option == "--window":
|
||||
window = True
|
||||
elif option in ("--app", "--dir", "--options") and argv:
|
||||
value = argv.pop(0)
|
||||
if option == "--app":
|
||||
app = value
|
||||
elif option == "--dir":
|
||||
start = value
|
||||
else:
|
||||
options = value
|
||||
elif option == "--":
|
||||
break
|
||||
else:
|
||||
say("unknown option %s" % option)
|
||||
return 2
|
||||
if not argv:
|
||||
if app is not None and not (app.isdigit() and 0 < int(app) < 2 ** 32):
|
||||
say("%s is not an app id" % app)
|
||||
return 2
|
||||
if not argv and app is None:
|
||||
say("usage: droiddeck-proton-run [--window] PROGRAM [ARGS...]")
|
||||
return 2
|
||||
program = os.path.abspath(argv[0])
|
||||
if not os.path.isfile(program):
|
||||
say("%s does not exist" % program)
|
||||
return 2
|
||||
root = os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or STEAM_ROOT
|
||||
target = locate(program, root)
|
||||
extra, args = split_options(options)
|
||||
if not argv:
|
||||
if int(app) >= STEAM_APP_LIMIT:
|
||||
say("shortcut %s needs its program" % app)
|
||||
return 2
|
||||
found = steam_launch(app, root)
|
||||
if found is None:
|
||||
say("Steam game %s is not installed, or has no Windows launch option" % app)
|
||||
return 2
|
||||
target, program, own = found
|
||||
args = own + args
|
||||
else:
|
||||
program = os.path.abspath(argv[0])
|
||||
if not os.path.isfile(program):
|
||||
say("%s does not exist" % program)
|
||||
return 2
|
||||
args = args + argv[1:]
|
||||
if app is not None and int(app) >= STEAM_APP_LIMIT:
|
||||
target = shortcut_target(app, program, start, root)
|
||||
else:
|
||||
target = locate(program, root)
|
||||
available = tools(root)
|
||||
name, why = choose_tool(target.appid, mapping(root), available)
|
||||
if name is None:
|
||||
@@ -318,13 +426,15 @@ def main(argv):
|
||||
folder, command = available[name]
|
||||
os.makedirs(target.compatdata, exist_ok=True)
|
||||
env = environment(os.environ, target, folder, root, window)
|
||||
say("%s with %s (%s), %s prefix %s" % (program, name, why, target.kind, target.compatdata))
|
||||
env.update(extra)
|
||||
say("%s with %s (%s), %s prefix %s%s" % (program, name, why, target.kind, target.compatdata,
|
||||
", without the Steam client" if app is not None else ""))
|
||||
try:
|
||||
os.chdir(target.start)
|
||||
except OSError:
|
||||
os.chdir(os.path.dirname(program))
|
||||
entry = os.path.join(folder, command)
|
||||
os.execve(entry, [entry, VERB] + arguments(program, argv[1:]), env)
|
||||
os.execve(entry, [entry, VERB] + arguments(program, args), env)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -6,9 +6,11 @@ LIBRARIES=${DROIDDECK_LIBRARIES-/mnt/droiddeck /mnt/droiddeck-sd}
|
||||
redist="$steam_root/steamapps/common/Steamworks Shared/_CommonRedist"
|
||||
|
||||
read_scripts() { xargs -0 -r awk -v want="${1:-redists}" '
|
||||
FNR == 1 { depth = 0; pending = "" }
|
||||
/^[[:space:]]*\{/ { depth++; name[depth] = pending; key[depth] = ""; vulkan[depth] = 0; pending = ""; next }
|
||||
FNR == 1 { depth = 0; pending = ""; appid = "" }
|
||||
/^[[:space:]]*\{/ { depth++; name[depth] = pending; key[depth] = ""; vulkan[depth] = 0; proc[depth] = 0; pending = ""; next }
|
||||
/^[[:space:]]*\}/ {
|
||||
if (depth > 0 && key[depth] == "" && proc[depth] && appid != "" && name[depth] != "" && vulkan[depth] == (want == "vulkan"))
|
||||
printf "HKEY_LOCAL_MACHINE\\\\Software\\\\Valve\\\\Steam\\\\Apps\\\\%s\t%s\n", appid, name[depth]
|
||||
if (depth > 0 && key[depth] != "" && name[depth] != "" && vulkan[depth] == (want == "vulkan"))
|
||||
printf "%s\t%s\n", key[depth], name[depth]
|
||||
if (depth > 0) depth--
|
||||
@@ -16,8 +18,10 @@ read_scripts() { xargs -0 -r awk -v want="${1:-redists}" '
|
||||
}
|
||||
{
|
||||
n = split($0, part, "\"")
|
||||
if (n >= 5 && tolower(part[2]) == "appid" && part[4] ~ /^[0-9]+$/) { appid = part[4]; next }
|
||||
if (n >= 5 && tolower(part[2]) == "hasrunkey") { key[depth] = part[4]; next }
|
||||
if (n >= 5 && tolower(part[2]) ~ /^process [0-9]+$/) {
|
||||
proc[depth] = 1
|
||||
program = tolower(part[4])
|
||||
sub(/.*[\\\/]/, "", program)
|
||||
if (program ~ /vulkan/) vulkan[depth] = 1
|
||||
|
||||
@@ -43,9 +43,9 @@ prepare_locale() {
|
||||
|
||||
clear_stale_tmp() {
|
||||
local running names=() n
|
||||
running=$(pgrep -af 'steamwebhelper|steamrtarm64/steam|--type=|droiddeck-appimage-run|dbus-run-session|dbus-daemon.*--session|dbus-launch|kwin|plasmashell' 2>/dev/null)
|
||||
running=$(pgrep -af 'steamwebhelper|steamrtarm64/steam|steamrt64/steam|--type=|droiddeck-appimage-run|dbus-run-session|dbus-daemon.*--session|dbus-launch|kwin|plasmashell' 2>/dev/null)
|
||||
case $running in
|
||||
*steamwebhelper* | *steamrtarm64/steam*) ;;
|
||||
*steamwebhelper* | *steamrtarm64/steam* | *steamrt64/steam*) ;;
|
||||
*) names+=(-o -name 'mangohud.????????' -o -name '.com.valvesoftware.Steam.??????'
|
||||
-o -name 'steam_chrome_shmem_uid*' -o \( -type d -empty -name 'steam??????' \)) ;;
|
||||
esac
|
||||
@@ -89,10 +89,11 @@ run_gamescope() (
|
||||
collect_steam_logs() {
|
||||
[ -n "${BL_DEBUG_DIR:-}" ] || return 0
|
||||
local steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam
|
||||
[ "${steam_x64:-0}" = 1 ] && steam_root=${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam
|
||||
mkdir -p "$BL_DEBUG_DIR/steam" 2>/dev/null || return 0
|
||||
[ -d "$steam_root/logs" ] && find "$steam_root/logs" -maxdepth 1 -type f -size -8192k \
|
||||
-exec cp {} "$BL_DEBUG_DIR/steam/" \; 2>/dev/null
|
||||
[ -f "$HOME/.steam/steam/logs/steamwebhelper.log" ] && cp "$HOME/.steam/steam/logs/steamwebhelper.log" "$BL_DEBUG_DIR/steam/" 2>/dev/null
|
||||
[ "${steam_x64:-0}" = 0 ] && [ -f "$HOME/.steam/steam/logs/steamwebhelper.log" ] && cp "$HOME/.steam/steam/logs/steamwebhelper.log" "$BL_DEBUG_DIR/steam/" 2>/dev/null
|
||||
local sync_store=$HOME/.local/share/droiddeck-esync sync_file
|
||||
if [ -d "$sync_store" ] && mkdir -p "$BL_DEBUG_DIR/droiddeck-esync" 2>/dev/null; then
|
||||
for sync_file in launches.log tools.tsv wanted.tsv prefixes.json; do
|
||||
@@ -428,6 +429,24 @@ case $mode in
|
||||
taskset -cp "$cores" $$ >/dev/null 2>&1 || true
|
||||
fi
|
||||
python3 /usr/local/bin/droiddeck-pad-defaults 2>&1 || true
|
||||
run_program() {
|
||||
local rc=0 child sig forwarded=0
|
||||
{ trap - INT QUIT; exec "$@"; } <&0 &
|
||||
child=$!
|
||||
for sig in TERM HUP INT; do
|
||||
trap "kill -$sig $child 2>/dev/null; forwarded=1" "$sig"
|
||||
done
|
||||
while :; do
|
||||
forwarded=0
|
||||
rc=0
|
||||
wait "$child" || rc=$?
|
||||
[ "$forwarded" = 1 ] || break
|
||||
done
|
||||
if [ -n "${BL_LAUNCH_DIR:-}" ]; then
|
||||
printf '%s\n' "$rc" > "$BL_LAUNCH_DIR/run-status.tmp" && mv -f "$BL_LAUNCH_DIR/run-status.tmp" "$BL_LAUNCH_DIR/run-status"
|
||||
fi
|
||||
exit "$rc"
|
||||
}
|
||||
fex=()
|
||||
if [ -x /usr/local/bin/droiddeck-fex ]; then
|
||||
case $(od -An -tu2 -j18 -N2 "$target" 2>/dev/null | tr -d ' ') in
|
||||
@@ -438,32 +457,67 @@ case $mode in
|
||||
*.appimage)
|
||||
export APPIMAGE_EXTRACT_AND_RUN=1
|
||||
chmod +x "$target" 2>/dev/null
|
||||
exec "${fex[@]}" "$target" "$@"
|
||||
run_program "${fex[@]}" "$target" "$@"
|
||||
;;
|
||||
*.sh)
|
||||
if [ -x /usr/local/bin/droiddeck-fex ]; then
|
||||
exec /usr/local/bin/droiddeck-fex run --for "$target" -- bash "$target" "$@"
|
||||
run_program /usr/local/bin/droiddeck-fex run --for "$target" -- bash "$target" "$@"
|
||||
fi
|
||||
exec bash "$target" "$@"
|
||||
run_program bash "$target" "$@"
|
||||
;;
|
||||
*)
|
||||
chmod +x "$target" 2>/dev/null
|
||||
cd "$(dirname "$target")" && exec "${fex[@]}" "$target" "$@"
|
||||
cd "$(dirname "$target")" && run_program "${fex[@]}" "$target" "$@"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
steam)
|
||||
step "checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)"
|
||||
droiddeck-steam-install || exit $?
|
||||
step "Steam client ready"
|
||||
steam_root=$XDG_DATA_HOME/Steam
|
||||
steam_x64=0
|
||||
[ "${BL_STEAM_CLIENT_ARCH:-}" = x86_64 ] && steam_x64=1
|
||||
steam_cef_gpu=1
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
step "checking the Steam client's arm64 parts (first run downloads them, ~1-2 min)"
|
||||
# droiddeck-steam-install removes the repair request: read it first so Repair Steam covers both clients.
|
||||
_bl_x64_repair=0
|
||||
[ -e "$HOME/.bl-steam-repair" ] && _bl_x64_repair=1
|
||||
droiddeck-steam-install || exit $?
|
||||
droiddeck-steam-install --sync steamdeck_publicbeta || step "could not update the arm64 client's parts; the x86-64 client keeps its own web helper"
|
||||
step "checking the x86-64 Steam client (FEX, experimental; the first run downloads ~2 GB)"
|
||||
BL_X64_REPAIR=$_bl_x64_repair droiddeck-steam-x64 --prepare || exit $?
|
||||
step "x86-64 Steam client ready"
|
||||
steam_root=${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam
|
||||
steam_client=(droiddeck-steam-x64 --exec)
|
||||
if [ "${BL_X64_X86_WEBHELPER:-0}" = 1 ] &&
|
||||
! droiddeck-steam-x64 --webhelper-gpu; then
|
||||
steam_cef_gpu=0
|
||||
fi
|
||||
else
|
||||
step "checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)"
|
||||
droiddeck-steam-install || exit $?
|
||||
step "Steam client ready"
|
||||
steam_root=$XDG_DATA_HOME/Steam
|
||||
if [ -f "${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam/local.vdf" ]; then
|
||||
droiddeck-steam-x64 --sync-login || true
|
||||
fi
|
||||
steam_client=("$steam_root/steamrtarm64/steam")
|
||||
fi
|
||||
_bl_proton_root=$steam_root
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
_bl_proton_root=$XDG_DATA_HOME/Steam
|
||||
if ! ls -d "$_bl_proton_root"/compatibilitytools.d/GE-Proton*-aarch64 >/dev/null 2>&1 &&
|
||||
! grep -q '^ge' "$HOME/.bl-proton-extra" 2>/dev/null; then
|
||||
echo ge >> "$HOME/.bl-proton-extra"
|
||||
fi
|
||||
fi
|
||||
if [ -s "$HOME/.bl-proton-extra" ]; then
|
||||
_bl_left=$HOME/.bl-proton-extra.left
|
||||
: > "$_bl_left"
|
||||
_bl_got_proton=0
|
||||
while read -r _bl_extra || [ -n "$_bl_extra" ]; do
|
||||
case ${_bl_extra# } in ""|"#"*) continue ;; esac
|
||||
step "installing Proton '$_bl_extra' (large download, several minutes)"
|
||||
if droiddeck-proton-extra "$steam_root" $_bl_extra; then
|
||||
if droiddeck-proton-extra "$_bl_proton_root" $_bl_extra; then
|
||||
_bl_got_proton=1
|
||||
step "installed Proton '$_bl_extra'"
|
||||
else
|
||||
step "Proton '$_bl_extra' failed; will retry next session"
|
||||
@@ -471,6 +525,9 @@ case $mode in
|
||||
fi
|
||||
done < "$HOME/.bl-proton-extra"
|
||||
mv -f "$_bl_left" "$HOME/.bl-proton-extra"
|
||||
if [ "$steam_x64" = 1 ] && [ "$_bl_got_proton" = 1 ]; then
|
||||
droiddeck-steam-x64 --prepare || true
|
||||
fi
|
||||
fi
|
||||
if [ -s "$HOME/.bl-steam-urls" ]; then
|
||||
while read -r _bl_url || [ -n "$_bl_url" ]; do
|
||||
@@ -490,7 +547,9 @@ case $mode in
|
||||
bl_zram_scan() {
|
||||
_bl_game=0 _bl_pids=()
|
||||
for _d in /proc/[0-9]*; do
|
||||
IFS= read -r -d '' _c 2>/dev/null < "$_d/cmdline" || continue
|
||||
# Under FEX the program is FEX's first argument.
|
||||
{ IFS= read -r -d '' _c && case ${_c##*/} in FEX|FEXInterpreter) IFS= read -r -d '' _c ;; esac; } \
|
||||
2>/dev/null < "$_d/cmdline" || continue
|
||||
case ${_c##*/} in
|
||||
reaper) _bl_game=1 ;;
|
||||
steam|steamwebhelper) _bl_pids+=("${_d#/proc/}") ;;
|
||||
@@ -539,6 +598,7 @@ case $mode in
|
||||
/usr/local/bin/droiddeck-launcher-cores "$BL_LAUNCH_DIR/agent/focus.json" 2>&1 &
|
||||
fi
|
||||
|
||||
if [ "$steam_x64" = 0 ]; then
|
||||
step "registering the app's game library with Steam"
|
||||
droiddeck-steam-library "$steam_root" || true
|
||||
step "setting up the ARM64 Proton compatibility tool"
|
||||
@@ -551,7 +611,22 @@ case $mode in
|
||||
droiddeck-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
|
||||
fi
|
||||
droiddeck-seed-redists "$steam_root" || true
|
||||
if [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then
|
||||
else
|
||||
_bl_x64_tool=$(droiddeck-steam-x64 --default-tool)
|
||||
if [ -n "$_bl_x64_tool" ]; then
|
||||
if [ -n "${BL_ADDED_GAMES:-}" ]; then
|
||||
step "adding the app's own games to the x86-64 client's library"
|
||||
BL_COMPAT_TOOL=$_bl_x64_tool droiddeck-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
|
||||
fi
|
||||
step "pointing the x86-64 client's Windows titles at $_bl_x64_tool"
|
||||
BL_COMPAT_TOOL=$_bl_x64_tool steam-compatibility "$steam_root" --x64 || true
|
||||
fi
|
||||
if [ -z "${BL_DESKTOP:-}" ] && [ "${BL_STEAM_UI:-}" != desktop ]; then
|
||||
droiddeck-steam-ui-scale "$steam_root" "${BL_WIDTH:-1280}" "${BL_HEIGHT:-720}" || true
|
||||
fi
|
||||
droiddeck-seed-redists "$steam_root" || true
|
||||
fi
|
||||
if [ "$steam_x64" = 0 ] && [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then
|
||||
step "asking the client to fetch the ARM64 Proton"
|
||||
set -- "$@" steam://install/4427310
|
||||
(
|
||||
@@ -563,7 +638,7 @@ case $mode in
|
||||
steam-compatibility "$steam_root" >/dev/null 2>&1 || true
|
||||
step "compatibility layer installed: restarting the Steam client once"
|
||||
: > "$HOME/.bl-restart-once"
|
||||
"$steam_root/steamrtarm64/steam" -shutdown >/dev/null 2>&1 || true
|
||||
"${steam_client[@]}" -shutdown >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
@@ -587,7 +662,7 @@ case $mode in
|
||||
sleep 10
|
||||
[ -f "$_bl_acf" ] && exit 0
|
||||
step "signed in: asking the client again for the ARM64 Proton (try $_bl_try of 3)"
|
||||
"$steam_root/steamrtarm64/steam" steam://install/4427310 >/dev/null 2>&1 || true
|
||||
"${steam_client[@]}" steam://install/4427310 >/dev/null 2>&1 || true
|
||||
sleep 50
|
||||
done
|
||||
exit 0
|
||||
@@ -622,6 +697,9 @@ case $mode in
|
||||
if [ "$pv" != "$app" ]; then
|
||||
app=$pv
|
||||
echo "== focused app: $app (touch mode ${tmode:-unset}) at $(date +%T)"
|
||||
if [ -n "${BL_LAUNCH_DIR:-}" ]; then
|
||||
printf '%s\n' "$app" > "$BL_LAUNCH_DIR/steam-focused-app.tmp" && mv -f "$BL_LAUNCH_DIR/steam-focused-app.tmp" "$BL_LAUNCH_DIR/steam-focused-app"
|
||||
fi
|
||||
fi
|
||||
[ "$restore" = 1 ] || continue
|
||||
case $pv in ''|*[!0-9]*) prev=; continue ;; esac
|
||||
@@ -641,6 +719,44 @@ case $mode in
|
||||
esac
|
||||
done < <(xprop -spy -root "${atoms[@]}" 2>/dev/null)
|
||||
) &
|
||||
steam_hold_launch() {
|
||||
_bl_launch_ready=
|
||||
_bl_end=$((SECONDS + 120))
|
||||
until [ "$(xprop -root GAMESCOPE_FOCUSED_APP 2>/dev/null | sed -n 's/.*= *//p')" = 769 ] || [ "$SECONDS" -ge "$_bl_end" ]; do
|
||||
sleep 1
|
||||
done
|
||||
# With a large library the overview can stay missing for 30+ minutes while Steam already takes the launch URL.
|
||||
_bl_overview_status=1
|
||||
_bl_overview_tries=0
|
||||
while [ "$_bl_overview_tries" -lt 2 ]; do
|
||||
if /usr/local/bin/droiddeck-agent --wait-steam-shortcut-overview "$1" 45; then
|
||||
_bl_overview_status=0
|
||||
else
|
||||
_bl_overview_status=$?
|
||||
fi
|
||||
if [ "$_bl_overview_status" -ne 1 ]; then
|
||||
break
|
||||
fi
|
||||
_bl_overview_tries=$((_bl_overview_tries + 1))
|
||||
echo "== steam: shortcut overview not ready yet (attempt $_bl_overview_tries of 2)"
|
||||
sleep 2
|
||||
done
|
||||
if [ "$_bl_overview_status" -eq 0 ]; then
|
||||
echo "== steam: shortcut overview ready; launching the requested game $1"
|
||||
_bl_launch_ready=1
|
||||
elif [ "$_bl_overview_status" -eq 3 ]; then
|
||||
echo "== steam: not a shortcut CGameID; keeping the existing launch path"
|
||||
sleep 4
|
||||
_bl_launch_ready=1
|
||||
else
|
||||
echo "== steam: shortcut overview not ready after about 90 s; launching the requested game anyway $1"
|
||||
_bl_launch_ready=1
|
||||
fi
|
||||
if [ "$_bl_launch_ready" = 1 ]; then
|
||||
echo "== steam: interface up; launching the requested game $1"
|
||||
printf '%s\n' "$1" > "$BL_LAUNCH_DIR/steam-game.tmp" && mv -f "$BL_LAUNCH_DIR/steam-game.tmp" "$BL_LAUNCH_DIR/steam-game"
|
||||
fi
|
||||
}
|
||||
if [ -n "${BL_LAUNCH_DIR:-}" ] && [ -z "${BL_DESKTOP:-}" ]; then
|
||||
_bl_held=
|
||||
_bl_uninstall=
|
||||
@@ -666,30 +782,7 @@ case $mode in
|
||||
fi
|
||||
if [ -n "$_bl_held" ]; then
|
||||
set -- "${_bl_rest[@]}"
|
||||
(
|
||||
_bl_launch_ready=
|
||||
_bl_end=$((SECONDS + 120))
|
||||
until [ "$(xprop -root GAMESCOPE_FOCUSED_APP 2>/dev/null | sed -n 's/.*= *//p')" = 769 ] || [ "$SECONDS" -ge "$_bl_end" ]; do
|
||||
sleep 1
|
||||
done
|
||||
if /usr/local/bin/droiddeck-agent --wait-steam-shortcut-overview "$_bl_held" 45; then
|
||||
echo "== steam: shortcut overview ready; launching the requested game $_bl_held"
|
||||
_bl_launch_ready=1
|
||||
else
|
||||
_bl_overview_status=$?
|
||||
if [ "$_bl_overview_status" -eq 3 ]; then
|
||||
echo "== steam: not a shortcut CGameID; keeping the existing launch path"
|
||||
sleep 4
|
||||
_bl_launch_ready=1
|
||||
else
|
||||
echo "== steam: expected shortcut overview did not become ready; holding the launch URL"
|
||||
fi
|
||||
fi
|
||||
if [ "$_bl_launch_ready" = 1 ]; then
|
||||
echo "== steam: interface up; launching the requested game $_bl_held"
|
||||
printf '%s\n' "$_bl_held" > "$BL_LAUNCH_DIR/steam-game.tmp" && mv -f "$BL_LAUNCH_DIR/steam-game.tmp" "$BL_LAUNCH_DIR/steam-game"
|
||||
fi
|
||||
) &
|
||||
steam_hold_launch "$_bl_held" &
|
||||
fi
|
||||
fi
|
||||
if [ -s "$HOME/.bl-autolaunch" ]; then
|
||||
@@ -749,6 +842,10 @@ BUSCONF
|
||||
exit 69
|
||||
fi
|
||||
|
||||
# The UI bridge launches SteamVR, which needs the guest agent's library environment.
|
||||
_bl_compat_env=(env -u LD_LIBRARY_PATH -u STEAM_RUNTIME)
|
||||
[ "${LD_LIBRARY_PATH+x}" ] && _bl_compat_env+=("LD_LIBRARY_PATH=$LD_LIBRARY_PATH")
|
||||
[ "${STEAM_RUNTIME+x}" ] && _bl_compat_env+=("STEAM_RUNTIME=$STEAM_RUNTIME")
|
||||
export STEAM_RUNTIME=1
|
||||
export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
|
||||
export SDL_VIDEO_X11_DGAMOUSE=0
|
||||
@@ -813,25 +910,28 @@ BUSCONF
|
||||
echo "== steam: devtools port $BL_CDP_PORT, guest processes only"
|
||||
fi
|
||||
[ -n "${BL_LAUNCH_DIR:-}" ] && mkdir -p "$BL_LAUNCH_DIR/agent" && echo "$BL_CDP_PORT" > "$BL_LAUNCH_DIR/agent/cdp-port"
|
||||
droiddeck-steam-compat "$steam_root" 2>&1 &
|
||||
[ "$steam_x64" = 1 ] || "${_bl_compat_env[@]}" droiddeck-steam-compat "$steam_root" 2>&1 &
|
||||
_bl_ui=(-gamepadui)
|
||||
[ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=()
|
||||
# bl_steam_angle / bl_steam_presentation (set above) default to the Adreno values (vulkan,
|
||||
# none); only the system-PowerVR path (BL_STEAM_GL_PRESENT=1) changes them.
|
||||
_bl_cef=(-cef-force-gpu "${bl_steam_presentation[@]}" -cef-use-gl=angle "-cef-use-angle=${bl_steam_angle:-vulkan}")
|
||||
[ "${steam_cef_gpu:-1}" = 1 ] || _bl_cef=(-cef-disable-gpu)
|
||||
if [ "${BL_DESKTOP:-}" = 1 ] && [ "${BL_STEAM_UI:-}" = desktop ]; then
|
||||
_bl_cef=(-cef-disable-gpu)
|
||||
_bl_ui=(-nobigpicture)
|
||||
fi
|
||||
if [ "${BL_STEAM_UI:-}" != desktop ]; then
|
||||
_bl_ui+=(-steamdeck -steamos3)
|
||||
export STEAM_GAMESCOPE_NIS_SUPPORTED=1
|
||||
export STEAM_GAMESCOPE_FANCY_SCALING_SUPPORT=1
|
||||
echo "== steam: Deck mode on (-steamdeck -steamos3)"
|
||||
if [ "$steam_x64" = 0 ] || [ "${BL_X64_DECK:-1}" != 0 ]; then
|
||||
_bl_ui+=(-steamdeck -steamos3)
|
||||
export STEAM_GAMESCOPE_NIS_SUPPORTED=1
|
||||
export STEAM_GAMESCOPE_FANCY_SCALING_SUPPORT=1
|
||||
echo "== steam: Deck mode on (-steamdeck -steamos3)"
|
||||
fi
|
||||
fi
|
||||
export STEAMOS_STEAM_SHUTDOWN_SENTINEL="$HOME/.bl-steam-shutdown"
|
||||
export STEAMOS_STEAM_REBOOT_SENTINEL="$HOME/.bl-steam-reboot"
|
||||
if ! pgrep -f 'steamwebhelper|steamrtarm64/steam' >/dev/null 2>&1; then
|
||||
if ! pgrep -f 'steamwebhelper|steamrtarm64/steam|steamrt64/steam' >/dev/null 2>&1; then
|
||||
_stale=""
|
||||
for _f in "$steam_root/.crash" "$steam_root/steam.pid" \
|
||||
"$steam_root/config/htmlcache/SingletonLock" "$steam_root/config/htmlcache/SingletonCookie" \
|
||||
@@ -846,12 +946,93 @@ BUSCONF
|
||||
[ -n "${BL_STEAM_LANGUAGE:-}" ] && _bl_lang=(-language "$BL_STEAM_LANGUAGE")
|
||||
steam_beta=$steam_root/package/beta
|
||||
if [ -n "${BL_ADDED_GAMES:-}" ] && [ -f "$BL_ADDED_GAMES" ]; then
|
||||
droiddeck-steam-games watch "$steam_root" "$BL_ADDED_GAMES" &
|
||||
if [ "$steam_x64" = 0 ]; then
|
||||
droiddeck-steam-games watch "$steam_root" "$BL_ADDED_GAMES" &
|
||||
else
|
||||
BL_STEAMCLIENT=$XDG_DATA_HOME/Steam/steamrtarm64/steamclient.so \
|
||||
BL_STEAM_SHUTDOWN="droiddeck-steam-x64 --exec -shutdown" \
|
||||
droiddeck-steam-games watch "$steam_root" "$BL_ADDED_GAMES" &
|
||||
fi
|
||||
games_watcher=$!
|
||||
fi
|
||||
echo "== steam args: ${_bl_ui[*]} ${_bl_cdp[*]} ${_bl_lang[*]} -clientbeta $steam_channel -no-cef-sandbox -cef-ozone-platform=x11 ${_bl_cef[*]} $*"
|
||||
echo "== steam args: ${_bl_ui[*]} ${_bl_cdp[*]} ${_bl_lang[*]} -clientbeta $steam_channel -no-cef-sandbox -cef-ozone-platform=x11 ${_bl_cef[*]} $*$([ "$steam_x64" = 1 ] && echo ' (x86-64 client under FEX)')"
|
||||
steam_updates=0
|
||||
rm -f "$HOME/.bl-stop-requested" "$STEAMOS_STEAM_SHUTDOWN_SENTINEL" "$STEAMOS_STEAM_REBOOT_SENTINEL"
|
||||
steam_other_game_running() {
|
||||
local line value n open
|
||||
open=$(cat "$BL_LAUNCH_DIR/epic-open" 2>/dev/null)
|
||||
case $open in ?|*[!0-9]*) open=${BL_EPIC_APP_ID:-$open} ;; esac
|
||||
line=$(xprop -root GAMESCOPE_FOCUSABLE_APPS 2>/dev/null) || return 1
|
||||
case $line in *=*) value=${line#*= } ;; *) return 1 ;; esac
|
||||
for n in ${value//,/ }; do
|
||||
[ "$n" = 769 ] || [ "$n" = "$open" ] || return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
steam_restart_for() {
|
||||
if [ "$(cat "$HOME/.bl-restarted-for" 2>/dev/null)" = "$1" ]; then
|
||||
echo "== steam: $2, but Steam was already restarted for it; launching it anyway"
|
||||
return 1
|
||||
fi
|
||||
printf '%s\n' "$1" > "$HOME/.bl-restarted-for"
|
||||
echo "== steam: $2; restarting Steam to launch it"
|
||||
printf '%s\n' "$1" > "$HOME/.bl-restart-game"
|
||||
"${steam_client[@]:-$steam_root/steamrtarm64/steam}" -shutdown >/dev/null 2>&1
|
||||
}
|
||||
steam_launch_game() {
|
||||
local state=0 tries
|
||||
/usr/local/bin/droiddeck-agent --steam-shortcut-state "$1" 6 >/dev/null 2>&1 || state=$?
|
||||
[ "$state" -eq 0 ] && rm -f "$HOME/.bl-restarted-for"
|
||||
if [ "$state" -eq 4 ]; then
|
||||
if steam_other_game_running; then
|
||||
echo "== steam: the client lost shortcut $1, but a game is running; launching it anyway"
|
||||
elif steam_restart_for "$1" "the client lost shortcut $1"; then
|
||||
return
|
||||
fi
|
||||
fi
|
||||
"${steam_client[@]:-$steam_root/steamrtarm64/steam}" "steam://rungameid/$1" >/dev/null 2>&1
|
||||
[ "$state" -eq 3 ] && return
|
||||
for tries in 1 2 3 4 5 6 7 8; do
|
||||
nap 1
|
||||
state=0
|
||||
/usr/local/bin/droiddeck-agent --steam-shortcut-state "$1" 1 >/dev/null 2>&1 || state=$?
|
||||
[ "$state" -eq 4 ] || continue
|
||||
if steam_other_game_running; then
|
||||
echo "== steam: the client dropped shortcut $1 while launching it, but a game is running"
|
||||
else
|
||||
steam_restart_for "$1" "the client dropped shortcut $1 while launching it"
|
||||
fi
|
||||
return 0
|
||||
done
|
||||
}
|
||||
steam_check_exits() {
|
||||
local ran n state lost=
|
||||
ran=$(pgrep -a -f 'SteamLaunch AppId=[0-9]' 2>/dev/null | sed -n 's/.* SteamLaunch AppId=\([0-9]*\).*/\1/p')
|
||||
if [ -n "$ran" ]; then
|
||||
for n in $ran; do
|
||||
[ "$n" -ge 2147483648 ] && _bl_ran[$n]=1
|
||||
done
|
||||
_bl_exited=
|
||||
return
|
||||
fi
|
||||
[ "${#_bl_ran[@]}" -gt 0 ] || return 0
|
||||
if [ -z "$_bl_exited" ]; then
|
||||
_bl_exited=1
|
||||
return
|
||||
fi
|
||||
_bl_exited=
|
||||
for n in "${!_bl_ran[@]}"; do
|
||||
state=0
|
||||
/usr/local/bin/droiddeck-agent --steam-shortcut-state "$(printf '%u' $(((n << 32) | 0x02000000)))" 3 >/dev/null 2>&1 || state=$?
|
||||
[ "$state" -eq 4 ] && lost="$lost $n"
|
||||
done
|
||||
_bl_ran=()
|
||||
[ -n "$lost" ] || return 0
|
||||
pgrep -f 'SteamLaunch AppId=[0-9]' >/dev/null 2>&1 && return 0
|
||||
echo "== steam: the client dropped shortcut(s)$lost when they exited; restarting Steam so it lists them again"
|
||||
: > "$HOME/.bl-restart-lost"
|
||||
"${steam_client[@]:-$steam_root/steamrtarm64/steam}" -shutdown >/dev/null 2>&1
|
||||
}
|
||||
steam_bring_forward() {
|
||||
local end=$((SECONDS + 600)) behind=0 line name value focused other n
|
||||
while [ "$SECONDS" -lt "$end" ]; do
|
||||
@@ -891,6 +1072,8 @@ BUSCONF
|
||||
rm -f "$lossless_asked"
|
||||
[ "${BL_LOSSLESS_OWNED:-0}" != 1 ] && lossless_left=60
|
||||
declare -A _bl_pinned=()
|
||||
declare -A _bl_ran=()
|
||||
_bl_exited=
|
||||
compat_stamp=$HOME/.bl-compat-beat
|
||||
seed_stamp=$HOME/.bl-seed-beat
|
||||
rm -f "$compat_stamp" "$seed_stamp"
|
||||
@@ -921,13 +1104,34 @@ BUSCONF
|
||||
done
|
||||
return 1
|
||||
}
|
||||
compat_pending=$HOME/.bl-compat-pending
|
||||
compat_restarted=$HOME/.bl-compat-restarted
|
||||
rm -f "$compat_pending"
|
||||
: > "$compat_restarted"
|
||||
compat_restarts=0
|
||||
compat_settled() {
|
||||
local app m flags r card=/mnt/droiddeck-sd
|
||||
# The arm64 card library may hold that client's copy of the same title.
|
||||
[ "$steam_x64" = 1 ] && card=/mnt/droiddeck-sd/x86-64
|
||||
while read -r app; do
|
||||
[ -n "$app" ] || continue
|
||||
m=
|
||||
for r in "$steam_root" "$card"; do
|
||||
[ -f "$r/steamapps/appmanifest_$app.acf" ] && { m=$r/steamapps/appmanifest_$app.acf; break; }
|
||||
done
|
||||
[ -n "$m" ] || return 1
|
||||
flags=$(sed -n 's/^[[:space:]]*"StateFlags"[[:space:]]*"\([0-9]*\)".*/\1/p' "$m" | head -n 1)
|
||||
[ "$flags" = 4 ] || return 1
|
||||
done < "$compat_pending"
|
||||
! pgrep -f 'reaper SteamLaunch' >/dev/null 2>&1
|
||||
}
|
||||
while :; do
|
||||
if [ -n "$requests" ]; then
|
||||
if [ -e "$BL_LAUNCH_DIR/steam-stop" ]; then
|
||||
rm -f "$BL_LAUNCH_DIR/steam-stop"
|
||||
: > "$HOME/.bl-stop-requested"
|
||||
echo "== steam: the app asked for a clean exit"
|
||||
"$steam_root/steamrtarm64/steam" -shutdown >/dev/null 2>&1 || true
|
||||
"${steam_client[@]}" -shutdown >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
fi
|
||||
if [ -f "$BL_LAUNCH_DIR/steam-uninstall" ]; then
|
||||
@@ -937,7 +1141,7 @@ BUSCONF
|
||||
''|0*|*[!0-9]*|???????????*) echo "== steam: ignored invalid uninstall request" ;;
|
||||
*)
|
||||
echo "== steam: opening the uninstall dialog for $uninstall_id"
|
||||
"$steam_root/steamrtarm64/steam" "steam://uninstall/$uninstall_id" >/dev/null 2>&1 &
|
||||
"${steam_client[@]}" "steam://uninstall/$uninstall_id" >/dev/null 2>&1 &
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
@@ -952,7 +1156,7 @@ BUSCONF
|
||||
[ "$game_id_length" -eq 20 ] && [[ "$game_id" < "18446744073709551616" ]];
|
||||
}; then
|
||||
echo "== steam: launching requested game $game_id in the running client"
|
||||
"$steam_root/steamrtarm64/steam" "steam://rungameid/$game_id" >/dev/null 2>&1 &
|
||||
steam_launch_game "$game_id" &
|
||||
[ -n "${forward_pid:-}" ] && kill "$forward_pid" 2>/dev/null
|
||||
steam_bring_forward &
|
||||
forward_pid=$!
|
||||
@@ -967,10 +1171,12 @@ BUSCONF
|
||||
tick=$((tick + 1))
|
||||
[ "$((tick % 10))" -eq 0 ] || continue
|
||||
beat=$((beat + 1))
|
||||
steam_check_exits
|
||||
if [ "$beat" -le 720 ] && [ -n "${BL_CLIENT_CPUS:-}" ]; then
|
||||
for _d in /proc/[0-9]*; do
|
||||
IFS= read -r -d '' _c < "$_d/cmdline" 2>/dev/null || continue
|
||||
case $_c in *steamwebhelper*|*steamrtarm64/steam|*gamescope*) ;; *) continue ;; esac
|
||||
{ IFS= read -r -d '' _c && { IFS= read -r -d '' _c1 || _c1=; }; } < "$_d/cmdline" 2>/dev/null || continue
|
||||
case $_c in FEX|*/FEX|FEXInterpreter|*/FEXInterpreter) _c=$_c1 ;; esac
|
||||
case $_c in *steamwebhelper*|*steamrtarm64/steam|*steamrt64/steam|*gamescope*) ;; *) continue ;; esac
|
||||
_t=("$_d"/task/*)
|
||||
_p=${_d#/proc/}
|
||||
[ "${_bl_pinned[$_p]:-}" = "${#_t[@]}" ] && client_single_core_matches "$BL_CLIENT_CPUS" "${_t[@]}" && continue
|
||||
@@ -988,17 +1194,42 @@ BUSCONF
|
||||
[ -n "$compat" ] && : > "$compat_stamp"
|
||||
(
|
||||
[ -z "$seed" ] || droiddeck-seed-redists "$steam_root" >/dev/null 2>&1 || true
|
||||
[ -z "$compat" ] || steam-compatibility "$steam_root" >/dev/null 2>&1 || true
|
||||
if [ -n "$compat" ]; then
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
[ -z "${_bl_x64_tool:-}" ] ||
|
||||
BL_COMPAT_TOOL=$_bl_x64_tool steam-compatibility "$steam_root" --x64 --live >/dev/null 2>&1 || true
|
||||
droiddeck-steam-x64 --map-direct --live >/dev/null 2>&1 || true
|
||||
else
|
||||
steam-compatibility "$steam_root" >/dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
) &
|
||||
library_job=$!
|
||||
fi
|
||||
fi
|
||||
if [ "$((beat % 3))" -eq 0 ] && [ -s "$compat_pending" ] && [ "$compat_restarts" -lt 3 ] && compat_settled; then
|
||||
_bl_new=$(sort -u "$compat_pending" | grep -vxF -f "$compat_restarted" || true)
|
||||
rm -f "$compat_pending"
|
||||
if [ -n "$_bl_new" ]; then
|
||||
compat_restarts=$((compat_restarts + 1))
|
||||
printf '%s\n' $_bl_new >> "$compat_restarted"
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
step "newly installed title(s) $(echo $_bl_new) set to an ARM64 Proton (Windows builds) or DroidDeck direct (Linux builds): restarting the Steam client once so it takes effect"
|
||||
else
|
||||
step "newly installed title(s) $(echo $_bl_new) set to the ARM64 Proton: restarting the Steam client once so it takes effect"
|
||||
fi
|
||||
: > "$HOME/.bl-restart-once"
|
||||
"${steam_client[@]}" -shutdown >/dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
if [ "$lossless_left" -gt 0 ] && [ "$((beat % 6))" -eq 0 ] && { [ -z "$lossless_job" ] || ! kill -0 "$lossless_job" 2>/dev/null; }; then
|
||||
lossless_left=$((lossless_left - 1))
|
||||
if [ -e "$lossless_owned" ] || [ -e "$lossless_asked" ]; then
|
||||
lossless_left=0
|
||||
elif ! pgrep -x wineserver >/dev/null 2>&1; then
|
||||
(
|
||||
# The probe reaches the x86-64 client through the arm64 client's steamclient.so, as the import watcher does.
|
||||
if [ "$steam_x64" = 1 ]; then export BL_STEAMCLIENT=$XDG_DATA_HOME/Steam/steamrtarm64/steamclient.so; fi
|
||||
answer=$(droiddeck-steam-games probe "$steam_root" 993090 2>/dev/null) || exit 0
|
||||
case $answer in
|
||||
*'"993090": true'*) mkdir -p "${lossless_owned%/*}" && : > "$lossless_owned" && echo "== Lossless Scaling: owned" ;;
|
||||
@@ -1042,8 +1273,9 @@ BUSCONF
|
||||
unset bl_gl_ok bl_variant bl_kv
|
||||
fi
|
||||
fi
|
||||
rm -f "$HOME/.bl-restart-game" "$HOME/.bl-restarted-for"
|
||||
while :; do
|
||||
rm -f "$HOME/.bl-restart-once"
|
||||
rm -f "$HOME/.bl-restart-once" "$HOME/.bl-restart-lost"
|
||||
if [ -f "$steam_beta" ] && [ "$(cat "$steam_beta" 2>/dev/null)" != "$steam_channel" ]; then
|
||||
echo "== steam: client branch on disk was '$(cat "$steam_beta" 2>/dev/null)', set to '$steam_channel' to match -clientbeta"
|
||||
echo "$steam_channel" > "$steam_beta"
|
||||
@@ -1053,7 +1285,11 @@ BUSCONF
|
||||
_bl_counted=1
|
||||
fi
|
||||
if [ -n "${BL_STEAM_LANGUAGE:-}" ]; then
|
||||
droiddeck-steam-language "$HOME" "$BL_STEAM_LANGUAGE" || true
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
droiddeck-steam-language "${BL_X64_HOME:-$HOME/.droiddeck-x64}" "$BL_STEAM_LANGUAGE" || true
|
||||
else
|
||||
droiddeck-steam-language "$HOME" "$BL_STEAM_LANGUAGE" || true
|
||||
fi
|
||||
fi
|
||||
step "starting the Steam client${BL_STEAM_UI:+ ($BL_STEAM_UI UI)}"
|
||||
desktop_ui_pid=
|
||||
@@ -1064,7 +1300,7 @@ BUSCONF
|
||||
steam_started=$SECONDS
|
||||
PATH="$bl_steam_path" \
|
||||
BL_STEAM_WEBHELPER="$steam_root/steamrtarm64/steamwebhelper" \
|
||||
"$steam_root/steamrtarm64/steam" "${_bl_ui[@]}" "${_bl_cdp[@]}" "${_bl_lang[@]}" -clientbeta "$steam_channel" \
|
||||
"${steam_client[@]}" "${_bl_ui[@]}" "${_bl_cdp[@]}" "${_bl_lang[@]}" -clientbeta "$steam_channel" \
|
||||
-no-cef-sandbox -cef-ozone-platform=x11 "${_bl_cef[@]}" "$@"
|
||||
rc=$?
|
||||
steam_ran=$((SECONDS - steam_started))
|
||||
@@ -1073,13 +1309,23 @@ BUSCONF
|
||||
wait "$desktop_ui_pid" 2>/dev/null || true
|
||||
fi
|
||||
echo "== steam exited rc=$rc"
|
||||
if [ -n "${BL_ADDED_GAMES:-}" ] && [ -f "$BL_ADDED_GAMES" ]; then
|
||||
droiddeck-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
|
||||
fi
|
||||
collect_steam_logs
|
||||
if [ -f "$HOME/.config/droiddeck/fex-wanted" ] && [ -x /usr/local/bin/droiddeck-fex ]; then
|
||||
/usr/local/bin/droiddeck-fex status >/dev/null 2>&1 || true
|
||||
fi
|
||||
if [ -n "${BL_ADDED_GAMES:-}" ] && [ -f "$BL_ADDED_GAMES" ]; then
|
||||
if [ "$steam_x64" = 0 ]; then
|
||||
droiddeck-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
|
||||
elif [ -n "${_bl_x64_tool:-}" ]; then
|
||||
BL_COMPAT_TOOL=$_bl_x64_tool droiddeck-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
|
||||
fi
|
||||
fi
|
||||
# The x86-64 client rewrote config.vdf from memory on exit, over the live passes' mapping.
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
[ -z "${_bl_x64_tool:-}" ] ||
|
||||
BL_COMPAT_TOOL=$_bl_x64_tool steam-compatibility "$steam_root" --x64 >/dev/null 2>&1 || true
|
||||
droiddeck-steam-x64 --map-direct || true
|
||||
fi
|
||||
if [ -f "$HOME/.bl-stop-requested" ]; then
|
||||
rm -f "$HOME/.bl-stop-requested" "$HOME/.bl-restart-once"
|
||||
break
|
||||
@@ -1096,6 +1342,25 @@ BUSCONF
|
||||
set --
|
||||
continue
|
||||
fi
|
||||
if [ -s "$HOME/.bl-restart-game" ]; then
|
||||
_bl_again=$(cat "$HOME/.bl-restart-game" 2>/dev/null)
|
||||
rm -f "$HOME/.bl-restart-game"
|
||||
case $_bl_again in
|
||||
''|0*|*[!0-9]*) ;;
|
||||
*)
|
||||
echo "== steam: starting the client again to launch $_bl_again"
|
||||
set --
|
||||
steam_hold_launch "$_bl_again" &
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
if [ -f "$HOME/.bl-restart-lost" ]; then
|
||||
rm -f "$HOME/.bl-restart-lost"
|
||||
echo "== steam: starting the client again so it lists every shortcut"
|
||||
set --
|
||||
continue
|
||||
fi
|
||||
if [ -f "$HOME/.bl-restart-once" ]; then
|
||||
echo "== steam: restarting once so the new compatibility layer is in the client's lists"
|
||||
set --
|
||||
|
||||
@@ -126,6 +126,29 @@ INSTALL_JS = r"""
|
||||
return "installed";
|
||||
})()
|
||||
""".replace("__BINDING__", BINDING)
|
||||
TOOLS_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckTools) return "present";
|
||||
const installs = SteamClient.Installs, downloads = SteamClient.Downloads;
|
||||
if (typeof installs?.OpenInstallWizard !== "function" || typeof installs?.RegisterForShowInstallWizard !== "function" ||
|
||||
typeof installs?.ContinueInstall !== "function" || typeof downloads?.QueueAppUpdate !== "function")
|
||||
throw new Error("the client's install calls are not ready");
|
||||
const self = { asked: new Map() };
|
||||
installs.RegisterForShowInstallWizard((state) => {
|
||||
const app = Number(state?.currentAppID);
|
||||
if (state?.eInstallState === 7 && Date.now() - (self.asked.get(app) || 0) < 120000) {
|
||||
self.asked.delete(app);
|
||||
installs.ContinueInstall();
|
||||
}
|
||||
});
|
||||
self.install = (app) => { self.asked.set(app, Date.now()); installs.OpenInstallWizard([app], "0"); return true; };
|
||||
self.update = (app) => { downloads.QueueAppUpdate(app, "0"); return true; };
|
||||
window.__droiddeckTools = self;
|
||||
return "installed";
|
||||
})()
|
||||
"""
|
||||
TOOL_CHECK_SECONDS = 60
|
||||
TOOL_RETRY_SECONDS = 300
|
||||
SWITCH_BINDING = "droiddeckSwitchToDesktop"
|
||||
SWITCH_JS = r"""
|
||||
(() => {
|
||||
@@ -153,6 +176,82 @@ SWITCH_JS = r"""
|
||||
})()
|
||||
""".replace("__BINDING__", SWITCH_BINDING)
|
||||
SESSION_SELECT = "/usr/bin/steamos-session-select"
|
||||
VR_BINDING = "droiddeckLaunchSteamVr"
|
||||
VR_HELPER = "/usr/local/bin/droiddeck-steamvr"
|
||||
VR_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckSteamVr) return "present";
|
||||
const apps = SteamClient.Apps;
|
||||
if (!apps || typeof apps.RunGame !== "function") throw new Error("Steam RunGame is not ready");
|
||||
const run = apps.RunGame;
|
||||
const self = { running: false, pending: new Map(), lastError: null };
|
||||
const flush = () => {
|
||||
if (!self.running) return;
|
||||
const queued = Array.from(self.pending.values());
|
||||
self.pending.clear();
|
||||
for (const item of queued) {
|
||||
clearTimeout(item.timer);
|
||||
run.call(item.receiver, item.id, ...item.args);
|
||||
}
|
||||
};
|
||||
if (typeof SteamClient.OpenVR?.RegisterForVRModeChange === "function") {
|
||||
self.subscription = SteamClient.OpenVR.RegisterForVRModeChange(running => {
|
||||
self.running = !!running;
|
||||
flush();
|
||||
});
|
||||
}
|
||||
const wrapped = function (id, ...args) {
|
||||
const gameid = String(id);
|
||||
if (typeof window.__BINDING__ !== "function") return run.call(this, id, ...args);
|
||||
if (gameid === "250820") {
|
||||
window.__BINDING__(gameid);
|
||||
return;
|
||||
}
|
||||
const overview = window.appStore?.GetAppOverviewByGameID?.(gameid);
|
||||
const vr = overview?.vr_only === true;
|
||||
if (vr && self.subscription && /^[1-9][0-9]{0,19}$/.test(gameid)) {
|
||||
if (self.pending.has(gameid)) return;
|
||||
self.lastError = null;
|
||||
const item = { receiver: this, id, args, timer: null };
|
||||
item.timer = setTimeout(() => {
|
||||
self.pending.delete(gameid);
|
||||
self.lastError = "SteamVR did not become ready. Start SteamVR from DroidDeck and try the game again.";
|
||||
console.error("DroidDeck: " + self.lastError);
|
||||
}, 600000);
|
||||
self.pending.set(gameid, item);
|
||||
try { window.__BINDING__(gameid); }
|
||||
catch (e) { clearTimeout(item.timer); self.pending.delete(gameid); throw e; }
|
||||
flush();
|
||||
return;
|
||||
}
|
||||
return run.call(this, id, ...args);
|
||||
};
|
||||
apps.RunGame = wrapped;
|
||||
if (apps.RunGame !== wrapped) throw new Error("Steam RunGame could not be redirected");
|
||||
if (typeof SteamClient.OpenVR?.StartVR === "function") {
|
||||
const start = SteamClient.OpenVR.StartVR;
|
||||
SteamClient.OpenVR.StartVR = function (...args) {
|
||||
if (typeof window.__BINDING__ === "function") return window.__BINDING__("250820");
|
||||
return start.apply(this, args);
|
||||
};
|
||||
}
|
||||
window.__droiddeckSteamVr = self;
|
||||
return "installed";
|
||||
})()
|
||||
""".replace("__BINDING__", VR_BINDING)
|
||||
|
||||
|
||||
def launch_steamvr():
|
||||
"""Keep downloads/startup off the Steam UI bridge's event loop."""
|
||||
say("SteamVR library launch: using the DroidDeck ARM64 helper")
|
||||
state = os.path.join(os.environ.get("XDG_RUNTIME_DIR", "/tmp"), "droiddeck-steamvr")
|
||||
try:
|
||||
os.makedirs(state, exist_ok=True)
|
||||
with open(os.path.join(state, "library-launch.log"), "a") as log:
|
||||
return subprocess.Popen([VR_HELPER, "launch"], stdin=subprocess.DEVNULL,
|
||||
stdout=log, stderr=subprocess.STDOUT, start_new_session=True)
|
||||
except OSError as e:
|
||||
say("SteamVR library launch failed: %s" % e)
|
||||
|
||||
|
||||
class Closed(Exception):
|
||||
@@ -321,6 +420,9 @@ class Page:
|
||||
raise RuntimeError((details.get("exception") or {}).get("description") or details.get("text") or "script failed")
|
||||
return result.get("result", {}).get("value")
|
||||
|
||||
def tools(self, call):
|
||||
return self.evaluate("%s;\nwindow.__droiddeckTools.%s" % (TOOLS_JS, call))
|
||||
|
||||
def compat(self, call):
|
||||
return self.evaluate("%s;\nwindow.__droiddeckCompat.%s" % (INSTALL_JS, call))
|
||||
|
||||
@@ -405,6 +507,9 @@ class Helper:
|
||||
self.known = set()
|
||||
self.installed = None
|
||||
self.fex_asked = set()
|
||||
self.tools_asked = {}
|
||||
self.tools_checked = None
|
||||
self.vr_launch = None
|
||||
|
||||
def attach(self):
|
||||
path = shared_context(self.port)
|
||||
@@ -415,6 +520,8 @@ class Helper:
|
||||
if page.evaluate("typeof SteamClient === 'object' && typeof SteamClient.WebUITransport === 'object'") is not True:
|
||||
raise LookupError("SteamClient is not ready")
|
||||
page.call("Runtime.addBinding", {"name": BINDING})
|
||||
page.call("Runtime.addBinding", {"name": VR_BINDING})
|
||||
page.evaluate(VR_JS)
|
||||
if not self.steamos:
|
||||
page.call("Runtime.addBinding", {"name": SWITCH_BINDING})
|
||||
page.evaluate(SWITCH_JS)
|
||||
@@ -445,7 +552,8 @@ class Helper:
|
||||
prior_auto = state.get("auto", {})
|
||||
if not isinstance(prior_auto, dict):
|
||||
prior_auto = {}
|
||||
prior_native = state.get("native", ())
|
||||
# "native" from earlier builds also lists dual-platform games nobody chose to run natively.
|
||||
prior_native = state.get("native_choices", ())
|
||||
native_choices = set(prior_native if isinstance(prior_native, (list, tuple, set)) else ())
|
||||
apps = sorted(set(installed) | set(picks) | set(prior_auto) | native_choices, key=COMPAT["app_order"])
|
||||
overrides = COMPAT["requested_games"](
|
||||
@@ -459,12 +567,19 @@ class Helper:
|
||||
if raw_mapping is None:
|
||||
for app in native_choices:
|
||||
current[app] = ""
|
||||
for app in set(native) - native_choices:
|
||||
if not current.get(app):
|
||||
current.pop(app, None)
|
||||
else:
|
||||
for app in set(native) | native_choices:
|
||||
if app in raw_mapping:
|
||||
current[app] = raw_mapping[app]
|
||||
# The client shows an explicit native choice as the tool it inherits, and writes config.vdf late.
|
||||
if raw_mapping[app] == "" or current.get(app) not in self.known:
|
||||
current[app] = raw_mapping[app]
|
||||
elif app in prior_auto or app in native_choices:
|
||||
current[app] = ""
|
||||
elif not current.get(app):
|
||||
current.pop(app, None)
|
||||
changes, auto = COMPAT["plan_mapping"](
|
||||
current, installed, [t["name"] for t in live], default,
|
||||
COMPAT["followers"](state, current), native, picks, overrides,
|
||||
@@ -475,18 +590,36 @@ class Helper:
|
||||
tool if tool is not None else "Steam native default"))
|
||||
state.update(
|
||||
auto={app: tool for app, tool in auto.items() if tool is not COMPAT["NATIVE_CHOICE"]},
|
||||
native=sorted(app for app, tool in auto.items() if tool is COMPAT["NATIVE_CHOICE"]),
|
||||
native_choices=sorted(app for app, tool in auto.items() if tool is COMPAT["NATIVE_CHOICE"]),
|
||||
tools=catalog, live=True)
|
||||
state.pop("native", None)
|
||||
if waiting:
|
||||
state["pending"] = wanted
|
||||
say("%s is new to the running client; it applies when Steam next starts" % wanted)
|
||||
else:
|
||||
state.pop("pending", None)
|
||||
COMPAT["write_json"](state_file, state)
|
||||
if (any(app in installed and tool == COMPAT["FEX_TOOL"] for app, tool in native.items()) or
|
||||
os.path.exists(COMPAT["fex_wanted_marker"]())):
|
||||
for app in COMPAT["request_fex"](self.steam_root, self.fex_asked):
|
||||
say("asked the client to install %s for x86 Linux titles and programs" % app)
|
||||
|
||||
def ensure_tools(self):
|
||||
"""Proton, FEX and the runtimes FEX needs are fetched as soon as the client is up, never left pending."""
|
||||
now = time.monotonic()
|
||||
if self.tools_checked is not None and now - self.tools_checked < TOOL_CHECK_SECONDS:
|
||||
return
|
||||
self.tools_checked = now
|
||||
if COMPAT["game_running"]():
|
||||
return
|
||||
for app, action in COMPAT["tool_downloads"](self.steam_root):
|
||||
if now - self.tools_asked.get(app, -TOOL_RETRY_SECONDS) < TOOL_RETRY_SECONDS:
|
||||
continue
|
||||
self.tools_asked[app] = now
|
||||
try:
|
||||
self.page.tools("%s(%d)" % (action, int(app)))
|
||||
say("asked the client to %s %s" % (action, app))
|
||||
except Exception as e:
|
||||
say("the client could not %s %s (%s)" % (action, app, e))
|
||||
if action == "install":
|
||||
for asked in COMPAT["request_fex"](self.steam_root, self.fex_asked):
|
||||
say("asked the client to install %s through steam://install" % asked)
|
||||
|
||||
def request_waiting(self):
|
||||
request = COMPAT["read_json"](COMPAT["state_path"]("request.json"))
|
||||
@@ -498,6 +631,14 @@ class Helper:
|
||||
events = self.page.drain()
|
||||
if any(called(e, SWITCH_BINDING) for e in events):
|
||||
switch_to_desktop()
|
||||
vr_games = {e.get("params", {}).get("payload") for e in events if called(e, VR_BINDING) and
|
||||
isinstance(e.get("params", {}).get("payload"), str)}
|
||||
vr_games = {game for game in vr_games if isinstance(game, str) and game.isascii() and
|
||||
game.isdecimal() and not game.startswith("0") and len(game) <= 20 and
|
||||
int(game) <= 0xffffffffffffffff}
|
||||
if vr_games and (self.vr_launch is None or self.vr_launch.poll() is not None):
|
||||
say("preparing SteamVR for library app(s): " + ", ".join(sorted(vr_games)))
|
||||
self.vr_launch = launch_steamvr()
|
||||
return events
|
||||
|
||||
def serve(self, watcher):
|
||||
@@ -505,6 +646,7 @@ class Helper:
|
||||
f.write("%d\n" % os.getpid())
|
||||
say("attached to the client on port %d" % self.port)
|
||||
self.reconcile()
|
||||
self.ensure_tools()
|
||||
while True:
|
||||
sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else [])
|
||||
ready = [self.page.ws] if self.page.ws.pending() else select.select(sources, [], [], 30 if watcher.fileno() >= 0 else 2)[0]
|
||||
@@ -519,6 +661,7 @@ class Helper:
|
||||
watcher.changed()
|
||||
self.drain()
|
||||
self.reconcile()
|
||||
self.ensure_tools()
|
||||
|
||||
|
||||
def detach():
|
||||
|
||||
@@ -5,6 +5,7 @@ import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
@@ -119,7 +120,7 @@ def method(obj, slot, result, *args):
|
||||
|
||||
|
||||
def probe(steam_root, ids):
|
||||
library = C.CDLL(str(Path(steam_root) / "steamrtarm64/steamclient.so"))
|
||||
library = C.CDLL(os.environ.get("BL_STEAMCLIENT") or str(Path(steam_root) / "steamrtarm64/steamclient.so"))
|
||||
library.CreateInterface.argtypes = [C.c_char_p, C.c_void_p]
|
||||
library.CreateInterface.restype = C.c_void_p
|
||||
client = library.CreateInterface(b"SteamClient020", None)
|
||||
@@ -173,7 +174,8 @@ def request_restart(steam_root):
|
||||
"""The client reads manifests and shortcuts only at start, so an import needs one restart;
|
||||
the session's loop runs the importer between the exit and the next start."""
|
||||
Path(os.environ.get("HOME", "/root"), ".bl-restart-once").touch()
|
||||
subprocess.run([str(Path(steam_root) / "steamrtarm64/steam"), "-shutdown"],
|
||||
command = shlex.split(os.environ.get("BL_STEAM_SHUTDOWN", "")) or [str(Path(steam_root) / "steamrtarm64/steam"), "-shutdown"]
|
||||
subprocess.run(command,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=30)
|
||||
|
||||
|
||||
@@ -184,7 +186,7 @@ def unimported(steam_root, snapshot, candidates):
|
||||
|
||||
|
||||
def watch(steam_root, listing):
|
||||
games = [game for game in read_json(listing, []) if not store_game(game)]
|
||||
games = [game for game in read_json(listing, []) if not store_game(game) and not game.get("native")]
|
||||
if os.environ.get("BL_STEAM_OFFLINE") == "1" or not games:
|
||||
return
|
||||
candidates, sources = {}, {}
|
||||
@@ -213,9 +215,10 @@ def watch(steam_root, listing):
|
||||
elif candidates and (key != probed or now >= next_probe):
|
||||
probed, next_probe = key, now + 300
|
||||
try:
|
||||
probe_env = dict(os.environ, HOME=os.environ["BL_STEAM_IPC_HOME"]) if os.environ.get("BL_STEAM_IPC_HOME") else None
|
||||
result = subprocess.run([sys.executable, __file__, "probe", steam_root,
|
||||
*map(str, sorted(set(candidates.values())))],
|
||||
capture_output=True, text=True, timeout=15)
|
||||
capture_output=True, text=True, timeout=15, env=probe_env)
|
||||
if result.returncode != 0:
|
||||
status = "ownership probe failed: " + (result.stderr.strip()[-300:] or str(result.returncode))
|
||||
failures += 1
|
||||
@@ -408,6 +411,9 @@ def route(steam_root, acct, games):
|
||||
print(f"droiddeck-steam-games: store import not undone ({error})")
|
||||
shortcuts.append(game)
|
||||
continue
|
||||
if game.get("native"):
|
||||
shortcuts.append(game)
|
||||
continue
|
||||
folder = game.get("folder", "")
|
||||
appid = candidates.get(folder, candidates.get(legacy_path(folder)))
|
||||
stamp = source_stamp(game)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
cdn=https://client-update.fastly.steamstatic.com
|
||||
cdn_list="https://client-update.steamstatic.com https://client-update.akamai.steamstatic.com https://client-update.fastly.steamstatic.com"
|
||||
steam_channel=steamdeck_publicbeta
|
||||
manifest=steam_client_${steam_channel}_linuxarm64
|
||||
steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam
|
||||
@@ -33,12 +33,37 @@ if [ -n "$repair" ]; then
|
||||
[ "$(sha1sum "$part" | cut -d' ' -f1)" = "$sum" ] || rm -f "$part"
|
||||
done
|
||||
fi
|
||||
[ -x "$steam_root/steamrtarm64/steam" ] && [ -f "$stamp" ] && exit 0
|
||||
sync=
|
||||
if [ "${1:-}" = --sync ]; then
|
||||
case "${2:-}" in publicbeta|steamdeck_publicbeta) sync=$2 ;; *) sync=$steam_channel ;; esac
|
||||
manifest=steam_client_${sync}_linuxarm64
|
||||
fi
|
||||
[ -z "$sync" ] && [ -x "$steam_root/steamrtarm64/steam" ] && [ -f "$stamp" ] && exit 0
|
||||
|
||||
work=$(mktemp -d)
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
curl -fsSL "$cdn/$manifest" -o "$work/manifest"
|
||||
cdn=""
|
||||
for candidate in $cdn_list; do
|
||||
if curl -fsSL --connect-timeout 10 --max-time 30 --retry 2 --retry-connrefused --retry-delay 3 \
|
||||
"$candidate/$manifest" -o "$work/manifest"; then
|
||||
cdn=$candidate
|
||||
break
|
||||
fi
|
||||
done
|
||||
[ -n "$cdn" ] || { echo "droiddeck-steam-install: no Steam client CDN answered for $manifest" >&2; exit 1; }
|
||||
cdn_order=("$cdn")
|
||||
for candidate in $cdn_list; do
|
||||
[ "$candidate" = "$cdn" ] || cdn_order+=("$candidate")
|
||||
done
|
||||
version=$(awk -F'"' '$2 == "version" { print $4; exit }' "$work/manifest")
|
||||
if [ -n "$sync" ]; then
|
||||
installed=$(awk -F'"' '$2 == "version" { print $4; exit }' "$steam_root/package/$manifest.manifest" 2>/dev/null || true)
|
||||
if [ -x "$steam_root/steamrtarm64/steam" ] && [ "$installed" = "$version" ]; then
|
||||
chmod -R a+x "$steam_root/steamrtarm64" "$steam_root/linuxarm64" 2>/dev/null || true
|
||||
exit 0
|
||||
fi
|
||||
echo "== STEP $(date -u +%H:%M:%S) updating the arm64 Steam client to $version (was ${installed:-none}) for the x86-64 client"
|
||||
fi
|
||||
awk -F'"' '
|
||||
/^\t"/ && NF >= 3 && $4 == "" { block = $2 }
|
||||
$2 == "file" { file[block] = $4 }
|
||||
@@ -52,8 +77,16 @@ mkdir -p "$steam_root/package"
|
||||
while read -r block file sum; do
|
||||
i=$((${i:-0} + 1))
|
||||
echo "== STEP $(date -u +%H:%M:%S) downloading Steam: $block ($i/$total)"
|
||||
curl -fsSL "$cdn/$file" -o "$work/$file"
|
||||
echo "$sum $work/$file" | sha256sum -c --quiet
|
||||
fetched=""
|
||||
for host in "${cdn_order[@]}"; do
|
||||
if curl -fsSL --connect-timeout 10 --speed-limit 1024 --speed-time 60 --max-time 1800 \
|
||||
"$host/$file" -o "$work/$file" && echo "$sum $work/$file" | sha256sum -c --quiet; then
|
||||
fetched=$host
|
||||
break
|
||||
fi
|
||||
rm -f "$work/$file"
|
||||
done
|
||||
[ -n "$fetched" ] || { echo "droiddeck-steam-install: $file failed on every CDN" >&2; exit 1; }
|
||||
unzip -qo "$work/$file" -d "$steam_root"
|
||||
rm -f "$work/$file"
|
||||
done < "$work/parts"
|
||||
@@ -66,14 +99,20 @@ find "$steam_root" -depth -name '*\\*' | while read -r odd; do
|
||||
mv -f "$odd" "$fixed"
|
||||
fi
|
||||
done
|
||||
echo "$steam_channel" > "$steam_root/package/beta"
|
||||
chmod -R a+x "$steam_root/steamrtarm64" "$steam_root/linuxarm64" 2>/dev/null || true
|
||||
if [ -n "$sync" ]; then
|
||||
cp -f "$work/manifest" "$steam_root/package/$manifest.manifest"
|
||||
else
|
||||
echo "$steam_channel" > "$steam_root/package/beta"
|
||||
fi
|
||||
ln -sfn "$steam_root/steamrtarm64" "$steam_root/steamrtarm32"
|
||||
chmod +x "$steam_root/steamrtarm64/steam" 2>/dev/null || true
|
||||
mkdir -p "$HOME/.steam"
|
||||
ln -sfn "$steam_root" "$HOME/.steam/root"
|
||||
ln -sfn "$steam_root" "$HOME/.steam/steam"
|
||||
ln -sfn "$steam_root/steamrtarm64" "$HOME/.steam/bin64"
|
||||
ln -sfn "$steam_root/linuxarm64" "$HOME/.steam/sdk64"
|
||||
# sdk64 is where x86_64 Steamworks looks for steamclient.so; arm64 builds look in sdkarm64.
|
||||
ln -sfn "$steam_root/linux64" "$HOME/.steam/sdk64"
|
||||
ln -sfn "$steam_root/linuxarm64" "$HOME/.steam/sdkarm64"
|
||||
ln -sfn "$steam_root/steamrtarm64" "$HOME/.steam/binarm64"
|
||||
ln -sfn "$steam_root/linux32" "$HOME/.steam/sdk32"
|
||||
|
||||
@@ -12,15 +12,22 @@ case $target in
|
||||
esac
|
||||
|
||||
if [ "$ui" = desktop ] && [ "${BL_DESKTOP:-}" = 1 ]; then
|
||||
steam_root=${XDG_DATA_HOME:-${HOME:-/root}/.local/share}/Steam
|
||||
export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
|
||||
if [ "${BL_STEAM_CLIENT_ARCH:-}" = x86_64 ]; then
|
||||
client_home=${BL_X64_HOME:-${HOME:-/root}/.droiddeck-x64}
|
||||
client=(/usr/local/bin/droiddeck-steam-x64 --exec)
|
||||
else
|
||||
steam_root=${XDG_DATA_HOME:-${HOME:-/root}/.local/share}/Steam
|
||||
export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
|
||||
client_home=$HOME
|
||||
client=("$steam_root/steamrtarm64/steam")
|
||||
fi
|
||||
mkdir -p "${XDG_CACHE_HOME:-$HOME/.cache}/droiddeck"
|
||||
exec 9>"${XDG_CACHE_HOME:-$HOME/.cache}/droiddeck/steam-desktop.lock"
|
||||
if ! flock -n 9; then
|
||||
for ((attempt = 0; attempt < 180; attempt++)); do
|
||||
pid=$(cat "$HOME/.steam/steam.pid" 2>/dev/null || true)
|
||||
if [ -p "$HOME/.steam/steam.pipe" ] && [[ "$pid" =~ ^[0-9]+$ ]] && kill -0 "$pid" 2>/dev/null; then
|
||||
exec "$steam_root/steamrtarm64/steam" -nobigpicture -no-cef-sandbox \
|
||||
pid=$(cat "$client_home/.steam/steam.pid" 2>/dev/null || true)
|
||||
if [ -p "$client_home/.steam/steam.pipe" ] && [[ "$pid" =~ ^[0-9]+$ ]] && kill -0 "$pid" 2>/dev/null; then
|
||||
exec "${client[@]}" -nobigpicture -no-cef-sandbox \
|
||||
-cef-ozone-platform=x11 -cef-disable-gpu "${url:-steam://open/library}"
|
||||
fi
|
||||
sleep 0.5
|
||||
|
||||
@@ -11,4 +11,5 @@ if [ "${BL_DESKTOP:-}" = 1 ]; then
|
||||
done
|
||||
exec /usr/local/bin/droiddeck-steam-launch "$ui" ${url:+"$url"}
|
||||
fi
|
||||
[ "${BL_STEAM_CLIENT_ARCH:-}" = x86_64 ] && exec /usr/local/bin/droiddeck-steam-x64 --exec "$@"
|
||||
exec "${HOME:-/root}/.local/share/Steam/steamrtarm64/steam" "$@"
|
||||
@@ -180,12 +180,14 @@ def merge(fresh, current, state, seen):
|
||||
def reconcile(existing, wanted, seen, record):
|
||||
games, away = record["games"], dict(record["away"])
|
||||
kept, ours, placed = [], [], {}
|
||||
claimed = {(unquoted(fresh["Exe"]), fresh["AppName"]) for fresh in wanted.values()}
|
||||
for value in existing.values():
|
||||
if not isinstance(value, dict):
|
||||
continue
|
||||
tags = value.get("tags")
|
||||
if not isinstance(tags, dict) or TAG not in tags.values():
|
||||
kept.append(value)
|
||||
if (unquoted(value.get("Exe")), value.get("AppName")) not in claimed:
|
||||
kept.append(value)
|
||||
continue
|
||||
appid = value.get("appid")
|
||||
if not isinstance(appid, int) or appid in placed:
|
||||
@@ -342,9 +344,21 @@ def main():
|
||||
spec.loader.exec_module(compat)
|
||||
cfg = os.path.join(steam_root, "config", "config.vdf")
|
||||
if os.path.isfile(cfg) and (ours or routes):
|
||||
compat.register_default(cfg, apps=[str(int(g["appid"]) & 0xFFFFFFFF) for g in games if g.get("exe")] + [str(appid) for appid in set(routes.values())],
|
||||
protect=compat.adopt_extras(os.path.join(steam_root, "compatibilitytools.d")))
|
||||
print("droiddeck-steam-shortcuts: mapped them to %s" % compat.TOOL)
|
||||
tools = os.path.join(steam_root, "compatibilitytools.d")
|
||||
x64_tool = os.environ.get("BL_COMPAT_TOOL")
|
||||
own = {}
|
||||
if x64_tool:
|
||||
protect = {compat.first_key(os.path.join(tools, e, "compatibilitytool.vdf"), ["compatibilitytools", "compat_tools"]) or e: e
|
||||
for e in (os.listdir(tools) if os.path.isdir(tools) else [])}
|
||||
# Its own state: the arm64 client's state.json lists which of that client's titles follow its default.
|
||||
own = {"default": x64_tool,
|
||||
"directory": os.path.join(os.path.dirname(os.path.abspath(steam_root)), "droiddeck-compat"),
|
||||
"linux_tool": "droiddeck-direct"}
|
||||
else:
|
||||
protect = compat.adopt_extras(tools)
|
||||
used = compat.register_default(cfg, apps=[str(int(g["appid"]) & 0xFFFFFFFF) for g in games if g.get("exe") and not g.get("native")] + [str(appid) for appid in set(routes.values())],
|
||||
protect=protect, **own)
|
||||
print("droiddeck-steam-shortcuts: mapped them to %s" % used)
|
||||
except Exception as e:
|
||||
print("droiddeck-steam-shortcuts: compat mapping skipped (%s)" % e)
|
||||
return 0
|
||||
|
||||
+1080
File diff suppressed because it is too large.
Load diff
Regular → Executable
+150
-6
@@ -7,13 +7,39 @@ driver=$vrdir/droiddeck
|
||||
layer=$vrdir/layer
|
||||
logs=$HOME/.local/share/Steam/logs
|
||||
state=${XDG_RUNTIME_DIR:-/tmp}/droiddeck-steamvr
|
||||
umask 077
|
||||
mkdir -p "$state"
|
||||
chmod 700 "$state"
|
||||
|
||||
PKG_URL=https://steamdeck-packages.steamos.cloud/archlinux-deckard-hotfixes/release/0.3.x/deckard-steamvr-rel-r25358740%2B28b72a4f-1-aarch64.pkg.tar.zst
|
||||
PKG_SHA256=90a600775eb3e8856dc475f83166a93a290a0b1f3b4e82a69c8e2a8f06b9ddc9
|
||||
|
||||
running() { pgrep -x vrserver >/dev/null 2>&1; }
|
||||
installed() { [ -x "$steamvr/bin/linuxarm64/vrstartup" ]; }
|
||||
quest_settings() {
|
||||
backup=$HOME/.local/share/droiddeck/steamvr-quest-settings.json
|
||||
[ "$1" != restore ] || [ -f "$backup" ] || return 0
|
||||
python3 "${DROIDDECK_VR_SETTINGS_HELPER:-/usr/local/bin/droiddeck-steamvr-settings}" "$1" \
|
||||
"$HOME/.local/share/Steam/config/steamvr.vrsettings" "$backup"
|
||||
}
|
||||
|
||||
configure_graphics() {
|
||||
case "$(cat /sys/class/kgsl/kgsl-3d0/gpu_model 2>/dev/null)" in
|
||||
Adreno840*)
|
||||
# The session's forced sysmem mode loses the Vulkan device in SteamVR.
|
||||
export TU_DEBUG="$(
|
||||
IFS=', '
|
||||
set -f
|
||||
separator=
|
||||
for flag in ${TU_DEBUG:-}; do
|
||||
case "$flag" in ''|sysmem) continue ;; esac
|
||||
printf '%s%s' "$separator" "$flag"
|
||||
separator=,
|
||||
done
|
||||
)"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
stop() {
|
||||
rm -f "$state/active"
|
||||
@@ -21,10 +47,29 @@ stop() {
|
||||
for p in $(pgrep -x "$n"); do kill "$p" 2>/dev/null; done
|
||||
done
|
||||
for p in $(pgrep -f "$steamvr/bin/linuxarm64/vrcompositor-launcher"); do kill "$p" 2>/dev/null; done
|
||||
return 0
|
||||
attempts=0
|
||||
while pgrep -x 'vrserver|vrcompositor' >/dev/null 2>&1; do
|
||||
attempts=$((attempts + 1))
|
||||
if [ "$attempts" = 10 ]; then
|
||||
for p in $(pgrep -x 'vrserver|vrcompositor'); do kill -KILL "$p" 2>/dev/null; done
|
||||
fi
|
||||
[ "$attempts" -lt 20 ] || { echo 'SteamVR did not stop; preferences remain backed up' >&2; return 1; }
|
||||
sleep 0.1
|
||||
done
|
||||
quest_settings restore
|
||||
}
|
||||
|
||||
case "${1:-status}" in
|
||||
launch)
|
||||
# Library/URL entry point: use the same installer and start path as the app.
|
||||
exec 8>"$state/launch.lock"
|
||||
flock -n 8 || exit 0
|
||||
if ! installed; then
|
||||
"$0" install || exit $?
|
||||
while [ -f "$state/installing" ]; do sleep 1; done
|
||||
fi
|
||||
"$0" start
|
||||
;;
|
||||
status)
|
||||
i=0; installed && i=1
|
||||
r=0; running && r=1
|
||||
@@ -34,8 +79,9 @@ status)
|
||||
echo "installed=$i running=$r installing=$n driver=$d"
|
||||
;;
|
||||
install)
|
||||
exec 7>"$state/install.lock"
|
||||
flock -n 7 || { echo "already installing"; exit 0; }
|
||||
installed && { echo "SteamVR is already in $steamvr"; exit 0; }
|
||||
[ -f "$state/installing" ] && { echo "already installing"; exit 0; }
|
||||
: > "$state/installing"
|
||||
trap 'rm -f "$state/installing"' EXIT
|
||||
cache=$HOME/.cache/droiddeck-vr
|
||||
@@ -52,14 +98,66 @@ install)
|
||||
echo "SteamVR installed in $steamvr"
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
stop || exit 1
|
||||
;;
|
||||
start)
|
||||
exec 9>"$state/start.lock"
|
||||
flock -n 9 || { echo "SteamVR start already in progress"; exit 0; }
|
||||
installed || { echo "SteamVR is not installed (droiddeck-steamvr install)"; exit 1; }
|
||||
[ -f "$driver/bin/linuxarm64/driver_droiddeck.so" ] || { echo "the Cardboard driver is missing from $driver"; exit 1; }
|
||||
stop
|
||||
if [ -f "$state/active" ] && { running || pgrep -x vrstartup >/dev/null 2>&1; }; then
|
||||
echo "DroidDeck SteamVR is already running"
|
||||
exit 0
|
||||
fi
|
||||
stop || exit 1
|
||||
sleep 1
|
||||
mkdir -p "$HOME/.config/openvr" "$HOME/.config/openxr/1" "$logs" "$HOME/.local/share/Steam/config"
|
||||
if [ -S "/run/droiddeck/droiddeck-xr-frames" ] && [ -z "${DROIDDECK_VR_PRESENT:-}" ]; then
|
||||
export DROIDDECK_VR_PRESENT=questwsi
|
||||
fi
|
||||
python3 - "$HOME/.local/share/Steam/config/steamvr.vrsettings" <<'PY'
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
path = Path(sys.argv[1])
|
||||
try:
|
||||
settings = json.loads(path.read_text()) if path.exists() else {}
|
||||
section = settings.setdefault("steamvr", {})
|
||||
defaults = {} if os.environ.get("DROIDDECK_VR_PRESENT", "").startswith("quest") else {"supersampleManualOverride": True, "supersampleScale": 1.0}
|
||||
changed = any(key not in section for key in defaults)
|
||||
for key, value in defaults.items():
|
||||
section.setdefault(key, value)
|
||||
driver = settings.get("driver_droiddeck")
|
||||
if isinstance(driver, dict) and driver.get("blocked_by_safe_mode") is True:
|
||||
driver["blocked_by_safe_mode"] = False
|
||||
changed = True
|
||||
print("SteamVR had blocked the DroidDeck driver after a crash; unblocked it")
|
||||
if changed:
|
||||
with tempfile.NamedTemporaryFile(mode="w", dir=path.parent, delete=False) as output:
|
||||
temporary = Path(output.name)
|
||||
try:
|
||||
json.dump(settings, output, indent=3)
|
||||
output.write("\n")
|
||||
except BaseException:
|
||||
temporary.unlink(missing_ok=True)
|
||||
raise
|
||||
try:
|
||||
os.replace(temporary, path)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
except (OSError, ValueError, AttributeError, TypeError) as error:
|
||||
print("Could not set SteamVR resolution defaults: " + str(error), file=sys.stderr)
|
||||
try:
|
||||
(path.parent / "vrserver_crash_timestamp.txt").unlink()
|
||||
print("Removed SteamVR's crash marker so it starts without safe mode")
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except OSError as error:
|
||||
print("Could not remove SteamVR's crash marker: " + str(error), file=sys.stderr)
|
||||
PY
|
||||
cat > "$HOME/.config/openvr/openvrpaths.vrpath" <<JSON
|
||||
{
|
||||
"config": ["$HOME/.local/share/Steam/config"],
|
||||
@@ -71,10 +169,53 @@ start)
|
||||
}
|
||||
JSON
|
||||
ln -sf "$steamvr/steamxr_linuxarm64.json" "$HOME/.config/openxr/1/active_runtime.json"
|
||||
chaperone=$HOME/.local/share/Steam/config/chaperone_info.vrchap
|
||||
[ -s "$chaperone" ] || cat > "$chaperone" <<'JSON'
|
||||
{
|
||||
"jsonid" : "chaperone_info",
|
||||
"universes" : [
|
||||
{
|
||||
"collision_bounds" : [
|
||||
[ [ -1.0, 0.0, -1.0 ], [ -1.0, 2.43, -1.0 ], [ -1.0, 2.43, 1.0 ], [ -1.0, 0.0, 1.0 ] ],
|
||||
[ [ -1.0, 0.0, 1.0 ], [ -1.0, 2.43, 1.0 ], [ 1.0, 2.43, 1.0 ], [ 1.0, 0.0, 1.0 ] ],
|
||||
[ [ 1.0, 0.0, 1.0 ], [ 1.0, 2.43, 1.0 ], [ 1.0, 2.43, -1.0 ], [ 1.0, 0.0, -1.0 ] ],
|
||||
[ [ 1.0, 0.0, -1.0 ], [ 1.0, 2.43, -1.0 ], [ -1.0, 2.43, -1.0 ], [ -1.0, 0.0, -1.0 ] ]
|
||||
],
|
||||
"play_area" : [ 2.0, 2.0 ],
|
||||
"seated" : { "translation" : [ 0.0, -1.6, 0.0 ], "yaw" : 0.0 },
|
||||
"standing" : { "translation" : [ 0.0, 0.0, 0.0 ], "yaw" : 0.0 },
|
||||
"universeID" : "2"
|
||||
}
|
||||
],
|
||||
"version" : 5
|
||||
}
|
||||
JSON
|
||||
|
||||
export VK_LAYER_PATH="$layer${VK_LAYER_PATH:+:$VK_LAYER_PATH}"
|
||||
export VK_INSTANCE_LAYERS="VK_LAYER_DROIDDECK_vr${VK_INSTANCE_LAYERS:+:$VK_INSTANCE_LAYERS}"
|
||||
export VK_LOADER_LAYERS_DISABLE="${VK_LOADER_LAYERS_DISABLE:-~implicit~}"
|
||||
configure_graphics
|
||||
export LD_PRELOAD="$layer/libdroiddeck_vr_scheduling.so${LD_PRELOAD:+:$LD_PRELOAD}"
|
||||
if [ "${DROIDDECK_VR_PRESENT:-}" = questwsi ]; then
|
||||
quest_settings apply || exit 1
|
||||
startup_handed_off=0
|
||||
trap '[ "$startup_handed_off" = 1 ] || quest_settings restore' EXIT
|
||||
# The pinned Frame package's CVP constructor exits on Quest's unsupported SoC.
|
||||
cvp=$steamvr/drivers/cv/bin/linuxarm64/libArcturusPerception.so
|
||||
if [ -f "$cvp" ]; then
|
||||
disabled=$cvp.droiddeck-disabled
|
||||
if [ -e "$disabled" ]; then disabled=$(mktemp "$disabled.XXXXXX") || exit 1; fi
|
||||
mv "$cvp" "$disabled" || exit 1
|
||||
echo "Disabled Frame-only CVP backend for Quest; SteamVR uses its normal compositor"
|
||||
fi
|
||||
fi
|
||||
if [ "${DROIDDECK_VR_PRESENT:-}" = questframes ]; then
|
||||
export DROIDDECK_VR_PRODUCER_LEASE=${DROIDDECK_VR_PRODUCER_LEASE:-1}
|
||||
fi
|
||||
if [ -z "${DROIDDECK_VR_DISPLAY_MODE:-}" ] && [ -x "$driver/bin/linuxarm64/xr-display-mode" ]; then
|
||||
mode=$("$driver/bin/linuxarm64/xr-display-mode") || mode=
|
||||
if [ -n "$mode" ]; then export DROIDDECK_VR_DISPLAY_MODE="$mode"; fi
|
||||
fi
|
||||
|
||||
shims=$state/shims
|
||||
mkdir -p "$shims"
|
||||
@@ -86,11 +227,14 @@ JSON
|
||||
|
||||
: > "$state/active"
|
||||
cd "$steamvr/bin/linuxarm64" || exit 1
|
||||
setsid ./vrstartup > "$state/vrstartup.log" 2>&1 < /dev/null &
|
||||
startup_log=$logs/droiddeck-vrstartup.log
|
||||
ln -sf "$startup_log" "$state/vrstartup.log"
|
||||
setsid ./vrstartup 8>&- 9>&- > "$startup_log" 2>&1 < /dev/null &
|
||||
startup_handed_off=1
|
||||
echo "SteamVR starting; logs in $logs and $state/vrstartup.log"
|
||||
;;
|
||||
*)
|
||||
echo "usage: droiddeck-steamvr status|install|start|stop" >&2
|
||||
echo "usage: droiddeck-steamvr status|install|start|stop|launch" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
[ "$#" -gt 0 ] || { echo 'usage: droiddeck-steamvr-game COMMAND [ARG...]' >&2; exit 2; }
|
||||
pgrep -x vrserver >/dev/null 2>&1 || {
|
||||
echo 'Start SteamVR before launching a game with droiddeck-steamvr-game.' >&2
|
||||
exit 1
|
||||
}
|
||||
vrdir=${DROIDDECK_VR_DIR:-/usr/local/lib/droiddeck-vr}
|
||||
export VK_LAYER_PATH="$vrdir/layer${VK_LAYER_PATH:+:$VK_LAYER_PATH}"
|
||||
export VK_INSTANCE_LAYERS="VK_LAYER_DROIDDECK_vr${VK_INSTANCE_LAYERS:+:$VK_INSTANCE_LAYERS}"
|
||||
export VK_LOADER_LAYERS_DISABLE="${VK_LOADER_LAYERS_DISABLE:-~implicit~}"
|
||||
# Quest's guest GPU images use Vulkan sharing rather than DMA-BUF modifiers.
|
||||
if [ -S "/run/droiddeck/droiddeck-xr-frames" ]; then
|
||||
export gamescope_vr_use_modifiers=${gamescope_vr_use_modifiers:-false}
|
||||
fi
|
||||
export gamescope_vr_nudge_to_visible=${gamescope_vr_nudge_to_visible:-true}
|
||||
exec gamescope --backend openvr \
|
||||
--vr-overlay-key "gamescope.droiddeck.game.$$" \
|
||||
--vr-overlay-default-name 'DroidDeck game' \
|
||||
--vr-overlay-show-immediately --vr-overlay-physical-width 2.4 -- "$@"
|
||||
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/python3
|
||||
"""Preserve SteamVR preferences across Quest's required compositor overrides."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
OVERRIDES = {'enableLinuxVulkanAsync': True, 'motionSmoothing': False}
|
||||
|
||||
|
||||
def read(path):
|
||||
try:
|
||||
with path.open() as source:
|
||||
settings = json.load(source)
|
||||
except FileNotFoundError:
|
||||
return {}
|
||||
if not isinstance(settings, dict) or not isinstance(settings.get('steamvr', {}), dict):
|
||||
raise ValueError('Invalid SteamVR settings object')
|
||||
return settings
|
||||
|
||||
|
||||
def write(path, value):
|
||||
path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
temporary = path.with_name(path.name + '.tmp')
|
||||
with os.fdopen(os.open(temporary, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, 0o600), 'w') as destination:
|
||||
json.dump(value, destination, indent=3)
|
||||
destination.write('\n')
|
||||
os.replace(temporary, path)
|
||||
|
||||
|
||||
def saved_preferences(path):
|
||||
try:
|
||||
backup = read(path)
|
||||
if not isinstance(backup.get('section'), bool) or not isinstance(backup.get('values'), dict):
|
||||
raise ValueError('invalid backup object')
|
||||
for key in OVERRIDES:
|
||||
entry = backup['values'].get(key)
|
||||
if not isinstance(entry, list) or len(entry) != 2 or not isinstance(entry[0], bool):
|
||||
raise ValueError('invalid saved preference: ' + key)
|
||||
return backup
|
||||
except ValueError as error:
|
||||
raise ValueError(f'Invalid preference backup {path}; repair the saved section/values and retry restore. '
|
||||
'The backup and current preferences have been preserved.') from error
|
||||
|
||||
|
||||
def update(operation, settings_path, backup_path):
|
||||
settings = read(settings_path)
|
||||
if operation == 'apply':
|
||||
if backup_path.exists():
|
||||
saved_preferences(backup_path)
|
||||
else:
|
||||
section = settings.get('steamvr', {})
|
||||
write(backup_path, {'section': 'steamvr' in settings,
|
||||
'values': {key: [key in section, section.get(key)] for key in OVERRIDES}})
|
||||
settings.setdefault('steamvr', {}).update(OVERRIDES)
|
||||
write(settings_path, settings)
|
||||
elif operation == 'restore':
|
||||
if not backup_path.exists():
|
||||
return
|
||||
backup = saved_preferences(backup_path)
|
||||
section = settings.setdefault('steamvr', {})
|
||||
for key in OVERRIDES:
|
||||
present, value = backup['values'][key]
|
||||
if present:
|
||||
section[key] = value
|
||||
else:
|
||||
section.pop(key, None)
|
||||
if not section and not backup['section']:
|
||||
settings.pop('steamvr')
|
||||
write(settings_path, settings)
|
||||
backup_path.unlink()
|
||||
else:
|
||||
raise ValueError('Expected apply or restore')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
update(sys.argv[1], Path(sys.argv[2]), Path(sys.argv[3]))
|
||||
except (OSError, ValueError, KeyError, IndexError, TypeError) as error:
|
||||
sys.exit('Could not update SteamVR settings: ' + str(error))
|
||||
@@ -6,8 +6,10 @@ whoever started it: the Games tab, a pinned shortcut, or the Steam client's own
|
||||
looks for the store launcher DroidDeck wrote (.droiddeck-launch.bat) among the arguments; beside it
|
||||
.droiddeck-store.json says which store and game it is.
|
||||
|
||||
For an Epic game the game needs a fresh exchange code to sign in, which only the app can mint. The
|
||||
request goes through files under $BL_LAUNCH_DIR/stores (the session root, the same path on both
|
||||
For an Epic game, once the Epic Games Launcher is installed (droiddeck-epic), the game is started
|
||||
through it: the hidden launcher signs the game in and hands its arguments back in
|
||||
.droiddeck-epic-args. Without the launcher, or when it cannot, the game needs a fresh exchange code
|
||||
to sign in, which only the app can mint. The request goes through files under $BL_LAUNCH_DIR/stores (the session root, the same path on both
|
||||
sides):
|
||||
|
||||
req/<id>.json {"op": "epic-code", "store": "epic", "id": "<app name>"} (tmp + rename)
|
||||
@@ -38,6 +40,11 @@ from pathlib import Path
|
||||
LAUNCHER = ".droiddeck-launch.bat"
|
||||
SIDECAR = ".droiddeck-store.json"
|
||||
EPIC_CODE = ".droiddeck-epic-code"
|
||||
EPIC_ARGS = ".droiddeck-epic-args"
|
||||
EPIC_CLIENT = "/usr/local/bin/droiddeck-epic"
|
||||
EPIC_CLIENT_CURRENT = ".local/share/droiddeck-epic/current.json"
|
||||
EPIC_HANDLED = "DROIDDECK_EPIC_HANDLED"
|
||||
CLIENT_TIMEOUT = 150.0
|
||||
TIMEOUT = 5.0
|
||||
STALE_SECONDS = 300
|
||||
SERVER_WAIT = 8.0
|
||||
@@ -98,6 +105,30 @@ def drop_stale(folder, now=None):
|
||||
return False
|
||||
|
||||
|
||||
def client_wanted():
|
||||
home = os.environ.get("HOME") or "/root"
|
||||
return os.access(EPIC_CLIENT, os.X_OK) and os.path.isfile(os.path.join(home, EPIC_CLIENT_CURRENT))
|
||||
|
||||
|
||||
def through_client(folder, sidecar, timeout=CLIENT_TIMEOUT):
|
||||
extra = sidecar.get("extra") if isinstance(sidecar.get("extra"), dict) else {}
|
||||
namespace, item = str(extra.get("namespace") or ""), str(extra.get("catalogItemId") or "")
|
||||
if not namespace or not item:
|
||||
return "no-catalog-ids"
|
||||
command = [EPIC_CLIENT, "launch", "--app", str(sidecar.get("id")), "--namespace", namespace, "--item", item,
|
||||
"--folder", str(folder), "--owner", str(os.getppid()), "--timeout", str(int(timeout))]
|
||||
try:
|
||||
run = subprocess.run(command, stdout=subprocess.PIPE, stdin=subprocess.DEVNULL, timeout=timeout + 30)
|
||||
answer = json.loads(run.stdout.decode("utf-8", "replace").strip().splitlines()[-1])
|
||||
except (OSError, ValueError, IndexError, subprocess.TimeoutExpired) as error:
|
||||
return "error-" + type(error).__name__
|
||||
if not isinstance(answer, dict):
|
||||
return "no-answer"
|
||||
if answer.get("ok") and (folder / EPIC_ARGS).is_file():
|
||||
return "ok"
|
||||
return str(answer.get("reason") or "failed")
|
||||
|
||||
|
||||
def ask(channel, request, timeout=TIMEOUT):
|
||||
"""Writes [request] under channel/req and waits for channel/resp; the answer, or None on timeout."""
|
||||
req_dir, resp_dir = channel / "req", channel / "resp"
|
||||
@@ -247,10 +278,16 @@ def cloud_on(sidecar):
|
||||
return str(sidecar.get("store")) in CLOUD_STORES and sidecar.get("cloud", True) is not False
|
||||
|
||||
|
||||
def exited(argv):
|
||||
def exited(argv, code=0):
|
||||
"""After the game: ask the app to upload what changed, without waiting for it."""
|
||||
found = find_store_game(argv)
|
||||
launch_dir = os.environ.get("BL_LAUNCH_DIR", "")
|
||||
if found is not None and str(found[1].get("store")) == "epic" and os.environ.get(EPIC_HANDLED) != "1" \
|
||||
and os.access(EPIC_CLIENT, os.X_OK):
|
||||
try:
|
||||
subprocess.run([EPIC_CLIENT, "exited", "--code", str(code)], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, timeout=10)
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
pass
|
||||
if found is None or not launch_dir or not cloud_on(found[1]):
|
||||
return 0
|
||||
store, game = str(found[1].get("store")), str(found[1].get("id"))
|
||||
@@ -329,7 +366,14 @@ def prepare_gog(sidecar, compat_data, launch_dir):
|
||||
|
||||
def main(argv):
|
||||
if argv and argv[0] == "--exited":
|
||||
return exited(argv[1:])
|
||||
rest, code = argv[1:], 0
|
||||
if rest[:1] == ["--code"] and len(rest) > 1:
|
||||
try:
|
||||
code = int(rest[1])
|
||||
except ValueError:
|
||||
pass
|
||||
rest = rest[2:]
|
||||
return exited(rest, code)
|
||||
found = find_store_game(argv)
|
||||
if found is None:
|
||||
return 0
|
||||
@@ -341,9 +385,27 @@ def main(argv):
|
||||
if store == "gog":
|
||||
prepare_gog(sidecar, compat_data, launch_dir)
|
||||
if store == "epic":
|
||||
drop_stale(folder)
|
||||
handled = os.environ.get(EPIC_HANDLED) == "1" and (folder / EPIC_ARGS).is_file()
|
||||
if not handled:
|
||||
drop_stale(folder)
|
||||
try:
|
||||
(folder / EPIC_ARGS).unlink()
|
||||
except OSError:
|
||||
pass
|
||||
choice = options(sidecar)
|
||||
if not (choice["eos"] and not choice["offline"]):
|
||||
client = None
|
||||
if handled:
|
||||
client = "ok"
|
||||
elif choice["eos"] and not choice["offline"] and client_wanted():
|
||||
client = through_client(folder, sidecar)
|
||||
log("epic launch id=%s client=%s" % (game, client))
|
||||
if client == "ok":
|
||||
try:
|
||||
(folder / EPIC_CODE).unlink()
|
||||
except OSError:
|
||||
pass
|
||||
log("epic launch id=%s through=client" % game)
|
||||
elif not (choice["eos"] and not choice["offline"]):
|
||||
try:
|
||||
(folder / EPIC_CODE).unlink()
|
||||
except OSError:
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
# Runs natively: droiddeck-steam-x64's x86 wrappers start it through an arm64 binary, which FEX hands to the CPU.
|
||||
tool=$1; shift
|
||||
x64_home=$HOME
|
||||
|
||||
# The game overlay tags the game's windows with the Steam app ID; without it gamescope never shows them.
|
||||
overlay=0
|
||||
case ${LD_PRELOAD:-} in *gameoverlayrenderer.so*) overlay=1 ;; esac
|
||||
|
||||
for v in $(compgen -e); do
|
||||
case $v in FEX_*) unset "$v" ;; esac
|
||||
done
|
||||
unset LD_LIBRARY_PATH LD_PRELOAD STEAM_RUNTIME_STEAMRT STEAM_STEAMRT_RECURSION_GUARD \
|
||||
LIBGL_ALWAYS_SOFTWARE LIBGL_DRI3_DISABLE GALLIUM_DRIVER BL_WEBHELPER_HIDE_TRACER PROOT_FP_OFF
|
||||
|
||||
game_display=${DISPLAY:-}
|
||||
if [ -f "$x64_home/arm-session.env" ]; then
|
||||
. "$x64_home/arm-session.env"
|
||||
else
|
||||
export HOME=/root
|
||||
fi
|
||||
[ -z "$game_display" ] || export DISPLAY=$game_display
|
||||
# Proton takes its Steam client parts from the client's install folder; the x86-64 client's are x86.
|
||||
export BL_X64_STEAM_ROOT=${STEAM_COMPAT_CLIENT_INSTALL_PATH:-}
|
||||
export STEAM_COMPAT_CLIENT_INSTALL_PATH=$HOME/.local/share/Steam
|
||||
arm_overlay=$STEAM_COMPAT_CLIENT_INSTALL_PATH/steamrtarm64/gameoverlayrenderer.so
|
||||
if [ "$overlay" = 1 ] && [ -f "$arm_overlay" ]; then
|
||||
export LD_PRELOAD=$arm_overlay${LD_PRELOAD:+:$LD_PRELOAD}
|
||||
fi
|
||||
|
||||
dir=$HOME/.local/share/Steam/compatibilitytools.d/$tool
|
||||
manifest=$dir/toolmanifest.vdf
|
||||
[ -f "$manifest" ] || { echo "droiddeck-x64-arm-proton: no tool $dir" >&2; exit 127; }
|
||||
if ! grep -q droiddeck-proton-wrap "$manifest" 2>/dev/null; then
|
||||
python3 - "${dir%/*}" <<'PY' >&2 || true
|
||||
import importlib.machinery, importlib.util, sys
|
||||
path = "/usr/local/bin/steam-compatibility"
|
||||
spec = importlib.util.spec_from_file_location("compat", path, loader=importlib.machinery.SourceFileLoader("compat", path))
|
||||
compat = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(compat)
|
||||
compat.adopt_extras(sys.argv[1])
|
||||
PY
|
||||
fi
|
||||
cmd=$(sed -n 's/^[[:space:]]*"commandline"[[:space:]]*"\([^"]*\)".*/\1/p' "$manifest" | head -n 1)
|
||||
entry=${cmd%% *}
|
||||
exec "$dir/${entry#/}" "$@"
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
# The arm64 client's web helper for the x86-64 client, run natively: FEX hands this arm64 program to the CPU.
|
||||
x64_home=$HOME
|
||||
arm=/root/.local/share/Steam/steamrtarm64
|
||||
|
||||
for v in $(compgen -e); do
|
||||
case $v in FEX_*) unset "$v" ;; esac
|
||||
done
|
||||
unset LD_PRELOAD LIBGL_ALWAYS_SOFTWARE LIBGL_DRI3_DISABLE BL_WEBHELPER_HIDE_TRACER BL_X64_ARM_WEBHELPER
|
||||
if [ -f "$x64_home/arm-session.env" ]; then
|
||||
eval "$(grep -E '^declare -x (VK_ICD_FILENAMES|VK_DRIVER_FILES|GALLIUM_DRIVER|MESA_LOADER_DRIVER_OVERRIDE|LIBGL_KOPPER_DRI2|TU_DEBUG|ZINK_DEBUG|ZINK_DESCRIPTORS|MESA_NO_ERROR|MESA_DISK_CACHE_DATABASE)=' "$x64_home/arm-session.env")"
|
||||
fi
|
||||
export LD_LIBRARY_PATH=$arm:$arm/panorama LIBGL_KOPPER_DISABLE=true
|
||||
|
||||
args=()
|
||||
for a in "$@"; do
|
||||
case $a in --disable-gpu|--disable-gpu-compositing) ;; *) args+=("$a") ;; esac
|
||||
done
|
||||
cd "$arm" || exit 1
|
||||
exec "$arm/steamwebhelper" "${args[@]}" --ignore-gpu-blocklist
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
# Steam's compositor draws each browser window from its X pixmap: frames must reach X, not gamescope's WSI layer.
|
||||
# gamescope sets vk_xwayland_wait_ready=false for its children; kopper swapchains flashed black even with the wait.
|
||||
unset BL_X64_ARM_WEBHELPER
|
||||
# The shim already added the GPU flags (preload/webhelper.c) to these arguments.
|
||||
export BL_WEBHELPER_ARGS=stock DISABLE_GAMESCOPE_WSI=1 vk_xwayland_wait_ready=true LIBGL_KOPPER_DISABLE=true
|
||||
if [ -x ./steamwebhelper ]; then
|
||||
exec ./steamwebhelper "$@"
|
||||
fi
|
||||
exec "$HOME/.local/share/Steam/steamrt64/steamwebhelper" "$@"
|
||||
@@ -21,7 +21,11 @@ FEX_LAUNCHER = "droiddeck-fex-tool"
|
||||
FEX_FILES = ("toolmanifest.vdf", "compatibilitytool.vdf", FEX_LAUNCHER)
|
||||
FEX_APPID = "3127680"
|
||||
SNIPER_APPID = "1628350"
|
||||
FEX_DEPENDENCIES = (FEX_APPID, SNIPER_APPID)
|
||||
SLR4_APPID = "4183110"
|
||||
FEX_DEPENDENCIES = (FEX_APPID, SNIPER_APPID, SLR4_APPID)
|
||||
REQUIRED_TOOLS = (PROTON_ARM64_APPID,) + FEX_DEPENDENCIES
|
||||
FULLY_INSTALLED = 4
|
||||
UPDATE_REQUIRED = 2
|
||||
REQUEST_HANDOFF_SECONDS = 30
|
||||
PLAYABLE_TYPES = frozenset(("game", "demo", "application", "beta"))
|
||||
COMPAT_DIR = os.path.join(os.environ.get("HOME", "/root"), ".local", "share", "droiddeck-compat")
|
||||
@@ -73,7 +77,7 @@ bl_run() {
|
||||
if [ -n "${BL_STORE_EXIT:-}" ]; then
|
||||
"$@"
|
||||
rc=$?
|
||||
/usr/local/bin/droiddeck-store-launch --exited "${BL_STORE_ARGS[@]}" || true
|
||||
/usr/local/bin/droiddeck-store-launch --exited --code "$rc" "${BL_STORE_ARGS[@]}" || true
|
||||
exit $rc
|
||||
fi
|
||||
exec "$@"
|
||||
@@ -213,6 +217,34 @@ bl_idtech3() {
|
||||
}
|
||||
"""
|
||||
|
||||
# Source games report VAC-secure or insecure only in their console, written to console.log only with -condebug.
|
||||
# The app keeps the switch and the records in /root: the x86-64 client runs games with its own HOME.
|
||||
BL_VACDIAG_SETUP = """
|
||||
bl_vacdiag() {
|
||||
[ -f /root/.droiddeck-vac-diagnostics ] || return 0
|
||||
[ "${verb:-}" = waitforexitandrun ] || return 0
|
||||
local exe= a dir added=no app=${SteamAppId:-${STEAM_COMPAT_APP_ID:-0}}
|
||||
for a in "$@"; do case $a in *.exe|*.EXE) exe=$a ;; esac; done
|
||||
[ -n "$exe" ] || return 0
|
||||
dir=$(dirname "$exe")
|
||||
# Source: <mod>/gameinfo.txt beside the exe. Source 2: game/bin/win64/<exe> with game/<mod>/gameinfo.gi.
|
||||
if ls "$dir"/*/gameinfo.txt >/dev/null 2>&1 || ls "$dir"/../../*/gameinfo.gi >/dev/null 2>&1; then
|
||||
case " $* " in
|
||||
*" -condebug "*) echo "droiddeck-proton: vac-diag: app $app already has -condebug" >&2 ;;
|
||||
*) BL_EXTRA_ARGS+=(-condebug); added=yes
|
||||
echo "droiddeck-proton: vac-diag: app $app is a Source title; launched with -condebug" >&2 ;;
|
||||
esac
|
||||
else
|
||||
added=not-source
|
||||
echo "droiddeck-proton: vac-diag: app $app is not a Source title; it keeps no console log to read" >&2
|
||||
fi
|
||||
case " $* " in
|
||||
*" -insecure "*) echo "droiddeck-proton: vac-diag: app $app has -insecure in its launch options - it can never be VAC-secure this way" >&2 ;;
|
||||
esac
|
||||
printf '%s\tapp %s\tcondebug %s\t%s\n' "$(date +%s)" "$app" "$added" "${exe##*/}" >> /root/.droiddeck-vac-launches
|
||||
}
|
||||
"""
|
||||
|
||||
BL_DIRECTAUDIO_SETUP = """
|
||||
bl_directaudio() {
|
||||
base=$1
|
||||
@@ -308,6 +340,7 @@ if [ -n "$depot" ]; then
|
||||
bl_directaudio "$depot"
|
||||
bl_game_cpus
|
||||
bl_idtech3 "$@"
|
||||
bl_vacdiag "$@"
|
||||
bl_libpath
|
||||
BL_STORE_PROTON="$depot/proton"; export BL_STORE_PROTON
|
||||
bl_store_launch "$@"
|
||||
@@ -323,7 +356,7 @@ LAUNCHER_TEMPLATE = LAUNCHER_SH
|
||||
def launcher_sh(sources=SOURCES):
|
||||
return (LAUNCHER_TEMPLATE % " ".join('"%s"' % n for n in sources)).replace(
|
||||
"verb=$1; shift", "verb=$1; shift\n" + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
+ BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
|
||||
|
||||
LAUNCHER_SH = launcher_sh()
|
||||
@@ -362,6 +395,7 @@ bl_components "$here"
|
||||
bl_directaudio "$here"
|
||||
bl_game_cpus
|
||||
bl_idtech3 "$@"
|
||||
bl_vacdiag "$@"
|
||||
bl_libpath
|
||||
BL_STORE_PROTON="$here/%s"; export BL_STORE_PROTON
|
||||
bl_store_launch "$@"
|
||||
@@ -589,7 +623,7 @@ def adopt_extras(tools):
|
||||
body = (EXTRA_WRAPPER_SH % entry_point).replace(
|
||||
'here=$(dirname "$0")',
|
||||
'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
|
||||
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
+ BL_VACDIAG_SETUP + BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP + BL_STORE_SETUP, 1)
|
||||
write_changed(wrapper, body, 0o755)
|
||||
write_changed(manifest, EXTRA_MANIFEST_VDF)
|
||||
write_changed(compat_vdf, EXTRA_COMPAT_TOOL_VDF % (name, display_name(entry)))
|
||||
@@ -663,6 +697,26 @@ def launch_programs(config):
|
||||
return found
|
||||
|
||||
|
||||
def launch_options(config):
|
||||
"""An app's launch options as Steam lists them: executable, arguments, working folder, type and oslist."""
|
||||
launch = config.get("launch") if isinstance(config, dict) else None
|
||||
found = []
|
||||
for key, option in launch.items() if isinstance(launch, dict) else ():
|
||||
if not isinstance(option, dict) or not option.get("executable"):
|
||||
continue
|
||||
settings = option.get("config") if isinstance(option.get("config"), dict) else {}
|
||||
found.append({
|
||||
"key": str(key),
|
||||
"executable": str(option["executable"]),
|
||||
"arguments": str(option.get("arguments", "")),
|
||||
"workingdir": str(option.get("workingdir", "")),
|
||||
"type": str(option.get("type", "")).lower(),
|
||||
"oslist": str(settings.get("oslist", "")).lower(),
|
||||
"betakey": str(settings.get("betakey", "")),
|
||||
})
|
||||
return found
|
||||
|
||||
|
||||
def appinfo_entries(path):
|
||||
import struct
|
||||
try:
|
||||
@@ -754,6 +808,7 @@ def appinfo_entries(path):
|
||||
"type": str(common.get("type", "")).lower(),
|
||||
"recommended": str(recommended),
|
||||
"launch": launch_programs(info.get("config")),
|
||||
"launch_options": launch_options(info.get("config")),
|
||||
}
|
||||
if app == STEAM_PLAY_MANIFESTS:
|
||||
extended = info.get("extended", {})
|
||||
@@ -802,6 +857,36 @@ def native_targets(steam_root, apps):
|
||||
return targets
|
||||
|
||||
|
||||
def app_manifest(steam_root, app):
|
||||
for library in libraries(steam_root):
|
||||
try:
|
||||
with open(os.path.join(library, "steamapps", "appmanifest_%s.acf" % app), encoding="utf-8", errors="replace") as f:
|
||||
return tokenize(f.read())
|
||||
except OSError:
|
||||
continue
|
||||
return None
|
||||
|
||||
|
||||
def manifest_flags(tokens):
|
||||
for i in range(len(tokens) - 1):
|
||||
if tokens[i].lower() == '"stateflags"':
|
||||
value = tokens[i + 1].strip('"')
|
||||
return int(value) if value.isdigit() else 0
|
||||
return 0
|
||||
|
||||
|
||||
def tool_downloads(steam_root):
|
||||
"""(app, "install" or "update") for each tool the client has yet to install or bring up to date."""
|
||||
wanted = []
|
||||
for app in REQUIRED_TOOLS:
|
||||
tokens = app_manifest(steam_root, app)
|
||||
if tokens is None:
|
||||
wanted.append((app, "install"))
|
||||
elif not manifest_flags(tokens) & FULLY_INSTALLED or manifest_flags(tokens) & UPDATE_REQUIRED:
|
||||
wanted.append((app, "update"))
|
||||
return wanted
|
||||
|
||||
|
||||
def fex_missing(steam_root):
|
||||
missing = []
|
||||
for app in FEX_DEPENDENCIES:
|
||||
@@ -1126,6 +1211,21 @@ def steam_running():
|
||||
return False
|
||||
|
||||
|
||||
def game_running():
|
||||
try:
|
||||
pids = [p for p in os.listdir("/proc") if p.isdigit()]
|
||||
except OSError:
|
||||
return False
|
||||
for pid in pids:
|
||||
try:
|
||||
with open("/proc/%s/cmdline" % pid, "rb") as f:
|
||||
if b"\0SteamLaunch\0AppId=" in f.read():
|
||||
return True
|
||||
except OSError:
|
||||
continue
|
||||
return False
|
||||
|
||||
|
||||
def live_helper_running(directory=None):
|
||||
try:
|
||||
with open(state_path("live.pid", directory)) as f:
|
||||
@@ -1136,7 +1236,8 @@ def live_helper_running(directory=None):
|
||||
return False
|
||||
|
||||
|
||||
def register_default(config_path, apps=(), protect=(), default=None, catalog=None, directory=None, settle=False, picks=()):
|
||||
def register_default(config_path, apps=(), protect=(), default=None, catalog=None, directory=None, settle=False, picks=(),
|
||||
linux_tool=FEX_TOOL):
|
||||
"""Writes the mapping: the "0" default and every title that follows it (see plan_mapping).
|
||||
With settle, the default itself is decided first (see choose_default): before the client
|
||||
starts, config.vdf holds what the client last kept, menu changes included."""
|
||||
@@ -1160,18 +1261,22 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
default = state.get("default") if state.get("default") in names else TOOL
|
||||
steam_root = os.path.dirname(os.path.dirname(os.path.abspath(config_path)))
|
||||
overrides = requested_games(game_requests(directory), catalog)
|
||||
managed = state.get("auto", {}).keys() if isinstance(state.get("auto"), dict) else ()
|
||||
native_choices = state.get("native_choices", ())
|
||||
native = native_targets(steam_root, set(apps) | set(picks) | set(managed) | set(native_choices))
|
||||
if linux_tool != FEX_TOOL:
|
||||
native = {app: linux_tool if tool == FEX_TOOL else tool for app, tool in native.items()}
|
||||
changes, auto = plan_mapping(
|
||||
current, apps, names, default, followers(state, current),
|
||||
native_targets(steam_root, set(apps) | set(picks)), picks,
|
||||
overrides, state.get("auto", {}).keys() if isinstance(state.get("auto"), dict) else (),
|
||||
state.get("native", ()))
|
||||
current, apps, names, default, followers(state, current), native, picks,
|
||||
overrides, managed, native_choices)
|
||||
for app, tool in changes.items():
|
||||
set_mapping(tokens, mapping, app, tool)
|
||||
text = serialize(tokens)
|
||||
if text != serialize(tokenize(original)):
|
||||
write_changed(config_path, text)
|
||||
state["auto"] = {app: tool for app, tool in auto.items() if tool is not NATIVE_CHOICE}
|
||||
state["native"] = sorted(app for app, tool in auto.items() if tool is NATIVE_CHOICE)
|
||||
state["native_choices"] = sorted(app for app, tool in auto.items() if tool is NATIVE_CHOICE)
|
||||
state.pop("native", None)
|
||||
state["tools"] = catalog
|
||||
state.setdefault("default", default)
|
||||
write_json(state_path("state.json", directory), state)
|
||||
@@ -1227,8 +1332,71 @@ def remove_tool(tool_dir):
|
||||
shutil.rmtree(tool_dir)
|
||||
|
||||
|
||||
def local_tools(steam_root):
|
||||
"""The names of the compatibility tools installed in steam_root/compatibilitytools.d."""
|
||||
names = set()
|
||||
tools = os.path.join(steam_root, "compatibilitytools.d")
|
||||
try:
|
||||
entries = os.listdir(tools)
|
||||
except OSError:
|
||||
return names
|
||||
for entry in entries:
|
||||
try:
|
||||
with open(os.path.join(tools, entry, "compatibilitytool.vdf"), encoding="utf-8", errors="replace") as f:
|
||||
m = re.search(r'"compat_tools"\s*\{\s*"([^"]+)"', f.read())
|
||||
except OSError:
|
||||
continue
|
||||
if m:
|
||||
names.add(m.group(1).lower())
|
||||
return names
|
||||
|
||||
|
||||
def x64_repoint(steam_root, tool, live=False):
|
||||
"""The x86-64 client (droiddeck-steam-x64): its tools are arm64 wrappers that script makes and
|
||||
its Linux titles run as Linux builds (FEX), so only the entries the client aimed at a Proton it
|
||||
cannot start are repointed, to `tool`. Tools in its own compatibilitytools.d are kept: the
|
||||
wrappers include proton-cachyos-*-a64, which starts with "proton" like Valve's own.
|
||||
Returns the app ids repointed."""
|
||||
config = os.path.join(steam_root, "config", "config.vdf")
|
||||
if not tool or not os.path.isfile(config):
|
||||
return []
|
||||
with open(config, encoding="utf-8", errors="replace") as f:
|
||||
original = f.read()
|
||||
tokens = tokenize(original)
|
||||
mapping = mapping_block(tokens)
|
||||
if mapping is None:
|
||||
return []
|
||||
keep = local_tools(steam_root)
|
||||
moved = []
|
||||
current = read_mapping(tokens, mapping)
|
||||
if "0" not in current:
|
||||
set_mapping(tokens, mapping, "0", tool)
|
||||
for app, name in current.items():
|
||||
named = name.lower()
|
||||
# A tool named arm64 is never this client's (its wrappers are -a64), so this legacy name is always repointed.
|
||||
legacy = named == "droiddeck-proton-arm64"
|
||||
if (named.startswith("proton") or legacy) and named != tool.lower() \
|
||||
and (legacy or named not in keep):
|
||||
set_mapping(tokens, mapping, app, tool)
|
||||
if app != "0":
|
||||
moved.append(app)
|
||||
text = serialize(tokens)
|
||||
if text != serialize(tokenize(original)):
|
||||
write_changed(config, text)
|
||||
print("steam-compatibility: x86-64 client's Proton entries point at %s" % tool)
|
||||
# Steam reads a mapping changed while it runs only at its next start; the session restarts it (.bl-compat-pending).
|
||||
if moved and live:
|
||||
with open(os.path.join(os.path.expanduser("~"), ".bl-compat-pending"), "a") as f:
|
||||
f.write("".join("%s\n" % a for a in moved))
|
||||
print("steam-compatibility: repointed while the client runs: %s" % " ".join(moved))
|
||||
return moved
|
||||
|
||||
|
||||
def main():
|
||||
steam_root = sys.argv[1]
|
||||
if "--x64" in sys.argv[2:]:
|
||||
x64_repoint(steam_root, os.environ.get("BL_COMPAT_TOOL"), "--live" in sys.argv[2:])
|
||||
return
|
||||
tools = os.path.join(steam_root, "compatibilitytools.d")
|
||||
os.makedirs(tools, exist_ok=True)
|
||||
legacy = os.path.join(tools, LEGACY_TOOL)
|
||||
|
||||
@@ -91,7 +91,8 @@ static int enabled(void) {
|
||||
if (cached < 0) {
|
||||
const char *off = getenv("BL_NO_DIR_CACHE");
|
||||
cached = strcmp(program_invocation_short_name, "steam") == 0 &&
|
||||
strstr(program_invocation_name, "steamrtarm64") != NULL && !(off && strcmp(off, "1") == 0);
|
||||
(strstr(program_invocation_name, "steamrtarm64") != NULL ||
|
||||
strstr(program_invocation_name, "steamrt64") != NULL) && !(off && strcmp(off, "1") == 0);
|
||||
if (cached) pthread_atfork(NULL, NULL, after_fork);
|
||||
}
|
||||
return cached && !forked;
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <limits.h>
|
||||
#include <linux/input.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -176,6 +178,24 @@ static int caller_is_winebus(void *caller) {
|
||||
return strstr(info.dli_fname, "winebus.so") != NULL;
|
||||
}
|
||||
|
||||
/* Wine's HID haptics give every XInput rumble a 1000 ms cutoff and xinput only writes on a change,
|
||||
* but XInput motors hold their speed until the next XInputSetState; evdev's length 0 holds until
|
||||
* stopped. Only this library, preloaded first, sees winebus as the caller. The length is put back
|
||||
* because winebus compares its copy with the next state to decide whether to upload again. */
|
||||
__attribute__((visibility("hidden"))) int bl_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd,
|
||||
unsigned long request, void *arg, void *caller,
|
||||
int *rc) {
|
||||
struct ff_effect *effect = arg;
|
||||
__u16 length;
|
||||
|
||||
if (request != EVIOCSFF || effect == NULL || effect->type != FF_RUMBLE || !caller_is_winebus(caller)) return 0;
|
||||
length = effect->replay.length;
|
||||
effect->replay.length = 0;
|
||||
*rc = real(fd, request, arg);
|
||||
effect->replay.length = length;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *realpath(const char *path, char *resolved) {
|
||||
static char *(*real_realpath)(const char *, char *);
|
||||
void *caller = __builtin_return_address(0);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <linux/netlink.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -309,11 +310,39 @@ static int maybe_answer_lsof(const char *path, char *const argv[]) {
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
static char **web_helper_redirect(const char *path, char *const argv[], const char **launcher) {
|
||||
const char *want = getenv("BL_X64_ARM_WEBHELPER");
|
||||
if (!want || !*want || !path) return NULL;
|
||||
const char *base = strrchr(path, '/');
|
||||
if (strcmp(base ? base + 1 : path, "steamwebhelper") != 0) return NULL;
|
||||
if (!strstr(path, "/steamrt64/")) {
|
||||
char cwd[PATH_MAX];
|
||||
size_t n;
|
||||
if (path[0] == '/' || !getcwd(cwd, sizeof(cwd))) return NULL;
|
||||
n = strlen(cwd);
|
||||
if (n < 10 || strcmp(cwd + n - 10, "/steamrt64") != 0) return NULL;
|
||||
}
|
||||
int argc = 0;
|
||||
while (argv && argv[argc]) argc++;
|
||||
char **out = calloc((size_t)argc + 2, sizeof(char *));
|
||||
if (!out) return NULL;
|
||||
out[0] = (char *)want;
|
||||
for (int i = 1; i < argc; i++) out[i] = argv[i];
|
||||
*launcher = want;
|
||||
return out;
|
||||
}
|
||||
|
||||
int execve(const char *path, char *const argv_in[], char *const envp[]) {
|
||||
char *const *argv = bl_webhelper_argv(path, argv_in);
|
||||
static int (*real)(const char *, char *const[], char *const[]);
|
||||
if (!real) real = (int (*)(const char *, char *const[], char *const[]))dlsym(RTLD_NEXT, "execve");
|
||||
maybe_answer_lsof(path, argv);
|
||||
const char *launcher = NULL;
|
||||
char **redirected = web_helper_redirect(path, argv, &launcher);
|
||||
if (redirected) {
|
||||
real(launcher, redirected, envp);
|
||||
free(redirected);
|
||||
}
|
||||
bl_binfmt_before(path, argv, envp);
|
||||
real(path, argv, envp);
|
||||
return bl_binfmt_retry(path, argv, envp, errno);
|
||||
@@ -349,6 +378,12 @@ int execv(const char *path, char *const argv_in[]) {
|
||||
static int (*real)(const char *, char *const[]);
|
||||
if (!real) real = (int (*)(const char *, char *const[]))dlsym(RTLD_NEXT, "execv");
|
||||
maybe_answer_lsof(path, argv);
|
||||
const char *launcher = NULL;
|
||||
char **redirected = web_helper_redirect(path, argv, &launcher);
|
||||
if (redirected) {
|
||||
real(launcher, redirected);
|
||||
free(redirected);
|
||||
}
|
||||
bl_binfmt_before(path, argv, environ);
|
||||
real(path, argv);
|
||||
return bl_binfmt_retry(path, argv, environ, errno);
|
||||
|
||||
@@ -406,6 +406,8 @@ int bl_kgsl_poll(int (*real)(int, unsigned long, void *), int fd, unsigned long
|
||||
void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_ntsync_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_drm_gem_close(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
|
||||
int bl_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request,
|
||||
void *arg, void *caller, int *rc) __attribute__((visibility("hidden")));
|
||||
|
||||
int ioctl(int fd, unsigned long request, ...) {
|
||||
typedef int (*ioctl_fn)(int, unsigned long, void *);
|
||||
@@ -419,6 +421,7 @@ int ioctl(int fd, unsigned long request, ...) {
|
||||
if (bl_ntsync_ioctl(fd, request, arg, &rc)) return rc;
|
||||
if (bl_drm_gem_close(fd, request, arg, &rc)) return rc;
|
||||
if (real == NULL) real = (ioctl_fn) dlsym(RTLD_NEXT, "ioctl");
|
||||
if (bl_winebus_rumble_ioctl(real, fd, request, arg, __builtin_return_address(0), &rc)) return rc;
|
||||
if (!bl_kgsl_poll(real, fd, request, arg, &rc)) rc = quest_kgsl_ioctl(real, fd, request, arg);
|
||||
bl_kgsl_chip_id_fixup(request, arg, rc);
|
||||
if (arg == NULL || !is_link_query(request)) return rc;
|
||||
@@ -535,13 +538,13 @@ static FILE *synthesize(const char *table) {
|
||||
return out;
|
||||
}
|
||||
|
||||
int bl_status_without_tracer(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_status_without_tracer(const char *path, int flags, const void *caller) __attribute__((visibility("hidden")));
|
||||
|
||||
const char *bl_oom_adj_redirect(const char *path, int writing) __attribute__((visibility("hidden")));
|
||||
|
||||
static FILE *open_stream(fopen_fn real, const char *path, const char *mode) {
|
||||
static FILE *open_stream(fopen_fn real, const char *path, const char *mode, const void *caller) {
|
||||
int status = mode && mode[0] == 'r' && !strchr(mode, '+')
|
||||
? bl_status_without_tracer(path, O_RDONLY | O_CLOEXEC) : -1;
|
||||
? bl_status_without_tracer(path, O_RDONLY | O_CLOEXEC, caller) : -1;
|
||||
if (status >= 0) {
|
||||
FILE *copy = fdopen(status, "r");
|
||||
if (copy == NULL) close(status);
|
||||
@@ -560,11 +563,11 @@ static FILE *open_stream(fopen_fn real, const char *path, const char *mode) {
|
||||
FILE *fopen(const char *path, const char *mode) {
|
||||
static fopen_fn real;
|
||||
if (real == NULL) real = (fopen_fn) dlsym(RTLD_NEXT, "fopen");
|
||||
return open_stream(real, path, mode);
|
||||
return open_stream(real, path, mode, __builtin_return_address(0));
|
||||
}
|
||||
|
||||
FILE *fopen64(const char *path, const char *mode) {
|
||||
static fopen_fn real;
|
||||
if (real == NULL) real = (fopen_fn) dlsym(RTLD_NEXT, "fopen64");
|
||||
return open_stream(real, path, mode);
|
||||
return open_stream(real, path, mode, __builtin_return_address(0));
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int bl_status_without_tracer(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_status_without_tracer(const char *path, int flags, const void *caller) __attribute__((visibility("hidden")));
|
||||
int bl_writable_retry(int dirfd, const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
int bl_ntsync_open(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
const char *bl_oom_adj_redirect(const char *path, int writing) __attribute__((visibility("hidden")));
|
||||
@@ -53,7 +53,7 @@ int open(const char *path, int flags, ...) {
|
||||
return -1;
|
||||
}
|
||||
path = bl_oom_adj_redirect(path, (flags & O_ACCMODE) != O_RDONLY);
|
||||
if ((fd = bl_status_without_tracer(path, flags)) >= 0) return fd;
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if (real_open == NULL) real_open = dlsym(RTLD_NEXT, "open");
|
||||
if (real_open == NULL) {
|
||||
@@ -79,7 +79,7 @@ int openat(int dirfd, const char *path, int flags, ...) {
|
||||
return -1;
|
||||
}
|
||||
path = bl_oom_adj_redirect(path, (flags & O_ACCMODE) != O_RDONLY);
|
||||
if ((fd = bl_status_without_tracer(path, flags)) >= 0) return fd;
|
||||
if ((fd = bl_status_without_tracer(path, flags, __builtin_return_address(0))) >= 0) return fd;
|
||||
if ((fd = bl_ntsync_open(path, flags)) != -2) return fd;
|
||||
if (real_openat == NULL) real_openat = dlsym(RTLD_NEXT, "openat");
|
||||
if (real_openat == NULL) {
|
||||
|
||||
@@ -42,7 +42,8 @@ static int enabled(void) {
|
||||
if (cached >= 0) return cached;
|
||||
off = getenv("BL_NO_PATH_CACHE");
|
||||
cached = strcmp(program_invocation_short_name, "steam") == 0 &&
|
||||
strstr(program_invocation_name, "steamrtarm64") != NULL &&
|
||||
(strstr(program_invocation_name, "steamrtarm64") != NULL ||
|
||||
strstr(program_invocation_name, "steamrt64") != NULL) &&
|
||||
!(off != NULL && off[0] == '1');
|
||||
return cached;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
static int in_steam_dirs(const char *path) {
|
||||
return path != NULL && (strstr(path, "/Steam/steamrtarm64/") != NULL
|
||||
return path != NULL && (strstr(path, "/Steam/steamrtarm64/") != NULL || strstr(path, "/Steam/steamrt64/") != NULL
|
||||
|| strstr(path, "/Steam/ubuntu12_64/") != NULL || strstr(path, "/Steam/linuxarm64/") != NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/* In Deck mode (-steamos3) the x86-64 client's SteamOS audio manager passes libpulse the NULL operation of a
|
||||
* failed request, and libpulse aborts on it ("Assertion 'o' failed ... pa_operation_get_state()"). */
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct pa_operation pa_operation;
|
||||
|
||||
#define PA_OPERATION_CANCELLED 2
|
||||
|
||||
/* A libpulse loaded with RTLD_LOCAL (Wine's winepulse.so) is not in RTLD_NEXT's scope. */
|
||||
static void *libpulse(const char *name) {
|
||||
void *fn = dlsym(RTLD_NEXT, name);
|
||||
if (!fn) {
|
||||
void *handle = dlopen("libpulse.so.0", RTLD_LAZY | RTLD_NOLOAD);
|
||||
if (handle) {
|
||||
fn = dlsym(handle, name);
|
||||
dlclose(handle);
|
||||
}
|
||||
}
|
||||
return fn;
|
||||
}
|
||||
|
||||
int pa_operation_get_state(pa_operation *o) {
|
||||
static int (*next)(pa_operation *);
|
||||
if (!o)
|
||||
return PA_OPERATION_CANCELLED;
|
||||
if (!next)
|
||||
next = (int (*)(pa_operation *))libpulse("pa_operation_get_state");
|
||||
return next ? next(o) : PA_OPERATION_CANCELLED;
|
||||
}
|
||||
|
||||
void pa_operation_unref(pa_operation *o) {
|
||||
static void (*next)(pa_operation *);
|
||||
if (!o)
|
||||
return;
|
||||
if (!next)
|
||||
next = (void (*)(pa_operation *))libpulse("pa_operation_unref");
|
||||
if (next)
|
||||
next(o);
|
||||
}
|
||||
|
||||
void pa_operation_cancel(pa_operation *o) {
|
||||
static void (*next)(pa_operation *);
|
||||
if (!o)
|
||||
return;
|
||||
if (!next)
|
||||
next = (void (*)(pa_operation *))libpulse("pa_operation_cancel");
|
||||
if (next)
|
||||
next(o);
|
||||
}
|
||||
#else
|
||||
typedef int pulseguard_arm_build_has_nothing_to_do;
|
||||
#endif
|
||||
@@ -2,14 +2,18 @@
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <linux/futex.h>
|
||||
#include <linux/magic.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef SYS_openat2
|
||||
@@ -18,6 +22,17 @@
|
||||
|
||||
#define BL_RESOLVE_BENEATH 0x08
|
||||
#define BL_RESOLVE_IN_ROOT 0x10
|
||||
// The kernel's MAXSYMLINKS.
|
||||
#define BL_MAX_SYMLINKS 40
|
||||
#define BL_PROC_ROOT_INO 1
|
||||
|
||||
#ifdef SYS_newfstatat
|
||||
#define BL_SYS_FSTATAT SYS_newfstatat
|
||||
typedef struct stat bl_stat;
|
||||
#else
|
||||
#define BL_SYS_FSTATAT SYS_fstatat64
|
||||
typedef struct stat64 bl_stat;
|
||||
#endif
|
||||
|
||||
struct bl_open_how {
|
||||
uint64_t flags;
|
||||
@@ -76,6 +91,151 @@ static struct robust_list_head *thread_robust_head(void) {
|
||||
return head;
|
||||
}
|
||||
|
||||
// Magic links are procfs links below a process's directory; procfs's root holds only plain ones (self, thread-self, mounts).
|
||||
static int is_magic_link(int dirfd, char *link, size_t parent_len) {
|
||||
int fd = (int)real_syscall(SYS_openat, (long)dirfd, (long)link, (long)(O_PATH | O_NOFOLLOW | O_CLOEXEC), 0L);
|
||||
if (fd < 0) {
|
||||
return 0;
|
||||
}
|
||||
struct statfs fs;
|
||||
int procfs = real_syscall(SYS_fstatfs, (long)fd, (long)&fs) == 0 && fs.f_type == PROC_SUPER_MAGIC;
|
||||
real_syscall(SYS_close, (long)fd);
|
||||
if (!procfs) {
|
||||
return 0;
|
||||
}
|
||||
char saved = link[parent_len];
|
||||
link[parent_len] = 0;
|
||||
bl_stat parent;
|
||||
long result = real_syscall(BL_SYS_FSTATAT, (long)dirfd, (long)(parent_len ? link : "."), (long)&parent, 0L);
|
||||
link[parent_len] = saved;
|
||||
return result != 0 || parent.st_ino != BL_PROC_ROOT_INO;
|
||||
}
|
||||
|
||||
// RESOLVE_IN_ROOT walked one component at a time: absolute symlinks restart at dirfd and ".." stops there.
|
||||
static long openat_in_root(int dirfd, const char *path, int flags, long mode) {
|
||||
char resolved[PATH_MAX];
|
||||
char pending[PATH_MAX];
|
||||
size_t resolved_len = 0;
|
||||
int symlinks = 0;
|
||||
int have_root = 0;
|
||||
int root_on_procfs = 0;
|
||||
dev_t root_dev = 0;
|
||||
// O_NOFOLLOW and O_CREAT | O_EXCL leave a final symlink alone, unless a trailing slash follows it.
|
||||
int nofollow = (flags & O_NOFOLLOW) || (flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
|
||||
const char *rest = path;
|
||||
for (;;) {
|
||||
while (*rest == '/') {
|
||||
rest++;
|
||||
}
|
||||
if (!*rest) {
|
||||
break;
|
||||
}
|
||||
const char *name = rest;
|
||||
const char *end = name;
|
||||
while (*end && *end != '/') {
|
||||
end++;
|
||||
}
|
||||
size_t len = (size_t)(end - name);
|
||||
rest = end;
|
||||
while (*rest == '/') {
|
||||
rest++;
|
||||
}
|
||||
int last = !*rest;
|
||||
int trailing_slash = last && rest != end;
|
||||
if (len == 1 && name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
if (len == 2 && name[0] == '.' && name[1] == '.') {
|
||||
while (resolved_len > 0 && resolved[resolved_len - 1] != '/') {
|
||||
resolved_len--;
|
||||
}
|
||||
if (resolved_len > 0) {
|
||||
resolved_len--;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
size_t separator = resolved_len > 0;
|
||||
size_t candidate_len = resolved_len + separator + len;
|
||||
if (candidate_len + 1 >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
if (separator) {
|
||||
resolved[resolved_len] = '/';
|
||||
}
|
||||
memcpy(resolved + resolved_len + separator, name, len);
|
||||
resolved[candidate_len] = 0;
|
||||
bl_stat st;
|
||||
int follow = !last || trailing_slash || !nofollow;
|
||||
long stat_result = follow ? real_syscall(BL_SYS_FSTATAT, (long)dirfd, (long)resolved, (long)&st, (long)AT_SYMLINK_NOFOLLOW) : -1;
|
||||
if (stat_result == 0 && S_ISLNK(st.st_mode)) {
|
||||
if (++symlinks > BL_MAX_SYMLINKS) {
|
||||
errno = ELOOP;
|
||||
return -1;
|
||||
}
|
||||
if (!have_root) {
|
||||
bl_stat root;
|
||||
struct statfs root_fs;
|
||||
if (real_syscall(BL_SYS_FSTATAT, (long)dirfd, (long)".", (long)&root, 0L) != 0) {
|
||||
return -1;
|
||||
}
|
||||
root_dev = root.st_dev;
|
||||
root_on_procfs = real_syscall(SYS_fstatfs, (long)dirfd, (long)&root_fs) == 0 && root_fs.f_type == PROC_SUPER_MAGIC;
|
||||
have_root = 1;
|
||||
}
|
||||
if ((st.st_dev != root_dev || root_on_procfs) && is_magic_link(dirfd, resolved, resolved_len)) {
|
||||
// RESOLVE_IN_ROOT refuses magic links.
|
||||
errno = EXDEV;
|
||||
return -1;
|
||||
}
|
||||
size_t rest_len = strlen(end);
|
||||
if (rest_len + 1 >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
char *tail = pending + PATH_MAX - rest_len - 1;
|
||||
memmove(tail, end, rest_len + 1);
|
||||
long target_len = real_syscall(SYS_readlinkat, (long)dirfd, (long)resolved, (long)pending, (long)(PATH_MAX - rest_len));
|
||||
if (target_len <= 0) {
|
||||
if (target_len == 0) {
|
||||
errno = ENOENT;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if ((size_t)target_len + rest_len >= PATH_MAX) {
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
memmove(pending + target_len, tail, rest_len + 1);
|
||||
if (pending[0] == '/') {
|
||||
resolved_len = 0;
|
||||
}
|
||||
rest = pending;
|
||||
continue;
|
||||
}
|
||||
if (last) {
|
||||
resolved_len = candidate_len;
|
||||
if (trailing_slash) {
|
||||
resolved[resolved_len++] = '/';
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (stat_result != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (!S_ISDIR(st.st_mode)) {
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
resolved_len = candidate_len;
|
||||
}
|
||||
if (resolved_len == 0) {
|
||||
resolved[resolved_len++] = '.';
|
||||
}
|
||||
resolved[resolved_len] = 0;
|
||||
return real_syscall(SYS_openat, (long)dirfd, (long)resolved, (long)flags, mode);
|
||||
}
|
||||
|
||||
static long openat2_via_openat(const long *args) {
|
||||
const char *path = (const char *)args[1];
|
||||
const struct bl_open_how *how = (const struct bl_open_how *)args[2];
|
||||
@@ -83,6 +243,9 @@ static long openat2_via_openat(const long *args) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if ((how->resolve & BL_RESOLVE_IN_ROOT) && (int)args[0] != AT_FDCWD) {
|
||||
return openat_in_root((int)args[0], path, (int)how->flags, (long)how->mode);
|
||||
}
|
||||
if (how->resolve & BL_RESOLVE_IN_ROOT) {
|
||||
while (*path == '/') {
|
||||
path++;
|
||||
|
||||
@@ -145,7 +145,8 @@ static int steam_client(void) {
|
||||
static int cached = -1;
|
||||
if (cached < 0)
|
||||
cached = strcmp(program_invocation_short_name, "steam") == 0 &&
|
||||
strstr(program_invocation_name, "steamrtarm64") != NULL;
|
||||
(strstr(program_invocation_name, "steamrtarm64") != NULL ||
|
||||
strstr(program_invocation_name, "steamrt64") != NULL);
|
||||
return cached;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <ctype.h>
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
@@ -31,9 +33,16 @@ static int is_status_path(const char *path) {
|
||||
return strcmp(rest, "/status") == 0;
|
||||
}
|
||||
|
||||
static int is_web_helper(void) {
|
||||
return strcmp(program_invocation_short_name, "steamwebhelper") == 0 ||
|
||||
strcmp(program_invocation_short_name, "vrwebhelper") == 0;
|
||||
static int is_web_helper(const void *caller) {
|
||||
if (strcmp(program_invocation_short_name, "steamwebhelper") != 0 &&
|
||||
strcmp(program_invocation_short_name, "vrwebhelper") != 0)
|
||||
return 0;
|
||||
const char *hide = getenv("BL_WEBHELPER_HIDE_TRACER");
|
||||
Dl_info info;
|
||||
if (hide && hide[0] == '1' && caller && dladdr(caller, &info) && info.dli_fname
|
||||
&& strstr(info.dli_fname, "libtier0_s.so"))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int write_all(int fd, const char *data, size_t len) {
|
||||
@@ -47,13 +56,13 @@ static int write_all(int fd, const char *data, size_t len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("hidden"))) int bl_status_without_tracer(const char *path, int flags) {
|
||||
__attribute__((visibility("hidden"))) int bl_status_without_tracer(const char *path, int flags, const void *caller) {
|
||||
char text[STATUS_MAX];
|
||||
size_t len = 0;
|
||||
int saved = errno;
|
||||
int out = -1;
|
||||
|
||||
if ((flags & O_ACCMODE) != O_RDONLY || !is_status_path(path) || is_web_helper()) return -1;
|
||||
if ((flags & O_ACCMODE) != O_RDONLY || !is_status_path(path) || is_web_helper(caller)) return -1;
|
||||
int in = (int)syscall(SYS_openat, AT_FDCWD, path, O_RDONLY | O_CLOEXEC);
|
||||
if (in < 0) goto done;
|
||||
for (;;) {
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
"""Prepare the audited Windows runtime from a pinned APK and rebuilt replacements.
|
||||
|
||||
The donor was built from a CI merge, not just the PR head. Only unchanged
|
||||
components are reused. Session helpers come from this checkout, libblsession
|
||||
must be rebuilt for all three architectures, Gamescope comes from the current
|
||||
checksum-pinned release, and the VR components are rebuilt in Docker (or reused
|
||||
from a verified build manifest). Store engines are omitted (build with skipRust).
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path, PurePosixPath
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
from zipfile import ZipFile
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / 'tools/release'))
|
||||
import runtime_inputs as runtime
|
||||
from check_session_assets import source_assets
|
||||
sys.path.insert(0, str(ROOT / 'tools/vr'))
|
||||
import build_windows as vr_build
|
||||
|
||||
|
||||
DONOR_SHA256 = 'b7efef6442f384446bdd1750cec21f0eda61b370bc21d9f55187448e5c256760'
|
||||
DONOR_PR_SOURCE = 'bdf876d47cc9bb6fa810d014370da5bbb3c28039'
|
||||
DONOR_MAIN_SOURCE = '46fac69438ed428f2ca43ea935cd47790264f380'
|
||||
DONOR_TREE = 'ddbca4d572b809fb969be0cf80ef83d6ef6580ce'
|
||||
DONOR_REVISION = 'cf24c5f2c771633ea426046006c2b977c7bd7d32'
|
||||
DONOR_CERT_SHA256 = 'b241ea7d77822d39b89d3227e06f3ecf62adec6cbfd38ad06196787991b5d3f0'
|
||||
DONOR_URL = 'https://github.com/Droid-Deck/DroidDeck-CI/releases/download/pr-732/DroidDeck-PR.732-bdf876d.apk'
|
||||
AUDITED_SOURCE = '1dc66bf9be64a404c80400049c0803614814461b'
|
||||
LOCAL_BUILD_PLUMBING = {'app/build.gradle', 'tools/release/runtime_inputs.py'}
|
||||
# These Android-only inputs are compiled by Gradle, never taken from the donor.
|
||||
# Keep this list explicit so unrelated native or Linux runtime edits still fail.
|
||||
LOCAL_ANDROID_SOURCES = {'app/src/main/cpp/CMakeLists.txt',
|
||||
'app/src/main/cpp/viture/sdk_bridge.cpp',
|
||||
'app/src/main/cpp/viture/display_modes.h',
|
||||
'app/src/main/cpp/viture/stereo_frame_gate.h',
|
||||
'app/src/main/cpp/viture/uvc_bridge.cpp',
|
||||
'app/src/main/cpp/waylandcomp/src/cardboard.c',
|
||||
'app/src/main/cpp/waylandcomp/src/cardboard.h',
|
||||
'app/src/main/cpp/waylandcomp/src/cardboard.frag',
|
||||
'app/src/main/cpp/waylandcomp/src/cardboard_frag.h',
|
||||
'app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c',
|
||||
'app/src/main/cpp/waylandcomp/src/spatialpose.c',
|
||||
'app/src/main/cpp/waylandcomp/CMakeLists.txt'}
|
||||
# These audited helper updates are copied from this checkout by runtime.record().
|
||||
# Permit them only while source_assets() still guarantees that staging path.
|
||||
LOCAL_SESSION_HELPERS = {'tools/linuxfs/overlay/usr/local/bin/droiddeck-steam-compat',
|
||||
'tools/linuxfs/overlay/usr/local/bin/droiddeck-steamvr'}
|
||||
VR_PREFIX = 'assets/linuxfs/usr/local/lib/droiddeck-vr/'
|
||||
CHECK_PATHS = list(dict.fromkeys(runtime.SOURCE_PATHS + [
|
||||
'app/src/main/cpp', 'app/src/main/jniLibs', 'app/src/main/rust/stores', 'tools/vr']))
|
||||
REBUILT = {'libblsession.so': 183, 'x86_64/libblsession.so': 62, 'i386/libblsession.so': 3}
|
||||
REBUILT_SHA256 = {
|
||||
'libblsession.so': '1093ce33ca6d0a17a2eec7b3a3cc53969b01ffc459aef16b320cd3857825b738',
|
||||
'x86_64/libblsession.so': 'd0a558fee1ac4d5b898170a96b03e15610d9835e7097425027b8c31728da870a',
|
||||
'i386/libblsession.so': '785d8d9bf1fa20d083a7fed65d064c7580684d7065530d95a648e2d32901d2a2',
|
||||
}
|
||||
JNI = ('libproot.so', 'libproot-loader.so', 'libdirectaudiorelay.so')
|
||||
PREPARED = ('pulseaudio.tzst',
|
||||
'graphics_driver/adrenotools-turnip25.1.0-quest1.tzst',
|
||||
'graphics_driver/adrenotools-turnip26.3.0-a6xx.tzst',
|
||||
'graphics_driver/adrenotools-turnip26.3.0-quest2.tzst')
|
||||
|
||||
|
||||
def git(*args):
|
||||
return subprocess.check_output(['git', '-C', str(ROOT), *args])
|
||||
|
||||
|
||||
def changed(base, target=None):
|
||||
args = ['diff', '--no-ext-diff', '--ignore-cr-at-eol', '--name-only', '-z', base]
|
||||
if target:
|
||||
args.append(target)
|
||||
return set(filter(None, git(*args, '--', *CHECK_PATHS).decode().split('\0')))
|
||||
|
||||
|
||||
def check_sources():
|
||||
# A branch label alone is insufficient: CI merged this main commit into it.
|
||||
if git('merge-tree', '--write-tree', DONOR_PR_SOURCE, DONOR_MAIN_SOURCE).decode().splitlines()[0] != DONOR_TREE:
|
||||
raise ValueError('The donor CI merge does not match the audited source tree')
|
||||
helper_sources = {path.relative_to(ROOT).as_posix() for path in source_assets()}
|
||||
reviewed = LOCAL_BUILD_PLUMBING | LOCAL_ANDROID_SOURCES | (LOCAL_SESSION_HELPERS & helper_sources)
|
||||
unexpected = {p for p in changed(AUDITED_SOURCE, 'HEAD') - reviewed if not vr_build.is_source(p)}
|
||||
if unexpected:
|
||||
raise ValueError('Sources changed since the component audit:\n' + '\n'.join(sorted(unexpected)))
|
||||
local = changed('HEAD')
|
||||
untracked = set(filter(None, git('ls-files', '--others', '--exclude-standard', '-z',
|
||||
'--', *CHECK_PATHS).decode().split('\0')))
|
||||
unexpected = {p for p in (local - reviewed) | (untracked - LOCAL_ANDROID_SOURCES)
|
||||
if not vr_build.is_source(p)}
|
||||
if unexpected:
|
||||
raise ValueError('Unreviewed runtime/native/Rust changes:\n' + '\n'.join(sorted(unexpected)))
|
||||
classifications = {}
|
||||
for path in sorted(changed(DONOR_TREE, 'HEAD') | local | untracked):
|
||||
if vr_build.is_source(path):
|
||||
action = 'VR component rebuilt from current source and verified; never imported from donor'
|
||||
elif path in LOCAL_ANDROID_SOURCES:
|
||||
action = 'Android native source compiled by Gradle; not imported from donor'
|
||||
elif path.startswith('app/src/main/rust/stores/'):
|
||||
action = 'store engines omitted; Gradle must use skipRust=true'
|
||||
elif path in helper_sources:
|
||||
action = 'restaged from current source with LF line endings'
|
||||
elif path in {'tools/linuxfs/preload/net.c', 'tools/linuxfs/preload/webhelper.c'}:
|
||||
action = 'all three libblsession libraries rebuilt from current source'
|
||||
elif path == 'tools/gamescope/release.env':
|
||||
action = 'current checksum-pinned Gamescope archive replaces donor'
|
||||
elif path in {'tools/build_local.sh', 'tools/directaudio/fetch.sh'}:
|
||||
action = 'audited download/build cache plumbing; component inputs unchanged'
|
||||
elif path == 'app/src/main/cpp/waylandcomp/src/compositor.c':
|
||||
action = 'Android native library rebuilt by Gradle; not imported'
|
||||
elif path in LOCAL_BUILD_PLUMBING:
|
||||
action = 'local Windows build plumbing; changes recorded below'
|
||||
else:
|
||||
raise ValueError('Unclassified donor source difference: ' + path)
|
||||
classifications[path] = action
|
||||
return classifications
|
||||
|
||||
|
||||
def validate_relative(name):
|
||||
path = PurePosixPath(name)
|
||||
if path.is_absolute() or not path.parts or any(part in {'.', '..'} or ':' in part for part in path.parts):
|
||||
raise ValueError('Unsafe archive member: ' + name)
|
||||
if '\\' in name:
|
||||
raise ValueError('Backslash in archive member: ' + name)
|
||||
return path
|
||||
|
||||
|
||||
def checked_output(relative):
|
||||
validate_relative(relative)
|
||||
target = (ROOT / relative).resolve()
|
||||
if not target.is_relative_to(ROOT.resolve()):
|
||||
raise ValueError('Output escapes the checkout: ' + relative)
|
||||
if git('ls-files', '--', relative).strip():
|
||||
raise ValueError('Refusing to overwrite tracked file: ' + relative)
|
||||
return target
|
||||
|
||||
|
||||
def read_gamescope(path):
|
||||
pins = dict(line.split('=', 1) for line in (ROOT / 'tools/gamescope/release.env').read_text().splitlines()
|
||||
if line and not line.startswith('#'))
|
||||
if runtime.digest(path) != pins['GAMESCOPE_SHA256']:
|
||||
raise ValueError('Gamescope archive checksum does not match tools/gamescope/release.env')
|
||||
data = subprocess.run(['zstd', '-dc', str(path)], capture_output=True, check=True).stdout
|
||||
files = {}
|
||||
with tarfile.open(fileobj=io.BytesIO(data)) as archive:
|
||||
for member in archive:
|
||||
name = member.name.removeprefix('./')
|
||||
validate_relative(name)
|
||||
if member.isdir():
|
||||
continue
|
||||
if not member.isfile():
|
||||
raise ValueError('Gamescope archive contains a non-regular member: ' + name)
|
||||
if name in files:
|
||||
raise ValueError('Duplicate Gamescope archive member: ' + name)
|
||||
files[name] = archive.extractfile(member).read()
|
||||
if set(files) != {'usr/local/bin/gamescope'}:
|
||||
raise ValueError('Unexpected Gamescope archive payload: ' + ', '.join(files))
|
||||
return files, pins
|
||||
|
||||
|
||||
def validate_rebuilt(path, machine):
|
||||
data = path.read_bytes()
|
||||
if len(data) < 20 or data[:4] != b'\x7fELF' or data[5] != 1 or struct.unpack('<H', data[18:20])[0] != machine:
|
||||
raise ValueError('Replacement has the wrong ELF architecture: ' + str(path))
|
||||
return data
|
||||
|
||||
|
||||
def validate_tracked_assets(package, llvm_strip):
|
||||
checked = {}
|
||||
for prefix, apk_prefix in [('app/src/main/jniLibs/', 'lib/'),
|
||||
('app/src/main/assets/desktop-removal/', 'assets/desktop-removal/')]:
|
||||
tracked = filter(None, git('ls-files', '-z', '--', prefix).decode().split('\0'))
|
||||
for name in tracked:
|
||||
archive_name = apk_prefix + name.removeprefix(prefix)
|
||||
content = (ROOT / name).read_bytes()
|
||||
donor_content = package.read(archive_name)
|
||||
verification = 'identical bytes'
|
||||
if content != donor_content:
|
||||
if prefix != 'app/src/main/jniLibs/':
|
||||
raise ValueError('Tracked bytes differ from the donor: ' + name +
|
||||
' (text inputs must be checked out with LF)')
|
||||
# AGP strips prebuilt JNI libraries during packaging. Verify that
|
||||
# deterministic transformation on a temporary copy, never the source.
|
||||
with tempfile.TemporaryDirectory(prefix='droiddeck-strip-check-') as temp:
|
||||
stripped = Path(temp) / 'library.so'
|
||||
subprocess.run([str(llvm_strip), '--strip-unneeded', '-o', str(stripped),
|
||||
str(ROOT / name)], check=True, capture_output=True)
|
||||
if stripped.read_bytes() != donor_content:
|
||||
raise ValueError('Stripped tracked binary differs from donor: ' + name)
|
||||
verification = 'identical after NDK llvm-strip --strip-unneeded'
|
||||
checked[name] = {'source_sha256': hashlib.sha256(content).hexdigest(),
|
||||
'packaged_sha256': hashlib.sha256(donor_content).hexdigest(),
|
||||
'verification': verification}
|
||||
return checked
|
||||
|
||||
|
||||
def prepare(apk, rebuilt_dir, gamescope, llvm_strip=None, rebuilt_vr=None, vk_include=None, vr_image=vr_build.IMAGE):
|
||||
classifications = check_sources()
|
||||
if runtime.digest(apk) != DONOR_SHA256:
|
||||
raise ValueError('Donor APK checksum mismatch')
|
||||
gamescope_files, pins = read_gamescope(gamescope)
|
||||
replacements = {name: validate_rebuilt(rebuilt_dir / name, machine) for name, machine in REBUILT.items()}
|
||||
for name, data in replacements.items():
|
||||
if hashlib.sha256(data).hexdigest() != REBUILT_SHA256[name]:
|
||||
raise ValueError('Replacement does not match the audited local rebuild: ' + name)
|
||||
if vk_include is None:
|
||||
if llvm_strip is None:
|
||||
raise ValueError('Set --vk-include or --llvm-strip to locate the NDK Vulkan headers')
|
||||
vk_include = llvm_strip.parent.parent / 'sysroot/usr/include'
|
||||
if rebuilt_vr is None:
|
||||
vr_files, vr_manifest = vr_build.build(ROOT / 'build/windows-setup/vr', vk_include, root=ROOT, image=vr_image)
|
||||
else:
|
||||
vr_files, vr_manifest = vr_build.validate(rebuilt_vr, vk_include, root=ROOT)
|
||||
helpers = source_assets()
|
||||
helper_assets = set(helpers.values())
|
||||
plan = {}
|
||||
origins = {}
|
||||
with ZipFile(apk) as package:
|
||||
names = package.namelist()
|
||||
if len(set(names)) != len(names):
|
||||
raise ValueError('Donor APK has duplicate ZIP entries')
|
||||
tracked = validate_tracked_assets(package, llvm_strip)
|
||||
excluded = {'assets/linuxfs/' + name for name in REBUILT}
|
||||
excluded.update('assets/linuxfs/' + name for name in gamescope_files)
|
||||
excluded.update(helper_assets)
|
||||
for name in names:
|
||||
if name.endswith('/') or name in excluded or name.startswith(VR_PREFIX):
|
||||
continue
|
||||
if name.startswith(('assets/linuxfs/', 'assets/directaudio/', 'assets/droiddeck-esync/')):
|
||||
target = 'app/src/main/' + name
|
||||
checked_output(target)
|
||||
plan[target] = package.read(name)
|
||||
origins[target] = 'verified donor APK'
|
||||
for name in JNI:
|
||||
target = 'app/src/main/jniLibs/arm64-v8a/' + name
|
||||
checked_output(target)
|
||||
plan[target] = package.read('lib/arm64-v8a/' + name)
|
||||
origins[target] = 'verified donor APK'
|
||||
for name in PREPARED:
|
||||
target = 'app/build/prepared-assets/' + name
|
||||
checked_output(target)
|
||||
plan[target] = package.read('assets/' + name)
|
||||
origins[target] = 'verified donor APK'
|
||||
for name, data in replacements.items():
|
||||
target = 'app/src/main/assets/linuxfs/' + name
|
||||
checked_output(target)
|
||||
plan[target] = data
|
||||
origins[target] = 'locally rebuilt libblsession'
|
||||
for name, data in gamescope_files.items():
|
||||
target = 'app/src/main/assets/linuxfs/' + name
|
||||
checked_output(target)
|
||||
plan[target] = data
|
||||
origins[target] = 'checksum-pinned Gamescope release'
|
||||
for name, data in vr_files.items():
|
||||
target = 'app/src/main/' + VR_PREFIX + name
|
||||
checked_output(target)
|
||||
plan[target] = data
|
||||
origins[target] = 'VR rebuilt from current source; source and output checksums verified'
|
||||
# Do not silently retain unrelated files from a prior preparation.
|
||||
expected = set(plan) | {'app/src/main/' + name for name in helper_assets}
|
||||
for tree in ('linuxfs', 'directaudio', 'droiddeck-esync'):
|
||||
base = ROOT / 'app/src/main/assets' / tree
|
||||
for path in base.rglob('*'):
|
||||
if path.is_file() and not any(part.startswith('.') for part in path.relative_to(base).parts):
|
||||
if path.relative_to(ROOT).as_posix() not in expected:
|
||||
raise ValueError('Unexpected existing generated asset: ' + str(path))
|
||||
for source in helpers:
|
||||
data = source.read_bytes()
|
||||
normalized = data.replace(b'\r\n', b'\n')
|
||||
if data != normalized:
|
||||
source.write_bytes(normalized)
|
||||
for target, data in plan.items():
|
||||
path = checked_output(target)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(data)
|
||||
runtime.record()
|
||||
runtime.verify()
|
||||
provenance = {
|
||||
'version': 1,
|
||||
'donor': {'url': DONOR_URL, 'sha256': DONOR_SHA256, 'signer_sha256': DONOR_CERT_SHA256,
|
||||
'pr_source': DONOR_PR_SOURCE, 'main_source': DONOR_MAIN_SOURCE,
|
||||
'source_tree': DONOR_TREE, 'embedded_revision': DONOR_REVISION},
|
||||
'source_commit': git('rev-parse', 'HEAD').decode().strip(),
|
||||
'classified_differences': classifications,
|
||||
'build_plumbing': {name: {'sha256': runtime.digest(ROOT / name),
|
||||
'diff': git('diff', 'HEAD', '--', name).decode()}
|
||||
for name in sorted(LOCAL_BUILD_PLUMBING)},
|
||||
'android_sources_built_by_gradle': {name: runtime.digest(ROOT / name)
|
||||
for name in sorted(LOCAL_ANDROID_SOURCES)
|
||||
if (ROOT / name).is_file()},
|
||||
'stores': 'omitted; use -PskipRust=true',
|
||||
'gamescope': {'repo': pins['GAMESCOPE_REPO'], 'tag': pins['GAMESCOPE_TAG'],
|
||||
'archive_sha256': pins['GAMESCOPE_SHA256']},
|
||||
'tracked_files_verified': tracked,
|
||||
'vr_build': vr_manifest,
|
||||
'outputs': {name: {'origin': origins[name], 'sha256': hashlib.sha256(data).hexdigest()}
|
||||
for name, data in sorted(plan.items())},
|
||||
'preload_sources': {path.relative_to(ROOT).as_posix(): runtime.digest(path)
|
||||
for path in sorted((ROOT / 'tools/linuxfs/preload').glob('*.c'))},
|
||||
'preload_build_scripts': {path.relative_to(ROOT).as_posix(): {
|
||||
'sha256': runtime.digest(path), 'script': path.read_text()}
|
||||
for path in sorted((ROOT / 'build/windows-setup').glob('build-preloads-*.sh'))},
|
||||
'runtime_manifest_sha256': runtime.digest(ROOT / runtime.MANIFEST),
|
||||
}
|
||||
output = ROOT / 'app/build/windows-runtime-provenance.json'
|
||||
output.write_text(json.dumps(provenance, indent=2, sort_keys=True) + '\n', encoding='utf-8')
|
||||
print('Runtime inputs verified; donor components, rebuilt preloads, rebuilt VR and pinned Gamescope recorded.')
|
||||
print('Store engines omitted: build with -PskipRust=true.')
|
||||
print(output)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--apk', type=Path, default=ROOT / 'build/windows-setup/DroidDeck-PR.732-bdf876d.apk')
|
||||
parser.add_argument('--rebuilt-linuxfs', type=Path, default=ROOT / 'build/windows-setup/rebuilt-linuxfs')
|
||||
parser.add_argument('--gamescope', type=Path, default=ROOT / 'build/windows-setup/gamescope.tzst')
|
||||
parser.add_argument('--llvm-strip', type=Path, default=Path.home() /
|
||||
'AppData/Local/Android/Sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/windows-x86_64/bin/llvm-strip.exe')
|
||||
parser.add_argument('--rebuilt-vr', type=Path, help='Reuse a VR build with vr-build.json; default rebuilds in Docker')
|
||||
parser.add_argument('--vk-include', type=Path, help='NDK Vulkan headers; defaults to the sysroot beside --llvm-strip')
|
||||
parser.add_argument('--vr-image', default=vr_build.IMAGE, help='Docker compiler image for a fresh VR build')
|
||||
parser.add_argument('--check-sources', action='store_true', help='Audit source differences without extracting files')
|
||||
args = parser.parse_args()
|
||||
zstd = ROOT / 'build/windows-setup/tools/zstd/zstd.exe'
|
||||
if not shutil.which('zstd') and zstd.is_file():
|
||||
import os
|
||||
os.environ['PATH'] = str(zstd.parent) + os.pathsep + os.environ.get('PATH', '')
|
||||
try:
|
||||
if args.check_sources:
|
||||
print(json.dumps(check_sources(), indent=2, sort_keys=True))
|
||||
else:
|
||||
prepare(args.apk.resolve(), args.rebuilt_linuxfs.resolve(), args.gamescope.resolve(), args.llvm_strip.resolve(),
|
||||
args.rebuilt_vr.resolve() if args.rebuilt_vr else None,
|
||||
args.vk_include.resolve() if args.vk_include else None, args.vr_image)
|
||||
except (ValueError, OSError, subprocess.CalledProcessError, KeyError) as error:
|
||||
parser.exit(1, str(error) + '\n')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -88,6 +88,12 @@ Added by DroidDeck:
|
||||
`mnt_id` from the pin's fdinfo. A later close/reuse of the tracee fd cannot redirect that read;
|
||||
a concurrent reuse for the same inode through a different bind mount is indistinguishable at
|
||||
the exit stop. It does not synthesize `STATX_MNT_ID_UNIQUE`.
|
||||
- `0016-robust-list-from-seccomp.patch` - Android's app policy refuses `set_robust_list` and
|
||||
`get_robust_list`. proot still answers the first with `ENOSYS` but keeps the head each thread
|
||||
offered (cleared on `execve`, none in a new task), and answers the second for the calling thread
|
||||
with it. SteamVR's `vrclient.so` asks for the head through libc's `syscall()`, which
|
||||
`libblsession.so`'s robust.c never sees: `libopenvr_api.so` opens it `RTLD_DEEPBIND`. Steam
|
||||
aborted on "futex robust_list not initialized by pthreads" as soon as SteamVR was registered.
|
||||
|
||||
Prototype (inert unless `PROOT_FASTPATH` is set; see `docs/development/proot-performance.md`):
|
||||
|
||||
|
||||
@@ -298,6 +298,27 @@ def deep_section():
|
||||
t("unlink missing", lambda: os.unlink(DEEP + "/new"))
|
||||
t("unlink", lambda: os.unlink(DEEP + "/renamed"))
|
||||
t("realpath", lambda: realpath(DEEP + "/sub/../sub/link"))
|
||||
srv = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
t("bind socket", lambda: srv.bind(DEEP + "/s.sock"))
|
||||
t("listen", lambda: srv.listen(1))
|
||||
cli = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
t("connect socket", lambda: cli.connect(DEEP + "/s.sock"))
|
||||
t("stat socket", lambda: mode_of(os.stat(DEEP + "/s.sock")))
|
||||
t("sockname", srv.getsockname)
|
||||
t("peername", cli.getpeername)
|
||||
t("accepted sockname", lambda: srv.accept()[0].getsockname())
|
||||
twin = DEEP[:-len("some")] + "more"
|
||||
os.makedirs(twin)
|
||||
other = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
t("bind same name elsewhere", lambda: other.bind(twin + "/s.sock"))
|
||||
t("sockname, first", srv.getsockname)
|
||||
t("sockname, same name elsewhere", other.getsockname)
|
||||
other.close()
|
||||
os.unlink(twin + "/s.sock")
|
||||
os.rmdir(twin)
|
||||
cli.close()
|
||||
srv.close()
|
||||
t("unlink socket", lambda: os.unlink(DEEP + "/s.sock"))
|
||||
t("listing", lambda: sorted(os.listdir(DEEP)))
|
||||
|
||||
|
||||
|
||||
+130
-12
@@ -109,7 +109,8 @@ static long tracer;
|
||||
|
||||
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t bind_lock;
|
||||
static void after_fork(void) { pthread_mutex_init(&cache_lock, NULL); pthread_mutex_init(&bind_lock, NULL); }
|
||||
static pthread_mutex_t long_lock;
|
||||
static void after_fork(void) { pthread_mutex_init(&cache_lock, NULL); pthread_mutex_init(&bind_lock, NULL); pthread_mutex_init(&long_lock, NULL); }
|
||||
|
||||
static int traced_by_match(const char *key) {
|
||||
static char buf[32768];
|
||||
@@ -140,6 +141,26 @@ static int traced_by_match(const char *key) {
|
||||
return found;
|
||||
}
|
||||
|
||||
static int fex_runs_32bit(void) {
|
||||
if (strcmp(program_invocation_short_name, "FEX") != 0 && strcmp(program_invocation_short_name, "FEXInterpreter") != 0)
|
||||
return 0;
|
||||
char args[PATH_MAX + 64];
|
||||
long fd = syscall(SYS_openat, AT_FDCWD, "/proc/self/cmdline", O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return 1;
|
||||
long n = syscall(SYS_read, fd, args, sizeof args - 1);
|
||||
syscall(SYS_close, fd);
|
||||
if (n <= 0) return 1;
|
||||
args[n] = 0;
|
||||
const char *prog = args + strlen(args) + 1;
|
||||
if (prog >= args + n || !*prog) return 1;
|
||||
unsigned char ident[5];
|
||||
fd = syscall(SYS_openat, AT_FDCWD, prog, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return 1;
|
||||
n = syscall(SYS_read, fd, ident, sizeof ident);
|
||||
syscall(SYS_close, fd);
|
||||
return !(n == 5 && memcmp(ident, "\x7f" "ELF", 4) == 0 && ident[4] == 2);
|
||||
}
|
||||
|
||||
static int in_tracer(struct bind *bd) {
|
||||
char h[PATH_MAX];
|
||||
if (snprintf(h, sizeof h, "/proc/%ld%s", tracer, bd->host + 10) >= (int)sizeof h) return 0;
|
||||
@@ -156,6 +177,7 @@ static void fp_init(void) {
|
||||
const char *r = getenv("PROOT_FP_ROOT"), *b = getenv("PROOT_FP_BINDS"), *t = getenv("PROOT_FP_TTL_MS");
|
||||
const char *key = getenv("PROOT_FP_KEY");
|
||||
if (!r || !*r || !key || !*key || getenv("PROOT_FP_OFF")) return;
|
||||
if (fex_runs_32bit()) return;
|
||||
void *p = mmap((void *)FP_STUB_ADDR, FP_STUB_SIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE, -1, 0);
|
||||
if (p != (void *)FP_STUB_ADDR) {
|
||||
@@ -1187,8 +1209,67 @@ int inotify_add_watch(int fd, const char *path, uint32_t mask) {
|
||||
}
|
||||
|
||||
|
||||
static long socket_address(const struct sockaddr *addr, socklen_t len, int follow, struct sockaddr_un *out, socklen_t *out_len) {
|
||||
/* The kernel reports a socket named through /proc/self/fd/N/<name> under that name: map it back, per socket. */
|
||||
enum { LONG_SELF, LONG_PEER };
|
||||
static struct { unsigned long ino; int kind; char name[sizeof ((struct sockaddr_un *)0)->sun_path]; char guest[sizeof ((struct sockaddr_un *)0)->sun_path]; } long_names[64];
|
||||
static unsigned long_next;
|
||||
static pthread_mutex_t long_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static const char *fd_name(const char *path) {
|
||||
if (strncmp(path, "/proc/self/fd/", 14) != 0) return NULL;
|
||||
const char *p = path + 14;
|
||||
if (*p < '0' || *p > '9') return NULL;
|
||||
while (*p >= '0' && *p <= '9') p++;
|
||||
return *p == '/' && p[1] ? p + 1 : NULL;
|
||||
}
|
||||
|
||||
static unsigned long socket_ino(int fd) {
|
||||
struct stat st;
|
||||
return sc(SYS_newfstatat, fd, (long)"", (long)&st, AT_EMPTY_PATH, 0) == 0 ? (unsigned long)st.st_ino : 0;
|
||||
}
|
||||
|
||||
static void remember_long(int fd, int kind, const char *name, const char *guest) {
|
||||
unsigned long ino = socket_ino(fd);
|
||||
if (!ino || !name || strlen(name) >= sizeof long_names[0].name || strlen(guest) >= sizeof long_names[0].guest) return;
|
||||
unsigned count = sizeof long_names / sizeof long_names[0], i = count;
|
||||
pthread_mutex_lock(&long_lock);
|
||||
for (unsigned n = 0; n < count && i == count; n++)
|
||||
if (long_names[n].ino == ino && long_names[n].kind == kind) i = n;
|
||||
if (i == count) i = long_next++ % count;
|
||||
long_names[i].ino = ino;
|
||||
long_names[i].kind = kind;
|
||||
snprintf(long_names[i].name, sizeof long_names[i].name, "%s", name);
|
||||
snprintf(long_names[i].guest, sizeof long_names[i].guest, "%s", guest);
|
||||
pthread_mutex_unlock(&long_lock);
|
||||
}
|
||||
|
||||
static int long_entry(int fd, int kind, const char *name, char *guest, size_t size) {
|
||||
unsigned long ino = socket_ino(fd);
|
||||
int found = -1;
|
||||
if (!ino || !name) return -1;
|
||||
pthread_mutex_lock(&long_lock);
|
||||
for (unsigned n = 0; n < sizeof long_names / sizeof long_names[0] && found < 0; n++)
|
||||
if (long_names[n].ino == ino && long_names[n].kind == kind && strcmp(long_names[n].name, name) == 0
|
||||
&& strlen(long_names[n].guest) < size) {
|
||||
memcpy(guest, long_names[n].guest, strlen(long_names[n].guest) + 1);
|
||||
found = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&long_lock);
|
||||
return found;
|
||||
}
|
||||
|
||||
static void remember_long_address(int fd, int kind, const struct sockaddr *addr, socklen_t len, const struct sockaddr_un *used) {
|
||||
const struct sockaddr_un *un = (const struct sockaddr_un *)addr;
|
||||
char guest[sizeof un->sun_path + 1];
|
||||
size_t glen = strnlen(un->sun_path, len - offsetof(struct sockaddr_un, sun_path));
|
||||
memcpy(guest, un->sun_path, glen);
|
||||
guest[glen] = 0;
|
||||
remember_long(fd, kind, fd_name(used->sun_path), guest);
|
||||
}
|
||||
|
||||
static long socket_address(const struct sockaddr *addr, socklen_t len, int follow, struct sockaddr_un *out, socklen_t *out_len, long *dir) {
|
||||
const struct sockaddr_un *un = (const struct sockaddr_un *)addr;
|
||||
*dir = -1;
|
||||
size_t room = sizeof un->sun_path;
|
||||
if (!addr || len <= offsetof(struct sockaddr_un, sun_path) || addr->sa_family != AF_UNIX || un->sun_path[0] == 0)
|
||||
return 0;
|
||||
@@ -1204,10 +1285,20 @@ static long socket_address(const struct sockaddr *addr, socklen_t len, int follo
|
||||
if (rs == 1 && follow) return -ENOENT;
|
||||
if (r.magic) return FP_SLOW;
|
||||
size_t hlen = strlen(r.host);
|
||||
if (hlen >= room) return FP_SLOW;
|
||||
memset(out, 0, sizeof *out);
|
||||
out->sun_family = AF_UNIX;
|
||||
memcpy(out->sun_path, r.host, hlen + 1);
|
||||
if (hlen >= room) {
|
||||
/* proot would bind it to a temporary name the fast path cannot see: name it through its directory. */
|
||||
char *slash = strrchr(r.host, '/');
|
||||
if (!slash || slash == r.host) return FP_SLOW;
|
||||
*slash = 0;
|
||||
*dir = sc(SYS_openat, AT_FDCWD, (long)r.host, O_PATH | O_DIRECTORY | O_CLOEXEC, 0, 0);
|
||||
if (*dir < 0) return FP_SLOW;
|
||||
hlen = snprintf(out->sun_path, room, "/proc/self/fd/%ld/%s", *dir, slash + 1);
|
||||
if (hlen >= room) { sc(SYS_close, *dir, 0, 0, 0, 0); *dir = -1; return FP_SLOW; }
|
||||
} else {
|
||||
memcpy(out->sun_path, r.host, hlen + 1);
|
||||
}
|
||||
*out_len = offsetof(struct sockaddr_un, sun_path) + hlen + 1;
|
||||
return 1;
|
||||
}
|
||||
@@ -1221,10 +1312,15 @@ int connect(int fd, const struct sockaddr *addr, socklen_t len) {
|
||||
REAL(connect, int (*)(int, const struct sockaddr *, socklen_t));
|
||||
struct sockaddr_un un;
|
||||
socklen_t un_len;
|
||||
long rs = fp_ready() ? socket_address(addr, len, 1, &un, &un_len) : FP_SLOW;
|
||||
long dir = -1;
|
||||
long rs = fp_ready() ? socket_address(addr, len, 1, &un, &un_len, &dir) : FP_SLOW;
|
||||
if (rs == 0 && !(addr && addr->sa_family == AF_UNIX) && !nonblocking(fd)) rs = FP_SLOW;
|
||||
if (rs == 0) rs = sc(SYS_connect, fd, (long)addr, len, 0, 0);
|
||||
else if (rs == 1) rs = sc(SYS_connect, fd, (long)&un, un_len, 0, 0);
|
||||
if (dir >= 0) {
|
||||
sc(SYS_close, dir, 0, 0, 0, 0);
|
||||
if (rs == 0 || rs == -EINPROGRESS) remember_long_address(fd, LONG_PEER, addr, len, &un);
|
||||
}
|
||||
ANSWER(rs, AT_FDCWD, "(connect)", real_connect(fd, addr, len));
|
||||
}
|
||||
|
||||
@@ -1232,13 +1328,18 @@ int bind(int fd, const struct sockaddr *addr, socklen_t len) {
|
||||
REAL(bind, int (*)(int, const struct sockaddr *, socklen_t));
|
||||
struct sockaddr_un un;
|
||||
socklen_t un_len;
|
||||
long rs = fp_ready() ? socket_address(addr, len, 0, &un, &un_len) : FP_SLOW;
|
||||
long dir = -1;
|
||||
long rs = fp_ready() ? socket_address(addr, len, 0, &un, &un_len, &dir) : FP_SLOW;
|
||||
if (rs == 0) rs = sc(SYS_bind, fd, (long)addr, len, 0, 0);
|
||||
else if (rs == 1) rs = sc(SYS_bind, fd, (long)&un, un_len, 0, 0);
|
||||
if (dir >= 0) {
|
||||
sc(SYS_close, dir, 0, 0, 0, 0);
|
||||
if (rs == 0) remember_long_address(fd, LONG_SELF, addr, len, &un);
|
||||
}
|
||||
ANSWER(rs, AT_FDCWD, "(bind)", real_bind(fd, addr, len));
|
||||
}
|
||||
|
||||
static void report_address(const struct sockaddr_storage *got, socklen_t got_len, struct sockaddr *addr, socklen_t *len) {
|
||||
static void report_address(int fd, int kind, const struct sockaddr_storage *got, socklen_t got_len, struct sockaddr *addr, socklen_t *len) {
|
||||
struct sockaddr_storage shown = *got;
|
||||
socklen_t shown_len = got_len;
|
||||
const struct sockaddr_un *un = (const struct sockaddr_un *)got;
|
||||
@@ -1248,7 +1349,7 @@ static void report_address(const struct sockaddr_storage *got, socklen_t got_len
|
||||
memcpy(h, un->sun_path, hl);
|
||||
h[hl] = 0;
|
||||
struct sockaddr_un *out = (struct sockaddr_un *)&shown;
|
||||
if (to_guest(h, g, sizeof g) == 0 && strlen(g) < sizeof out->sun_path) {
|
||||
if ((long_entry(fd, kind, fd_name(h), g, sizeof g) == 0 || to_guest(h, g, sizeof g) == 0) && strlen(g) < sizeof out->sun_path) {
|
||||
memset(out->sun_path, 0, sizeof out->sun_path);
|
||||
strcpy(out->sun_path, g);
|
||||
shown_len = offsetof(struct sockaddr_un, sun_path) + strlen(g) + 1;
|
||||
@@ -1259,6 +1360,22 @@ static void report_address(const struct sockaddr_storage *got, socklen_t got_len
|
||||
}
|
||||
|
||||
|
||||
static void inherit_long_name(int listener, int accepted) {
|
||||
unsigned long ino = socket_ino(listener);
|
||||
char name[sizeof long_names[0].name], guest[sizeof long_names[0].guest];
|
||||
int found = -1;
|
||||
if (!ino) return;
|
||||
pthread_mutex_lock(&long_lock);
|
||||
for (unsigned n = 0; n < sizeof long_names / sizeof long_names[0] && found < 0; n++)
|
||||
if (long_names[n].ino == ino && long_names[n].kind == LONG_SELF) {
|
||||
snprintf(name, sizeof name, "%s", long_names[n].name);
|
||||
snprintf(guest, sizeof guest, "%s", long_names[n].guest);
|
||||
found = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&long_lock);
|
||||
if (found == 0) remember_long(accepted, LONG_SELF, name, guest);
|
||||
}
|
||||
|
||||
static int pending(int fd) {
|
||||
struct pollfd p = { .fd = fd, .events = POLLIN };
|
||||
struct timespec now = { 0, 0 };
|
||||
@@ -1269,11 +1386,12 @@ static int accept_common(int fd, struct sockaddr *addr, socklen_t *len, int flag
|
||||
REAL(accept4, int (*)(int, struct sockaddr *, socklen_t *, int));
|
||||
if (!fp_ready() || (addr && !len) || (!nonblocking(fd) && !pending(fd))) { missed(__func__, AT_FDCWD, "(accept)"); return real_accept4(fd, addr, len, flags); }
|
||||
hits++;
|
||||
if (!addr) return ret(sc(SYS_accept4, fd, 0, 0, flags, 0));
|
||||
struct sockaddr_storage got;
|
||||
socklen_t got_len = sizeof got;
|
||||
long r = sc(SYS_accept4, fd, (long)&got, (long)&got_len, flags, 0);
|
||||
if (r >= 0) report_address(&got, got_len, addr, len);
|
||||
long r = sc(SYS_accept4, fd, addr ? (long)&got : 0, addr ? (long)&got_len : 0, flags, 0);
|
||||
if (r >= 0) inherit_long_name(fd, (int)r);
|
||||
if (!addr) return ret(r);
|
||||
if (r >= 0) report_address((int)r, LONG_PEER, &got, got_len, addr, len);
|
||||
return ret(r);
|
||||
}
|
||||
int accept4(int fd, struct sockaddr *addr, socklen_t *len, int flags) { return accept_common(fd, addr, len, flags); }
|
||||
@@ -1285,7 +1403,7 @@ static int name_common(long nr, int fd, struct sockaddr *addr, socklen_t *len, i
|
||||
struct sockaddr_storage got;
|
||||
socklen_t got_len = sizeof got;
|
||||
long r = sc(nr, fd, (long)&got, (long)&got_len, 0, 0);
|
||||
if (r == 0) report_address(&got, got_len, addr, len);
|
||||
if (r == 0) report_address(fd, nr == SYS_getsockname ? LONG_SELF : LONG_PEER, &got, got_len, addr, len);
|
||||
return ret(r);
|
||||
}
|
||||
int getsockname(int fd, struct sockaddr *addr, socklen_t *len) {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: DroidDeck <droiddeck@users.noreply.github.com>
|
||||
Date: Tue, 13 Oct 2026 00:00:00 +0000
|
||||
Subject: [PATCH] seccomp: answer get_robust_list with the head set_robust_list
|
||||
was refused for
|
||||
|
||||
diff --git a/src/execve/exit.c b/src/execve/exit.c
|
||||
index f32d3ec..b5475b3 100644
|
||||
--- a/src/execve/exit.c
|
||||
+++ b/src/execve/exit.c
|
||||
@@ -473,6 +473,8 @@ void translate_execve_exit(Tracee *tracee)
|
||||
talloc_set_name_const(tracee->exe, "$exe");
|
||||
}
|
||||
|
||||
+ tracee->robust_list = 0;
|
||||
+
|
||||
/* New processes have no heap. */
|
||||
if (talloc_reference_count(tracee->heap) >= 1) {
|
||||
talloc_unlink(tracee, tracee->heap);
|
||||
diff --git a/src/tracee/seccomp.c b/src/tracee/seccomp.c
|
||||
index 77d5b27..0af232b 100644
|
||||
--- a/src/tracee/seccomp.c
|
||||
+++ b/src/tracee/seccomp.c
|
||||
@@ -559,6 +559,24 @@ static int handle_seccomp_event_common(Tracee *tracee)
|
||||
}
|
||||
|
||||
case PR_set_robust_list:
|
||||
+ tracee->robust_list = peek_reg(tracee, CURRENT, SYSARG_1);
|
||||
+ set_result_after_seccomp(tracee, -ENOSYS);
|
||||
+ break;
|
||||
+
|
||||
+ case PR_get_robust_list:
|
||||
+ {
|
||||
+ pid_t pid = (pid_t) peek_reg(tracee, CURRENT, SYSARG_1);
|
||||
+ if (tracee->robust_list == 0 || (pid != 0 && pid != tracee->pid)) {
|
||||
+ set_result_after_seccomp(tracee, -ENOSYS);
|
||||
+ break;
|
||||
+ }
|
||||
+ poke_word(tracee, peek_reg(tracee, CURRENT, SYSARG_2), tracee->robust_list);
|
||||
+ if (errno == 0)
|
||||
+ poke_word(tracee, peek_reg(tracee, CURRENT, SYSARG_3), 3 * sizeof_word(tracee));
|
||||
+ set_result_after_seccomp(tracee, errno != 0 ? -EFAULT : 0);
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
default:
|
||||
/* Set errno to -ENOSYS */
|
||||
set_result_after_seccomp(tracee, -ENOSYS);
|
||||
diff --git a/src/tracee/tracee.h b/src/tracee/tracee.h
|
||||
index 1fca85f..496ca75 100644
|
||||
--- a/src/tracee/tracee.h
|
||||
+++ b/src/tracee/tracee.h
|
||||
@@ -248,6 +248,8 @@ typedef struct tracee {
|
||||
* has to be ignored as it's same syscall entry */
|
||||
bool seccomp_already_handled_enter;
|
||||
|
||||
+ word_t robust_list;
|
||||
+
|
||||
/**********************************************************************
|
||||
* Shared or private resources, depending on the CLONE_FS/VM flags. *
|
||||
**********************************************************************/
|
||||
@@ -8,7 +8,7 @@ from zipfile import ZipFile
|
||||
|
||||
|
||||
SYSTEM = set('libc.so libm.so libdl.so liblog.so libandroid.so libz.so libvulkan.so libstdc++.so '
|
||||
'libGLESv2.so libEGL.so libnativewindow.so libjnigraphics.so libaaudio.so '
|
||||
'libGLESv2.so libGLESv3.so libEGL.so libnativewindow.so libjnigraphics.so libaaudio.so '
|
||||
'libOpenSLES.so libmediandk.so libcamera2ndk.so libsync.so libneuralnetworks.so'.split())
|
||||
EXPORTS = ['Java_com_droiddeck_launcher_stores_StoresNative_nativeVersion',
|
||||
'Java_com_droiddeck_launcher_stores_gog_GogNative_nativeStart',
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
"""Reject an APK with missing or stale session helpers, including cached local bundles."""
|
||||
from pathlib import Path
|
||||
import importlib.util
|
||||
import re
|
||||
import sys
|
||||
from zipfile import ZipFile
|
||||
|
||||
|
||||
OVERLAY = Path(__file__).resolve().parents[1] / 'linuxfs/overlay'
|
||||
SESSION_FILES = OVERLAY.parents[2] / 'app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt'
|
||||
|
||||
|
||||
def check_extraction(overlay, source):
|
||||
deployed = set(re.findall(r'"(usr/local/bin/droiddeck-[^"]+)"\s+to\s+"\1"', source))
|
||||
return ['not extracted at session start: ' + path.relative_to(overlay).as_posix()
|
||||
for path in sorted((overlay / 'usr/local/bin').glob('droiddeck-*'))
|
||||
if path.relative_to(overlay).as_posix() not in deployed]
|
||||
|
||||
|
||||
def source_assets(overlay=OVERLAY):
|
||||
@@ -24,7 +33,7 @@ def source_assets(overlay=OVERLAY):
|
||||
|
||||
|
||||
def check(apk, overlay=OVERLAY):
|
||||
errors = []
|
||||
errors = check_extraction(overlay, SESSION_FILES.read_text()) if overlay == OVERLAY else []
|
||||
with ZipFile(apk) as package:
|
||||
for source, asset in source_assets(overlay).items():
|
||||
try:
|
||||
|
||||
@@ -20,6 +20,8 @@ SOURCE_PATHS = ['app/build.gradle', 'app/src/main/cpp/fakeinput_steam.cpp', 'app
|
||||
'tools/powervr', 'tools/hybris', 'tools/dxvk', 'tools/vulkan-wsi',
|
||||
'tools/release/runtime_inputs.py', 'app/src/main/assets/desktop-removal',
|
||||
'tools/quest', 'tools/vr/src', 'tools/vr/driver_droiddeck', 'tools/vr/layer', 'tools/vr/build.sh',
|
||||
'app/src/main/cpp/waylandcomp/src/headpose_shm.h',
|
||||
'app/src/main/cpp/waylandcomp/src/spatialpose_shm.h',
|
||||
'app/src/main/cpp/adrenotools/src/hook/kgsl.h',
|
||||
'app/src/main/assets/graphics_driver/adrenotools-turnip25.1.0.tzst']
|
||||
|
||||
@@ -71,16 +73,22 @@ def required():
|
||||
for arch in ['x86_64', 'i386']:
|
||||
paths += ['assets/linuxfs/' + arch + '/' + lib for lib in ['libfakeinput.so', 'libblsession.so']]
|
||||
paths += ['assets/linuxfs/x86_64/' + lib for lib in
|
||||
['libfaultreport.so', 'libthunkaudit.so', 'libvulkan-thunk.so']]
|
||||
['libfaultreport.so', 'libvulkan-thunk.so', 'libwebkitinput.so']]
|
||||
paths += ['assets/linuxfs/i386/libfaultreport.so']
|
||||
paths += ['assets/linuxfs/usr/local/lib/droiddeck-msitools/' + name for name in
|
||||
['msiinfo', 'cabextract', '7z', '7z.so', 'libmsi-1.0.so.0', 'libgsf-1.so.114', 'libgcab-1.0.so.0']]
|
||||
paths += ['assets/linuxfs/usr/local/lib/droiddeck-xclipse/' + name for name in
|
||||
['libVkLayer_droiddeck_xclipse.so', 'VkLayer_droiddeck_xclipse.json']]
|
||||
paths += ['assets/linuxfs/usr/local/lib/droiddeck-vr/' + name for name in
|
||||
['droiddeck/bin/linuxarm64/driver_droiddeck.so', 'droiddeck/driver.vrdrivermanifest',
|
||||
['droiddeck/bin/linuxarm64/driver_droiddeck.so', 'droiddeck/bin/linuxarm64/xr-display-mode',
|
||||
'droiddeck/driver.vrdrivermanifest',
|
||||
'droiddeck/resources/settings/default.vrsettings', 'layer/libVkLayer_droiddeck_vr.so',
|
||||
'layer/VK_LAYER_DROIDDECK_vr.json', 'layer/VK_LAYER_DROIDDECK_vr_implicit.json']]
|
||||
'layer/VK_LAYER_DROIDDECK_vr.json', 'layer/VK_LAYER_DROIDDECK_vr_implicit.json',
|
||||
'layer/libdroiddeck_vr_scheduling.so']]
|
||||
for side in ['left', 'right']:
|
||||
paths += [f'assets/linuxfs/usr/local/lib/droiddeck-vr/droiddeck/resources/rendermodels/droiddeck_hand_{side}/{name}'
|
||||
for name in [f'droiddeck_hand_{side}.json', 'hand.mtl', 'hand.png', 'hand_open.obj', 'hand_fist.obj',
|
||||
'thumb_index_open.obj', 'thumb_index_pinch.obj']]
|
||||
paths += ['assets/linuxfs/usr/local/lib/mangoapp/' + name for name in
|
||||
['mangoapp', 'libfmt.so.10', 'libspdlog.so.1.13', 'libglfw.so.3', 'libtraceevent.so.1', 'libtracefs.so.1']]
|
||||
paths += ['assets/linuxfs/usr/local/lib/droiddeck-comet/' + name for name in
|
||||
|
||||
@@ -28,6 +28,7 @@ else
|
||||
python3 "$here/axml_rename.py" "$in" "$work/renamed.apk" \
|
||||
"$P=$pkg" "$P.androidx-startup=$pkg.androidx-startup" "$P.logs=$pkg.logs" \
|
||||
"$P.documents=$pkg.documents" "$P.home=$pkg.home" "$P.agent=$pkg.agent" \
|
||||
"$P.vr_recovery=$pkg.vr_recovery" \
|
||||
"$P.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION=$pkg.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION"
|
||||
fi
|
||||
got=$("$BUILD_TOOLS/aapt" dump badging "$work/renamed.apk" | sed -n "s/^package: name='\([^']*\)'.*/\1/p")
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
param([string]$Serial)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
Push-Location $repoRoot
|
||||
try {
|
||||
$javaConfig = if (Test-Path -LiteralPath '.gradle/config.properties' -PathType Leaf) {
|
||||
Get-Content -LiteralPath '.gradle/config.properties' | Where-Object { $_ -match '^java.home=' } | Select-Object -First 1
|
||||
}
|
||||
if ($javaConfig) { $env:JAVA_HOME = $javaConfig.Substring('java.home='.Length).Replace('\\', '\').Replace('\:', ':') }
|
||||
& .\gradlew.bat :app:assembleDebug --console=plain
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Android build failed.' }
|
||||
$adbArgs = @()
|
||||
if ($Serial) { $adbArgs = @('-s', $Serial) }
|
||||
& adb @adbArgs install -r 'app/build/outputs/apk/debug/app-debug.apk'
|
||||
if ($LASTEXITCODE -ne 0) { throw 'APK installation failed; existing app data was not removed.' }
|
||||
$suffixLine = if (Test-Path -LiteralPath 'local.properties' -PathType Leaf) {
|
||||
Get-Content -LiteralPath 'local.properties' | Where-Object { $_ -match '^droiddeck.debugApplicationIdSuffix=' } | Select-Object -First 1
|
||||
}
|
||||
$suffix = if ($suffixLine) { $suffixLine.Substring('droiddeck.debugApplicationIdSuffix='.Length) } else { '' }
|
||||
& adb @adbArgs shell am start -W -n "com.droiddeck.launcher$suffix/com.droiddeck.launcher.MainActivity"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'App launch failed.' }
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from adb_device import resolve_serial
|
||||
|
||||
|
||||
def validate_samples(samples, require_controllers=False):
|
||||
if len(samples) < 2:
|
||||
return 'No advancing telemetry; check runtime initialization and headset wake/proximity'
|
||||
if samples[-1]['rendered'] - samples[0]['rendered'] < 72:
|
||||
return 'Fewer than 72 additional stereo frames were submitted'
|
||||
if not any(sample['sessionState'] == 5 and sample['headFlags'] & 15 == 15 for sample in samples):
|
||||
return 'No focused session with tracked 6DoF position and orientation'
|
||||
if samples[-1]['sessionState'] != 5 or samples[-1]['headFlags'] & 15 != 15:
|
||||
return 'Session did not remain focused with tracked 6DoF through the final sample'
|
||||
if require_controllers and not any(all(sample['controllersActive']) for sample in samples):
|
||||
return 'Both controllers did not become active'
|
||||
if samples[-1].get('uploadedFrames', 0) - samples[0].get('uploadedFrames', 0) < 72:
|
||||
return 'No advancing owned SteamVR images; XR submissions alone are insufficient'
|
||||
if samples[-1].get('sourceFrameId', 0) <= samples[0].get('sourceFrameId', 0):
|
||||
return 'SteamVR source frame IDs did not advance'
|
||||
if samples[-1].get('steamvrState') != 4:
|
||||
return 'SteamVR did not report RUNNING'
|
||||
expected = 'frames'
|
||||
if samples[-1].get('source') != expected:
|
||||
return 'Wrong projection source'
|
||||
return None
|
||||
|
||||
|
||||
def summarize_samples(samples):
|
||||
result = {'sampleCount': len(samples), 'focusedTrackedFraction': None, 'observedSeconds': None, 'ratesHz': {}}
|
||||
if not samples:
|
||||
return result
|
||||
result['focusedTrackedFraction'] = sum(sample.get('sessionState') == 5 and sample.get('headFlags', 0) & 15 == 15
|
||||
for sample in samples) / len(samples)
|
||||
if len(samples) < 2 or '_hostMonotonicSeconds' not in samples[0] or '_hostMonotonicSeconds' not in samples[-1]:
|
||||
return result
|
||||
duration = samples[-1]['_hostMonotonicSeconds'] - samples[0]['_hostMonotonicSeconds']
|
||||
if duration <= 0:
|
||||
return result
|
||||
result['observedSeconds'] = duration
|
||||
for counter in ('rendered', 'guestFrames', 'receivedFrames', 'rejectedFrames', 'uploadedFrames'):
|
||||
if counter in samples[0] and counter in samples[-1]:
|
||||
delta = samples[-1][counter] - samples[0][counter]
|
||||
result['ratesHz'][counter] = delta / duration if delta >= 0 else None
|
||||
period = samples[-1].get('periodNs', 0)
|
||||
result['runtimeRefreshHz'] = 1000000000 / period if period > 0 else None
|
||||
return result
|
||||
|
||||
|
||||
def collect_device_metrics(adb, package):
|
||||
result = {}
|
||||
for name, command in [('battery', ('shell', 'dumpsys', 'battery')),
|
||||
('thermal', ('shell', 'dumpsys', 'thermalservice')),
|
||||
('memory', ('shell', 'dumpsys', 'meminfo', package))]:
|
||||
try:
|
||||
result[name] = {'available': True, 'text': adb(*command)}
|
||||
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as error:
|
||||
result[name] = {'available': False, 'error': type(error).__name__}
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Validate immersive DroidDeck XR on a connected Quest')
|
||||
parser.add_argument('--adb', default=os.environ.get('ADB', 'adb'))
|
||||
parser.add_argument('--serial')
|
||||
parser.add_argument('--seconds', type=int, default=20)
|
||||
parser.add_argument('--output', type=Path, default=Path('build/questxr-validation'))
|
||||
parser.add_argument('--require-controllers', action='store_true')
|
||||
parser.add_argument('--keep-awake', action='store_true')
|
||||
parser.add_argument('--metrics', action='store_true', help='Record public battery, thermal and package memory dumps before/after testing')
|
||||
args = parser.parse_args()
|
||||
if args.seconds < 5 or args.seconds > 600:
|
||||
parser.error('--seconds must be between 5 and 600')
|
||||
serial = resolve_serial(args.adb, args.serial)
|
||||
args.output.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def adb(*command):
|
||||
return subprocess.run([args.adb, '-s', serial, *command], check=True,
|
||||
capture_output=True, text=True, timeout=15).stdout
|
||||
|
||||
package = 'com.droiddeck.launcher'
|
||||
health_path = f'/sdcard/Android/data/{package}/files/xr-health.json'
|
||||
adb('shell', 'rm', '-f', health_path)
|
||||
adb('shell', 'input', 'keyevent', 'KEYCODE_WAKEUP')
|
||||
launch = ['shell', 'am', 'start', '-n', f'{package}/.QuestXrActivity']
|
||||
samples = []
|
||||
failure = None
|
||||
metrics = {'before': collect_device_metrics(adb, package)} if args.metrics else None
|
||||
try:
|
||||
adb('shell', 'am', 'broadcast', '-a', 'com.oculus.vrpowermanager.prox_close')
|
||||
adb(*launch)
|
||||
deadline = time.monotonic() + args.seconds
|
||||
while time.monotonic() < deadline:
|
||||
time.sleep(1)
|
||||
adb('shell', 'am', 'broadcast', '-a', 'com.oculus.vrpowermanager.prox_close')
|
||||
try:
|
||||
sample = json.loads(adb('shell', 'cat', health_path))
|
||||
sample['_hostMonotonicSeconds'] = time.monotonic()
|
||||
samples.append(sample)
|
||||
if sample.get('error'):
|
||||
failure = sample['error']
|
||||
break
|
||||
except (subprocess.CalledProcessError, json.JSONDecodeError):
|
||||
pass
|
||||
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as error:
|
||||
failure = f'ADB operation failed: {type(error).__name__}'
|
||||
finally:
|
||||
if not args.keep_awake:
|
||||
try:
|
||||
adb('shell', 'am', 'broadcast', '-a', 'com.oculus.vrpowermanager.prox_far')
|
||||
except (subprocess.CalledProcessError, subprocess.TimeoutExpired):
|
||||
failure = failure or 'Could not restore headset proximity after testing'
|
||||
try:
|
||||
log = adb('logcat', '-d', '-s', 'DroidDeckXR:I', 'OpenXR-Loader:W', 'AndroidRuntime:E')
|
||||
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as error:
|
||||
log = str(error)
|
||||
(args.output / 'logcat.txt').write_text(log, encoding='utf-8')
|
||||
if metrics is not None:
|
||||
metrics['after'] = collect_device_metrics(adb, package)
|
||||
failure = failure or validate_samples(samples, args.require_controllers)
|
||||
report = {'ok': failure is None, 'error': failure, 'samples': samples, 'summary': summarize_samples(samples), 'deviceMetrics': metrics}
|
||||
(args.output / 'report.json').write_text(json.dumps(report, indent=2), encoding='utf-8')
|
||||
print(json.dumps({'ok': report['ok'], 'error': failure, 'samples': len(samples),
|
||||
'last': samples[-1] if samples else None}, indent=2))
|
||||
return 0 if report['ok'] else 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,83 @@
|
||||
const assert = require('assert');
|
||||
const vm = require('vm');
|
||||
const source = require('fs').readFileSync(process.argv[2], 'utf8');
|
||||
const calls = [], requests = [], errors = [], timers = new Set();
|
||||
let changed;
|
||||
const apps = { RunGame(...args) { calls.push({receiver: this, args}); return 'native'; } };
|
||||
const openvr = {
|
||||
RegisterForVRModeChange(callback) { changed = callback; callback(false); return {unregister() {}}; },
|
||||
StartVR(...args) { return args; },
|
||||
};
|
||||
const overview = new Map([
|
||||
['611670', {vr_only: true}],
|
||||
['620980', {vr_supported: true}],
|
||||
['730', {vr_only: false, vr_supported: false}],
|
||||
['18446744069414584320', {BSupportsVR() { return true; }}],
|
||||
]);
|
||||
const context = {
|
||||
SteamClient: {Apps: apps, OpenVR: openvr},
|
||||
appStore: {GetAppOverviewByGameID: id => overview.get(id)},
|
||||
droiddeckLaunchSteamVr: id => requests.push(id),
|
||||
setTimeout(callback, ms) { assert.strictEqual(ms, 600000); timers.add(callback); return callback; },
|
||||
clearTimeout: timer => timers.delete(timer),
|
||||
console: {error: message => errors.push(message)},
|
||||
};
|
||||
context.window = context;
|
||||
vm.createContext(context);
|
||||
assert.strictEqual(vm.runInContext(source, context), 'installed');
|
||||
assert.strictEqual(vm.runInContext(source, context), 'present');
|
||||
|
||||
assert.strictEqual(apps.RunGame(730, '', -1, 100), 'native');
|
||||
assert.deepStrictEqual(requests, []);
|
||||
assert.strictEqual(calls[0].receiver, apps);
|
||||
|
||||
const receiver = {};
|
||||
apps.RunGame.call(receiver, '611670', 'custom args', 2, 100);
|
||||
apps.RunGame('611670', 'duplicate', -1, 100);
|
||||
assert.strictEqual(apps.RunGame(620980, '', -1, 100), 'native');
|
||||
assert.deepStrictEqual(requests, ['611670']);
|
||||
assert.strictEqual(calls.length, 2);
|
||||
assert.deepStrictEqual(calls[1].args, [620980, '', -1, 100]);
|
||||
changed(false);
|
||||
assert.strictEqual(calls.length, 2);
|
||||
changed(true);
|
||||
assert.strictEqual(calls.length, 3);
|
||||
assert.strictEqual(calls[2].receiver, receiver);
|
||||
assert.deepStrictEqual(calls[2].args, ['611670', 'custom args', 2, 100]);
|
||||
assert.strictEqual(timers.size, 0);
|
||||
changed(true);
|
||||
assert.strictEqual(calls.length, 3);
|
||||
|
||||
changed(false);
|
||||
assert.strictEqual(apps.RunGame('18446744069414584320', '', -1, 100), 'native');
|
||||
assert.deepStrictEqual(calls[3].args, ['18446744069414584320', '', -1, 100]);
|
||||
assert.deepStrictEqual(requests, ['611670']);
|
||||
assert.strictEqual(timers.size, 0);
|
||||
changed(true);
|
||||
|
||||
apps.RunGame('250820', '', -1, 100);
|
||||
openvr.StartVR(true);
|
||||
assert.deepStrictEqual(requests.slice(-2), ['250820', '250820']);
|
||||
assert.strictEqual(calls.length, 4);
|
||||
|
||||
changed(false);
|
||||
apps.RunGame('611670', '', -1, 100);
|
||||
for (const timeout of [...timers]) { timers.delete(timeout); timeout(); }
|
||||
assert.strictEqual(context.__droiddeckSteamVr.pending.size, 0);
|
||||
assert.strictEqual(errors.length, 1);
|
||||
changed(true);
|
||||
assert.strictEqual(calls.length, 4);
|
||||
apps.RunGame('611670', '', -1, 100);
|
||||
assert.strictEqual(calls.length, 5);
|
||||
assert.strictEqual(context.__droiddeckSteamVr.lastError, null);
|
||||
|
||||
changed(false);
|
||||
context.droiddeckLaunchSteamVr = () => { throw new Error('bridge disconnected'); };
|
||||
assert.throws(() => apps.RunGame('611670', '', -1, 100), /bridge disconnected/);
|
||||
assert.strictEqual(context.__droiddeckSteamVr.pending.size, 0);
|
||||
assert.strictEqual(timers.size, 0);
|
||||
delete context.droiddeckLaunchSteamVr;
|
||||
assert.strictEqual(apps.RunGame('611670', '', -1, 100), 'native');
|
||||
assert.strictEqual(apps.RunGame('250820', '', -1, 100), 'native');
|
||||
assert.deepStrictEqual(openvr.StartVR(true), [true]);
|
||||
assert.strictEqual(calls.length, 7);
|
||||
@@ -0,0 +1,35 @@
|
||||
import importlib.util
|
||||
import io
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
import zipfile
|
||||
|
||||
|
||||
spec = importlib.util.spec_from_file_location('build_hand_lite', Path(__file__).parents[1] / 'build_hand_lite.py')
|
||||
builder = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(builder)
|
||||
|
||||
|
||||
class HandLiteBundleTest(unittest.TestCase):
|
||||
def test_embedded_labels_are_reproducible_without_changing_model_bytes(self):
|
||||
model = b'\x08\x00\x00\x00TFL3model tensors and weights'
|
||||
outputs = []
|
||||
for year, order in [(2020, ['labels.txt', 'handedness.txt']),
|
||||
(2026, ['handedness.txt', 'labels.txt'])]:
|
||||
source = io.BytesIO(model)
|
||||
with zipfile.ZipFile(source, 'a') as archive:
|
||||
for name in order:
|
||||
entry = zipfile.ZipInfo(name, (year, 10, 16, 12, 30, 0))
|
||||
archive.writestr(entry, name.encode())
|
||||
output = builder.canonicalize_associated_files(source.getvalue())
|
||||
self.assertEqual(model, output[:len(model)])
|
||||
self.assertEqual(output, builder.canonicalize_associated_files(output))
|
||||
with zipfile.ZipFile(io.BytesIO(output)) as archive:
|
||||
for name in order:
|
||||
self.assertEqual(name.encode(), archive.read(name))
|
||||
outputs.append(output)
|
||||
self.assertEqual(*outputs)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -516,6 +516,65 @@ class ProtonRunTest(Temp):
|
||||
self.assertEqual(env["SteamAppId"], "413150")
|
||||
self.assertTrue((self.root / "steamapps/compatdata/413150").is_dir())
|
||||
|
||||
def run_main(self, argv):
|
||||
calls, dirs = [], []
|
||||
with mock.patch.dict(os.environ, {"STEAM_COMPAT_CLIENT_INSTALL_PATH": str(self.root)}), \
|
||||
mock.patch.object(RUN["os"], "execve", lambda *a: calls.append(a)), \
|
||||
mock.patch.object(RUN["os"], "chdir", dirs.append), mock.patch.dict(RUN, {"say": lambda message: None}):
|
||||
code = RUN["main"](argv)
|
||||
return code, calls, dirs
|
||||
|
||||
def test_without_steam_a_steam_game_starts_its_default_windows_launch(self):
|
||||
info = {"common": {"type": "Game", "oslist": "windows,linux"}, "config": {"launch": {
|
||||
"0": {"executable": "Bin\\Game.exe", "arguments": "-dx11 \"-name=Two Words\"", "workingdir": "bin",
|
||||
"type": "default", "config": {"oslist": "windows"}},
|
||||
"1": {"executable": "game.sh", "type": "default", "config": {"oslist": "linux"}},
|
||||
"2": {"executable": "Beta.exe", "type": "default", "config": {"oslist": "windows", "betakey": "beta"}},
|
||||
"3": {"executable": "Tools\\Editor.exe", "type": "option1"},
|
||||
}}}
|
||||
self.write("Steam/appcache/appinfo.vdf", appinfo({413150: info}))
|
||||
program = self.game("413150", "Some Game", "bin/game.exe")
|
||||
self.game("413150", "Some Game", "Tools/Editor.exe")
|
||||
code, calls, dirs = self.run_main(["--app", "413150", "--options", "-windowed"])
|
||||
self.assertIsNone(code)
|
||||
entry, argv, env = calls[0]
|
||||
self.assertEqual(argv[1:], ["waitforexitandrun", str(program), "-dx11", "-name=Two Words", "-windowed"])
|
||||
self.assertEqual((env["SteamAppId"], env["STEAM_COMPAT_DATA_PATH"]),
|
||||
("413150", str(self.root / "steamapps/compatdata/413150")))
|
||||
self.assertEqual(dirs, [str(program.parent)])
|
||||
|
||||
def test_without_steam_a_game_steam_cannot_start_is_refused(self):
|
||||
self.write("Steam/appcache/appinfo.vdf", appinfo({413150: STARDEW}))
|
||||
self.assertEqual(self.run_main(["--app", "413150"])[0], 2)
|
||||
self.assertEqual(self.run_main(["--app", "3384071994"])[0], 2)
|
||||
self.assertEqual(self.run_main(["--app", "0"])[0], 2)
|
||||
self.assertEqual(self.run_main(["--app", "game"])[0], 2)
|
||||
linux = {"common": {"type": "Game"}, "config": {"launch": {"0": {"executable": "run.sh", "config": {"oslist": "linux"}}}}}
|
||||
self.write("Steam/appcache/appinfo.vdf", appinfo({70: linux}))
|
||||
self.game("70", "Linux Game", "run.sh")
|
||||
self.assertEqual(self.run_main(["--app", "70"])[0], 2)
|
||||
|
||||
def test_without_steam_a_shortcut_keeps_its_prefix_folder_and_launch_options(self):
|
||||
bat = self.write("Games/Epic/Game/.droiddeck-launch.bat", b"@echo off")
|
||||
start = self.tmp / "Games/Epic/Game/Binaries"
|
||||
start.mkdir()
|
||||
code, calls, dirs = self.run_main(["--app", "2733369024", "--dir", str(start), "--options",
|
||||
"PROTON_LOG=1 %command% -epicportal", "--", str(bat)])
|
||||
self.assertIsNone(code)
|
||||
entry, argv, env = calls[0]
|
||||
self.assertEqual(argv[1:], ["waitforexitandrun", str(bat), "-epicportal"])
|
||||
self.assertEqual((env["STEAM_COMPAT_DATA_PATH"], env["SteamAppId"], env["SteamGameId"], env["PROTON_LOG"]),
|
||||
(str(self.root / "steamapps/compatdata/2733369024"), "0", str(2733369024 << 32 | 0x02000000), "1"))
|
||||
self.assertTrue((self.root / "steamapps/compatdata/2733369024").is_dir())
|
||||
self.assertEqual(dirs, [str(start)])
|
||||
|
||||
def test_launch_options_split_like_steam_does(self):
|
||||
split = RUN["split_options"]
|
||||
self.assertEqual(split(""), ({}, []))
|
||||
self.assertEqual(split("-windowed -w 1280"), ({}, ["-windowed", "-w", "1280"]))
|
||||
self.assertEqual(split("A=1 B=\"x y\" gamemoderun %command% -dx12"), ({"A": "1", "B": "x y"}, ["-dx12"]))
|
||||
self.assertEqual(split("\"unterminated -x"), ({}, ["\"unterminated", "-x"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -291,6 +291,53 @@ class AgentTest(unittest.TestCase):
|
||||
self.assertFalse(result["supported"])
|
||||
evaluate.assert_not_called()
|
||||
|
||||
def test_shortcut_state_tells_a_lost_shortcut_from_a_loading_library(self):
|
||||
game_id = str((3333273269 << 32) | 0x02000000)
|
||||
self.assertEqual("not-shortcut", agent.steam_shortcut_state(self.dir, "413150"))
|
||||
for values, wanted, calls in ((["loading", "ready"], "ready", 2), (["loading", "missing"], "missing", 3),
|
||||
([None], "loading", 3)):
|
||||
clock = [0.0]
|
||||
replies = [{"value": v} for v in values] + [{"value": values[-1]}] * 10
|
||||
with self.subTest(values=values), patch.object(agent, "cdp_eval", side_effect=replies) as evaluate, \
|
||||
patch.object(agent.time, "monotonic", side_effect=lambda: clock[0]), \
|
||||
patch.object(agent.time, "sleep", side_effect=lambda delay: clock.__setitem__(0, clock[0] + delay)):
|
||||
self.assertEqual(wanted, agent.steam_shortcut_state(self.dir, game_id, timeout=1))
|
||||
self.assertEqual(calls, evaluate.call_count)
|
||||
self.assertIn("GetAppOverviewByGameID(%s)" % json.dumps(game_id), evaluate.call_args_list[0].args[1])
|
||||
|
||||
def test_shortcut_state_waits_out_an_unreachable_client_but_not_other_errors(self):
|
||||
game_id = str((3333273269 << 32) | 0x02000000)
|
||||
clock = [0.0]
|
||||
with patch.object(agent, "cdp_eval", side_effect=agent.AgentError("NO_DEVTOOLS", "down")), \
|
||||
patch.object(agent.time, "monotonic", side_effect=lambda: clock[0]), \
|
||||
patch.object(agent.time, "sleep", side_effect=lambda delay: clock.__setitem__(0, clock[0] + delay)):
|
||||
self.assertEqual("loading", agent.steam_shortcut_state(self.dir, game_id, timeout=1))
|
||||
with patch.object(agent, "cdp_eval", side_effect=agent.AgentError("CDP_EXCEPTION", "boom")):
|
||||
with self.assertRaises(agent.AgentError):
|
||||
agent.steam_shortcut_state(self.dir, game_id, timeout=1)
|
||||
|
||||
def test_shortcut_state_command_exits_with_the_state(self):
|
||||
game_id = str((3333273269 << 32) | 0x02000000)
|
||||
launch = self.dir.parent
|
||||
with patch.dict(os.environ, {"BL_LAUNCH_DIR": str(launch)}):
|
||||
for state, code in (("ready", 0), ("missing", 4), ("not-shortcut", 3), ("loading", 1)):
|
||||
with self.subTest(state=state), patch.object(agent, "steam_shortcut_state", return_value=state) as ask:
|
||||
self.assertEqual(code, agent.main(["--steam-shortcut-state", game_id, "2"]))
|
||||
self.assertEqual((launch / "agent", game_id, "2"), ask.call_args.args)
|
||||
with patch.object(agent, "steam_shortcut_state", side_effect=agent.AgentError("CDP_EXCEPTION", "boom")):
|
||||
self.assertEqual(1, agent.main(["--steam-shortcut-state", game_id]))
|
||||
self.assertEqual(2, agent.main(["--steam-shortcut-state"]))
|
||||
|
||||
def test_asleep_command_reports_steams_own_sleep_state(self):
|
||||
with patch.dict(os.environ, {"BL_LAUNCH_DIR": str(self.dir.parent)}):
|
||||
for value, code in (("yes", 0), ("no", 5), ("unknown", 1), (None, 1)):
|
||||
with self.subTest(value=value), patch.object(agent, "cdp_eval", return_value={"value": value}) as ask:
|
||||
self.assertEqual(code, agent.main(["--steam-asleep"]))
|
||||
self.assertIn("m_bSuspending", ask.call_args.args[1])
|
||||
self.assertFalse(ask.call_args.kwargs["await_promise"])
|
||||
with patch.object(agent, "cdp_eval", side_effect=agent.AgentError("NO_DEVTOOLS", "down")):
|
||||
self.assertEqual(1, agent.main(["--steam-asleep"]))
|
||||
|
||||
def test_cdp_exception(self):
|
||||
server = FakeDevTools({"result": {"result": {"type": "object"}, "exceptionDetails": {
|
||||
"text": "Uncaught", "exception": {"description": "ReferenceError: SteamClient is not defined"}}}})
|
||||
@@ -335,5 +382,35 @@ class AgentTest(unittest.TestCase):
|
||||
self.assertIn(child.pid, agent.game_pids(424242))
|
||||
|
||||
|
||||
class VrFocusTest(unittest.TestCase):
|
||||
def test_scene_dashboard_and_external_focus_changes(self):
|
||||
focus = agent.VrSceneFocus()
|
||||
self.assertEqual(focus.order([9, 7], [7, 42], 42), [42, 9, 7])
|
||||
self.assertIsNone(focus.order([42, 9, 7], [7, 42], 42))
|
||||
self.assertEqual(focus.order([42, 9, 7], [7, 42], None), [9, 7])
|
||||
self.assertIsNone(focus.order([9, 7], [7], 42))
|
||||
self.assertEqual(focus.order([9, 7], [7, 42], 42), [42, 9, 7])
|
||||
# Do not overwrite a different focus order installed after our last write.
|
||||
self.assertIsNone(focus.order([123, 7], [7, 42], None))
|
||||
|
||||
def test_scene_requires_live_server_and_game_environment(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
state = root / 'scene.json'
|
||||
for pid in (100, 200):
|
||||
(root / str(pid)).mkdir()
|
||||
(root / '100/comm').write_text('vrserver\n')
|
||||
(root / '200/environ').write_bytes(b'SteamAppId=42\0Other=value\0')
|
||||
state.write_text(json.dumps(dict(serverPid=100, scenePid=200, dashboard=False)))
|
||||
self.assertEqual(agent.vr_scene_app(state, root), 42)
|
||||
state.write_text(json.dumps(dict(serverPid=100, scenePid=200, dashboard=True)))
|
||||
self.assertIsNone(agent.vr_scene_app(state, root))
|
||||
state.write_text(json.dumps(dict(serverPid=100, scenePid=200, dashboard=False)))
|
||||
(root / '100/comm').write_text('other\n')
|
||||
self.assertIsNone(agent.vr_scene_app(state, root))
|
||||
(root / '100/comm').unlink()
|
||||
self.assertIsNone(agent.vr_scene_app(state, root))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
File diff suppressed because it is too large.
Load diff
@@ -92,6 +92,38 @@ class FexTestCase(unittest.TestCase):
|
||||
self.write(self.steam / "steamapps/appmanifest_1628350.acf", '"AppState" { "installdir" "SteamLinuxRuntime_sniper" }')
|
||||
return platform
|
||||
|
||||
def graphics(self, sniper, libc=b"GLIBC_2.2.5 GLIBC_2.31 GLIBC_2.34 GLIBC_2.41", libstdcxx=b"GLIBCXX_3.4.28 GLIBCXX_3.4.33"):
|
||||
files = Path(sniper) / "files"
|
||||
x86 = files / "lib/x86_64-linux-gnu"
|
||||
self.write(x86 / "libc-2.31.so", b"GLIBC_2.2.5 GLIBC_2.31")
|
||||
os.unlink(x86 / "libc.so.6")
|
||||
os.symlink("libc-2.31.so", x86 / "libc.so.6")
|
||||
self.write(x86 / "ld-2.31.so", b"old ld")
|
||||
os.symlink("ld-2.31.so", x86 / "ld-linux-x86-64.so.2")
|
||||
self.write(x86 / "libstdc++.so.6", b"GLIBCXX_3.4.28")
|
||||
self.write(x86 / "libSegFault.so", b"old")
|
||||
self.write(x86 / "libSDL2-2.0.so.0", b"sdl")
|
||||
self.write(x86 / "libfoo.so.1.2", b"foo")
|
||||
os.symlink("libfoo.so.1.2", x86 / "libfoo.so.1")
|
||||
self.write(x86 / "gconv/OLD.so", b"old gconv")
|
||||
self.write(files / "lib/i386-linux-gnu/libc.so.6", b"GLIBC_2.31")
|
||||
self.write(files / "lib/i386-linux-gnu/ld-2.31.so", b"old ld32")
|
||||
os.symlink("i386-linux-gnu/ld-2.31.so", files / "lib/ld-linux.so.2")
|
||||
os.unlink(files / "lib64/ld-linux-x86-64.so.2")
|
||||
os.symlink("../lib/x86_64-linux-gnu/ld-2.31.so", files / "lib64/ld-linux-x86-64.so.2")
|
||||
platform = self.steam / "steamapps/common/SteamLinuxRuntime_4/steamrt4_platform_4.0.20260928.262390"
|
||||
provided = platform / "files/lib/x86_64-linux-gnu"
|
||||
self.write(provided / "libc.so.6", libc)
|
||||
self.write(provided / "libstdc++.so.6", libstdcxx)
|
||||
self.write(provided / "ld-linux-x86-64.so.2", b"new ld")
|
||||
self.write(provided / "gconv/NEW.so", b"new gconv")
|
||||
self.write(platform / "files/lib/i386-linux-gnu/libc.so.6", b"GLIBC_2.41")
|
||||
self.write(platform / "files/lib/i386-linux-gnu/ld-linux.so.2", b"new ld32")
|
||||
with gzip.open(platform / "usr-mtree.txt.gz", "wt") as out:
|
||||
out.write("#mtree\n. type=dir\n")
|
||||
self.write(self.steam / "steamapps/appmanifest_4183110.acf", '"AppState" { "installdir" "SteamLinuxRuntime_4" }')
|
||||
return platform
|
||||
|
||||
def quiet(self, function, *args):
|
||||
with contextlib.redirect_stderr(io.StringIO()) as err:
|
||||
return function(*args), err.getvalue()
|
||||
@@ -198,12 +230,11 @@ class PrepareTest(FexTestCase):
|
||||
for arch in ("x86_64", "i386"):
|
||||
for name in ("libblsession.so", "libfakeinput.so"):
|
||||
self.write(self.tmp / "preloads" / arch / name, arch.encode() + name.encode())
|
||||
self.write(self.tmp / "preloads/x86_64/libthunkaudit.so", b"audit")
|
||||
self.write(self.tmp / "preloads/x86_64/libvulkan-thunk.so", b"pin")
|
||||
self.write(self.tmp / "ld.so.preload", "/usr/local/lib/libblsession.so\n/usr/local/lib/libfakeinput.so\n")
|
||||
FEX["install_preloads"](str(root))
|
||||
self.assertEqual((root / "lib/x86_64-linux-gnu/droiddeck/libthunkaudit.so").read_bytes(), b"audit")
|
||||
self.assertEqual((root / "lib/x86_64-linux-gnu/droiddeck/libvulkan-thunk.so").read_bytes(), b"pin")
|
||||
self.assertEqual((root / "lib/x86_64-linux-gnu/droiddeck/vulkan/libvulkan.so.1").read_bytes(), b"pin")
|
||||
self.assertEqual(os.readlink(root / "lib/x86_64-linux-gnu/droiddeck/vulkan/libvulkan.so"), "libvulkan.so.1")
|
||||
self.assertEqual((root / "etc/ld.so.preload").read_text(),
|
||||
"/usr/$LIB/droiddeck/libblsession.so\n/usr/$LIB/droiddeck/libfakeinput.so\n")
|
||||
self.assertEqual((root / "lib/i386-linux-gnu/droiddeck/libfakeinput.so").read_bytes(), b"i386libfakeinput.so")
|
||||
@@ -252,7 +283,71 @@ class PrepareTest(FexTestCase):
|
||||
status = json.loads((self.home / ".local/share/droiddeck-fex/status.json").read_text())
|
||||
self.assertEqual((status["ready"], status["runtime"], status["thunks"]), (True, str(platform), True))
|
||||
self.assertFalse((self.home / ".config/droiddeck/fex-wanted").exists())
|
||||
self.assertEqual(self.quiet(FEX["prepare"])[1], "")
|
||||
self.assertNotIn("prepared", self.quiet(FEX["prepare"])[1])
|
||||
|
||||
def test_a_newer_runtime_supplies_the_c_and_cxx_libraries(self):
|
||||
self.fex_tool()
|
||||
sniper = self.runtime()
|
||||
FEX["materialize"](str(sniper))
|
||||
provider = self.graphics(sniper)
|
||||
fex, said = self.quiet(FEX["prepare"])
|
||||
root = self.home / ".local/share/droiddeck-fex/rootfs"
|
||||
self.assertIn("built the x86 runtime from sniper_platform_", said)
|
||||
self.assertEqual(fex["rootfs"], str(root))
|
||||
config = json.loads((self.home / ".local/share/droiddeck-fex/config/Config.json").read_text())
|
||||
self.assertEqual(config["Config"]["RootFS"], str(root))
|
||||
x86 = root / "lib/x86_64-linux-gnu"
|
||||
self.assertEqual((x86 / "libc.so.6").read_bytes(), b"GLIBC_2.2.5 GLIBC_2.31 GLIBC_2.34 GLIBC_2.41")
|
||||
self.assertEqual((x86 / "libstdc++.so.6").read_bytes(), b"GLIBCXX_3.4.28 GLIBCXX_3.4.33")
|
||||
self.assertEqual((x86 / "ld-linux-x86-64.so.2").read_bytes(), b"new ld")
|
||||
self.assertEqual((x86 / "gconv/NEW.so").read_bytes(), b"new gconv")
|
||||
self.assertEqual((root / "lib/i386-linux-gnu/libc.so.6").read_bytes(), b"GLIBC_2.41")
|
||||
self.assertEqual((x86 / "libSDL2-2.0.so.0").read_bytes(), b"sdl")
|
||||
self.assertEqual(os.readlink(x86 / "libfoo.so.1"), "libfoo.so.1.2")
|
||||
self.assertEqual((x86 / "libfoo.so.1").read_bytes(), b"foo")
|
||||
for stale in ("libc-2.31.so", "ld-2.31.so", "libSegFault.so"):
|
||||
self.assertFalse(os.path.lexists(x86 / stale), stale)
|
||||
self.assertEqual(os.readlink(root / "lib/ld-linux.so.2"), "i386-linux-gnu/ld-linux.so.2")
|
||||
self.assertEqual((root / "lib/ld-linux.so.2").read_bytes(), b"new ld32")
|
||||
self.assertEqual(os.readlink(root / "lib64/ld-linux-x86-64.so.2"), "../lib/x86_64-linux-gnu/ld-linux-x86-64.so.2")
|
||||
self.assertEqual((root / "lib64/ld-linux-x86-64.so.2").read_bytes(), b"new ld")
|
||||
self.assertEqual(os.readlink(root / "usr"), ".")
|
||||
self.assertEqual((root / "usr/bin/[").read_bytes(), b"blob")
|
||||
self.assertEqual((sniper / "files/lib/x86_64-linux-gnu/libc.so.6").read_bytes(), b"GLIBC_2.2.5 GLIBC_2.31")
|
||||
status = json.loads((self.home / ".local/share/droiddeck-fex/status.json").read_text())
|
||||
self.assertEqual(status["graphics"], str(provider))
|
||||
self.assertNotIn("built", self.quiet(FEX["prepare"])[1])
|
||||
os.utime(provider / "usr-mtree.txt.gz", ns=(1, 1))
|
||||
self.assertIn("built the x86 runtime", self.quiet(FEX["prepare"])[1])
|
||||
self.assertEqual(sorted(os.listdir(root.parent)), ["config", "lock", "rootfs", "status.json"])
|
||||
|
||||
def test_a_runtime_that_is_not_newer_is_left_out(self):
|
||||
self.fex_tool()
|
||||
sniper = self.runtime()
|
||||
FEX["materialize"](str(sniper))
|
||||
self.graphics(sniper, libc=b"GLIBC_2.2.5 GLIBC_2.31", libstdcxx=b"GLIBCXX_3.4.28")
|
||||
fex, said = self.quiet(FEX["prepare"])
|
||||
self.assertEqual(fex["rootfs"], str(sniper / "files"))
|
||||
self.assertIn("has no newer C and C++ libraries than sniper_platform_", said)
|
||||
self.assertFalse((self.home / ".local/share/droiddeck-fex/rootfs").exists())
|
||||
|
||||
def test_x86_steamworks_finds_the_x86_client(self):
|
||||
for directory, machine in (("linux64", 62), ("linux32", 3), ("linuxarm64", 183)):
|
||||
self.write(self.steam / directory / "steamclient.so", elf(machine))
|
||||
sdk = self.home / ".steam"
|
||||
sdk.mkdir(parents=True)
|
||||
os.symlink(self.steam / "linuxarm64", sdk / "sdk64")
|
||||
os.symlink(self.steam / "linuxarm64", sdk / "sdkarm64")
|
||||
FEX["link_steam_sdk"]()
|
||||
self.assertEqual(os.readlink(sdk / "sdk64"), str(self.steam / "linux64"))
|
||||
self.assertEqual(os.readlink(sdk / "sdk32"), str(self.steam / "linux32"))
|
||||
self.assertEqual(os.readlink(sdk / "sdkarm64"), str(self.steam / "linuxarm64"))
|
||||
os.unlink(sdk / "sdk32")
|
||||
os.symlink(self.tmp / "elsewhere", sdk / "sdk32")
|
||||
self.write(self.tmp / "elsewhere/steamclient.so", elf(3))
|
||||
FEX["link_steam_sdk"]()
|
||||
self.assertEqual(os.readlink(sdk / "sdk32"), str(self.tmp / "elsewhere"))
|
||||
self.assertEqual(sorted(os.listdir(sdk)), ["sdk32", "sdk64", "sdkarm64"])
|
||||
|
||||
def test_status_refreshes_what_the_app_reads_once_steam_installed_fex(self):
|
||||
with mock.patch.dict(G, {"steam_running": lambda: False}):
|
||||
@@ -317,6 +412,35 @@ class ExtractTest(FexTestCase):
|
||||
self.assertTrue((self.home / ".config/droiddeck/fex-wanted").is_file())
|
||||
self.assertFalse(json.loads((self.home / ".local/share/droiddeck-fex/status.json").read_text())["ready"])
|
||||
|
||||
def test_uruntime_that_only_drops_extended_attributes_still_unpacks(self):
|
||||
tool = self.uruntime(
|
||||
"mkdir -p AppDir && touch AppDir/AppRun\n"
|
||||
"echo 'Failed to exec memfd: EACCES: Permission denied. Trying tmpfile in /tmp...' >&2\n"
|
||||
"echo 'write_xattr: could not write xattr security.selinux for file ./AppDir/.DirIcon because you are not superuser!' >&2\n"
|
||||
"echo 'Further error messages of this type are suppressed!' >&2\n"
|
||||
"exit 2\n")
|
||||
with mock.patch.dict(G, {"URUNTIME": tool, "fex_install": lambda: None, "steam_running": lambda: False}):
|
||||
status, said = self.quiet(FEX["extract"], "image.AppImage")
|
||||
self.assertEqual(status, 0)
|
||||
self.assertIn("could not keep the image's extended attributes", said)
|
||||
self.assertTrue(Path("squashfs-root/AppRun").is_file())
|
||||
|
||||
def test_an_attribute_only_failure_without_apprun_is_not_taken_as_unpacked(self):
|
||||
tool = self.uruntime(
|
||||
"mkdir -p AppDir\n"
|
||||
"echo 'write_xattr: could not write xattr security.selinux for file ./AppDir/.DirIcon because you are not superuser!' >&2\n"
|
||||
"exit 2\n")
|
||||
with mock.patch.dict(G, {"URUNTIME": tool, "fex_install": lambda: None, "steam_running": lambda: False, "prepare": lambda: None}):
|
||||
status, said = self.quiet(FEX["extract"], "image.AppImage")
|
||||
self.assertIn("uruntime could not extract it (status 2)", said)
|
||||
self.assertNotIn("could not keep the image's extended attributes", said)
|
||||
self.assertFalse(os.path.lexists("squashfs-root/AppRun"))
|
||||
|
||||
def test_other_uruntime_errors_are_not_taken_as_unpacked(self):
|
||||
self.assertFalse(FEX["only_xattrs_failed"]("write_xattr: could not write xattr\nwrite_file: failed to create file x\n"))
|
||||
self.assertFalse(FEX["only_xattrs_failed"](""))
|
||||
self.assertTrue(FEX["only_xattrs_failed"]("proot error: execveat() failed\nwrite_xattr: could not write xattr\n"))
|
||||
|
||||
def test_an_arm64_image_does_not_ask_for_fex(self):
|
||||
self.write(self.image, elf(183) + b"payload", 0o755)
|
||||
tool = self.uruntime("mkdir -p squashfs-root\n")
|
||||
@@ -335,13 +459,40 @@ class ExtractTest(FexTestCase):
|
||||
self.assertIn("no AppImage runtime for ARM64, no FEX yet and no unsquashfs", said)
|
||||
self.assertFalse(os.path.lexists("squashfs-root"))
|
||||
|
||||
def test_unsquashfs_fallback_disables_unwritable_xattrs(self):
|
||||
tool = self.uruntime("exit 1\n")
|
||||
commands = []
|
||||
|
||||
def call(argv, **kwargs):
|
||||
commands.append(argv)
|
||||
if argv[0] == tool:
|
||||
return 1
|
||||
(self.work / "squashfs-root").mkdir()
|
||||
(self.work / "squashfs-root/AppRun").touch()
|
||||
return 0
|
||||
|
||||
with mock.patch.dict(G, {
|
||||
"URUNTIME": tool,
|
||||
"prepare": lambda: None,
|
||||
"fex_install": lambda: None,
|
||||
"steam_running": lambda: False,
|
||||
"want_fex": lambda: None,
|
||||
}), mock.patch("shutil.which", return_value="/usr/bin/unsquashfs"), \
|
||||
mock.patch("subprocess.call", side_effect=call):
|
||||
status, said = self.quiet(FEX["extract"], "image.AppImage")
|
||||
self.assertEqual(status, 0)
|
||||
self.assertIn("uruntime could not extract it (status 1)", said)
|
||||
self.assertEqual(commands[-1][0], "/usr/bin/unsquashfs")
|
||||
self.assertIn("-no-xattrs", commands[-1])
|
||||
self.assertTrue(Path("squashfs-root/AppRun").is_file())
|
||||
|
||||
|
||||
class LaunchTest(FexTestCase):
|
||||
def test_the_guest_environment(self):
|
||||
arm = self.write(self.tmp / "arm.so", elf(183))
|
||||
x86 = self.write(self.tmp / "x86.so", elf(62))
|
||||
env = {"LD_PRELOAD": "%s:%s %s" % (arm, x86, self.tmp / "gone.so"),
|
||||
"LD_LIBRARY_PATH": "/steam/steamrtarm64:/usr/lib/aarch64-linux-gnu:/game/lib",
|
||||
"LD_LIBRARY_PATH": "/steam/steamrtarm64:/usr/lib/aarch64-linux-gnu:/game/lib:/steam/linuxarm64",
|
||||
"FEX_ROOTFS": "/usr/share/guestos/fex-mesa", "FEX_TSOENABLED": "1"}
|
||||
guest = FEX["guest_environment"]({"portable": True}, env)
|
||||
self.assertEqual((guest["LD_PRELOAD"], guest["LD_LIBRARY_PATH"], guest["FEX_PORTABLE"]), (str(x86), "/game/lib", "1"))
|
||||
@@ -349,8 +500,10 @@ class LaunchTest(FexTestCase):
|
||||
self.assertEqual(guest["FEX_TSOENABLED"], "1")
|
||||
self.assertTrue(guest["FEX_APP_CONFIG_LOCATION"].endswith("/config/"))
|
||||
self.assertEqual((guest["FEX_SILENTLOG"], guest["FEX_OUTPUTLOG"]), ("0", "stderr"))
|
||||
guest = FEX["guest_environment"]({"portable": False}, {"LD_PRELOAD": str(arm), "FEX_PORTABLE": "1", "FEX_OUTPUTLOG": "/tmp/fex.log"})
|
||||
self.assertEqual(guest["FEX_OUTPUTLOG"], "/tmp/fex.log")
|
||||
self.assertEqual(guest["GC_DISABLE_INCREMENTAL"], "1")
|
||||
guest = FEX["guest_environment"]({"portable": False}, {"LD_PRELOAD": str(arm), "FEX_PORTABLE": "1", "FEX_OUTPUTLOG": "/tmp/fex.log",
|
||||
"GC_DISABLE_INCREMENTAL": "0"})
|
||||
self.assertEqual((guest["FEX_OUTPUTLOG"], guest["GC_DISABLE_INCREMENTAL"]), ("/tmp/fex.log", "0"))
|
||||
self.assertNotIn("LD_PRELOAD", guest)
|
||||
self.assertNotIn("FEX_PORTABLE", guest)
|
||||
|
||||
@@ -414,9 +567,8 @@ class LaunchTest(FexTestCase):
|
||||
self.runtime()
|
||||
self.write(tool / "usr/share/fex-emu/GuestThunks/libvulkan-guest.so",
|
||||
elf(62) + b"\0libstdc++.so.6\0GLIBCXX_3.4\0GLIBCXX_3.4.29\0libc.so.6\0GLIBC_2.2.5\0GLIBC_2.34\0")
|
||||
self.write(self.tmp / "preloads/x86_64/libthunkaudit.so", elf(62))
|
||||
pin = self.write(self.tmp / "preloads/x86_64/libvulkan-thunk.so", elf(62))
|
||||
audit = "/usr/lib/x86_64-linux-gnu/droiddeck/libthunkaudit.so"
|
||||
pin = self.write(self.tmp / "preloads/x86_64/libvulkan-thunk.so", elf(62) + b"\0libc.so.6\0GLIBC_2.2.5\0")
|
||||
pinned = "/usr/lib/x86_64-linux-gnu/droiddeck/vulkan"
|
||||
|
||||
def app(name, glibc=b"GLIBC_2.34\0GLIBC_2.44", glibcxx=b"GLIBCXX_3.4.29\0GLIBCXX_3.4.36", bundled=True):
|
||||
run = self.write(self.tmp / name / "AppRun", elf(62), 0o755)
|
||||
@@ -431,25 +583,32 @@ class LaunchTest(FexTestCase):
|
||||
_, said = self.quiet(FEX["launch"], [str(program)], dict(env or {}), "on", decide)
|
||||
return emulated.call_args[0][2], said
|
||||
|
||||
def search(env):
|
||||
return env.get("LD_LIBRARY_PATH", "").split(":")[0]
|
||||
|
||||
env, said = started(app("new"))
|
||||
self.assertEqual(env["LD_AUDIT"], audit)
|
||||
self.assertIn("thunks on, its own Vulkan loader too", said)
|
||||
env, _ = started(app("kept"), {"LD_AUDIT": "/opt/audit.so"})
|
||||
self.assertEqual(env["LD_AUDIT"], audit + ":/opt/audit.so")
|
||||
env, _ = started(self.write(self.tmp / "elsewhere/run.sh", "#!/bin/sh\n", 0o755), decide=str(self.tmp / "new"))
|
||||
self.assertEqual(env["LD_AUDIT"], audit)
|
||||
env, said = started(app("old-cxx", glibcxx=b"GLIBCXX_3.4.28"))
|
||||
self.assertEqual(search(env), pinned)
|
||||
self.assertNotIn("LD_AUDIT", env)
|
||||
self.assertNotIn("LD_BIND_NOW", env)
|
||||
self.assertIn("thunks on, its own Vulkan loader too", said)
|
||||
env, _ = started(app("kept"), {"LD_LIBRARY_PATH": "/game/lib"})
|
||||
self.assertEqual(env["LD_LIBRARY_PATH"], pinned + ":/game/lib")
|
||||
env, _ = started(self.write(self.tmp / "elsewhere/run.sh", "#!/bin/sh\n", 0o755), decide=str(self.tmp / "new"))
|
||||
self.assertEqual(search(env), pinned)
|
||||
env, said = started(app("old-cxx", glibcxx=b"GLIBCXX_3.4.28"))
|
||||
self.assertNotEqual(search(env), pinned)
|
||||
self.assertIn("thunks on)", said)
|
||||
self.assertNotIn("LD_AUDIT", started(app("old-libc", glibc=b"GLIBC_2.31"))[0])
|
||||
self.assertNotIn("LD_AUDIT", started(app("runtime-only", bundled=False))[0])
|
||||
self.assertNotEqual(search(started(app("old-libc", glibc=b"GLIBC_2.31"))[0]), pinned)
|
||||
self.assertNotEqual(search(started(app("runtime-only", bundled=False))[0]), pinned)
|
||||
i386 = self.write(self.tmp / "new/game.i386", elf(3), 0o755)
|
||||
self.assertNotIn("LD_AUDIT", started(i386)[0])
|
||||
self.assertNotEqual(search(started(i386)[0]), pinned)
|
||||
self.write(pin, elf(62) + b"\0libc.so.6\0GLIBC_2.45\0")
|
||||
self.assertNotEqual(search(started(app("new"))[0]), pinned)
|
||||
pin.unlink()
|
||||
self.assertNotIn("LD_AUDIT", started(app("no-pin"))[0])
|
||||
self.assertNotEqual(search(started(app("no-pin"))[0]), pinned)
|
||||
self.write(pin, elf(62))
|
||||
(tool / "usr/share/fex-emu/GuestThunks/libvulkan-guest.so").unlink()
|
||||
self.assertNotIn("LD_AUDIT", started(app("no-thunk"))[0])
|
||||
self.assertNotEqual(search(started(app("no-thunk"))[0]), pinned)
|
||||
|
||||
def test_steam_verbs(self):
|
||||
with mock.patch.dict(G, {"launch": mock.Mock(return_value=0)}):
|
||||
@@ -517,6 +676,53 @@ class AppInfoTest(unittest.TestCase):
|
||||
"40": None, "41": None, "50": "droiddeck-fex",
|
||||
}, hex(magic))
|
||||
|
||||
@staticmethod
|
||||
def manifest(steam, app, flags="4"):
|
||||
(steam / "steamapps").mkdir(exist_ok=True)
|
||||
(steam / ("steamapps/appmanifest_%s.acf" % app)).write_text('"AppState" { "appid" "%s" "StateFlags" "%s" }' % (app, flags))
|
||||
|
||||
def test_dual_platform_titles_keep_the_proton_default_unless_the_user_picks_fex(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
steam = Path(tmp) / "Steam"
|
||||
(steam / "appcache").mkdir(parents=True)
|
||||
(steam / "appcache/appinfo.vdf").write_bytes(self.appinfo({
|
||||
10: ("windows,linux", "", "game"), 20: ("windows,linux", "", "game"), 30: ("windows,linux", "", "game"),
|
||||
40: ("linux", "", "game"),
|
||||
}))
|
||||
self.COMPAT["APPINFO_CACHE"].clear()
|
||||
for app in ("3127680", "1628350", "4183110"):
|
||||
self.manifest(steam, app)
|
||||
tool, fex = self.COMPAT["TOOL"], self.COMPAT["FEX_TOOL"]
|
||||
state = Path(tmp) / "state"
|
||||
state.mkdir()
|
||||
(state / "state.json").write_text(json.dumps({"auto": {"20": fex}}))
|
||||
catalog = [{"name": tool, "display": "Proton Experimental ARM64", "dir": "Proton Experimental (ARM64)", "valve": True}]
|
||||
config = steam / "config/config.vdf"
|
||||
config.parent.mkdir()
|
||||
config.write_text('"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { '
|
||||
'"0" { "name" "%s" "config" "" "priority" "75" } '
|
||||
'"20" { "name" "%s" "config" "" "priority" "250" } '
|
||||
'"30" { "name" "%s" "config" "" "priority" "250" } } } } } }' % (tool, fex, fex))
|
||||
self.COMPAT["register_default"](str(config), ["10", "20", "30", "40"], catalog=catalog, directory=str(state))
|
||||
self.assertEqual(self.COMPAT["read_config_mapping"](str(config)),
|
||||
{"0": tool, "10": tool, "20": tool, "30": fex, "40": fex})
|
||||
|
||||
def test_tools_are_fetched_until_fully_installed_and_up_to_date(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
steam = Path(tmp)
|
||||
(steam / "steamapps").mkdir()
|
||||
downloads = self.COMPAT["tool_downloads"]
|
||||
self.assertEqual(downloads(str(steam)), [
|
||||
("4427310", "install"), ("3127680", "install"), ("1628350", "install"), ("4183110", "install")])
|
||||
self.manifest(steam, "4427310", flags="6")
|
||||
self.manifest(steam, "3127680", flags="1026")
|
||||
self.manifest(steam, "1628350", flags="4")
|
||||
(steam / "steamapps/appmanifest_4183110.acf").write_text('"AppState" { "appid" "4183110" }')
|
||||
self.assertEqual(downloads(str(steam)), [("4427310", "update"), ("3127680", "update"), ("4183110", "update")])
|
||||
for app in ("4427310", "3127680", "4183110"):
|
||||
self.manifest(steam, app)
|
||||
self.assertEqual(downloads(str(steam)), [])
|
||||
|
||||
def test_titles_with_a_valve_pick_are_found_installed_or_not(self):
|
||||
def deck(oslist, runtime, kind="game"):
|
||||
common = {"type": kind, "oslist": oslist, "steam_deck_compatibility": {"configuration": {"recommended_runtime": runtime}}}
|
||||
|
||||
@@ -160,6 +160,16 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
started = [e["args"] for e in self.calls() if e["args"][:3] == ["shell", "am", "start"]]
|
||||
self.assertIn("com.antutu.benchmark.full/com.droiddeck.launcher.agent.AgentStartActivity", started[0])
|
||||
|
||||
def test_a_malformed_package_is_refused_before_adb(self):
|
||||
with unittest.mock.patch.dict(os.environ, {"DROIDDECK_PACKAGE": "com.example;reboot"}):
|
||||
variant = load("droiddeckctl")
|
||||
out = io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(io.StringIO()):
|
||||
code = variant.main(["--adb", str(self.adb), "--serial", "fake-1", "state"])
|
||||
self.assertEqual(2, code)
|
||||
self.assertEqual("INVALID_REQUEST", json.loads(out.getvalue())["error"]["code"])
|
||||
self.assertFalse(self.calls())
|
||||
|
||||
def test_state_passes_through_with_the_serial(self):
|
||||
self.configure({"state": state()})
|
||||
code, out = self.run_ctl("state")
|
||||
@@ -305,6 +315,65 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
self.assertEqual(4, code)
|
||||
self.assertEqual("NO_FRAMES", out["error"]["code"])
|
||||
|
||||
def test_pacing_counts_both_buckets_of_one_cadence_and_only_the_chosen_layers_rates(self):
|
||||
text = "SurfaceFlinger TimeStats:\n" + "".join([
|
||||
timestats_record("droiddeck_wayland_game#7", 910, {16: 450, 17: 450, 33: 10}, 60),
|
||||
timestats_record("StatusBar#106", 4, {8: 3}, 90),
|
||||
])
|
||||
summary = ctl.pacing_summary(text, "com.droiddeck.launcher")
|
||||
self.assertEqual(10, summary["offCadence"])
|
||||
self.assertEqual([60], summary["refreshRates"])
|
||||
|
||||
def test_pacing_skips_a_game_layer_with_no_frames_for_the_surfaceview(self):
|
||||
text = "SurfaceFlinger TimeStats:\n" + "".join([
|
||||
timestats_record("droiddeck_wayland_game#7", 0, {}, 120),
|
||||
timestats_record("a1 SurfaceView[com.droiddeck.launcher/com.droiddeck.launcher.SessionActivity]#8", 600, {16: 598, 33: 1}, 120),
|
||||
])
|
||||
summary = ctl.pacing_summary(text, "com.droiddeck.launcher")
|
||||
self.assertEqual(600, summary["frames"])
|
||||
self.assertIn("SurfaceView[com.droiddeck.launcher/", summary["layers"][0])
|
||||
|
||||
def test_pacing_with_a_layer_that_drew_no_frames_exits_4(self):
|
||||
self.configure({}, timestats="SurfaceFlinger TimeStats:\n" + timestats_record("droiddeck_wayland_game#7", 0, {}, 120))
|
||||
with unittest.mock.patch.object(ctl.time, "sleep"):
|
||||
code, out = self.run_ctl("pacing", "--seconds", "1")
|
||||
self.assertEqual(4, code)
|
||||
self.assertEqual("NO_FRAMES", out["error"]["code"])
|
||||
|
||||
def test_pacing_turns_timestats_off_when_the_dump_fails(self):
|
||||
calls = []
|
||||
|
||||
def adb(_adb, _serial, *args, timeout=30):
|
||||
calls.append(args[3:])
|
||||
if "-dump" in args:
|
||||
raise ctl.ControlError("timed out", "ADB_FAILED")
|
||||
return ctl.subprocess.CompletedProcess(args, 0, b"", b"")
|
||||
|
||||
with unittest.mock.patch.object(ctl, "run_adb", adb), unittest.mock.patch.object(ctl.time, "sleep"):
|
||||
with self.assertRaises(ctl.ControlError) as caught:
|
||||
ctl.pacing("adb", "fake-1", 1)
|
||||
self.assertEqual("PACING_FAILED", caught.exception.code)
|
||||
self.assertEqual(("--timestats", "-disable"), calls[-1])
|
||||
|
||||
def test_pacing_fails_when_timestats_cannot_be_turned_off(self):
|
||||
def adb(_adb, _serial, *args, timeout=30):
|
||||
return ctl.subprocess.CompletedProcess(args, 1 if "-disable" in args else 0, b"", b"")
|
||||
|
||||
with unittest.mock.patch.object(ctl, "run_adb", adb), unittest.mock.patch.object(ctl.time, "sleep"):
|
||||
with self.assertRaises(ctl.ControlError) as caught:
|
||||
ctl.pacing("adb", "fake-1", 1)
|
||||
self.assertEqual("PACING_FAILED", caught.exception.code)
|
||||
self.assertIn("timestats off", str(caught.exception))
|
||||
|
||||
def test_pacing_maps_an_adb_failure_while_enabling_to_pacing_failed(self):
|
||||
def adb(*_args, **_kwargs):
|
||||
raise ctl.ControlError("adb vanished", "ADB_FAILED")
|
||||
|
||||
with unittest.mock.patch.object(ctl, "run_adb", adb):
|
||||
with self.assertRaises(ctl.ControlError) as caught:
|
||||
ctl.pacing("adb", "fake-1", 1)
|
||||
self.assertEqual("PACING_FAILED", caught.exception.code)
|
||||
|
||||
def test_input_requests(self):
|
||||
self.configure({"input": {"ok": True, "command": "input"}})
|
||||
self.run_ctl("input", "tap", "0.5", "0.25", "--space", "fraction")
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
import json
|
||||
import gzip
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
import zlib
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(TOOLS))
|
||||
loader = importlib.machinery.SourceFileLoader('ctl_xr', str(TOOLS / 'droiddeckctl'))
|
||||
spec = importlib.util.spec_from_loader(loader.name, loader)
|
||||
ctl = importlib.util.module_from_spec(spec)
|
||||
loader.exec_module(ctl)
|
||||
|
||||
|
||||
class XrCaptureTest(unittest.TestCase):
|
||||
def test_png_keeps_rgb_rows_and_dimensions(self):
|
||||
pixels = bytes([255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 255])
|
||||
png = ctl.xr_ppm_to_png(b'P6\n2 2\n255\n' + pixels)
|
||||
self.assertEqual(png[:8], b'\x89PNG\r\n\x1a\n')
|
||||
self.assertEqual(struct.unpack('>II', png[16:24]), (2, 2))
|
||||
position = png.index(b'IDAT')
|
||||
size = struct.unpack('>I', png[position - 4:position])[0]
|
||||
self.assertEqual(zlib.decompress(png[position + 4:position + 4 + size]),
|
||||
b'\0' + pixels[:6] + b'\0' + pixels[6:])
|
||||
|
||||
def test_incomplete_or_invalid_images_are_rejected(self):
|
||||
for data in (b'P6\n2 2\n255\nabc', b'P6\n0 1\n255\n', b'P6\n999999 1\n255\n', b'junk'):
|
||||
with self.subTest(data=data), self.assertRaises(ctl.ControlError):
|
||||
ctl.xr_ppm_to_png(data)
|
||||
|
||||
def test_linear_source_and_display_eye_have_distinct_png_transfer_tags(self):
|
||||
image = b'P6\n1 1\n255\n\x37\x37\x37'
|
||||
self.assertIn(b'gAMA' + struct.pack('>I', 100000), ctl.xr_ppm_to_png(image, linear=True))
|
||||
self.assertIn(b'sRGB\0', ctl.xr_ppm_to_png(image))
|
||||
|
||||
def capture(self, root, failed=False, replaced=False, no_response=False, source=False, truncated=False):
|
||||
calls = []
|
||||
token = None
|
||||
reads = 0
|
||||
def adb(_adb, _serial, *args, **kwargs):
|
||||
nonlocal token, reads
|
||||
calls.append(args)
|
||||
stdout = b''
|
||||
if args[0] == 'push':
|
||||
token = Path(args[1]).read_text()
|
||||
if args[:2] == ('shell', 'cat'):
|
||||
reads += 1
|
||||
stdout = json.dumps({'id': ('old' if reads == 1 or no_response or (replaced and reads > 2) else token),
|
||||
'ok': not failed, 'validLayer': not failed, 'sourceImage': source}).encode()
|
||||
if args[0] == 'exec-out':
|
||||
stdout = gzip.compress(b'P6\n1 1\n255\n\x12\x34\x56')
|
||||
if truncated:
|
||||
stdout = stdout[:-5]
|
||||
return subprocess.CompletedProcess(args, 0, stdout, b'')
|
||||
with patch.object(ctl, 'run_adb', side_effect=adb), patch.object(ctl.time, 'sleep'):
|
||||
result = ctl.xr_capture('adb', 'quest', root, 0.01 if no_response else 2)
|
||||
return result, calls
|
||||
|
||||
def test_stale_response_is_ignored_and_matching_pair_is_published(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory) / 'capture'
|
||||
result, calls = self.capture(root)
|
||||
self.assertTrue(result['ok'])
|
||||
self.assertEqual((root / 'left.png').read_bytes(), (root / 'right.png').read_bytes())
|
||||
self.assertEqual(len([c for c in calls if c[:2] == ('shell', 'cat')]), 3)
|
||||
self.assertTrue((root / 'capture.json').is_file())
|
||||
|
||||
def test_invalid_layer_replaced_capture_and_timeout_publish_no_images(self):
|
||||
for flags in ({'failed': True}, {'replaced': True}, {'no_response': True}, {'truncated': True}):
|
||||
with self.subTest(flags=flags), tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory) / 'capture'
|
||||
with self.assertRaises(ctl.ControlError):
|
||||
self.capture(root, **flags)
|
||||
self.assertFalse(root.exists())
|
||||
|
||||
def test_source_capture_is_pulled_when_supported_by_the_headset(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory) / 'capture'
|
||||
result, calls = self.capture(root, source=True)
|
||||
self.assertEqual(result['source'], str((root / 'source.png').resolve()))
|
||||
self.assertEqual(len([c for c in calls if c[0] == 'exec-out']), 3)
|
||||
|
||||
def test_output_creation_and_write_failures_are_file_errors(self):
|
||||
for operation in ('mkdir', 'write_bytes'):
|
||||
with self.subTest(operation=operation), tempfile.TemporaryDirectory() as directory:
|
||||
with patch.object(Path, operation, side_effect=PermissionError('output denied')):
|
||||
with self.assertRaises(ctl.ControlError) as caught:
|
||||
self.capture(Path(directory) / 'capture')
|
||||
self.assertEqual(caught.exception.code, 'FILE_IO')
|
||||
self.assertEqual(ctl.exit_code(caught.exception), 6)
|
||||
|
||||
def test_stalled_metadata_read_uses_capture_deadline_and_reports_timeout(self):
|
||||
calls = []
|
||||
def adb(_adb, _serial, *args, **kwargs):
|
||||
calls.append((args, kwargs))
|
||||
if args[:2] == ('shell', 'cat'):
|
||||
self.assertGreater(kwargs['timeout'], 0)
|
||||
self.assertLessEqual(kwargs['timeout'], 0.1)
|
||||
try:
|
||||
raise subprocess.TimeoutExpired('adb', kwargs['timeout'])
|
||||
except subprocess.TimeoutExpired as cause:
|
||||
raise ctl.ControlError('metadata stalled', 'ADB_FAILED') from cause
|
||||
return subprocess.CompletedProcess(args, 0, b'', b'')
|
||||
with tempfile.TemporaryDirectory() as directory, patch.object(ctl, 'run_adb', side_effect=adb):
|
||||
with self.assertRaises(ctl.ControlError) as caught:
|
||||
ctl.xr_capture('adb', 'quest', Path(directory) / 'capture', 0.1)
|
||||
self.assertEqual(caught.exception.code, 'TIMEOUT')
|
||||
self.assertTrue(any(args[:3] == ('shell', 'rm', '-f') for args, _ in calls))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,144 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[2] / "app/src/main/cpp/fakeinput_steam.cpp"
|
||||
RING_MAGIC = 0x46494252
|
||||
DESCRIPTION_MAGIC = 0x46495544
|
||||
HEADER = 64
|
||||
EVENT = 24
|
||||
CAPACITY = 4096
|
||||
DESCRIPTION = 1824
|
||||
READER = r"""
|
||||
#include <fcntl.h>
|
||||
#include <linux/input.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct input_event events[64];
|
||||
int fd = open("/dev/input/event16", O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
while (read(fd, events, sizeof(events)) > 0)
|
||||
;
|
||||
puts("ready");
|
||||
fflush(stdout);
|
||||
char go;
|
||||
if (read(0, &go, 1) != 1)
|
||||
return 1;
|
||||
ssize_t got = read(fd, events, sizeof(events));
|
||||
for (ssize_t i = 0; i < got / (ssize_t)sizeof(events[0]); i++)
|
||||
printf("%ld.%06ld %u %u %d\n", (long)events[i].time.tv_sec, (long)events[i].time.tv_usec, events[i].type,
|
||||
events[i].code, events[i].value);
|
||||
return got > 0 ? 0 : 1;
|
||||
}
|
||||
"""
|
||||
PROBE = r"""
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/joystick.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char name[128] = "";
|
||||
struct input_id id = {0};
|
||||
int fd = open("/dev/input/event16", O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
return 1;
|
||||
int joydev = ioctl(fd, JSIOCGNAME(sizeof(name)), name);
|
||||
printf("JSIOCGNAME %d %s\n", joydev, joydev < 0 && errno == EINVAL ? "EINVAL" : name);
|
||||
if (ioctl(fd, EVIOCGID, &id) < 0 || ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0)
|
||||
return 1;
|
||||
printf("%04x:%04x %s\n", id.vendor, id.product, name);
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def can_build(bits):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
probe = Path(tmp) / "probe.cpp"
|
||||
probe.write_text("#include <string>\nint main() { return std::string().size(); }\n")
|
||||
return subprocess.run(["g++", bits, "-static-libstdc++", "-o", str(Path(tmp) / "probe"), str(probe)],
|
||||
capture_output=True).returncode == 0
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == "linux" and os.uname().machine == "x86_64" and shutil.which("g++")
|
||||
and shutil.which("gcc"), "needs gcc and g++ on an x86-64 Linux host")
|
||||
class FakeinputRingTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(shutil.rmtree, self.tmp, True)
|
||||
|
||||
def ring(self):
|
||||
hooks = self.tmp / "hooks"
|
||||
hooks.mkdir()
|
||||
(hooks / "event16").touch()
|
||||
ring = bytearray(HEADER + CAPACITY * EVENT + DESCRIPTION)
|
||||
struct.pack_into("<IIIIQQQ", ring, 0, RING_MAGIC, 2, EVENT, CAPACITY, 5, 0, 0)
|
||||
struct.pack_into("<IiHHHHI80s", ring, HEADER + CAPACITY * EVENT, DESCRIPTION_MAGIC, os.getpid(),
|
||||
3, 0x28de, 0x11ff, 1, 16, b"Microsoft X-Box 360 pad 0")
|
||||
path = hooks / ".uinput-event16"
|
||||
path.write_bytes(bytes(ring))
|
||||
return hooks, path
|
||||
|
||||
def build(self, bits, program, name):
|
||||
if not can_build(bits):
|
||||
self.skipTest("no %s C++ toolchain" % bits)
|
||||
library = self.tmp / ("libfakeinput%s.so" % bits)
|
||||
subprocess.run(["g++", bits, "-shared", "-fPIC", "-O2", "-Wno-attributes", "-pthread", "-std=c++17",
|
||||
"-static-libstdc++", "-static-libgcc", "-Wl,--exclude-libs,ALL", "-o", str(library),
|
||||
str(SOURCE), "-ldl"], check=True, capture_output=True)
|
||||
binary = self.tmp / (name + bits)
|
||||
(self.tmp / (name + ".c")).write_text(program)
|
||||
subprocess.run(["gcc", bits, "-o", str(binary), str(self.tmp / (name + ".c"))], check=True)
|
||||
return library, binary
|
||||
|
||||
def read_through(self, bits):
|
||||
library, reader = self.build(bits, READER, "reader")
|
||||
hooks, path = self.ring()
|
||||
env = dict(os.environ, LD_PRELOAD=str(library), FAKE_EVDEV_DIR=str(hooks))
|
||||
process = subprocess.Popen([str(reader)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, env=env, text=True)
|
||||
self.addCleanup(process.kill)
|
||||
self.assertEqual(process.stdout.readline(), "ready\n")
|
||||
with open(path, "r+b") as ring:
|
||||
for i, (kind, code, value) in enumerate(((1, 304, 1), (3, 1, -32768), (0, 0, 0))):
|
||||
ring.seek(HEADER + (5 + i) * EVENT)
|
||||
ring.write(struct.pack("<qqHHi", 1700000000 + i, 250000, kind, code, value))
|
||||
ring.seek(16)
|
||||
ring.write(struct.pack("<Q", 8))
|
||||
output, _ = process.communicate("g", timeout=10)
|
||||
self.assertEqual(process.returncode, 0)
|
||||
return output
|
||||
|
||||
def test_a_32_bit_guest_reads_the_64_bit_ring(self):
|
||||
self.assertEqual(self.read_through("-m32"),
|
||||
"1700000000.250000 1 304 1\n1700000001.250000 3 1 -32768\n1700000002.250000 0 0 0\n")
|
||||
|
||||
def test_a_64_bit_guest_reads_the_same_ring(self):
|
||||
self.assertEqual(self.read_through("-m64"),
|
||||
"1700000000.250000 1 304 1\n1700000001.250000 3 1 -32768\n1700000002.250000 0 0 0\n")
|
||||
|
||||
def test_an_event_node_rejects_joydev_requests_so_sdl_reads_its_id(self):
|
||||
library, probe = self.build("-m64", PROBE, "probe")
|
||||
hooks, _ = self.ring()
|
||||
run = subprocess.run([str(probe)], capture_output=True, text=True, timeout=10,
|
||||
env=dict(os.environ, LD_PRELOAD=str(library), FAKE_EVDEV_DIR=str(hooks)))
|
||||
self.assertEqual(run.returncode, 0, run.stderr)
|
||||
self.assertEqual(run.stdout, "JSIOCGNAME -1 EINVAL\n28de:11ff Microsoft X-Box 360 pad 0\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,91 @@
|
||||
import hashlib
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-steam-x64"
|
||||
SOURCE = SCRIPT.read_text()
|
||||
START = SOURCE.index("fex_install() {")
|
||||
END = SOURCE.index("\n}\n", START) + 3
|
||||
FEX_INSTALL = SOURCE[START:END]
|
||||
|
||||
HARNESS = textwrap.dedent("""\
|
||||
set -eu
|
||||
# The archive comes from PKG; the installed tree loads when INSTALLED_LOADS=1, any staged tree always does.
|
||||
curl() { local out=; while [ $# -gt 0 ]; do [ "$1" = -o ] && out=$2; shift; done; cp "$PKG" "$out"; }
|
||||
fex_loads() { case $1 in "$ROOT"/) [ "${INSTALLED_LOADS:-1}" = 1 ] ;; *) true ;; esac; }
|
||||
""")
|
||||
|
||||
|
||||
class FexInstallTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
base = Path(self.temp.name)
|
||||
self.root = base / "root"
|
||||
old = self.root / "usr/local"
|
||||
(old / "bin").mkdir(parents=True)
|
||||
(old / "bin/FEX").write_text("old FEX\n")
|
||||
(old / "share/fex-emu").mkdir(parents=True)
|
||||
(old / "share/fex-emu/.droiddeck-tag").write_text("fex-2610-r5\n")
|
||||
new = base / "pkg/usr/local"
|
||||
(new / "bin").mkdir(parents=True)
|
||||
(new / "bin/FEX").write_text("new FEX\n")
|
||||
(new / "lib").mkdir()
|
||||
(new / "lib/libxxhash.so.0").write_text("lib\n")
|
||||
self.pkg = base / "fex.tzst"
|
||||
subprocess.run(f"tar -C '{base / 'pkg'}' -c . | zstd -q -o '{self.pkg}'", shell=True, check=True)
|
||||
self.sha = hashlib.sha256(self.pkg.read_bytes()).hexdigest()
|
||||
|
||||
def install(self, installed_loads, sha=None):
|
||||
body = FEX_INSTALL.replace("local tag=$1 sha=$2 urls=$3 dst=/ ", "local tag=$1 sha=$2 urls=$3 dst=$ROOT/ ")
|
||||
self.assertNotEqual(body, FEX_INSTALL)
|
||||
script = HARNESS + body + 'if fex_install fex-2610-r6 "$SHA" u; then echo OK; else echo FAILED; fi\n'
|
||||
env = dict(os.environ, ROOT=str(self.root), PKG=str(self.pkg), SHA=sha or self.sha,
|
||||
INSTALLED_LOADS="1" if installed_loads else "0")
|
||||
out = subprocess.run(["bash", "-c", script], env=env, text=True, capture_output=True, timeout=30)
|
||||
self.assertEqual(0, out.returncode, out.stderr)
|
||||
return out.stdout.strip().splitlines()[-1], out.stderr
|
||||
|
||||
def tag(self):
|
||||
return (self.root / "usr/local/share/fex-emu/.droiddeck-tag").read_text().strip()
|
||||
|
||||
def test_a_build_that_loads_once_installed_replaces_the_old_one(self):
|
||||
result, _ = self.install(installed_loads=True)
|
||||
self.assertEqual("OK", result)
|
||||
self.assertEqual("new FEX\n", (self.root / "usr/local/bin/FEX").read_text())
|
||||
self.assertTrue((self.root / "usr/local/lib/libxxhash.so.0").is_file())
|
||||
self.assertEqual("fex-2610-r6", self.tag())
|
||||
|
||||
def test_an_installed_copy_that_does_not_load_puts_the_old_files_back(self):
|
||||
result, err = self.install(installed_loads=False)
|
||||
self.assertEqual("FAILED", result)
|
||||
self.assertIn("putting the previous files back", err)
|
||||
self.assertEqual("old FEX\n", (self.root / "usr/local/bin/FEX").read_text())
|
||||
self.assertFalse((self.root / "usr/local/lib/libxxhash.so.0").exists())
|
||||
self.assertEqual("fex-2610-r5", self.tag())
|
||||
|
||||
def test_a_tag_that_cannot_be_written_puts_the_old_files_back(self):
|
||||
share = self.root / "usr/local/share/fex-emu"
|
||||
(share / ".droiddeck-tag").unlink()
|
||||
share.rmdir()
|
||||
share.write_text("not a folder\n")
|
||||
result, err = self.install(installed_loads=True)
|
||||
self.assertEqual("FAILED", result)
|
||||
self.assertIn("putting the previous files back", err)
|
||||
self.assertEqual("old FEX\n", (self.root / "usr/local/bin/FEX").read_text())
|
||||
self.assertFalse((self.root / "usr/local/lib/libxxhash.so.0").exists())
|
||||
|
||||
def test_an_archive_that_does_not_match_installs_nothing(self):
|
||||
result, err = self.install(installed_loads=True, sha="0" * 64)
|
||||
self.assertEqual("FAILED", result)
|
||||
self.assertIn("no source gave the archive", err)
|
||||
self.assertEqual("old FEX\n", (self.root / "usr/local/bin/FEX").read_text())
|
||||
self.assertEqual("fex-2610-r5", self.tag())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,85 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-steam-x64"
|
||||
SOURCE = SCRIPT.read_text()
|
||||
START = SOURCE.index("x64_fex() {")
|
||||
END = SOURCE.index("\n}\n", START) + 3
|
||||
X64_FEX = SOURCE[START:END]
|
||||
|
||||
HARNESS = textwrap.dedent("""\
|
||||
set -eu
|
||||
FEX_TAG=fex-2610-r5 FEX_SHA256=builtin FEX_URL=builtin-url
|
||||
step() { echo "STEP $*"; }
|
||||
# Installed FEX loads when LOADS=1; a build installs when its tag is in INSTALLABLE.
|
||||
fex_loads() { [ "${LOADS:-0}" = 1 ]; }
|
||||
fex_install() {
|
||||
echo "INSTALL $1 $2 $3"
|
||||
case " ${INSTALLABLE:-} " in *" $1 "*) echo "$1" > "$ROOT/tag"; : > "$ROOT/FEX"; chmod +x "$ROOT/FEX"; return 0 ;; esac
|
||||
return 1
|
||||
}
|
||||
""")
|
||||
|
||||
|
||||
class FexSelectTest(unittest.TestCase):
|
||||
def run_select(self, installed=None, loads=False, catalog=None, installable=()):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
if installed:
|
||||
Path(root, "tag").write_text(installed + "\n")
|
||||
fex = Path(root, "FEX")
|
||||
fex.write_text("")
|
||||
fex.chmod(0o755)
|
||||
body = (X64_FEX.replace("/usr/local/share/fex-emu/.droiddeck-tag", "$ROOT/tag")
|
||||
.replace("/usr/local/bin/FEX", "$ROOT/FEX"))
|
||||
script = HARNESS + body + 'if x64_fex; then echo "NOW $FEX_NOW|$FEX_FROM"; else echo FAILED; fi\n'
|
||||
env = dict(os.environ, ROOT=root, LOADS="1" if loads else "0", INSTALLABLE=" ".join(installable))
|
||||
env.pop("BL_FEX_TAG", None)
|
||||
if catalog:
|
||||
env.update(BL_FEX_TAG=catalog, BL_FEX_SHA256="catsha", BL_FEX_URLS="a b")
|
||||
out = subprocess.run(["bash", "-c", script], env=env, text=True, capture_output=True, timeout=10)
|
||||
self.assertEqual(0, out.returncode, out.stderr)
|
||||
lines = out.stdout.splitlines()
|
||||
return [l for l in lines if l.startswith("INSTALL")], lines[-1]
|
||||
|
||||
def test_the_catalog_build_already_installed_is_used(self):
|
||||
installs, now = self.run_select(installed="fex-2610-r6", loads=True, catalog="fex-2610-r6")
|
||||
self.assertEqual([], installs)
|
||||
self.assertEqual("NOW fex-2610-r6|catalog", now)
|
||||
|
||||
def test_a_newer_catalog_build_is_installed(self):
|
||||
installs, now = self.run_select(installed="fex-2610-r5", loads=True, catalog="fex-2610-r6", installable=["fex-2610-r6"])
|
||||
self.assertEqual(["INSTALL fex-2610-r6 catsha a b"], installs)
|
||||
self.assertEqual("NOW fex-2610-r6|catalog", now)
|
||||
|
||||
def test_a_catalog_build_that_does_not_install_keeps_the_working_one(self):
|
||||
installs, now = self.run_select(installed="fex-2610-r5", loads=True, catalog="fex-2610-r6")
|
||||
self.assertEqual(["INSTALL fex-2610-r6 catsha a b"], installs)
|
||||
self.assertEqual("NOW fex-2610-r5|kept; fex-2610-r6 did not install", now)
|
||||
|
||||
def test_without_a_catalog_the_built_in_build_replaces_an_older_one(self):
|
||||
installs, now = self.run_select(installed="fex-2610-r4", loads=True, installable=["fex-2610-r5"])
|
||||
self.assertEqual(["INSTALL fex-2610-r5 builtin builtin-url"], installs)
|
||||
self.assertEqual("NOW fex-2610-r5|built-in", now)
|
||||
|
||||
def test_an_installed_build_that_does_not_load_is_replaced(self):
|
||||
installs, now = self.run_select(installed="fex-2610-r6", loads=False, catalog="fex-2610-r6", installable=["fex-2610-r6"])
|
||||
self.assertEqual(["INSTALL fex-2610-r6 catsha a b"], installs)
|
||||
self.assertEqual("NOW fex-2610-r6|catalog", now)
|
||||
|
||||
def test_a_first_install_falls_back_to_the_built_in_build(self):
|
||||
installs, now = self.run_select(catalog="fex-2610-r6", installable=["fex-2610-r5"])
|
||||
self.assertEqual(["INSTALL fex-2610-r6 catsha a b", "INSTALL fex-2610-r5 builtin builtin-url"], installs)
|
||||
self.assertEqual("NOW fex-2610-r5|built-in", now)
|
||||
|
||||
def test_nothing_usable_fails(self):
|
||||
installs, now = self.run_select(catalog="fex-2610-r6")
|
||||
self.assertEqual(2, len(installs))
|
||||
self.assertEqual("FAILED", now)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -220,6 +220,12 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
self.assertEqual(env["REMOVE"], "inherited")
|
||||
self.assertEqual(MODULE["apply_config"](env, config, "43")["CUSTOM"], "shared")
|
||||
|
||||
def test_a_games_wine_sync_choice_also_reaches_its_setup_runs(self):
|
||||
env = {"BL_SYNC": "1", "BL_SYNC_FALLBACK": "1", "BL_FSYNC_FIRST": "0", "OTHER": "kept"}
|
||||
config = {"version": 1, "games": {"42": {"BL_SYNC": "0", "BL_FSYNC_FIRST": "1", "PROTON_NO_ESYNC": "1", "FEX_TSOENABLED": "1"}}}
|
||||
chosen = MODULE["apply_config"](env, MODULE["sync_config"](config, "42"), "42")
|
||||
self.assertEqual(chosen, {"BL_SYNC": "0", "BL_SYNC_FALLBACK": "1", "BL_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)
|
||||
@@ -729,7 +735,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
(root / "state.json").write_text(json.dumps({
|
||||
"default": self.TOOL,
|
||||
"auto": {},
|
||||
"native": [app],
|
||||
"native_choices": [app],
|
||||
}))
|
||||
|
||||
globals_ = COMPAT["register_default"].__globals__
|
||||
@@ -741,7 +747,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL})
|
||||
state = json.loads((root / "state.json").read_text())
|
||||
self.assertEqual(state["auto"], {})
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
finally:
|
||||
globals_["native_targets"] = original_native_targets
|
||||
|
||||
@@ -758,7 +764,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
(root / "state.json").write_text(json.dumps({
|
||||
"default": self.TOOL,
|
||||
"auto": {},
|
||||
"native": [app],
|
||||
"native_choices": [app],
|
||||
}))
|
||||
|
||||
globals_ = COMPAT["register_default"].__globals__
|
||||
@@ -769,12 +775,12 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
try:
|
||||
COMPAT["register_default"](
|
||||
str(config), [app], catalog=self.CATALOG, directory=tmp)
|
||||
self.assertEqual(json.loads((root / "state.json").read_text())["native"], [app])
|
||||
self.assertEqual(json.loads((root / "state.json").read_text())["native_choices"], [app])
|
||||
|
||||
COMPAT["register_default"](
|
||||
str(config), [added_shortcut], catalog=self.CATALOG, directory=tmp)
|
||||
state = json.loads((root / "state.json").read_text())
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
self.assertEqual(state["auto"], {added_shortcut: self.TOOL})
|
||||
self.assertEqual(mapping_of(config.read_text()), {
|
||||
"0": self.TOOL,
|
||||
@@ -820,7 +826,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
self.assertEqual(COMPAT["tokenize"](first.decode()),
|
||||
COMPAT["tokenize"](config_text([("0", self.TOOL)])))
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["auto"], {})
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native"], ["427520"])
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native_choices"], ["427520"])
|
||||
|
||||
COMPAT["register_default"](
|
||||
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
||||
@@ -832,7 +838,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
native_choice = config.read_bytes()
|
||||
self.assertEqual(mapping_of(native_choice.decode()), {"0": self.TOOL, "427520": ""})
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["auto"], {})
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native"], ["427520"])
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native_choices"], ["427520"])
|
||||
COMPAT["register_default"](
|
||||
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
||||
self.assertEqual(config.read_bytes(), native_choice)
|
||||
@@ -842,10 +848,10 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
COMPAT["register_default"](
|
||||
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
||||
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, "427520": choice})
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native"], [])
|
||||
self.assertEqual(json.loads((Path(tmp) / "state.json").read_text())["native_choices"], [])
|
||||
|
||||
state = json.loads((Path(tmp) / "state.json").read_text())
|
||||
state["native"] = ["427520"]
|
||||
state["native_choices"] = ["427520"]
|
||||
state["auto"] = {}
|
||||
(Path(tmp) / "state.json").write_text(json.dumps(state))
|
||||
config.write_text(config_text([("0", self.TOOL), ("427520", "proton_experimental")]))
|
||||
@@ -853,7 +859,7 @@ class ProtonDefaultTest(unittest.TestCase):
|
||||
str(config), ["427520"], catalog=self.CATALOG, directory=tmp)
|
||||
self.assertEqual(mapping_of(config.read_text()), {"0": self.TOOL, "427520": self.TOOL})
|
||||
saved = json.loads((Path(tmp) / "state.json").read_text())
|
||||
self.assertEqual(saved["native"], [])
|
||||
self.assertEqual(saved["native_choices"], [])
|
||||
self.assertEqual(saved["auto"], {"427520": self.TOOL})
|
||||
finally:
|
||||
globals_["appinfo_platforms"] = original_platforms
|
||||
@@ -1160,28 +1166,6 @@ if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class StartWithoutSteamTest(unittest.TestCase):
|
||||
def test_start_without_steam_uses_umu_or_runinprefix_and_only_when_asked(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
ge = Path(tmp) / "ge/proton"
|
||||
ge.parent.mkdir()
|
||||
ge.write_text('if "UMU_ID" in os.environ:\n argv = [wine, "c:\\\\windows\\\\system32\\\\umu.exe"]\n')
|
||||
valve = Path(tmp) / "valve/proton"
|
||||
valve.parent.mkdir()
|
||||
valve.write_text('argv = [wine, "c:\\\\windows\\\\system32\\\\steam.exe"]\n')
|
||||
start = MODULE["start_without_steam"]
|
||||
game = [str(ge), "waitforexitandrun", "/games/Game.exe", "-windowed"]
|
||||
self.assertEqual(start(game, {}, "3384071994"), (game, {}))
|
||||
on = {"DROIDDECK_NO_STEAM": "1"}
|
||||
self.assertEqual(start(game, on, "3384071994"), (game, dict(on, UMU_ID="0")))
|
||||
self.assertEqual(start(game, on, "570940")[1]["UMU_ID"], "570940")
|
||||
self.assertEqual(start(game, dict(on, UMU_ID="umu-1"), "570940")[1]["UMU_ID"], "umu-1")
|
||||
plain = [str(valve)] + game[1:]
|
||||
self.assertEqual(start(plain, on, "570940"), ([str(valve), "runinprefix", "/games/Game.exe", "-windowed"], on))
|
||||
for other in ([str(ge), "run", "/x.exe"], [str(ge), "waitforexitandrun"], [str(valve), "getcompatpath", "/x"]):
|
||||
self.assertEqual(start(other, on, "570940"), (other, on))
|
||||
|
||||
|
||||
class ForceSsbsTest(unittest.TestCase):
|
||||
def test_libssbs_is_preloaded_only_when_asked_and_only_into_arm64_proton(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import collections
|
||||
from pathlib import Path
|
||||
import re
|
||||
import unicodedata
|
||||
import unittest
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
RES = ROOT / "app/src/main/res"
|
||||
FORMAT = re.compile(r"%(?:\d+\$)?[-#+ 0,(]*\d*(?:\.\d+)?[a-zA-Z%]")
|
||||
|
||||
|
||||
def strings(path):
|
||||
return {
|
||||
element.attrib["name"]: "".join(element.itertext())
|
||||
for element in ET.parse(path).getroot()
|
||||
if element.tag == "string" and element.get("translatable") != "false"
|
||||
}
|
||||
|
||||
|
||||
class GlassesLocalizationTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.english = strings(RES / "values/strings.xml")
|
||||
cls.required = {
|
||||
key: value for key, value in cls.english.items()
|
||||
if key.startswith(("glasses_", "spatial_", "tracking_recovery_", "setup_glasses_", "phone_camera_tracking_"))
|
||||
or key in ("setup_tab_glasses", "hand_camera_prompt_title", "hand_camera_prompt_body", "hand_camera_setting_hint")
|
||||
}
|
||||
language_source = (ROOT / "app/src/main/java/com/droiddeck/launcher/core/AppLanguage.kt").read_text(encoding="utf-8")
|
||||
tags = re.findall(r'"([a-zA-Z0-9-]+)"', re.search(r"val supported:.*?listOf\((.*?)\)", language_source, re.S).group(1))
|
||||
special = {"id": "in", "es-419": "b+es+419", "pt-BR": "pt"}
|
||||
cls.locales = {}
|
||||
for tag in tags:
|
||||
if tag == "en":
|
||||
continue
|
||||
qualifier = special.get(tag, tag.replace("-", "-r"))
|
||||
cls.locales[tag] = strings(RES / f"values-{qualifier}/strings.xml")
|
||||
|
||||
def test_every_supported_language_has_nonempty_glasses_and_calibration_text(self):
|
||||
for locale, translated in self.locales.items():
|
||||
for key in self.required:
|
||||
with self.subTest(locale=locale, key=key):
|
||||
self.assertTrue(translated.get(key, "").strip(), "Missing translation would fall back to English")
|
||||
|
||||
def test_translations_preserve_format_arguments_and_explicit_line_breaks(self):
|
||||
for locale, translated in self.locales.items():
|
||||
for key, source in self.required.items():
|
||||
with self.subTest(locale=locale, key=key):
|
||||
target = translated.get(key, "")
|
||||
self.assertEqual(collections.Counter(FORMAT.findall(source)), collections.Counter(FORMAT.findall(target)))
|
||||
self.assertEqual(source.count(r"\n"), target.count(r"\n"))
|
||||
|
||||
def test_printed_board_and_distance_guidance_preserve_measurements(self):
|
||||
keys = ("spatial_print_hint", "spatial_print_scale", "spatial_print_check", "spatial_distance_12in",
|
||||
"spatial_distance_30cm", "spatial_distance_20in", "spatial_distance_50cm",
|
||||
"spatial_distance_hint", "spatial_distance_corners")
|
||||
|
||||
def numbers(value):
|
||||
value = "".join(str(unicodedata.decimal(char)) if char.isdecimal() else char for char in value)
|
||||
return collections.Counter(number.replace(",", ".") for number in re.findall(r"\d+(?:[.,]\d+)?", value))
|
||||
|
||||
for locale, translated in self.locales.items():
|
||||
for key in keys:
|
||||
with self.subTest(locale=locale, key=key):
|
||||
self.assertEqual(numbers(self.english[key]), numbers(translated.get(key, "")))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -23,6 +23,7 @@ IFACE = NAME + ".Manager"
|
||||
@unittest.skipUnless(Gio and os.environ.get("DBUS_SESSION_BUS_ADDRESS"), "requires dbus-run-session and PyGObject")
|
||||
class SleepHandshakeTest(unittest.TestCase):
|
||||
ARGS = []
|
||||
AGENT_EXIT = None
|
||||
|
||||
def setUp(self):
|
||||
self.directory = tempfile.TemporaryDirectory()
|
||||
@@ -37,7 +38,16 @@ class SleepHandshakeTest(unittest.TestCase):
|
||||
lambda bus, sender, path, interface, name, body: self.signals.append(body.unpack()[0]))
|
||||
env = dict(os.environ, BL_LAUNCH_DIR=str(self.dir),
|
||||
DBUS_SYSTEM_BUS_ADDRESS=os.environ["DBUS_SESSION_BUS_ADDRESS"])
|
||||
self.process = subprocess.Popen(["/usr/bin/python3", str(SCRIPT), *self.ARGS], env=env,
|
||||
script = SCRIPT
|
||||
if self.AGENT_EXIT is not None:
|
||||
bin_dir = self.dir / "bin"
|
||||
bin_dir.mkdir()
|
||||
script = bin_dir / SCRIPT.name
|
||||
script.write_text(SCRIPT.read_text())
|
||||
agent = bin_dir / "droiddeck-agent"
|
||||
agent.write_text("#!/bin/sh\necho \"$@\" >> \"%s\"\nexit %d\n" % (self.dir / "agent-calls", self.AGENT_EXIT))
|
||||
agent.chmod(0o755)
|
||||
self.process = subprocess.Popen(["/usr/bin/python3", str(script), *self.ARGS], env=env,
|
||||
stdout=subprocess.DEVNULL)
|
||||
self.wait_for(lambda: (self.dir / "steam-sleep-ready").exists())
|
||||
|
||||
@@ -220,6 +230,53 @@ class SleepHandshakeTest(unittest.TestCase):
|
||||
self.call(IFACE, "PowerOff", GLib.Variant("(b)", (True,)))
|
||||
|
||||
|
||||
class FakeAgentCase(unittest.TestCase):
|
||||
ARGS = []
|
||||
setUp = SleepHandshakeTest.setUp
|
||||
tearDown = SleepHandshakeTest.tearDown
|
||||
wait_for = SleepHandshakeTest.wait_for
|
||||
call = SleepHandshakeTest.call
|
||||
suspend = SleepHandshakeTest.suspend
|
||||
state = SleepHandshakeTest.state
|
||||
request_wake = SleepHandshakeTest.request_wake
|
||||
|
||||
def asked(self):
|
||||
path = self.dir / "agent-calls"
|
||||
return path.read_text().split() if path.exists() else []
|
||||
|
||||
|
||||
@unittest.skipUnless(Gio and os.environ.get("DBUS_SESSION_BUS_ADDRESS"), "requires dbus-run-session and PyGObject")
|
||||
class AwakeSteamTest(FakeAgentCase):
|
||||
AGENT_EXIT = 5
|
||||
|
||||
def test_resuming_an_awake_steam_sends_no_sleep_wake_pair(self):
|
||||
self.request_wake()
|
||||
self.wait_for(lambda: self.asked())
|
||||
deadline = time.monotonic() + 1.5
|
||||
while time.monotonic() < deadline:
|
||||
self.wait_for(lambda: True)
|
||||
time.sleep(0.05)
|
||||
self.assertEqual([], self.signals)
|
||||
self.assertEqual(["--steam-asleep"], self.asked())
|
||||
|
||||
def test_a_pending_sleep_still_wakes_without_asking_steam(self):
|
||||
token = self.suspend()
|
||||
self.state(token, "paused")
|
||||
self.request_wake()
|
||||
self.wait_for(lambda: self.signals == [True, False])
|
||||
self.assertEqual([], self.asked())
|
||||
|
||||
|
||||
@unittest.skipUnless(Gio and os.environ.get("DBUS_SESSION_BUS_ADDRESS"), "requires dbus-run-session and PyGObject")
|
||||
class AsleepSteamTest(FakeAgentCase):
|
||||
AGENT_EXIT = 0
|
||||
|
||||
def test_resuming_a_sleeping_steam_replays_the_pair(self):
|
||||
self.request_wake()
|
||||
self.wait_for(lambda: self.signals == [True, False])
|
||||
self.assertEqual(["--steam-asleep"], self.asked())
|
||||
|
||||
|
||||
class WithNetworkManagerTest(SleepHandshakeTest):
|
||||
ARGS = ["--with-netmanager"]
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "../../app/src/main/cpp/viture/mjpeg_payload.h"
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
int main() {
|
||||
const uint8_t jpeg[] = {0xff,0xd8,0xff,0xc0,0,4,1,2,0xff,0xd9};
|
||||
uint8_t frame[32]{};
|
||||
std::memcpy(frame,jpeg,sizeof(jpeg));
|
||||
for (std::size_t padding=0; padding<=7; ++padding)
|
||||
assert(mjpeg_payload_size(frame,sizeof(jpeg)+padding) == sizeof(jpeg));
|
||||
assert(mjpeg_payload_size(frame,sizeof(jpeg)+8) == 0);
|
||||
for (std::size_t size=0; size<sizeof(jpeg); ++size)
|
||||
assert(mjpeg_payload_size(frame,size) == 0);
|
||||
frame[sizeof(jpeg)] = 0x42;
|
||||
assert(mjpeg_payload_size(frame,sizeof(jpeg)+1) == 0);
|
||||
frame[sizeof(jpeg)] = 0;
|
||||
frame[0] = 0;
|
||||
assert(mjpeg_payload_size(frame,sizeof(jpeg)) == 0);
|
||||
assert(mjpeg_payload_size(nullptr,10) == 0);
|
||||
assert(mjpeg_payload_size(jpeg,4*1024*1024+1) == 0);
|
||||
std::puts("PASS: JPEG boundaries, 0-7 padding bytes, truncation, garbage, and bounds");
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
import errno
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload"
|
||||
|
||||
# Opens each "<dirfd>\t<flags>\t<path>" case with openat2(RESOLVE_IN_ROOT) as FEX does: first through the kernel's own
|
||||
# openat2 on argv[1] when it has one, then, with openat2 failing ENOSYS as under proot, through the preload on argv[2].
|
||||
PROGRAM = r"""
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/filter.h>
|
||||
#include <linux/seccomp.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef SYS_openat2
|
||||
#define SYS_openat2 437
|
||||
#endif
|
||||
|
||||
struct how { uint64_t flags, mode, resolve; };
|
||||
static char cases[256][512];
|
||||
static int count;
|
||||
|
||||
static void run(long (*call)(long, ...), const char *tree) {
|
||||
int root = open(tree, O_PATH | O_DIRECTORY | O_CLOEXEC), outer = open("/", O_PATH | O_DIRECTORY | O_CLOEXEC);
|
||||
for (int i = 0; i < count; i++) {
|
||||
char *flags = strchr(cases[i], '\t') + 1, *path = strchr(flags, '\t') + 1;
|
||||
struct how h = {strtoull(flags, NULL, 0), 0, 0x10};
|
||||
if (h.flags & O_CREAT) h.mode = 0644;
|
||||
long fd = call(SYS_openat2, (long)(cases[i][0] == 'o' ? outer : root), (long)path, (long)&h, (long)sizeof(h));
|
||||
struct stat st;
|
||||
if (fd < 0) {
|
||||
printf("ERR %d\n", errno);
|
||||
} else {
|
||||
fstat((int)fd, &st);
|
||||
printf("OK %llu %llu\n", (unsigned long long)st.st_dev, (unsigned long long)st.st_ino);
|
||||
close((int)fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) return 2;
|
||||
while (count < 256 && fgets(cases[count], sizeof(cases[count]), stdin)) {
|
||||
cases[count][strcspn(cases[count], "\n")] = 0;
|
||||
count++;
|
||||
}
|
||||
long (*kernel)(long, ...) = (long (*)(long, ...))dlsym(dlopen("libc.so.6", RTLD_LAZY | RTLD_NOLOAD), "syscall");
|
||||
struct how probe = {O_RDONLY, 0, 0x10};
|
||||
long fd = kernel(SYS_openat2, (long)AT_FDCWD, (long)".", (long)&probe, (long)sizeof(probe));
|
||||
if (fd >= 0) {
|
||||
close((int)fd);
|
||||
printf("kernel\n");
|
||||
run(kernel, argv[1]);
|
||||
struct sock_filter filter[] = {
|
||||
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
|
||||
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_openat2, 0, 1),
|
||||
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | ENOSYS),
|
||||
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
|
||||
};
|
||||
struct sock_fprog prog = {sizeof(filter) / sizeof(filter[0]), filter};
|
||||
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) || prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) {
|
||||
perror("seccomp");
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
printf("preload\n");
|
||||
run(syscall, argv[2]);
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
O_PATH = getattr(os, "O_PATH", 0o10000000)
|
||||
|
||||
# (dirfd: r = the tree, o = "/"), flags, path, expected: a path in the tree, an errno name, or "proc" for a file outside it.
|
||||
CASES = [
|
||||
("r", os.O_RDONLY, "etc/alternatives/hn", "etc/hostname"),
|
||||
("r", os.O_RDONLY, "/lib64/x86_64-linux-gnu/libfoo.so.1", "usr/lib/x86_64-linux-gnu/libfoo.so.1.2"),
|
||||
("r", os.O_RDONLY, "lib/x86_64-linux-gnu/libfoo.so.1", "usr/lib/x86_64-linux-gnu/libfoo.so.1.2"),
|
||||
("r", os.O_RDONLY, "etc/escape", "etc/hostname"),
|
||||
("r", os.O_RDONLY, "dirlink/../etc/hostname", "etc/hostname"),
|
||||
("r", os.O_RDONLY, "rootlink/rootlink//etc/./hostname", "etc/hostname"),
|
||||
("r", os.O_RDONLY, "../../etc/hostname", "etc/hostname"),
|
||||
("r", os.O_RDONLY | os.O_DIRECTORY, "/", "."),
|
||||
("r", os.O_RDONLY | os.O_DIRECTORY, "usr/../..", "."),
|
||||
("r", os.O_RDONLY, "chain/l2", "chain/end"),
|
||||
("r", os.O_RDONLY, "chain/l1", "ELOOP"),
|
||||
("r", os.O_RDONLY, "loop/a/x", "ELOOP"),
|
||||
("r", os.O_RDONLY | os.O_NOFOLLOW, "etc/alternatives/hn", "ELOOP"),
|
||||
("r", O_PATH | os.O_NOFOLLOW, "etc/alternatives/hn", "etc/alternatives/hn"),
|
||||
("r", os.O_RDONLY | os.O_NOFOLLOW, "lib/x86_64-linux-gnu/libfoo.so.1.2", "usr/lib/x86_64-linux-gnu/libfoo.so.1.2"),
|
||||
("r", os.O_RDONLY | os.O_NOFOLLOW | os.O_DIRECTORY, "dirlink/", "usr"),
|
||||
("r", os.O_RDONLY, "file/", "ENOTDIR"),
|
||||
("r", os.O_RDONLY, "file/../etc/hostname", "ENOTDIR"),
|
||||
("r", os.O_RDONLY, "nonexist/../etc/hostname", "ENOENT"),
|
||||
("r", os.O_RDWR | os.O_CREAT | os.O_EXCL, "dangling", "EEXIST"),
|
||||
("r", os.O_RDWR | os.O_CREAT, "dangling", "usr/newfile"),
|
||||
("r", os.O_RDWR | os.O_CREAT, "missing/newfile", "ENOENT"),
|
||||
("r", os.O_RDWR | os.O_CREAT, "newdir/", "EISDIR"),
|
||||
("o", os.O_RDONLY | os.O_NONBLOCK, "proc/self/fd/0", "EXDEV"),
|
||||
("o", os.O_RDONLY, "proc/self/exe", "EXDEV"),
|
||||
("o", os.O_RDONLY, "proc/self/cwd/x", "EXDEV"),
|
||||
("o", os.O_RDONLY, "proc/self/status", "proc"),
|
||||
]
|
||||
|
||||
|
||||
def make_tree(root):
|
||||
for folder in ("usr/lib/x86_64-linux-gnu", "etc/alternatives", "loop", "chain"):
|
||||
(root / folder).mkdir(parents=True)
|
||||
(root / "usr/lib/x86_64-linux-gnu/libfoo.so.1.2").write_text("x86")
|
||||
(root / "etc/hostname").write_text("inside")
|
||||
(root / "file").write_text("f")
|
||||
(root / "chain/end").write_text("end")
|
||||
links = {"usr/lib/x86_64-linux-gnu/libfoo.so.1": "libfoo.so.1.2", "lib": "usr/lib", "lib64": "/usr/lib",
|
||||
"etc/alternatives/hn": "/etc/hostname", "etc/escape": "../../../../../../etc/hostname", "loop/a": "b",
|
||||
"loop/b": "a", "dirlink": "/usr", "rootlink": "/", "dangling": "/usr/newfile"}
|
||||
links.update({"chain/l%d" % i: ("l%d" % (i + 1) if i < 41 else "end") for i in range(1, 42)})
|
||||
for link, target in links.items():
|
||||
os.symlink(target, root / link)
|
||||
|
||||
|
||||
def labels(lines, root):
|
||||
inodes = {(os.lstat(root).st_dev, os.lstat(root).st_ino): "."}
|
||||
for folder, dirs, files in os.walk(root):
|
||||
for name in dirs + files:
|
||||
st = os.lstat(os.path.join(folder, name))
|
||||
inodes[(st.st_dev, st.st_ino)] = os.path.relpath(os.path.join(folder, name), root)
|
||||
out = []
|
||||
for line in lines:
|
||||
kind, *values = line.split()
|
||||
if kind == "OK":
|
||||
out.append(inodes.get((int(values[0]), int(values[1])), "proc"))
|
||||
else:
|
||||
out.append(errno.errorcode[int(values[0])])
|
||||
return out
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("cc") and os.path.isdir("/proc/self"), "needs cc and procfs")
|
||||
class Openat2PreloadTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.tmp = Path(tempfile.mkdtemp())
|
||||
cls.lib = cls.tmp / "libopenat2.so"
|
||||
subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-fPIC", "-shared", "-pthread", "-o", str(cls.lib),
|
||||
str(PRELOAD / "robust.c"), str(PRELOAD / "fsync.c"), str(PRELOAD / "noexec.c"), "-ldl"], check=True)
|
||||
source = cls.tmp / "openat2.c"
|
||||
source.write_text(PROGRAM)
|
||||
subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-o", str(cls.tmp / "openat2"), str(source), "-ldl"], check=True)
|
||||
cls.trees = (cls.tmp / "kernel", cls.tmp / "preload")
|
||||
for tree in cls.trees:
|
||||
make_tree(tree)
|
||||
cases = "".join("%s\t%d\t%s\n" % case[:3] for case in CASES)
|
||||
result = subprocess.run([str(cls.tmp / "openat2"), *map(str, cls.trees)], input=cases, capture_output=True, text=True,
|
||||
env=dict(os.environ, LD_PRELOAD=str(cls.lib)), timeout=60)
|
||||
if result.returncode != 0:
|
||||
raise AssertionError(result.stdout + result.stderr)
|
||||
lines = result.stdout.splitlines()
|
||||
cls.kernel = labels(lines[1:1 + len(CASES)], cls.trees[0]) if lines[0] == "kernel" else None
|
||||
cls.preload = labels(lines[-len(CASES):], cls.trees[1])
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
shutil.rmtree(cls.tmp, ignore_errors=True)
|
||||
|
||||
def test_preload_resolves_in_the_root_without_openat2(self):
|
||||
for case, got in zip(CASES, self.preload):
|
||||
self.assertEqual(got, case[3], case)
|
||||
self.assertTrue((self.trees[1] / "usr/newfile").exists())
|
||||
|
||||
def test_the_kernel_agrees(self):
|
||||
if self.kernel is None:
|
||||
self.skipTest("this kernel or sandbox has no openat2")
|
||||
for case, got in zip(CASES, self.kernel):
|
||||
self.assertEqual(got, case[3], case)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,170 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SOURCE = ROOT / 'app/src/main/cpp/waylandcomp/src/compositor.c'
|
||||
|
||||
|
||||
def extract_function(source, name):
|
||||
match = re.search(r'^(?:static )?(?:void|int|uint32_t) ' + re.escape(name) + r'\([^;]*?\) \{',
|
||||
source, re.MULTILINE)
|
||||
if match is None:
|
||||
raise AssertionError(f'Missing compositor function: {name}')
|
||||
cursor, depth = match.end(), 1
|
||||
while depth:
|
||||
depth += (source[cursor] == '{') - (source[cursor] == '}')
|
||||
cursor += 1
|
||||
return source[match.start():cursor]
|
||||
|
||||
|
||||
PREAMBLE = r'''
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
struct wl_resource { int version, modes, done, hz, w, h; struct wl_resource *next; };
|
||||
struct surface { int xdg_toplevel, toplevel_committed; struct surface *next; };
|
||||
struct input_msg { int type, p1, p2, p3, p4; };
|
||||
static struct wl_resource second = { .version = 1 };
|
||||
static struct wl_resource first = { .version = 4, .next = &second };
|
||||
static struct surface surface = { .xdg_toplevel = 1, .toplevel_committed = 1 };
|
||||
static int g_input_pipe[2] = {-1, -1};
|
||||
static atomic_int g_output_refresh_mhz = 60000;
|
||||
static atomic_int g_output_refresh_pending;
|
||||
static int g_output_announced_refresh_mhz = 60000;
|
||||
static int g_output_w = 1920, g_output_h = 1080;
|
||||
static int flushes, resizes, pointers, ticks;
|
||||
static int scale_changes, scale_mode, scale_alignment, renders;
|
||||
static void *g_display;
|
||||
#define WL_OUTPUT_MODE_CURRENT 1
|
||||
#define WL_OUTPUT_MODE_PREFERRED 2
|
||||
#define wl_resource_for_each(r, list) for ((r) = &first; (r); (r) = (r)->next)
|
||||
#define wl_list_for_each(s, list, link) for ((s) = &surface; (s); (s) = (s)->next)
|
||||
static int wl_resource_get_version(struct wl_resource *r) { return r->version; }
|
||||
static void wl_output_send_mode(struct wl_resource *r, int flags, int w, int h, int hz) {
|
||||
assert(flags == 3); r->modes++; r->hz = hz; r->w = w; r->h = h;
|
||||
}
|
||||
static void wl_output_send_done(struct wl_resource *r) { r->done++; }
|
||||
static void wl_display_flush_clients(void *display) { (void)display; flushes++; }
|
||||
static void send_toplevel_configure(struct surface *s) { (void)s; resizes++; }
|
||||
#define droiddeck_log(...) ((void)0)
|
||||
#define deliver_key(m) ((void)0)
|
||||
#define pointer_event(...) ((void)0)
|
||||
#define pointer_button(...) ((void)0)
|
||||
#define scroll_event(...) ((void)0)
|
||||
#define axis_event(...) ((void)0)
|
||||
#define pointer_delta(...) ((void)0)
|
||||
#define deliver_touch(m) ((void)0)
|
||||
#define deliver_pointer(m) (pointers++)
|
||||
static void on_vsync(int64_t ns) { assert(ns > 0); ticks++; }
|
||||
static void vk_present_set_scale_mode(int mode, int alignment) {
|
||||
scale_changes++; scale_mode = mode; scale_alignment = alignment;
|
||||
}
|
||||
static void schedule_render(void) { renders++; }
|
||||
'''
|
||||
|
||||
CHECKS = r'''
|
||||
static int queued(void) { int n; assert(ioctl(g_input_pipe[0], FIONREAD, &n) == 0); return n; }
|
||||
static void drain(void) { on_input_readable(g_input_pipe[0], 0, NULL); }
|
||||
static void expect(int modes, int hz, int resize_count) {
|
||||
assert(first.modes == modes && second.modes == modes);
|
||||
assert(first.hz == hz && second.hz == hz);
|
||||
assert(first.w == 1920 && second.w == 1920 && first.h == 1080 && second.h == 1080);
|
||||
assert(first.done == modes && second.done == 0);
|
||||
assert(resizes == resize_count);
|
||||
assert(pointers == 0);
|
||||
}
|
||||
int main(void) {
|
||||
droiddeck_wayland_set_output_refresh_rate(120000);
|
||||
assert(atomic_load(&g_output_refresh_mhz) == 120000);
|
||||
assert(!atomic_load(&g_output_refresh_pending));
|
||||
assert(first.modes == 0 && second.modes == 0);
|
||||
assert(pipe2(g_input_pipe, O_CLOEXEC | O_NONBLOCK) == 0);
|
||||
g_output_announced_refresh_mhz = atomic_load(&g_output_refresh_mhz);
|
||||
droiddeck_wayland_set_scale_mode(1, 4);
|
||||
assert(queued() == sizeof(struct input_msg));
|
||||
drain();
|
||||
assert(scale_changes == 1 && scale_mode == 1 && scale_alignment == 4 && renders == 1);
|
||||
assert(first.modes == 0 && second.modes == 0);
|
||||
droiddeck_wayland_set_output_refresh_rate(120000);
|
||||
assert(queued() == 0);
|
||||
droiddeck_wayland_set_output_refresh_rate(60000);
|
||||
assert(first.modes == 0 && queued() == sizeof(struct input_msg));
|
||||
drain(); expect(1, 60000, 0); assert(flushes == 1);
|
||||
droiddeck_wayland_set_output_refresh_rate(60000);
|
||||
assert(queued() == 0); drain(); expect(1, 60000, 0);
|
||||
droiddeck_wayland_set_output_refresh_rate(90000);
|
||||
droiddeck_wayland_set_output_refresh_rate(120000);
|
||||
drain(); expect(2, 120000, 0);
|
||||
droiddeck_wayland_set_output_refresh_rate(90000);
|
||||
droiddeck_wayland_set_output_refresh_rate(120000);
|
||||
drain(); expect(2, 120000, 0);
|
||||
droiddeck_wayland_set_output_refresh_rate(60000);
|
||||
droiddeck_wayland_output_resized();
|
||||
drain(); expect(3, 60000, 1); assert(flushes == 3);
|
||||
struct input_msg wake = {10, 0, 0, 0, 0};
|
||||
int n = 0;
|
||||
while (write(g_input_pipe[1], &wake, sizeof(wake)) == sizeof(wake)) n++;
|
||||
assert(n > 0 && errno == EAGAIN);
|
||||
droiddeck_wayland_set_output_refresh_rate(120000);
|
||||
drain(); expect(4, 120000, 1);
|
||||
droiddeck_wayland_set_output_refresh_rate(0);
|
||||
drain(); expect(5, 60000, 1);
|
||||
droiddeck_wayland_set_output_refresh_rate(-1);
|
||||
assert(queued() == 0);
|
||||
struct input_msg vsync = {5, 0, 16000000, 0, 0};
|
||||
assert(write(g_input_pipe[1], &vsync, sizeof(vsync)) == sizeof(vsync));
|
||||
drain(); expect(5, 60000, 1); assert(ticks == 1);
|
||||
assert(nominal_refresh_ns() == 16666666);
|
||||
assert(flushes == 5);
|
||||
assert(scale_changes == 1 && scale_mode == 1 && scale_alignment == 4 && renders == 1);
|
||||
droiddeck_wayland_set_scale_mode(1, 3);
|
||||
droiddeck_wayland_set_output_refresh_rate(90000);
|
||||
drain(); expect(6, 90000, 1);
|
||||
assert(scale_changes == 2 && scale_mode == 1 && scale_alignment == 3 && renders == 2);
|
||||
close(g_input_pipe[0]); close(g_input_pipe[1]);
|
||||
puts("PASS");
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform.startswith('linux'), 'needs Linux nonblocking pipes')
|
||||
class OutputRefreshTest(unittest.TestCase):
|
||||
def test_refresh_notifications_preserve_client_pacing_without_resizing(self):
|
||||
compiler = shutil.which(os.environ.get('CC', 'cc'))
|
||||
if compiler is None:
|
||||
self.skipTest('A host C compiler is required')
|
||||
source = SOURCE.read_text()
|
||||
functions = ('nominal_refresh_ns', 'output_send_mode', 'output_notify_mode',
|
||||
'output_resized', 'on_input_readable', 'droiddeck_wayland_output_resized',
|
||||
'droiddeck_wayland_set_scale_mode',
|
||||
'droiddeck_wayland_set_output_refresh_rate')
|
||||
harness = PREAMBLE + '\n'.join(extract_function(source, name) for name in functions) + CHECKS
|
||||
with tempfile.TemporaryDirectory(prefix='droiddeck-output-refresh-') as folder:
|
||||
path = Path(folder)
|
||||
(path / 'refresh.c').write_text(harness)
|
||||
binary = path / 'refresh-test'
|
||||
build = subprocess.run([compiler, '-std=c11', '-Wall', '-Wextra', '-Werror',
|
||||
'-Wno-unused-parameter', '-O2', str(path / 'refresh.c'),
|
||||
'-o', str(binary)], capture_output=True, text=True)
|
||||
self.assertEqual(0, build.returncode, build.stderr)
|
||||
result = subprocess.run([str(binary)], capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual('PASS', result.stdout.strip())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,179 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
from zipfile import ZipFile
|
||||
|
||||
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
'prepare_windows_runtime', Path(__file__).resolve().parents[1] / 'prepare_windows_runtime.py')
|
||||
prepare = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(prepare)
|
||||
|
||||
|
||||
class WindowsRuntimePreparationTest(unittest.TestCase):
|
||||
def test_archive_paths_cannot_escape_destination(self):
|
||||
for name in ('../outside', '/absolute', 'dir/../../outside', 'C:/absolute', 'dir\\outside', '.'):
|
||||
with self.subTest(name=name), self.assertRaises(ValueError):
|
||||
prepare.validate_relative(name)
|
||||
|
||||
def test_tracked_outputs_cannot_be_overwritten(self):
|
||||
with mock.patch.object(prepare, 'git', return_value=b'tracked/file\n'):
|
||||
with self.assertRaisesRegex(ValueError, 'overwrite tracked'):
|
||||
prepare.checked_output('tracked/file')
|
||||
|
||||
def test_rebuilt_libraries_must_match_each_architecture(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path = Path(folder) / 'libblsession.so'
|
||||
elf = bytearray(64)
|
||||
elf[:4] = b'\x7fELF'
|
||||
elf[5] = 1
|
||||
elf[18:20] = struct.pack('<H', 183)
|
||||
path.write_bytes(elf)
|
||||
self.assertEqual(prepare.validate_rebuilt(path, 183), elf)
|
||||
with self.assertRaisesRegex(ValueError, 'wrong ELF architecture'):
|
||||
prepare.validate_rebuilt(path, 62)
|
||||
path.write_bytes(b'not an ELF')
|
||||
with self.assertRaisesRegex(ValueError, 'wrong ELF architecture'):
|
||||
prepare.validate_rebuilt(path, 183)
|
||||
|
||||
def test_new_committed_native_changes_reject_donor_reuse(self):
|
||||
with mock.patch.object(prepare, 'git', return_value=prepare.DONOR_TREE.encode()), \
|
||||
mock.patch.object(prepare, 'changed', return_value={'tools/linuxfs/preload/net.c'}):
|
||||
with self.assertRaisesRegex(ValueError, 'Sources changed since'):
|
||||
prepare.check_sources()
|
||||
|
||||
def test_vr_sources_are_classified_as_rebuilt_including_local_and_new_files(self):
|
||||
committed = {'tools/vr/src/vk_layer_droiddeck_vr.c', 'tools/vr/build.sh'}
|
||||
local = {'tools/vr/src/presenter.cpp'}
|
||||
new = {'tools/vr/src/fence_tracker.h'}
|
||||
with mock.patch.object(prepare, 'changed', side_effect=[committed, local, committed]), \
|
||||
mock.patch.object(prepare, 'git', side_effect=[prepare.DONOR_TREE.encode(),
|
||||
b'tools/vr/src/fence_tracker.h\0']):
|
||||
classifications = prepare.check_sources()
|
||||
self.assertEqual(set(classifications), committed | local | new)
|
||||
self.assertTrue(all('never imported from donor' in value for value in classifications.values()))
|
||||
|
||||
def test_preparation_excludes_all_donor_vr_files_and_records_replacement_origin(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
root = Path(folder)
|
||||
apk = root / 'donor.apk'
|
||||
vr_name = 'layer/libVkLayer_droiddeck_vr.so'
|
||||
with ZipFile(apk, 'w') as package:
|
||||
package.writestr(prepare.VR_PREFIX + vr_name, b'old library')
|
||||
package.writestr(prepare.VR_PREFIX + 'obsolete.so', b'obsolete donor file')
|
||||
package.writestr('assets/linuxfs/unchanged.so', b'unchanged component')
|
||||
(root / 'app/build').mkdir(parents=True)
|
||||
(root / 'app/build/runtime-inputs.json').write_text('{}')
|
||||
vr_manifest = {'version': 1, 'source_commit': 'current', 'outputs': {vr_name: 'verified'}}
|
||||
with mock.patch.object(prepare, 'ROOT', root), \
|
||||
mock.patch.object(prepare, 'check_sources', return_value={}), \
|
||||
mock.patch.object(prepare, 'DONOR_SHA256', prepare.runtime.digest(apk)), \
|
||||
mock.patch.object(prepare, 'REBUILT', {}), \
|
||||
mock.patch.object(prepare, 'JNI', ()), mock.patch.object(prepare, 'PREPARED', ()), \
|
||||
mock.patch.object(prepare, 'LOCAL_BUILD_PLUMBING', set()), \
|
||||
mock.patch.object(prepare, 'source_assets', return_value={}), \
|
||||
mock.patch.object(prepare, 'read_gamescope', return_value=({}, {
|
||||
'GAMESCOPE_REPO': 'repo', 'GAMESCOPE_TAG': 'tag', 'GAMESCOPE_SHA256': 'hash'})), \
|
||||
mock.patch.object(prepare, 'validate_tracked_assets', return_value={}), \
|
||||
mock.patch.object(prepare, 'git', return_value=b''), \
|
||||
mock.patch.object(prepare.runtime, 'record'), mock.patch.object(prepare.runtime, 'verify'), \
|
||||
mock.patch.object(prepare.vr_build, 'build', return_value=({vr_name: b'new library'}, vr_manifest)) as build:
|
||||
prepare.prepare(apk, root, root, llvm_strip=root / 'bin/llvm-strip')
|
||||
build.assert_called_once()
|
||||
vr_folder = root / 'app/src/main' / prepare.VR_PREFIX
|
||||
self.assertEqual((vr_folder / vr_name).read_bytes(), b'new library')
|
||||
self.assertFalse((vr_folder / 'obsolete.so').exists())
|
||||
import json
|
||||
provenance = json.loads((root / 'app/build/windows-runtime-provenance.json').read_text())
|
||||
self.assertEqual(provenance['vr_build'], vr_manifest)
|
||||
self.assertIn('VR rebuilt', provenance['outputs']['app/src/main/' + prepare.VR_PREFIX + vr_name]['origin'])
|
||||
|
||||
def test_invalid_cached_vr_stops_before_reading_or_staging_the_donor(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
root = Path(folder)
|
||||
apk = root / 'donor.apk'
|
||||
apk.write_bytes(b'donor')
|
||||
with mock.patch.object(prepare, 'check_sources', return_value={}), \
|
||||
mock.patch.object(prepare, 'DONOR_SHA256', prepare.runtime.digest(apk)), \
|
||||
mock.patch.object(prepare, 'REBUILT', {}), \
|
||||
mock.patch.object(prepare, 'read_gamescope', return_value=({}, {})), \
|
||||
mock.patch.object(prepare.vr_build, 'validate', side_effect=ValueError('VR build is stale')), \
|
||||
mock.patch.object(prepare.vr_build, 'build') as build, \
|
||||
mock.patch.object(prepare, 'ZipFile') as archive:
|
||||
with self.assertRaisesRegex(ValueError, 'VR build is stale'):
|
||||
prepare.prepare(apk, root, root, rebuilt_vr=root, vk_include=root)
|
||||
build.assert_not_called()
|
||||
archive.assert_not_called()
|
||||
|
||||
def test_current_helpers_are_allowed_only_when_restaged_from_source(self):
|
||||
helpers = prepare.LOCAL_SESSION_HELPERS
|
||||
sources = {prepare.ROOT / path: 'assets/linuxfs/' + path.split('/overlay/')[1]
|
||||
for path in helpers}
|
||||
for local_changes in (set(), helpers):
|
||||
with self.subTest(local_changes=local_changes), \
|
||||
mock.patch.object(prepare, 'source_assets', return_value=sources), \
|
||||
mock.patch.object(prepare, 'changed', side_effect=[helpers, local_changes, helpers]), \
|
||||
mock.patch.object(prepare, 'git', side_effect=[prepare.DONOR_TREE.encode(), b'']):
|
||||
classifications = prepare.check_sources()
|
||||
self.assertEqual(set(classifications), helpers)
|
||||
self.assertTrue(all('restaged from current source' in action
|
||||
for action in classifications.values()))
|
||||
with mock.patch.object(prepare, 'source_assets', return_value={}), \
|
||||
mock.patch.object(prepare, 'changed', return_value=helpers), \
|
||||
mock.patch.object(prepare, 'git', return_value=prepare.DONOR_TREE.encode()):
|
||||
with self.assertRaisesRegex(ValueError, 'Sources changed since'):
|
||||
prepare.check_sources()
|
||||
|
||||
def test_cardboard_changes_are_compiled_by_gradle_not_reused_from_donor(self):
|
||||
changed = {'app/src/main/cpp/waylandcomp/src/cardboard.c'}
|
||||
with mock.patch.object(prepare, 'changed', side_effect=[changed, changed, changed]), \
|
||||
mock.patch.object(prepare, 'git', side_effect=[prepare.DONOR_TREE.encode(), b'']):
|
||||
classifications = prepare.check_sources()
|
||||
self.assertEqual(set(classifications), changed)
|
||||
self.assertIn('compiled by Gradle; not imported', next(iter(classifications.values())))
|
||||
|
||||
def test_other_helper_changes_still_need_an_audit(self):
|
||||
with mock.patch.object(prepare, 'git', return_value=prepare.DONOR_TREE.encode()), \
|
||||
mock.patch.object(prepare, 'changed', return_value={
|
||||
'tools/linuxfs/overlay/usr/local/bin/droiddeck-session'}):
|
||||
with self.assertRaisesRegex(ValueError, 'Sources changed since'):
|
||||
prepare.check_sources()
|
||||
|
||||
def test_uncommitted_native_changes_reject_donor_reuse(self):
|
||||
with mock.patch.object(prepare, 'git', side_effect=[prepare.DONOR_TREE.encode(), b'']), \
|
||||
mock.patch.object(prepare, 'changed', side_effect=[set(), {'tools/linuxfs/preload/net.c'}]):
|
||||
with self.assertRaisesRegex(ValueError, 'Unreviewed runtime'):
|
||||
prepare.check_sources()
|
||||
|
||||
def test_wrong_apk_hash_fails_before_replacement_or_output_access(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
apk = Path(folder) / 'incorrect.apk'
|
||||
apk.write_bytes(b'incorrect donor')
|
||||
with mock.patch.object(prepare, 'check_sources', return_value={}), \
|
||||
mock.patch.object(prepare, 'read_gamescope') as read_gamescope:
|
||||
with self.assertRaisesRegex(ValueError, 'Donor APK checksum mismatch'):
|
||||
prepare.prepare(apk, Path(folder) / 'missing', Path(folder) / 'missing.tzst')
|
||||
read_gamescope.assert_not_called()
|
||||
|
||||
def test_sdk_bridge_is_compiled_locally_while_other_untracked_native_files_fail(self):
|
||||
with mock.patch.object(prepare, 'source_assets', return_value={}), \
|
||||
mock.patch.object(prepare, 'changed', side_effect=[set(), {'app/src/main/cpp/CMakeLists.txt'}, set()]), \
|
||||
mock.patch.object(prepare, 'git', side_effect=[prepare.DONOR_TREE.encode(),
|
||||
b'app/src/main/cpp/viture/sdk_bridge.cpp\0app/src/main/cpp/viture/stereo_frame_gate.h\0']):
|
||||
classifications = prepare.check_sources()
|
||||
self.assertEqual(set(classifications), {'app/src/main/cpp/CMakeLists.txt',
|
||||
'app/src/main/cpp/viture/sdk_bridge.cpp',
|
||||
'app/src/main/cpp/viture/stereo_frame_gate.h'})
|
||||
self.assertTrue(all('compiled by Gradle' in action for action in classifications.values()))
|
||||
with mock.patch.object(prepare, 'changed', side_effect=[set(), set()]), \
|
||||
mock.patch.object(prepare, 'git', side_effect=[prepare.DONOR_TREE.encode(),
|
||||
b'app/src/main/cpp/unreviewed.cpp\0']):
|
||||
with self.assertRaisesRegex(ValueError, 'Unreviewed runtime'):
|
||||
prepare.check_sources()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,85 @@
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
from test_quest_xr import collect_device_metrics, summarize_samples, validate_samples
|
||||
import subprocess
|
||||
|
||||
|
||||
class QuestXrValidationTest(unittest.TestCase):
|
||||
def samples(self, source='frames'):
|
||||
return [{'rendered': count, 'sessionState': 5, 'headFlags': 15, 'source': source,
|
||||
'controllersActive': [False, False], 'guestFrames': count,
|
||||
'uploadedFrames': count, 'sourceFrameId': count + 1, 'steamvrState': 4}
|
||||
for count in (0, 144)]
|
||||
|
||||
def test_requires_owned_frame_projection(self):
|
||||
self.assertIsNone(validate_samples(self.samples()))
|
||||
self.assertEqual('Wrong projection source', validate_samples(self.samples('surface')))
|
||||
|
||||
def test_position_must_be_tracked_not_merely_valid(self):
|
||||
samples = self.samples()
|
||||
for sample in samples:
|
||||
sample['headFlags'] = 7
|
||||
self.assertIn('tracked 6DoF', validate_samples(samples))
|
||||
|
||||
def test_optional_controllers_cannot_be_claimed_as_tested(self):
|
||||
self.assertIn('controllers', validate_samples(self.samples(), require_controllers=True))
|
||||
|
||||
def test_one_early_tracked_sample_cannot_hide_final_tracking_loss(self):
|
||||
samples = self.samples()
|
||||
samples[-1]['headFlags'] = 7
|
||||
self.assertIn('final sample', validate_samples(samples))
|
||||
samples[-1]['headFlags'] = 15
|
||||
samples[-1]['sessionState'] = 4
|
||||
self.assertIn('final sample', validate_samples(samples))
|
||||
|
||||
def test_measured_rates_are_separate_from_runtime_refresh(self):
|
||||
samples = self.samples('frames')
|
||||
samples[0]['_hostMonotonicSeconds'] = 10
|
||||
samples[-1]['_hostMonotonicSeconds'] = 12
|
||||
samples[-1]['periodNs'] = 8333333
|
||||
summary = summarize_samples(samples)
|
||||
self.assertEqual(summary['observedSeconds'], 2)
|
||||
self.assertEqual(summary['ratesHz']['uploadedFrames'], 72)
|
||||
self.assertAlmostEqual(summary['runtimeRefreshHz'], 120, places=3)
|
||||
self.assertEqual(summary['focusedTrackedFraction'], 1)
|
||||
samples[-1]['uploadedFrames'] = -1
|
||||
self.assertIsNone(summarize_samples(samples)['ratesHz']['uploadedFrames'])
|
||||
self.assertIsNone(summarize_samples(self.samples())['observedSeconds'])
|
||||
self.assertIsNone(summarize_samples([])['focusedTrackedFraction'])
|
||||
|
||||
def test_metrics_failures_stay_unavailable_without_privileged_fallback(self):
|
||||
commands = []
|
||||
def adb(*command):
|
||||
commands.append(command)
|
||||
if command[-1] == 'battery':
|
||||
return 'temperature: 310'
|
||||
raise subprocess.CalledProcessError(1, command, stderr='Permission denied')
|
||||
metrics = collect_device_metrics(adb, 'com.droiddeck.launcher')
|
||||
self.assertEqual(len(commands), 3)
|
||||
self.assertTrue(metrics['battery']['available'])
|
||||
self.assertFalse(metrics['thermal']['available'])
|
||||
self.assertFalse(metrics['memory']['available'])
|
||||
|
||||
def test_steamvr_requires_owned_images_and_source_frame_ids(self):
|
||||
samples = self.samples('frames')
|
||||
self.assertIsNone(validate_samples(samples))
|
||||
samples[-1]['uploadedFrames'] = 0
|
||||
self.assertIn('owned SteamVR images', validate_samples(samples))
|
||||
samples[-1]['uploadedFrames'] = 144
|
||||
samples[-1]['sourceFrameId'] = samples[0]['sourceFrameId']
|
||||
self.assertIn('frame IDs', validate_samples(samples))
|
||||
|
||||
def test_running_process_alone_is_not_success(self):
|
||||
samples = self.samples('frames')
|
||||
samples[-1]['rendered'] = 0
|
||||
self.assertIn('stereo frames', validate_samples(samples))
|
||||
samples[-1]['rendered'] = 144
|
||||
samples[-1]['steamvrState'] = 3
|
||||
self.assertIn('RUNNING', validate_samples(samples))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -32,8 +32,10 @@ class RequestFexTest(unittest.TestCase):
|
||||
"start steam://install/1628350", "end steam://install/1628350"],
|
||||
self.log.read_text().splitlines())
|
||||
self.install("1628350")
|
||||
self.assertEqual(["4183110"], COMPAT["request_fex"](str(self.root), asked))
|
||||
self.install("4183110")
|
||||
self.assertEqual([], COMPAT["request_fex"](str(self.root), asked))
|
||||
self.assertEqual({"3127680", "1628350"}, asked)
|
||||
self.assertEqual({"3127680", "1628350", "4183110"}, asked)
|
||||
|
||||
def test_a_declined_install_is_not_asked_again_in_the_same_session(self):
|
||||
asked = set()
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
"""Exercise the Windows launcher without building an APK or contacting a phone."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
POWERSHELL = shutil.which('pwsh') or shutil.which('powershell')
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / 'run_windows.ps1'
|
||||
|
||||
|
||||
@unittest.skipUnless(os.name == 'nt' and POWERSHELL, 'Windows PowerShell launcher')
|
||||
class WindowsLauncherTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory(prefix='droiddeck windows launcher ')
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.root = Path(self.temp.name)
|
||||
(self.root / 'tools').mkdir()
|
||||
shutil.copyfile(SCRIPT, self.root / 'tools/run_windows.ps1')
|
||||
self.calls = self.root / 'calls.txt'
|
||||
(self.root / 'gradlew.bat').write_text(
|
||||
'@echo off\necho gradle JAVA_HOME=%JAVA_HOME%>>"%DROIDDECK_TEST_CALLS%"\n'
|
||||
'exit /b %DROIDDECK_TEST_GRADLE_EXIT%\n')
|
||||
(self.root / 'adb.cmd').write_text(
|
||||
'@echo off\necho adb %*>>"%DROIDDECK_TEST_CALLS%"\nexit /b 0\n')
|
||||
self.env = dict(os.environ, JAVA_HOME=r'C:\provided-java',
|
||||
DROIDDECK_TEST_CALLS=str(self.calls), DROIDDECK_TEST_GRADLE_EXIT='0')
|
||||
self.env['PATH'] = str(self.root) + os.pathsep + self.env.get('PATH', '')
|
||||
|
||||
def launch(self):
|
||||
return subprocess.run(
|
||||
[POWERSHELL, '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass',
|
||||
'-File', str(self.root / 'tools/run_windows.ps1'), '-Serial', 'test-phone'],
|
||||
env=self.env, cwd=self.root, capture_output=True, text=True, timeout=30)
|
||||
|
||||
def test_missing_optional_configs_keep_environment_java_and_base_package(self):
|
||||
result = self.launch()
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
calls = self.calls.read_text().splitlines()
|
||||
self.assertEqual(calls[0], r'gradle JAVA_HOME=C:\provided-java')
|
||||
self.assertEqual(calls[1], 'adb -s test-phone install -r app/build/outputs/apk/debug/app-debug.apk')
|
||||
self.assertEqual(calls[2], 'adb -s test-phone shell am start -W -n '
|
||||
'com.droiddeck.launcher/com.droiddeck.launcher.MainActivity')
|
||||
|
||||
def test_existing_configs_select_java_and_suffixed_package(self):
|
||||
(self.root / '.gradle').mkdir()
|
||||
(self.root / '.gradle/config.properties').write_text('java.home=C\\:\\\\configured-java\n')
|
||||
(self.root / 'local.properties').write_text('droiddeck.debugApplicationIdSuffix=.xr\n')
|
||||
result = self.launch()
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
calls = self.calls.read_text().splitlines()
|
||||
self.assertEqual(calls[0], r'gradle JAVA_HOME=C:\configured-java')
|
||||
self.assertTrue(calls[2].endswith('com.droiddeck.launcher.xr/com.droiddeck.launcher.MainActivity'))
|
||||
|
||||
def test_empty_configs_use_defaults(self):
|
||||
(self.root / '.gradle').mkdir()
|
||||
(self.root / '.gradle/config.properties').touch()
|
||||
(self.root / 'local.properties').touch()
|
||||
result = self.launch()
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
calls = self.calls.read_text().splitlines()
|
||||
self.assertEqual(calls[0], r'gradle JAVA_HOME=C:\provided-java')
|
||||
self.assertTrue(calls[2].endswith('com.droiddeck.launcher/com.droiddeck.launcher.MainActivity'))
|
||||
|
||||
def test_build_failure_still_stops_before_installation(self):
|
||||
self.env['DROIDDECK_TEST_GRADLE_EXIT'] = '1'
|
||||
result = self.launch()
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn('Android build failed.', result.stderr)
|
||||
self.assertEqual(self.calls.read_text().splitlines(), [r'gradle JAVA_HOME=C:\provided-java'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,12 +1,13 @@
|
||||
import importlib.util
|
||||
import gzip
|
||||
import io
|
||||
from pathlib import Path
|
||||
from pathlib import Path, PureWindowsPath
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from unittest import mock
|
||||
from zipfile import ZipFile
|
||||
|
||||
|
||||
@@ -114,6 +115,29 @@ class RuntimeInputsTest(unittest.TestCase):
|
||||
package.writestr(name, (self.root / output['path']).read_bytes())
|
||||
runtime.check_apk(apk, self.root)
|
||||
|
||||
def test_windows_manifest_matches_portable_apk_paths(self):
|
||||
path_type = type(self.root)
|
||||
original_relative_to = path_type.relative_to
|
||||
|
||||
def windows_relative_to(path, *args, **kwargs):
|
||||
return PureWindowsPath(original_relative_to(path, *args, **kwargs))
|
||||
|
||||
with mock.patch.object(path_type, 'relative_to', windows_relative_to):
|
||||
runtime.record(self.root)
|
||||
data = runtime.verify(self.root)
|
||||
self.assertIn('tools/linuxfs/preload/test.c', data['sources'])
|
||||
nested_asset = 'assets/linuxfs/usr/local/bin/gamescope'
|
||||
self.assertEqual(data['outputs'][nested_asset]['path'], 'app/src/main/' + nested_asset)
|
||||
for name in data['sources']:
|
||||
self.assertNotIn('\\', name)
|
||||
apk = self.root / 'portable.apk'
|
||||
with ZipFile(apk, 'w') as package:
|
||||
for name, output in data['outputs'].items():
|
||||
self.assertNotIn('\\', name)
|
||||
self.assertNotIn('\\', output['path'])
|
||||
package.writestr(name, (self.root / output['path']).read_bytes())
|
||||
runtime.check_apk(apk, self.root)
|
||||
|
||||
def test_android_expanding_or_renaming_a_compressed_inventory_is_rejected(self):
|
||||
runtime.record(self.root)
|
||||
data = runtime.verify(self.root)
|
||||
|
||||
@@ -37,3 +37,9 @@ class SessionAssetsTest(unittest.TestCase):
|
||||
with ZipFile(self.apk, 'w') as package:
|
||||
package.writestr(self.name, self.helper.read_bytes())
|
||||
self.assertEqual([], assets.check(self.apk, self.overlay))
|
||||
|
||||
def test_bundled_helper_must_also_be_extracted(self):
|
||||
self.assertEqual(['not extracted at session start: usr/local/bin/droiddeck-login1'],
|
||||
assets.check_extraction(self.overlay, ''))
|
||||
mapping = '"usr/local/bin/droiddeck-login1" to "usr/local/bin/droiddeck-login1"'
|
||||
self.assertEqual([], assets.check_extraction(self.overlay, mapping))
|
||||
@@ -0,0 +1,74 @@
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session"
|
||||
|
||||
|
||||
def run_program_function():
|
||||
match = re.search(r"^ run_program\(\) \{\n.*?^ \}\n", SESSION.read_text(), re.M | re.S)
|
||||
return match.group(0)
|
||||
|
||||
|
||||
class RunStatusTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.dir = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(shutil.rmtree, self.dir, True)
|
||||
|
||||
def run_with(self, command, launch_dir=True):
|
||||
env = dict(os.environ)
|
||||
env.pop("BL_LAUNCH_DIR", None)
|
||||
if launch_dir:
|
||||
env["BL_LAUNCH_DIR"] = str(self.dir)
|
||||
return subprocess.run(["bash", "-c", run_program_function() + "run_program " + command + "; echo unreachable"],
|
||||
env=env, capture_output=True, text=True, timeout=30)
|
||||
|
||||
def test_the_program_status_is_kept_for_the_app(self):
|
||||
run = self.run_with("sh -c 'exit 7'")
|
||||
self.assertEqual(7, run.returncode)
|
||||
self.assertNotIn("unreachable", run.stdout)
|
||||
self.assertEqual("7\n", (self.dir / "run-status").read_text())
|
||||
self.assertFalse((self.dir / "run-status.tmp").exists())
|
||||
|
||||
def test_a_clean_exit_is_recorded_as_zero(self):
|
||||
self.assertEqual(0, self.run_with("true").returncode)
|
||||
self.assertEqual("0\n", (self.dir / "run-status").read_text())
|
||||
|
||||
def test_nothing_is_written_without_a_launch_dir(self):
|
||||
self.assertEqual(3, self.run_with("sh -c 'exit 3'", launch_dir=False).returncode)
|
||||
self.assertEqual([], os.listdir(self.dir))
|
||||
|
||||
def signalled(self, sig, program):
|
||||
env = dict(os.environ, BL_LAUNCH_DIR=str(self.dir))
|
||||
ready = self.dir / "ready"
|
||||
proc = subprocess.Popen(["bash", "-c", run_program_function() + "run_program " + program],
|
||||
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
self.addCleanup(proc.kill)
|
||||
deadline = time.monotonic() + 10
|
||||
while not ready.exists() and time.monotonic() < deadline:
|
||||
time.sleep(0.05)
|
||||
self.assertTrue(ready.exists())
|
||||
proc.send_signal(sig)
|
||||
return proc.wait(timeout=10)
|
||||
|
||||
def test_a_stop_signal_reaches_the_program(self):
|
||||
program = ("python3 -c 'import signal, sys, time; signal.signal(signal.SIGTERM, lambda *a: sys.exit(9)); "
|
||||
"open(sys.argv[1], \"w\").close(); time.sleep(30)' %s" % (self.dir / "ready"))
|
||||
self.assertEqual(9, self.signalled(signal.SIGTERM, program))
|
||||
self.assertEqual("9\n", (self.dir / "run-status").read_text())
|
||||
|
||||
def test_an_interrupt_reaches_the_program(self):
|
||||
program = ("python3 -c 'import sys, time; open(sys.argv[1], \"w\").close(); time.sleep(30)' %s"
|
||||
% (self.dir / "ready"))
|
||||
self.assertEqual(130, self.signalled(signal.SIGINT, program))
|
||||
self.assertEqual("130\n", (self.dir / "run-status").read_text())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -8,15 +8,8 @@ import unittest
|
||||
|
||||
SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session"
|
||||
SOURCE = SESSION.read_text()
|
||||
END = SOURCE.index(
|
||||
' if [ -s "$HOME/.bl-autolaunch" ]; then',
|
||||
SOURCE.index(" _bl_launch_ready="),
|
||||
)
|
||||
START = SOURCE.rfind(
|
||||
' if [ -n "${BL_LAUNCH_DIR:-}" ] && [ -z "${BL_DESKTOP:-}" ]; then',
|
||||
0,
|
||||
END,
|
||||
)
|
||||
START = SOURCE.index(" steam_hold_launch() {")
|
||||
END = SOURCE.index(' if [ -s "$HOME/.bl-autolaunch" ]; then', START)
|
||||
assert START >= 0
|
||||
LAUNCH_BLOCK = textwrap.dedent(SOURCE[START:END])
|
||||
|
||||
@@ -32,12 +25,19 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
self.bin.mkdir()
|
||||
self.agent_args = self.root / "agent-args"
|
||||
self.sleep_args = self.root / "sleep-args"
|
||||
self.agent_count = self.root / "agent-count"
|
||||
|
||||
xprop = self.bin / "xprop"
|
||||
xprop.write_text("#!/bin/sh\necho 'GAMESCOPE_FOCUSED_APP(CARDINAL) = 769'\n")
|
||||
xprop.chmod(0o755)
|
||||
agent = self.bin / "droiddeck-agent"
|
||||
agent.write_text("#!/bin/sh\nprintf '%s\\n' \"$@\" > \"$AGENT_ARGS\"\nexit \"$AGENT_STATUS\"\n")
|
||||
agent.write_text(
|
||||
"#!/bin/sh\n"
|
||||
"printf '%s\\n' \"$@\" > \"$AGENT_ARGS\"\n"
|
||||
"n=$(cat \"$AGENT_COUNT\" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > \"$AGENT_COUNT\"\n"
|
||||
"i=0; last=1\n"
|
||||
"for s in $AGENT_STATUS; do i=$((i + 1)); last=$s; [ \"$i\" -eq \"$n\" ] && exit \"$s\"; done\n"
|
||||
"exit \"$last\"\n")
|
||||
agent.chmod(0o755)
|
||||
sleep = self.bin / "sleep"
|
||||
sleep.write_text("#!/bin/sh\nprintf '%s\\n' \"$@\" >> \"$SLEEP_ARGS\"\n")
|
||||
@@ -48,7 +48,7 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
env = dict(os.environ, HOME=str(self.root), BL_LAUNCH_DIR=str(self.launch_dir),
|
||||
PATH=str(self.bin) + os.pathsep + os.environ["PATH"],
|
||||
AGENT_ARGS=str(self.agent_args), SLEEP_ARGS=str(self.sleep_args),
|
||||
AGENT_STATUS=str(helper_status))
|
||||
AGENT_COUNT=str(self.agent_count), AGENT_STATUS=str(helper_status))
|
||||
script = self.block + "\nprintf 'ARG:%s\\n' \"$@\"\nwait\n"
|
||||
url = target if target.startswith("steam://") else "steam://rungameid/" + target
|
||||
result = subprocess.run(["bash", "-c", script, "cold-launch", url],
|
||||
@@ -71,13 +71,45 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
self.assertEqual(["--wait-steam-shortcut-overview", game_id, "45"], self.agent_args.read_text().splitlines())
|
||||
self.assertEqual("4", self.sleep_args.read_text().strip())
|
||||
|
||||
def test_shortcut_without_the_expected_overview_does_not_forward_cgameid(self):
|
||||
def test_a_shortcut_whose_overview_never_appears_is_launched_after_a_bounded_wait(self):
|
||||
game_id = str((3551182975 << 32) | 0x02000000)
|
||||
result = self.run_launch(game_id, 1)
|
||||
self.assertFalse((self.launch_dir / "steam-game").exists(), result.stdout)
|
||||
self.assertEqual(game_id, (self.launch_dir / "steam-game").read_text().strip(), result.stdout)
|
||||
self.assertEqual(["--wait-steam-shortcut-overview", game_id, "45"], self.agent_args.read_text().splitlines())
|
||||
self.assertEqual("2", self.agent_count.read_text().strip())
|
||||
self.assertEqual(["2", "2"], self.sleep_args.read_text().split())
|
||||
self.assertIn("launching the requested game anyway", result.stdout)
|
||||
|
||||
def test_a_late_overview_is_still_waited_for_once_more(self):
|
||||
game_id = str((3551182975 << 32) | 0x02000000)
|
||||
result = self.run_launch(game_id, "1 0")
|
||||
self.assertEqual(game_id, (self.launch_dir / "steam-game").read_text().strip(), result.stdout)
|
||||
self.assertEqual("2", self.agent_count.read_text().strip())
|
||||
self.assertEqual(["2"], self.sleep_args.read_text().split())
|
||||
self.assertIn("attempt 1 of 2", result.stdout)
|
||||
self.assertNotIn("anyway", result.stdout)
|
||||
|
||||
def test_an_agent_failure_other_than_a_timeout_launches_without_retrying(self):
|
||||
game_id = str((3551182975 << 32) | 0x02000000)
|
||||
result = self.run_launch(game_id, 2)
|
||||
self.assertEqual(game_id, (self.launch_dir / "steam-game").read_text().strip(), result.stdout)
|
||||
self.assertEqual("1", self.agent_count.read_text().strip())
|
||||
self.assertFalse(self.sleep_args.exists())
|
||||
|
||||
def test_a_restart_for_a_game_waits_for_its_overview_too(self):
|
||||
game_id = str((3551182975 << 32) | 0x02000000)
|
||||
loop = SOURCE[SOURCE.index(' if [ -s "$HOME/.bl-restart-game" ]; then'):SOURCE.index(' if [ -f "$HOME/.bl-restart-once" ]; then')]
|
||||
self.assertIn('steam_hold_launch "$_bl_again" &', loop)
|
||||
self.assertNotIn("set -- \"steam://rungameid/", loop)
|
||||
script = self.block + '\nsteam_hold_launch "%s"\n' % game_id
|
||||
env = dict(os.environ, HOME=str(self.root), BL_LAUNCH_DIR=str(self.launch_dir),
|
||||
PATH=str(self.bin) + os.pathsep + os.environ["PATH"],
|
||||
AGENT_ARGS=str(self.agent_args), SLEEP_ARGS=str(self.sleep_args),
|
||||
AGENT_COUNT=str(self.agent_count), AGENT_STATUS="1 0")
|
||||
result = subprocess.run(["bash", "-c", script, "restart"], env=env, text=True, capture_output=True, timeout=10, check=True)
|
||||
self.assertEqual(game_id, (self.launch_dir / "steam-game").read_text().strip(), result.stdout)
|
||||
self.assertEqual(["--wait-steam-shortcut-overview", game_id, "45"], self.agent_args.read_text().splitlines())
|
||||
|
||||
def test_non_game_steam_urls_remain_on_the_original_startup_arguments(self):
|
||||
url = "steam://open/library"
|
||||
result = self.run_launch(url, 0)
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin'
|
||||
|
||||
|
||||
class SteamCompatEnvironmentTest(unittest.TestCase):
|
||||
def test_library_launch_preserves_guest_environment_without_steam_client_libraries(self):
|
||||
source = (BIN / 'droiddeck-session').read_text()
|
||||
setup = source[source.index(' _bl_compat_env='):source.index(' export SDL_VIDEO_X11_DGAMOUSE=')]
|
||||
launch = next(line for line in source.splitlines()
|
||||
if 'droiddeck-steam-compat "$steam_root"' in line)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
helper = root / 'droiddeck-steam-compat'
|
||||
helper.write_text('#!/usr/bin/env python3\nimport json, os, sys\n'
|
||||
'json.dump({"env": dict(os.environ), "args": sys.argv[1:]}, '
|
||||
'open(os.environ["BRIDGE_CAPTURE"], "w"))\n')
|
||||
helper.chmod(0o755)
|
||||
for inherited in ({}, {'LD_LIBRARY_PATH': '/guest/driver:/guest/libs'},
|
||||
{'LD_LIBRARY_PATH': '', 'STEAM_RUNTIME': ''},
|
||||
{'LD_LIBRARY_PATH': '/custom path/lib', 'STEAM_RUNTIME': '0'}):
|
||||
with self.subTest(inherited=inherited):
|
||||
env = dict(os.environ, PATH=str(root) + os.pathsep + os.environ['PATH'],
|
||||
BRIDGE_CAPTURE=str(root / 'captured.json'),
|
||||
VK_ICD_FILENAMES='/guest/driver/turnip.json', steam_root='/steam')
|
||||
for key in ('LD_LIBRARY_PATH', 'STEAM_RUNTIME'):
|
||||
env.pop(key, None)
|
||||
env.update(inherited)
|
||||
result = subprocess.run(['bash', '-c', setup + '\n' + launch + '\nwait $!\n'
|
||||
'printf "%s\\n" "$STEAM_RUNTIME" "$LD_LIBRARY_PATH"'],
|
||||
env=env, capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
bridge = json.loads((root / 'captured.json').read_text())
|
||||
self.assertEqual(bridge['args'], ['/steam'])
|
||||
for key in ('LD_LIBRARY_PATH', 'STEAM_RUNTIME', 'VK_ICD_FILENAMES'):
|
||||
self.assertEqual(bridge['env'].get(key), env.get(key), key)
|
||||
client_path = '/steam/steamrtarm64:/steam/steamrtarm64/panorama'
|
||||
if inherited.get('LD_LIBRARY_PATH'):
|
||||
client_path += ':' + inherited['LD_LIBRARY_PATH']
|
||||
self.assertEqual(result.stdout.splitlines(), ['1', client_path])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -108,6 +108,86 @@ class FakePage:
|
||||
|
||||
@unittest.skipUnless(shutil.which("node"), "node is not installed")
|
||||
class PageScriptTest(unittest.TestCase):
|
||||
def test_vr_games_wait_for_steamvr_and_preserve_the_original_launch(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
script = Path(tmp) / "vr.js"
|
||||
script.write_text(LIVE["VR_JS"])
|
||||
harness = Path(__file__).with_name("steam_vr_launch_harness.js")
|
||||
result = subprocess.run(["node", str(harness), str(script)],
|
||||
capture_output=True, text=True, timeout=20)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_tool_installs_skip_only_their_own_install_dialog(self):
|
||||
harness_source = r"""
|
||||
const assert = require('assert');
|
||||
globalThis.window = globalThis;
|
||||
const script = require('fs').readFileSync(process.argv[2], 'utf8');
|
||||
globalThis.SteamClient = { Installs: {}, Downloads: {} };
|
||||
assert.throws(() => eval(script), /install calls are not ready/);
|
||||
const opened = [], queued = [];
|
||||
let wizard = null, continued = 0;
|
||||
globalThis.SteamClient = {
|
||||
Installs: {
|
||||
OpenInstallWizard(apps, client) { opened.push([apps, client]); },
|
||||
RegisterForShowInstallWizard(callback) { assert.strictEqual(wizard, null); wizard = callback; return { unregister() {} }; },
|
||||
ContinueInstall() { continued++; },
|
||||
},
|
||||
Downloads: { QueueAppUpdate(app, client) { queued.push([app, client]); } },
|
||||
};
|
||||
assert.strictEqual(eval(script), 'installed');
|
||||
assert.strictEqual(eval(script), 'present');
|
||||
const tools = window.__droiddeckTools;
|
||||
wizard({ eInstallState: 7, currentAppID: 4183110 });
|
||||
assert.strictEqual(continued, 0);
|
||||
tools.install(4183110);
|
||||
assert.deepStrictEqual(opened, [[[4183110], '0']]);
|
||||
wizard({ eInstallState: 8, currentAppID: 4183110 });
|
||||
wizard({ eInstallState: 7, currentAppID: 892970 });
|
||||
assert.strictEqual(continued, 0);
|
||||
wizard({ eInstallState: 7, currentAppID: 4183110 });
|
||||
wizard({ eInstallState: 7, currentAppID: 4183110 });
|
||||
assert.strictEqual(continued, 1);
|
||||
tools.update(4427310);
|
||||
assert.deepStrictEqual(queued, [[4427310, '0']]);
|
||||
"""
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
script = Path(tmp) / "tools.js"
|
||||
script.write_text(LIVE["TOOLS_JS"])
|
||||
harness = Path(tmp) / "harness.js"
|
||||
harness.write_text(harness_source)
|
||||
result = subprocess.run(["node", str(harness), str(script)], capture_output=True, text=True, timeout=20)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_steamvr_library_launch_uses_binding_and_other_games_pass_through(self):
|
||||
harness_source = r"""
|
||||
const assert = require('assert');
|
||||
globalThis.window = globalThis;
|
||||
const calls = [], requests = [];
|
||||
const apps = { RunGame(...args) { assert.strictEqual(this, apps); calls.push(args); return 'native'; } };
|
||||
globalThis.SteamClient = { Apps: apps };
|
||||
window.droiddeckLaunchSteamVr = id => requests.push(id);
|
||||
const script = require('fs').readFileSync(process.argv[2], 'utf8');
|
||||
assert.strictEqual(eval(script), 'installed');
|
||||
assert.strictEqual(eval(script), 'present');
|
||||
assert.strictEqual(apps.RunGame('250820', '', -1, 100), undefined);
|
||||
apps.RunGame(250820, '', -1, 100);
|
||||
assert.deepStrictEqual(requests, ['250820', '250820']);
|
||||
assert.deepStrictEqual(calls, []);
|
||||
assert.strictEqual(apps.RunGame('611670', 'custom args', -1, 100), 'native');
|
||||
assert.strictEqual(apps.RunGame('2508200', '', -1, 100), 'native');
|
||||
delete window.droiddeckLaunchSteamVr;
|
||||
assert.strictEqual(apps.RunGame('250820', '', -1, 100), 'native');
|
||||
assert.deepStrictEqual(calls, [['611670', 'custom args', -1, 100], ['2508200', '', -1, 100], ['250820', '', -1, 100]]);
|
||||
"""
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
script = Path(tmp) / "vr.js"
|
||||
script.write_text(LIVE["VR_JS"])
|
||||
harness = Path(tmp) / "test.js"
|
||||
harness.write_text(harness_source)
|
||||
result = subprocess.run(["node", str(harness), str(script)],
|
||||
capture_output=True, text=True, timeout=20)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_transport_framing_auth_and_notifications(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
script = Path(tmp) / "install.js"
|
||||
@@ -295,19 +375,19 @@ class ReconcileTest(unittest.TestCase):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["auto"], {})
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
self.assertEqual(COMPAT["read_config_mapping"](str(config)), {"0": TOOL})
|
||||
|
||||
page.sets.clear()
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
restarted = LIVE["Helper"](str(self.steam), 1)
|
||||
restarted.page = page
|
||||
restarted.reconcile()
|
||||
state = json.loads((self.state / "state.json").read_text())
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
|
||||
config.write_text(
|
||||
'"InstallConfigStore" { "Software" { "Valve" { "Steam" { '
|
||||
@@ -317,13 +397,13 @@ class ReconcileTest(unittest.TestCase):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.mapping[app], "GE-Proton11-7")
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native"], [])
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
|
||||
for choice in ("steamlinuxruntime", COMPAT["FEX_TOOL"], TOOL_11):
|
||||
(self.state / "state.json").write_text(json.dumps({
|
||||
"default": TOOL,
|
||||
"auto": {},
|
||||
"native": [app],
|
||||
"native_choices": [app],
|
||||
}))
|
||||
config.write_text(
|
||||
'"InstallConfigStore" { "Software" { "Valve" { "Steam" { '
|
||||
@@ -334,7 +414,7 @@ class ReconcileTest(unittest.TestCase):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.mapping[app], choice)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native"], [], choice)
|
||||
self.assertEqual(state["native_choices"], [], choice)
|
||||
finally:
|
||||
COMPAT["native_targets"] = original_native_targets
|
||||
|
||||
@@ -348,7 +428,7 @@ class ReconcileTest(unittest.TestCase):
|
||||
(self.state / "state.json").write_text(json.dumps({
|
||||
"default": TOOL,
|
||||
"auto": {},
|
||||
"native": [app],
|
||||
"native_choices": [app],
|
||||
}))
|
||||
|
||||
original_native_targets = COMPAT["native_targets"]
|
||||
@@ -357,14 +437,14 @@ class ReconcileTest(unittest.TestCase):
|
||||
page = FakePage({"0": TOOL, app: "proton"}, [TOOL, TOOL_11])
|
||||
state = self.reconcile(page)
|
||||
self.assertNotIn(app, self.helper.installed)
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
self.assertNotIn(app, state["auto"])
|
||||
self.assertNotIn((app, TOOL), page.sets)
|
||||
self.assertEqual(COMPAT["read_config_mapping"](str(config)), {"0": TOOL})
|
||||
|
||||
config.write_text('"InstallConfigStore" { "Software" { "Other" {} } }')
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(state["native"], [app])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
self.assertNotIn((app, TOOL), page.sets)
|
||||
|
||||
config.write_text(
|
||||
@@ -373,12 +453,72 @@ class ReconcileTest(unittest.TestCase):
|
||||
'"%s" { "name" "GE-Proton11-7" } } } } } }' % (TOOL, app))
|
||||
page.mapping[app] = "proton"
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(state["native"], [])
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
self.assertNotIn((app, TOOL), page.sets)
|
||||
self.assertEqual(COMPAT["read_config_mapping"](str(config))[app], "GE-Proton11-7")
|
||||
finally:
|
||||
COMPAT["native_targets"] = original_native_targets
|
||||
|
||||
def dual_platform_game(self, state):
|
||||
app = "892970"
|
||||
(self.steam / ("steamapps/appmanifest_%s.acf" % app)).write_text("")
|
||||
config = self.steam / "config/config.vdf"
|
||||
config.parent.mkdir(parents=True)
|
||||
config.write_text(
|
||||
'"InstallConfigStore" { "Software" { "Valve" { "Steam" { '
|
||||
'"CompatToolMapping" { "0" { "name" "%s" } } } } } }' % TOOL)
|
||||
(self.state / "state.json").write_text(json.dumps(state))
|
||||
patcher = mock.patch.dict(COMPAT, {"native_targets": lambda _root, apps: {
|
||||
app: COMPAT["NATIVE_CHOICE"]
|
||||
} if app in apps else {}})
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
return app, FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11])
|
||||
|
||||
def test_unmapped_dual_platform_game_gets_the_default_live(self):
|
||||
app, page = self.dual_platform_game({"default": TOOL, "auto": {"10": TOOL, "11": TOOL}})
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, TOOL)])
|
||||
self.assertEqual(state["auto"][app], TOOL)
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
|
||||
page.mapping[app] = ""
|
||||
page.sets.clear()
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["native_choices"], [app])
|
||||
|
||||
def test_unmapped_dual_platform_game_gets_the_default_without_a_readable_config(self):
|
||||
app, page = self.dual_platform_game({"default": TOOL, "auto": {"10": TOOL}, "native_choices": ["11"]})
|
||||
(self.steam / "config/config.vdf").unlink()
|
||||
page.mapping["11"] = ""
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, TOOL)])
|
||||
self.assertEqual(state["auto"][app], TOOL)
|
||||
self.assertEqual(state["native_choices"], ["11"])
|
||||
|
||||
def test_a_tool_set_live_is_kept_before_the_client_writes_its_config(self):
|
||||
app, page = self.dual_platform_game({"default": TOOL, "auto": {"10": TOOL, "11": TOOL, "892970": TOOL}})
|
||||
page.known.append(COMPAT["FEX_TOOL"])
|
||||
page.mapping[app] = TOOL
|
||||
config = self.steam / "config/config.vdf"
|
||||
config.write_text(
|
||||
'"InstallConfigStore" { "Software" { "Valve" { "Steam" { '
|
||||
'"CompatToolMapping" { "0" { "name" "%s" } "%s" { "name" "%s" } } } } } }' % (TOOL, app, TOOL))
|
||||
with mock.patch.dict(COMPAT, {"native_targets": lambda _root, apps: {app: COMPAT["FEX_TOOL"]} if app in apps else {}}):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, COMPAT["FEX_TOOL"])])
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, COMPAT["FEX_TOOL"])])
|
||||
self.assertEqual(state["auto"][app], COMPAT["FEX_TOOL"])
|
||||
|
||||
def test_native_list_from_earlier_builds_is_not_trusted(self):
|
||||
app, page = self.dual_platform_game({"default": TOOL, "auto": {"10": TOOL, "11": TOOL}, "native": ["892970"]})
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, TOOL)])
|
||||
self.assertNotIn("native", state)
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
|
||||
def test_factorio_without_prior_auto_state_uses_the_default_proton(self):
|
||||
app = "427520"
|
||||
(self.steam / ("steamapps/appmanifest_%s.acf" % app)).write_text("")
|
||||
@@ -397,7 +537,7 @@ class ReconcileTest(unittest.TestCase):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [(app, TOOL)])
|
||||
self.assertEqual(state["auto"], {app: TOOL})
|
||||
self.assertEqual(state["native"], [])
|
||||
self.assertEqual(state["native_choices"], [])
|
||||
self.assertEqual(COMPAT["read_config_mapping"](str(config)), {"0": TOOL})
|
||||
finally:
|
||||
COMPAT["native_targets"] = original_native_targets
|
||||
@@ -446,6 +586,79 @@ console.log(JSON.stringify({ sent: sent.length, asked: asked.length }));
|
||||
"""
|
||||
|
||||
|
||||
class ToolPage(FakePage):
|
||||
def __init__(self, fail=False):
|
||||
super().__init__({"0": TOOL}, [TOOL])
|
||||
self.calls = []
|
||||
self.fail = fail
|
||||
|
||||
def tools(self, call):
|
||||
self.calls.append(call)
|
||||
if self.fail:
|
||||
raise RuntimeError("the client's install calls are not ready")
|
||||
return True
|
||||
|
||||
|
||||
class ToolDownloadTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
self.steam = Path(tmp.name) / "Steam"
|
||||
(self.steam / "steamapps").mkdir(parents=True)
|
||||
self.helper = LIVE["Helper"](str(self.steam), 1)
|
||||
self.now = [1000.0]
|
||||
self.running = [False]
|
||||
self.requested = []
|
||||
patcher = mock.patch.dict(COMPAT, {
|
||||
"game_running": lambda: self.running[0],
|
||||
"request_fex": lambda root, asked: self.requested.append(root) or ["3127680"],
|
||||
})
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
clock = mock.patch.object(LIVE["time"], "monotonic", lambda: self.now[0])
|
||||
clock.start()
|
||||
self.addCleanup(clock.stop)
|
||||
|
||||
def manifest(self, app, flags):
|
||||
(self.steam / ("steamapps/appmanifest_%s.acf" % app)).write_text('"AppState" { "StateFlags" "%s" }' % flags)
|
||||
|
||||
def test_missing_tools_are_installed_and_deferred_ones_queued(self):
|
||||
self.manifest("4427310", "6")
|
||||
self.manifest("3127680", "4")
|
||||
self.manifest("1628350", "1026")
|
||||
self.helper.page = page = ToolPage()
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(page.calls, ["update(4427310)", "update(1628350)", "install(4183110)"])
|
||||
self.now[0] += 30
|
||||
self.helper.ensure_tools()
|
||||
self.now[0] += 60
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(len(page.calls), 3)
|
||||
self.now[0] += 300
|
||||
self.manifest("4427310", "4")
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(page.calls[3:], ["update(1628350)", "install(4183110)"])
|
||||
self.assertEqual(self.requested, [])
|
||||
|
||||
def test_nothing_is_queued_while_a_game_runs(self):
|
||||
self.running[0] = True
|
||||
self.helper.page = page = ToolPage()
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(page.calls, [])
|
||||
self.running[0] = False
|
||||
self.now[0] += 60
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(len(page.calls), 4)
|
||||
|
||||
def test_an_install_falls_back_to_the_steam_url(self):
|
||||
for app in ("4427310", "1628350", "4183110"):
|
||||
self.manifest(app, "4")
|
||||
self.helper.page = page = ToolPage(fail=True)
|
||||
self.helper.ensure_tools()
|
||||
self.assertEqual(page.calls, ["install(3127680)"])
|
||||
self.assertEqual(self.requested, [str(self.steam)])
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("node"), "node is not installed")
|
||||
class SwitchScriptTest(unittest.TestCase):
|
||||
def test_the_request_is_reported_and_still_sent(self):
|
||||
@@ -493,6 +706,54 @@ class SwitchToDesktopTest(unittest.TestCase):
|
||||
self.assertNotIn(("Runtime.addBinding", LIVE["SWITCH_BINDING"]), helper.page.calls)
|
||||
self.assertNotIn(LIVE["SWITCH_JS"], helper.page.scripts)
|
||||
|
||||
def test_vr_bridge_is_installed_for_both_steam_ui_modes(self):
|
||||
for steamos in (False, True):
|
||||
helper = LIVE["Helper"]("/steam", 1, steamos=steamos)
|
||||
helper.attach()
|
||||
self.assertIn(("Runtime.addBinding", LIVE["VR_BINDING"]), helper.page.calls)
|
||||
self.assertIn(LIVE["VR_JS"], helper.page.scripts)
|
||||
|
||||
def test_vr_bridge_accepts_only_steamvr_and_coalesces_requests(self):
|
||||
helper = LIVE["Helper"]("/steam", 1)
|
||||
helper.page = mock.Mock()
|
||||
event = lambda payload: {"method": "Runtime.bindingCalled", "params": {
|
||||
"name": LIVE["VR_BINDING"], "payload": payload}}
|
||||
with mock.patch.dict(self.globals, {"launch_steamvr": mock.Mock()}) as patched:
|
||||
launch = patched["launch_steamvr"]
|
||||
helper.page.drain.return_value = [event("0"), event("250820; touch /tmp/wrong"),
|
||||
event("-1"), event("01"), event("18446744073709551616"),
|
||||
event("\u0661"), event(None), event({})]
|
||||
helper.drain()
|
||||
launch.assert_not_called()
|
||||
helper.page.drain.return_value = [event("250820"), event("250820")]
|
||||
helper.drain()
|
||||
launch.assert_called_once_with()
|
||||
|
||||
def test_vr_game_requests_share_an_in_progress_helper_and_retry_after_it_exits(self):
|
||||
helper = LIVE["Helper"]("/steam", 1)
|
||||
helper.page = mock.Mock()
|
||||
event = lambda app: {"method": "Runtime.bindingCalled", "params": {
|
||||
"name": LIVE["VR_BINDING"], "payload": app}}
|
||||
child = mock.Mock()
|
||||
child.poll.return_value = None
|
||||
with mock.patch.dict(self.globals, {"launch_steamvr": mock.Mock(return_value=child)}) as patched:
|
||||
helper.page.drain.return_value = [event("611670"), event("620980")]
|
||||
helper.drain()
|
||||
helper.drain()
|
||||
patched["launch_steamvr"].assert_called_once_with()
|
||||
child.poll.return_value = 0
|
||||
helper.drain()
|
||||
self.assertEqual(patched["launch_steamvr"].call_count, 2)
|
||||
|
||||
def test_vr_launch_runs_helper_without_shell_in_background(self):
|
||||
with tempfile.TemporaryDirectory() as tmp, mock.patch.dict(os.environ, {"XDG_RUNTIME_DIR": tmp}):
|
||||
with mock.patch.object(self.globals["subprocess"], "Popen") as popen:
|
||||
LIVE["launch_steamvr"]()
|
||||
self.assertEqual(popen.call_args.args, ([LIVE["VR_HELPER"], "launch"],))
|
||||
self.assertTrue(popen.call_args.kwargs["start_new_session"])
|
||||
self.assertNotIn("shell", popen.call_args.kwargs)
|
||||
self.assertTrue((Path(tmp) / "droiddeck-steamvr/library-launch.log").exists())
|
||||
|
||||
def test_the_request_goes_to_steamos_session_select(self):
|
||||
helper = LIVE["Helper"]("/steam", 1)
|
||||
helper.page = mock.Mock()
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
COMPAT = runpy.run_path(str(BIN / "steam-compatibility"))
|
||||
|
||||
CONFIG = '''"InstallConfigStore"
|
||||
{
|
||||
\t"Software"
|
||||
\t{
|
||||
\t\t"Valve"
|
||||
\t\t{
|
||||
\t\t\t"Steam"
|
||||
\t\t\t{
|
||||
\t\t\t\t"CompatToolMapping"
|
||||
\t\t\t\t{
|
||||
\t\t\t\t\t"550"
|
||||
\t\t\t\t\t{
|
||||
\t\t\t\t\t\t"name"\t\t"proton_experimental"
|
||||
\t\t\t\t\t\t"config"\t\t""
|
||||
\t\t\t\t\t\t"priority"\t\t"250"
|
||||
\t\t\t\t\t}
|
||||
\t\t\t\t\t"620"
|
||||
\t\t\t\t\t{
|
||||
\t\t\t\t\t\t"name"\t\t"proton-cachyos-a64"
|
||||
\t\t\t\t\t\t"config"\t\t""
|
||||
\t\t\t\t\t\t"priority"\t\t"250"
|
||||
\t\t\t\t\t}
|
||||
\t\t\t\t\t"880"
|
||||
\t\t\t\t\t{
|
||||
\t\t\t\t\t\t"name"\t\t"droiddeck-proton-arm64"
|
||||
\t\t\t\t\t\t"config"\t\t""
|
||||
\t\t\t\t\t\t"priority"\t\t"250"
|
||||
\t\t\t\t\t}
|
||||
\t\t\t\t\t"730"
|
||||
\t\t\t\t\t{
|
||||
\t\t\t\t\t\t"name"\t\t"steamlinuxruntime"
|
||||
\t\t\t\t\t\t"config"\t\t""
|
||||
\t\t\t\t\t\t"priority"\t\t"250"
|
||||
\t\t\t\t\t}
|
||||
\t\t\t\t}
|
||||
\t\t\t}
|
||||
\t\t}
|
||||
\t}
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class X64RepointTest(unittest.TestCase):
|
||||
"""steam-compatibility --x64: the x86-64 client's Proton entries go to its arm64 wrapper."""
|
||||
|
||||
def setUp(self):
|
||||
self.home = tempfile.TemporaryDirectory()
|
||||
self.root = Path(self.home.name) / "Steam"
|
||||
(self.root / "config").mkdir(parents=True)
|
||||
(self.root / "config" / "config.vdf").write_text(CONFIG)
|
||||
# A wrapper of its own whose name starts with "proton": kept, never repointed.
|
||||
own = self.root / "compatibilitytools.d" / "proton-cachyos-a64"
|
||||
own.mkdir(parents=True)
|
||||
(own / "compatibilitytool.vdf").write_text('"compatibilitytools"\n{\n\t"compat_tools"\n\t{\n\t\t"proton-cachyos-a64"\n\t\t{\n\t\t}\n\t}\n}\n')
|
||||
self.old_home = os.environ.get("HOME")
|
||||
os.environ["HOME"] = self.home.name
|
||||
|
||||
def tearDown(self):
|
||||
if self.old_home is None:
|
||||
os.environ.pop("HOME", None)
|
||||
else:
|
||||
os.environ["HOME"] = self.old_home
|
||||
self.home.cleanup()
|
||||
|
||||
def mapping(self):
|
||||
tokens = COMPAT["tokenize"]((self.root / "config" / "config.vdf").read_text())
|
||||
return COMPAT["read_mapping"](tokens, COMPAT["mapping_block"](tokens))
|
||||
|
||||
def test_repoints_valve_proton_only(self):
|
||||
moved = COMPAT["x64_repoint"](str(self.root), "GE-Proton11-7-a64")
|
||||
self.assertEqual(moved, ["550", "880"])
|
||||
m = self.mapping()
|
||||
self.assertEqual(m["550"], "GE-Proton11-7-a64")
|
||||
self.assertEqual(m["620"], "proton-cachyos-a64")
|
||||
self.assertEqual(m["730"], "steamlinuxruntime")
|
||||
# The arm64 client's own Proton name, which this client ignores.
|
||||
self.assertEqual(m["880"], "GE-Proton11-7-a64")
|
||||
self.assertEqual(m["0"], "GE-Proton11-7-a64")
|
||||
|
||||
def test_repoints_arm64_name_even_with_its_stray_tool(self):
|
||||
# An arm64 compat pass that ran against this client also left its tool folder here.
|
||||
stray = self.root / "compatibilitytools.d" / "droiddeck-proton-arm64"
|
||||
stray.mkdir(parents=True)
|
||||
(stray / "compatibilitytool.vdf").write_text('"compatibilitytools"\n{\n\t"compat_tools"\n\t{\n\t\t"droiddeck-proton-arm64"\n\t\t{\n\t\t}\n\t}\n}\n')
|
||||
self.assertIn("880", COMPAT["x64_repoint"](str(self.root), "GE-Proton11-7-a64"))
|
||||
self.assertEqual(self.mapping()["880"], "GE-Proton11-7-a64")
|
||||
|
||||
def test_live_notes_pending_restart(self):
|
||||
COMPAT["x64_repoint"](str(self.root), "GE-Proton11-7-a64", live=True)
|
||||
self.assertEqual((Path(self.home.name) / ".bl-compat-pending").read_text(), "550\n880\n")
|
||||
|
||||
def test_no_tool_changes_nothing(self):
|
||||
before = (self.root / "config" / "config.vdf").read_text()
|
||||
self.assertEqual(COMPAT["x64_repoint"](str(self.root), None), [])
|
||||
self.assertEqual((self.root / "config" / "config.vdf").read_text(), before)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -23,9 +23,13 @@ class DesktopSteamLaunchTest(unittest.TestCase):
|
||||
supervisor = self.root / 'supervisor'
|
||||
supervisor.write_text('#!/bin/bash\nprintf "%s\\n" "$BL_INSIDE" "$BL_STEAM_UI" "$DISPLAY" "$@"\n')
|
||||
supervisor.chmod(0o755)
|
||||
x64 = self.root / 'steam-x64'
|
||||
x64.write_text('#!/bin/bash\nprintf "%s\\n" x64 "$@"\n')
|
||||
x64.chmod(0o755)
|
||||
self.launcher = self.root / 'launch'
|
||||
self.launcher.write_text((BIN / 'droiddeck-steam-launch').read_text().replace(
|
||||
'/usr/local/bin/droiddeck-session', str(supervisor)))
|
||||
'/usr/local/bin/droiddeck-session', str(supervisor)).replace(
|
||||
'/usr/local/bin/droiddeck-steam-x64', str(x64)))
|
||||
|
||||
def launch(self, *args):
|
||||
return subprocess.run(['bash', str(self.launcher), *args], env=self.env,
|
||||
@@ -62,6 +66,22 @@ class DesktopSteamLaunchTest(unittest.TestCase):
|
||||
'-cef-disable-gpu', 'steam://open/settings'])
|
||||
self.assertFalse((self.session / 'steam-launch').exists())
|
||||
|
||||
def test_second_click_forwards_to_the_x86_64_client_in_its_own_home(self):
|
||||
lock = self.root / 'cache/droiddeck/steam-desktop.lock'
|
||||
lock.parent.mkdir(parents=True)
|
||||
x64_home = self.root / 'x64'
|
||||
(x64_home / '.steam').mkdir(parents=True)
|
||||
os.mkfifo(x64_home / '.steam/steam.pipe')
|
||||
(x64_home / '.steam/steam.pid').write_text(str(os.getpid()))
|
||||
self.env.update(BL_STEAM_CLIENT_ARCH='x86_64', BL_X64_HOME=str(x64_home))
|
||||
with lock.open('w') as handle:
|
||||
fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
result = self.launch('desktop', '501590')
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout.splitlines(), ['x64', '--exec', '-nobigpicture', '-no-cef-sandbox',
|
||||
'-cef-ozone-platform=x11', '-cef-disable-gpu',
|
||||
'steam://rungameid/501590'])
|
||||
|
||||
def test_second_click_waits_for_steam_ipc_during_startup(self):
|
||||
lock = self.root / 'cache/droiddeck/steam-desktop.lock'
|
||||
lock.parent.mkdir(parents=True)
|
||||
|
||||
@@ -84,6 +84,17 @@ class ImportsTest(unittest.TestCase):
|
||||
imports.watch(str(self.steam), str(listing))
|
||||
identify.assert_not_called()
|
||||
|
||||
def test_native_programs_stay_shortcuts_and_are_never_looked_up(self):
|
||||
self.snapshot()
|
||||
game = dict(self.game, native=True)
|
||||
self.assertEqual(([game], {}), imports.route(self.steam, self.acct, [game]))
|
||||
self.assertFalse((self.steam / 'steamapps/appmanifest_42.acf').exists())
|
||||
listing = self.root / 'games.json'
|
||||
listing.write_text(json.dumps([game]))
|
||||
with patch.object(imports, 'identify') as identify:
|
||||
imports.watch(str(self.steam), str(listing))
|
||||
identify.assert_not_called()
|
||||
|
||||
def test_migrates_only_unchanged_legacy_import_manifests(self):
|
||||
self.snapshot()
|
||||
imports.route(self.steam, self.acct, [self.game])
|
||||
|
||||
@@ -28,8 +28,21 @@ class SteamInstallTest(unittest.TestCase):
|
||||
curl = self.bin / 'curl'
|
||||
curl.write_text('''#!/bin/bash
|
||||
set -eu
|
||||
printf '%s\\n' "$2" >> "$TEST_REQUESTS"
|
||||
cp "$TEST_CDN/${2##*/}" "$4"
|
||||
url=""
|
||||
out=""
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
-o) out=$2; shift 2 ;;
|
||||
--connect-timeout|--max-time|--speed-limit|--speed-time|--retry|--retry-delay) shift 2 ;;
|
||||
-*) shift ;;
|
||||
*) url=$1; shift ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\\n' "$url" >> "$TEST_REQUESTS"
|
||||
if [ -n "${TEST_FAIL_HOST:-}" ]; then
|
||||
case $url in *"$TEST_FAIL_HOST"*) exit 22 ;; esac
|
||||
fi
|
||||
cp "$TEST_CDN/${url##*/}" "$out"
|
||||
''')
|
||||
curl.chmod(0o755)
|
||||
if shutil.which('sha256sum') is None:
|
||||
@@ -55,11 +68,12 @@ cp "$TEST_CDN/${2##*/}" "$4"
|
||||
f'\t\t"file" "{archive.name}"\n\t\t"sha2" "{digest}"\n'
|
||||
'\t}\n}\n')
|
||||
|
||||
def install(self):
|
||||
return subprocess.run(['bash', str(SCRIPT)], env=self.env, text=True, capture_output=True)
|
||||
def install(self, fail_host=None):
|
||||
env = self.env if fail_host is None else dict(self.env, TEST_FAIL_HOST=fail_host)
|
||||
return subprocess.run(['bash', str(SCRIPT)], env=env, text=True, capture_output=True)
|
||||
|
||||
def assert_installed(self, channel='steamdeck_publicbeta'):
|
||||
result = self.install()
|
||||
def assert_installed(self, channel='steamdeck_publicbeta', fail_host=None, expected=None):
|
||||
result = self.install(fail_host)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.assertEqual(channel + '\n', (self.steam / 'package/beta').read_text())
|
||||
self.assertEqual('123456\n', (self.steam / 'package/droiddeck-installed').read_text())
|
||||
@@ -67,14 +81,24 @@ cp "$TEST_CDN/${2##*/}" "$4"
|
||||
self.assertTrue(os.access(client, os.X_OK))
|
||||
self.assertEqual(channel, client.read_text())
|
||||
self.assertEqual((self.steam / 'linuxarm64').resolve(), (self.home / '.steam/sdkarm64').resolve())
|
||||
self.assertEqual([
|
||||
'https://client-update.fastly.steamstatic.com/steam_client_' + channel + '_linuxarm64',
|
||||
'https://client-update.fastly.steamstatic.com/' + channel + '.zip',
|
||||
], self.requests.read_text().splitlines())
|
||||
if expected is None:
|
||||
expected = [
|
||||
'https://client-update.steamstatic.com/steam_client_' + channel + '_linuxarm64',
|
||||
'https://client-update.steamstatic.com/' + channel + '.zip',
|
||||
]
|
||||
self.assertEqual(expected, self.requests.read_text().splitlines())
|
||||
|
||||
def test_downloads_the_deck_beta_client(self):
|
||||
self.assert_installed()
|
||||
|
||||
def test_a_cdn_that_does_not_answer_hands_over_to_the_next_one(self):
|
||||
akamai = 'https://client-update.akamai.steamstatic.com'
|
||||
self.assert_installed(fail_host='client-update.steamstatic.com', expected=[
|
||||
'https://client-update.steamstatic.com/steam_client_steamdeck_publicbeta_linuxarm64',
|
||||
akamai + '/steam_client_steamdeck_publicbeta_linuxarm64',
|
||||
akamai + '/steamdeck_publicbeta.zip',
|
||||
])
|
||||
|
||||
def test_an_install_from_another_branch_is_left_for_steam_to_move(self):
|
||||
self.assert_installed()
|
||||
requests = self.requests.read_text()
|
||||
|
||||
@@ -121,7 +121,7 @@ class CompatLibrariesTest(unittest.TestCase):
|
||||
manifest(self.pc / "steamapps", 30)
|
||||
manifest(self.pc / "steamapps", 3127680, installdir="FEX")
|
||||
self.assertEqual(["20", "30"], COMPAT["installed_apps"](str(self.steam)))
|
||||
self.assertEqual(["1628350"], COMPAT["fex_missing"](str(self.steam)))
|
||||
self.assertEqual(["1628350", "4183110"], COMPAT["fex_missing"](str(self.steam)))
|
||||
|
||||
def test_newest_proton_across_libraries_wins(self):
|
||||
for root, build in ((self.steam, "100"), (self.pc, "200")):
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
|
||||
SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session"
|
||||
SOURCE = SESSION.read_text()
|
||||
START = SOURCE.index(" steam_other_game_running() {")
|
||||
END = SOURCE.index(" steam_bring_forward() {", START)
|
||||
FUNCTIONS = textwrap.dedent(SOURCE[START:END])
|
||||
GAME = str((3333273269 << 32) | 0x02000000)
|
||||
|
||||
|
||||
class SteamShortcutRecoveryTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temp.cleanup)
|
||||
self.root = Path(self.temp.name)
|
||||
self.launch = self.root / "session"
|
||||
self.launch.mkdir()
|
||||
self.bin = self.root / "bin"
|
||||
self.bin.mkdir()
|
||||
steam = self.root / "steam/steamrtarm64"
|
||||
steam.mkdir(parents=True)
|
||||
self.steam_log = self.root / "steam-args"
|
||||
(steam / "steam").write_text("#!/bin/sh\nprintf '%s\\n' \"$*\" >> \"$STEAM_LOG\"\n")
|
||||
(steam / "steam").chmod(0o755)
|
||||
self.agent = self.bin / "droiddeck-agent"
|
||||
self.agent.write_text(
|
||||
"#!/bin/sh\n"
|
||||
"n=$(cat \"$AGENT_COUNT\" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > \"$AGENT_COUNT\"\n"
|
||||
"i=0; last=0\n"
|
||||
"for s in $AGENT_STATES; do i=$((i + 1)); last=$s; [ \"$i\" -eq \"$n\" ] && exit \"$s\"; done\n"
|
||||
"exit \"$last\"\n")
|
||||
self.agent.chmod(0o755)
|
||||
|
||||
def launch_game(self, states, focusable="769", extra=None, client=None):
|
||||
xprop = self.bin / "xprop"
|
||||
xprop.write_text("#!/bin/sh\necho 'GAMESCOPE_FOCUSABLE_APPS(CARDINAL) = %s'\n" % focusable)
|
||||
xprop.chmod(0o755)
|
||||
script = "nap() { :; }\nsteam_root=%s\n%s%s\nsteam_launch_game %s\n" % (
|
||||
self.root / "steam", "steam_client=(%s --exec)\n" % client if client else "",
|
||||
FUNCTIONS.replace("/usr/local/bin/droiddeck-agent", str(self.agent)), GAME)
|
||||
env = dict(os.environ, HOME=str(self.root), BL_LAUNCH_DIR=str(self.launch),
|
||||
PATH=str(self.bin) + os.pathsep + os.environ["PATH"], STEAM_LOG=str(self.steam_log),
|
||||
AGENT_COUNT=str(self.root / "agent-count"), AGENT_STATES=states, **(extra or {}))
|
||||
result = subprocess.run(["bash", "-c", script], env=env, text=True, capture_output=True, timeout=10)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
steam = self.steam_log.read_text().splitlines() if self.steam_log.exists() else []
|
||||
restart = self.root / ".bl-restart-game"
|
||||
return steam, restart.read_text().strip() if restart.exists() else None, result.stdout
|
||||
|
||||
def test_a_shortcut_that_stays_known_launches_once(self):
|
||||
steam, restart, _ = self.launch_game("0")
|
||||
self.assertEqual(["steam://rungameid/" + GAME], steam)
|
||||
self.assertIsNone(restart)
|
||||
self.assertEqual("9", (self.root / "agent-count").read_text().strip())
|
||||
|
||||
def test_a_shortcut_dropped_while_launching_restarts_steam_for_it(self):
|
||||
steam, restart, out = self.launch_game("0 0 4")
|
||||
self.assertEqual(["steam://rungameid/" + GAME, "-shutdown"], steam)
|
||||
self.assertEqual(GAME, restart)
|
||||
self.assertIn("dropped shortcut", out)
|
||||
|
||||
def test_the_running_x86_64_client_gets_the_launch_and_the_restart(self):
|
||||
x64 = self.bin / "droiddeck-steam-x64"
|
||||
x64_log = self.root / "x64-args"
|
||||
x64.write_text("#!/bin/sh\nprintf '%s\\n' \"$*\" >> \"$X64_LOG\"\n")
|
||||
x64.chmod(0o755)
|
||||
steam, restart, _ = self.launch_game("0 0 4", client=x64, extra={"X64_LOG": str(x64_log)})
|
||||
self.assertEqual([], steam)
|
||||
self.assertEqual(["--exec steam://rungameid/" + GAME, "--exec -shutdown"], x64_log.read_text().splitlines())
|
||||
self.assertEqual(GAME, restart)
|
||||
|
||||
def test_a_shortcut_already_lost_restarts_steam_without_launching(self):
|
||||
steam, restart, out = self.launch_game("4")
|
||||
self.assertEqual(["-shutdown"], steam)
|
||||
self.assertEqual(GAME, restart)
|
||||
self.assertIn("lost shortcut", out)
|
||||
|
||||
def test_steam_is_restarted_only_once_for_the_same_game(self):
|
||||
steam, restart, _ = self.launch_game("4")
|
||||
self.assertEqual(GAME, restart)
|
||||
(self.root / ".bl-restart-game").unlink()
|
||||
self.steam_log.unlink()
|
||||
(self.root / "agent-count").unlink()
|
||||
steam, restart, out = self.launch_game("4")
|
||||
self.assertEqual(["steam://rungameid/" + GAME], steam)
|
||||
self.assertIsNone(restart)
|
||||
self.assertIn("already restarted", out)
|
||||
|
||||
def test_a_ready_shortcut_allows_a_later_restart_again(self):
|
||||
self.launch_game("4")
|
||||
(self.root / ".bl-restart-game").unlink()
|
||||
(self.root / "agent-count").unlink()
|
||||
self.launch_game("0")
|
||||
self.assertFalse((self.root / ".bl-restarted-for").exists())
|
||||
|
||||
def test_a_running_game_is_never_cut_off_by_a_restart(self):
|
||||
steam, restart, _ = self.launch_game("0 4", focusable="769,3703311242")
|
||||
self.assertEqual(["steam://rungameid/" + GAME], steam)
|
||||
self.assertIsNone(restart)
|
||||
steam, restart, _ = self.launch_game("4", focusable="769,3703311242")
|
||||
self.assertIsNone(restart)
|
||||
|
||||
def test_the_open_launcher_does_not_count_as_a_running_game(self):
|
||||
(self.launch / "epic-open").write_text("2702387189\n")
|
||||
steam, restart, _ = self.launch_game("0 4", focusable="769,2702387189")
|
||||
self.assertEqual(GAME, restart)
|
||||
|
||||
def test_the_launcher_without_its_steam_id_still_does_not_count_as_a_running_game(self):
|
||||
(self.launch / "epic-open").write_text("1\n")
|
||||
launcher = {"BL_EPIC_APP_ID": "2702387189"}
|
||||
steam, restart, _ = self.launch_game("0 4", focusable="769,2702387189", extra=launcher)
|
||||
self.assertEqual(GAME, restart)
|
||||
for marker in (".bl-restart-game", ".bl-restarted-for", "agent-count"):
|
||||
(self.root / marker).unlink(missing_ok=True)
|
||||
steam, restart, _ = self.launch_game("4", focusable="769,2702387189,3703311242", extra=launcher)
|
||||
self.assertIsNone(restart)
|
||||
|
||||
def test_steam_games_are_launched_without_watching(self):
|
||||
steam, restart, _ = self.launch_game("3")
|
||||
self.assertEqual(["steam://rungameid/" + GAME], steam)
|
||||
self.assertIsNone(restart)
|
||||
self.assertEqual("1", (self.root / "agent-count").read_text().strip())
|
||||
|
||||
def check_exits(self, listings, states, beats):
|
||||
pgrep = self.bin / "pgrep"
|
||||
pgrep.write_text(
|
||||
"#!/bin/bash\n"
|
||||
"n=$(cat \"$PGREP_COUNT\" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > \"$PGREP_COUNT\"\n"
|
||||
"IFS='|' read -r -a runs <<< \"$PGREP_RUNS\"\n"
|
||||
"line=${runs[$((n - 1))]:-}\n"
|
||||
"[ -n \"$line\" ] || exit 1\n"
|
||||
"printf '%s\\n' \"$line\"\n")
|
||||
pgrep.chmod(0o755)
|
||||
script = "steam_root=%s\n%s\ndeclare -A _bl_ran=()\n_bl_exited=\n%s" % (
|
||||
self.root / "steam", FUNCTIONS.replace("/usr/local/bin/droiddeck-agent", str(self.agent)),
|
||||
"steam_check_exits\n" * beats)
|
||||
env = dict(os.environ, HOME=str(self.root), BL_LAUNCH_DIR=str(self.launch),
|
||||
PATH=str(self.bin) + os.pathsep + os.environ["PATH"], STEAM_LOG=str(self.steam_log),
|
||||
AGENT_COUNT=str(self.root / "agent-count"), AGENT_STATES=states,
|
||||
PGREP_COUNT=str(self.root / "pgrep-count"), PGREP_RUNS="|".join(listings))
|
||||
result = subprocess.run(["bash", "-c", script], env=env, text=True, capture_output=True, timeout=10)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
steam = self.steam_log.read_text().splitlines() if self.steam_log.exists() else []
|
||||
agent = self.root / "agent-count"
|
||||
return steam, (self.root / ".bl-restart-lost").exists(), int(agent.read_text()) if agent.exists() else 0, result.stdout
|
||||
|
||||
RUNNING = "41 /root/.local/share/Steam/steamrtarm64/reaper SteamLaunch AppId=3333273269 -- /x/.droiddeck-launch.bat"
|
||||
|
||||
def test_a_shortcut_dropped_when_its_game_exits_restarts_steam_once_nothing_runs(self):
|
||||
steam, marker, asked, out = self.check_exits([self.RUNNING, "", "", ""], "4", 3)
|
||||
self.assertEqual(["-shutdown"], steam)
|
||||
self.assertTrue(marker)
|
||||
self.assertEqual(1, asked)
|
||||
self.assertIn("3333273269", out)
|
||||
|
||||
def test_a_shortcut_still_listed_after_its_game_exits_is_left_alone(self):
|
||||
steam, marker, asked, _ = self.check_exits([self.RUNNING, "", "", ""], "0", 4)
|
||||
self.assertEqual([], steam)
|
||||
self.assertFalse(marker)
|
||||
self.assertEqual(1, asked)
|
||||
|
||||
def test_the_check_waits_a_quiet_beat_after_the_exit(self):
|
||||
steam, _, asked, _ = self.check_exits([self.RUNNING, ""], "4", 2)
|
||||
self.assertEqual([], steam)
|
||||
self.assertEqual(0, asked)
|
||||
|
||||
def test_a_game_started_meanwhile_is_never_cut_off(self):
|
||||
steam, marker, _, _ = self.check_exits([self.RUNNING, "", "", self.RUNNING], "4", 3)
|
||||
self.assertEqual([], steam)
|
||||
self.assertFalse(marker)
|
||||
|
||||
def test_steam_games_are_not_checked(self):
|
||||
game = "41 /root/.local/share/Steam/steamrtarm64/reaper SteamLaunch AppId=1245620 -- /x/eldenring.exe"
|
||||
steam, _, asked, _ = self.check_exits([game, "", "", ""], "4", 3)
|
||||
self.assertEqual([], steam)
|
||||
self.assertEqual(0, asked)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -147,6 +147,18 @@ class ShortcutsTest(unittest.TestCase):
|
||||
self.assertEqual({'1': 'Favorites', '0': shortcuts.TAG}, entry['tags'])
|
||||
self.assertEqual({'0': shortcuts.TAG}, shortcuts.merge(shortcuts.shortcut(self.game()), dict(shortcuts.shortcut(self.game()), tags={}), None, 0)[0]['tags'])
|
||||
|
||||
def test_a_copy_the_running_client_added_of_an_added_game_is_dropped(self):
|
||||
self.run_writer(self.game())
|
||||
path = self.config / 'shortcuts.vdf'
|
||||
data = shortcuts.parse(path.read_bytes())['shortcuts']
|
||||
live = dict(shortcuts.shortcut(self.game(appid=0x91234567)), tags={})
|
||||
own = dict(shortcuts.shortcut(self.game(exe='Other.exe', appid=0x92345678)), tags={})
|
||||
renamed = dict(shortcuts.shortcut(self.game(appid=0x93456789, name='My copy')), tags={})
|
||||
data.update({'7': live, '8': own, '9': renamed})
|
||||
path.write_bytes(shortcuts.write({'shortcuts': data}))
|
||||
entries = self.run_writer(self.game())
|
||||
self.assertEqual({APPID, 0x92345678, 0x93456789}, set(entries))
|
||||
|
||||
def test_a_damaged_record_is_started_over(self):
|
||||
self.run_writer(self.game())
|
||||
(self.config / shortcuts.RECORD).write_text('{not json')
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steamvr-game'
|
||||
|
||||
|
||||
class SteamVrGameTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temporary.cleanup)
|
||||
self.root = Path(temporary.name)
|
||||
self.helper = self.root / 'helper'
|
||||
self.assertIn('/run/droiddeck/droiddeck-xr-frames', SOURCE.read_text())
|
||||
self.helper.write_text(SOURCE.read_text().replace('/run/droiddeck/droiddeck-xr-frames',
|
||||
str(self.root / 'droiddeck-xr-frames')), encoding='utf-8')
|
||||
self.command('pgrep', '#!/bin/sh\nexit 0\n')
|
||||
self.command('gamescope', '#!/usr/bin/env python3\nimport json, os, sys\n'
|
||||
'print(json.dumps(dict(argv=sys.argv[1:], modifiers=os.getenv("gamescope_vr_use_modifiers"), '
|
||||
'layers=os.getenv("VK_INSTANCE_LAYERS"))))\n')
|
||||
self.env = {key: value for key, value in os.environ.items()
|
||||
if not key.startswith(('gamescope_vr_', 'VK_'))}
|
||||
self.env.update(PATH=str(self.root) + os.pathsep + os.environ['PATH'],
|
||||
XDG_RUNTIME_DIR=str(self.root))
|
||||
|
||||
def command(self, name, text):
|
||||
path = self.root / name
|
||||
path.write_text(text, encoding='utf-8')
|
||||
path.chmod(0o755)
|
||||
|
||||
def run_game(self, *args):
|
||||
return subprocess.run(['sh', str(self.helper), *args], env=self.env,
|
||||
capture_output=True, text=True, timeout=5)
|
||||
|
||||
def test_native_backend_preserves_command_arguments_and_nonquest_defaults(self):
|
||||
result = self.run_game('game with spaces', 'a b', '$literal')
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
data = json.loads(result.stdout)
|
||||
self.assertEqual(data['argv'][:2], ['--backend', 'openvr'])
|
||||
self.assertEqual(data['argv'][-4:], ['--', 'game with spaces', 'a b', '$literal'])
|
||||
self.assertIsNone(data['modifiers'])
|
||||
self.assertEqual(data['layers'], 'VK_LAYER_DROIDDECK_vr')
|
||||
|
||||
def test_quest_selects_vulkan_sharing_and_preserves_explicit_override(self):
|
||||
with socket.socket(socket.AF_UNIX) as receiver:
|
||||
receiver.bind(str(self.root / 'droiddeck-xr-frames'))
|
||||
self.assertEqual(json.loads(self.run_game('game').stdout)['modifiers'], 'false')
|
||||
self.env['gamescope_vr_use_modifiers'] = 'true'
|
||||
self.assertEqual(json.loads(self.run_game('game').stdout)['modifiers'], 'true')
|
||||
|
||||
def test_missing_runtime_and_missing_command_fail_clearly(self):
|
||||
self.assertEqual(self.run_game().returncode, 2)
|
||||
self.command('pgrep', '#!/bin/sh\nexit 1\n')
|
||||
result = self.run_game('game')
|
||||
self.assertEqual(result.returncode, 1)
|
||||
self.assertIn('Start SteamVR', result.stderr)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,79 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
||||
|
||||
HELPER = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steamvr'
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which('sh'), 'requires a POSIX shell')
|
||||
class SteamVrGraphicsTest(unittest.TestCase):
|
||||
def launch(self, model, debug=None, action='start', preload=None):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
bindir = root / 'bin'
|
||||
bindir.mkdir()
|
||||
runtime = root / 'steamvr/bin/linuxarm64'
|
||||
runtime.mkdir(parents=True)
|
||||
(runtime / 'vrstartup').touch(mode=0o755)
|
||||
driver = root / 'driver/droiddeck/bin/linuxarm64'
|
||||
driver.mkdir(parents=True)
|
||||
(driver / 'driver_droiddeck.so').touch()
|
||||
result = root / 'launch-env'
|
||||
preloads = root / 'launch-preload'
|
||||
scripts = {
|
||||
'cat': 'if [ "$1" = /sys/class/kgsl/kgsl-3d0/gpu_model ]; then printf "%s" "$TEST_GPU_MODEL"; else exec /bin/cat "$@"; fi',
|
||||
'pgrep': 'exit 1',
|
||||
'setsid': 'printf "%s" "$LD_PRELOAD" > "$TEST_LAUNCH_PRELOAD"; printf "%s" "${TU_DEBUG-unset}" > "$TEST_LAUNCH_ENV"',
|
||||
}
|
||||
for name, script in scripts.items():
|
||||
path = bindir / name
|
||||
path.write_text('#!/bin/sh\n' + script + '\n')
|
||||
path.chmod(0o755)
|
||||
env = dict(os.environ, HOME=str(root), XDG_RUNTIME_DIR=str(root / 'run'),
|
||||
STEAMVR=str(root / 'steamvr'), DROIDDECK_VR_DIR=str(root / 'driver'),
|
||||
PATH=str(bindir) + os.pathsep + os.environ['PATH'],
|
||||
TEST_GPU_MODEL=model, TEST_LAUNCH_ENV=str(result), TEST_LAUNCH_PRELOAD=str(preloads))
|
||||
env.pop('TU_DEBUG', None)
|
||||
env.pop('LD_PRELOAD', None)
|
||||
if debug is not None:
|
||||
env['TU_DEBUG'] = debug
|
||||
if preload is not None:
|
||||
env['LD_PRELOAD'] = preload
|
||||
run = subprocess.run(['sh', str(HELPER), action], env=env,
|
||||
capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(run.returncode, 0, run.stderr)
|
||||
until = time.monotonic() + 2
|
||||
while not result.exists() and time.monotonic() < until:
|
||||
time.sleep(0.01)
|
||||
self.assertEqual(preloads.read_text(), str(root / 'driver/layer/libdroiddeck_vr_scheduling.so') +
|
||||
(':' + preload if preload else ''))
|
||||
return result.read_text()
|
||||
|
||||
def test_adreno_840_start_removes_forced_sysmem(self):
|
||||
self.assertEqual(self.launch('Adreno840v2', 'sysmem'), '')
|
||||
self.assertEqual(self.launch('Adreno840v2'), '')
|
||||
|
||||
def test_preserves_other_debug_flags_and_removes_repeated_sysmem(self):
|
||||
self.assertEqual(self.launch('Adreno840v2', 'sysmem,forcecb,sysmem,noubwc'), 'forcecb,noubwc')
|
||||
self.assertEqual(self.launch('Adreno840v2', 'forcecb sysmem flushall'), 'forcecb,flushall')
|
||||
|
||||
def test_library_launch_uses_the_same_graphics_setup(self):
|
||||
self.assertEqual(self.launch('Adreno840v2', 'sysmem,forcecb', action='launch'), 'forcecb')
|
||||
|
||||
def test_scheduling_preload_preserves_existing_preloads(self):
|
||||
self.assertEqual(self.launch('Adreno840v2', 'sysmem', action='launch',
|
||||
preload='/existing/preload.so'), '')
|
||||
|
||||
def test_other_and_unknown_gpus_keep_their_environment(self):
|
||||
self.assertEqual(self.launch('Adreno740'), 'unset')
|
||||
self.assertEqual(self.launch('Adreno740', 'sysmem,forcecb'), 'sysmem,forcecb')
|
||||
self.assertEqual(self.launch('', 'sysmem'), 'sysmem')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,215 @@
|
||||
import os
|
||||
import json
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-steamvr'
|
||||
|
||||
|
||||
class SteamVrHelperTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.compiler_output = tempfile.TemporaryDirectory()
|
||||
cls.addClassCleanup(cls.compiler_output.cleanup)
|
||||
cls.scheduling = Path(cls.compiler_output.name) / 'libdroiddeck_vr_scheduling.so'
|
||||
source = Path(__file__).resolve().parents[1] / 'vr/src/scheduling.c'
|
||||
subprocess.run(['cc', '-shared', '-fPIC', '-o', str(cls.scheduling), str(source), '-ldl'], check=True)
|
||||
|
||||
def setUp(self):
|
||||
self.temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temporary.cleanup)
|
||||
self.root = Path(self.temporary.name)
|
||||
self.home = self.root / 'home'
|
||||
self.runtime = self.root / 'runtime'
|
||||
self.commands = self.root / 'commands'
|
||||
self.driver = self.root / 'driver/droiddeck/bin/linuxarm64'
|
||||
self.steamvr = self.root / 'steamvr'
|
||||
for directory in (self.commands, self.driver, self.steamvr / 'bin/linuxarm64'):
|
||||
directory.mkdir(parents=True)
|
||||
self.helper = self.root / 'droiddeck-steamvr'
|
||||
self.assertIn('/run/droiddeck/droiddeck-xr-frames', SOURCE.read_text())
|
||||
self.helper.write_text(SOURCE.read_text().replace('/run/droiddeck/droiddeck-xr-frames',
|
||||
str(self.runtime / 'droiddeck-xr-frames')), encoding='utf-8')
|
||||
self.executable(self.commands / 'pgrep', 'exit 1')
|
||||
self.executable(self.commands / 'sleep', 'exit 0')
|
||||
self.executable(self.commands / 'xset', 'exit 0')
|
||||
self.executable(self.commands / 'setsid', 'exec "$@"')
|
||||
self.executable(self.driver / 'xr-display-mode', 'echo 3360x1760@120')
|
||||
self.executable(self.steamvr / 'bin/linuxarm64/vrstartup',
|
||||
'echo "display=${DROIDDECK_VR_DISPLAY_MODE:-unset}"')
|
||||
(self.driver / 'driver_droiddeck.so').touch()
|
||||
layer = self.root / 'driver/layer'
|
||||
layer.mkdir()
|
||||
shutil.copyfile(self.scheduling, layer / self.scheduling.name)
|
||||
self.environment = dict(os.environ)
|
||||
self.environment.pop('DROIDDECK_VR_DISPLAY_MODE', None)
|
||||
self.environment.pop('DROIDDECK_VR_PRESENT', None)
|
||||
self.environment.pop('DROIDDECK_VR_PRODUCER_LEASE', None)
|
||||
self.environment.update(HOME=str(self.home), XDG_RUNTIME_DIR=str(self.runtime),
|
||||
STEAMVR=str(self.steamvr), DROIDDECK_VR_DIR=str(self.root / 'driver'),
|
||||
DROIDDECK_VR_SETTINGS_HELPER=str(SOURCE.with_name('droiddeck-steamvr-settings')),
|
||||
PATH=str(self.commands) + os.pathsep + os.environ['PATH'])
|
||||
|
||||
def executable(self, destination, body):
|
||||
destination.write_text('#!/bin/sh\n' + body + '\n', encoding='utf-8')
|
||||
destination.chmod(0o755)
|
||||
|
||||
def start(self):
|
||||
result = subprocess.run(['sh', str(self.helper), 'start'], env=self.environment,
|
||||
capture_output=True, text=True, timeout=5)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
log = self.home / '.local/share/Steam/logs/droiddeck-vrstartup.log'
|
||||
deadline = time.monotonic() + 2
|
||||
while time.monotonic() < deadline:
|
||||
if log.is_file() and 'display=' in log.read_text():
|
||||
return log
|
||||
time.sleep(0.01)
|
||||
self.fail('Startup log did not arrive')
|
||||
|
||||
def test_fresh_runtime_mode_is_selected_and_log_survives_runtime_cleanup(self):
|
||||
log = self.start()
|
||||
self.assertEqual((self.runtime / 'droiddeck-steamvr').stat().st_mode & 0o777, 0o700)
|
||||
self.assertEqual(log.read_text().strip(), 'display=3360x1760@120')
|
||||
self.assertEqual((self.runtime / 'droiddeck-steamvr/vrstartup.log').resolve(), log)
|
||||
shutil.rmtree(self.runtime)
|
||||
self.assertTrue(log.is_file())
|
||||
|
||||
def test_explicit_display_override_is_preserved(self):
|
||||
self.environment['DROIDDECK_VR_DISPLAY_MODE'] = '1920x1080@90'
|
||||
self.assertEqual(self.start().read_text().strip(), 'display=1920x1080@90')
|
||||
|
||||
def test_stale_or_missing_tracking_keeps_the_default(self):
|
||||
self.executable(self.driver / 'xr-display-mode', 'exit 1')
|
||||
self.assertEqual(self.start().read_text().strip(), 'display=unset')
|
||||
|
||||
def test_older_runtime_without_the_reader_still_starts(self):
|
||||
(self.driver / 'xr-display-mode').unlink()
|
||||
self.assertEqual(self.start().read_text().strip(), 'display=unset')
|
||||
|
||||
def lease_log(self):
|
||||
self.executable(self.steamvr / 'bin/linuxarm64/vrstartup',
|
||||
'printf "display=%s present=%s lease=%s\\n" "${DROIDDECK_VR_DISPLAY_MODE:-unset}" '
|
||||
'"${DROIDDECK_VR_PRESENT:-unset}" "${DROIDDECK_VR_PRODUCER_LEASE:-unset}"')
|
||||
return self.start().read_text().strip()
|
||||
|
||||
def test_quest_receiver_uses_normal_compositor_and_excludes_unsupported_frame_backend(self):
|
||||
self.runtime.mkdir()
|
||||
cvp = self.steamvr / 'drivers/cv/bin/linuxarm64/libArcturusPerception.so'
|
||||
cvp.parent.mkdir(parents=True)
|
||||
cvp.write_bytes(b'frame-only backend')
|
||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as receiver:
|
||||
receiver.bind(str(self.runtime / 'droiddeck-xr-frames'))
|
||||
self.assertIn('present=questwsi lease=unset', self.lease_log())
|
||||
settings = json.loads((self.home / '.local/share/Steam/config/steamvr.vrsettings').read_text())
|
||||
self.assertEqual(settings['steamvr'], {'enableLinuxVulkanAsync': True, 'motionSmoothing': False})
|
||||
self.assertFalse(cvp.exists())
|
||||
self.assertEqual(Path(str(cvp) + '.droiddeck-disabled').read_bytes(), b'frame-only backend')
|
||||
|
||||
def test_quest_settings_preserve_other_preferences_and_start_is_idempotent(self):
|
||||
self.environment['DROIDDECK_VR_PRESENT'] = 'questwsi'
|
||||
path = self.home / '.local/share/Steam/config/steamvr.vrsettings'
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_text(json.dumps({'steamvr': {'somePreference': 42}, 'dashboard': {'somePreference': True}}))
|
||||
self.start()
|
||||
self.start()
|
||||
settings = json.loads(path.read_text())
|
||||
self.assertEqual(settings['steamvr']['somePreference'], 42)
|
||||
self.assertEqual(settings['dashboard'], {'somePreference': True})
|
||||
|
||||
def test_quest_refuses_to_overwrite_malformed_settings(self):
|
||||
self.environment['DROIDDECK_VR_PRESENT'] = 'questwsi'
|
||||
path = self.home / '.local/share/Steam/config/steamvr.vrsettings'
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_text('invalid json')
|
||||
result = subprocess.run(['sh', str(self.helper), 'start'], env=self.environment,
|
||||
capture_output=True, text=True, timeout=5)
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(path.read_text(), 'invalid json')
|
||||
|
||||
def test_quest_stop_restores_only_overridden_preferences(self):
|
||||
self.environment['DROIDDECK_VR_PRESENT'] = 'questwsi'
|
||||
path = self.home / '.local/share/Steam/config/steamvr.vrsettings'
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_text(json.dumps({'steamvr': {'motionSmoothing': True, 'somePreference': 42}}))
|
||||
self.start()
|
||||
settings = json.loads(path.read_text())
|
||||
settings['dashboard'] = {'changedDuringSession': True}
|
||||
path.write_text(json.dumps(settings))
|
||||
subprocess.run(['sh', str(self.helper), 'stop'], env=self.environment, check=True)
|
||||
self.assertEqual(json.loads(path.read_text()), {'steamvr': {'motionSmoothing': True, 'somePreference': 42},
|
||||
'dashboard': {'changedDuringSession': True}})
|
||||
|
||||
def test_invalid_backup_preserves_preferences_until_repaired(self):
|
||||
settings = self.root / 'steamvr.vrsettings'
|
||||
backup = self.root / 'quest-backup.json'
|
||||
helper = SOURCE.with_name('droiddeck-steamvr-settings')
|
||||
original = {'steamvr': {'motionSmoothing': True}, 'dashboard': {'unchanged': 42}}
|
||||
settings.write_text(json.dumps(original))
|
||||
subprocess.run([sys.executable, str(helper), 'apply', str(settings), str(backup)], check=True)
|
||||
valid_backup = backup.read_bytes()
|
||||
applied = settings.read_bytes()
|
||||
invalid = ['truncated {', '{}', '{"section": true, "values": []}',
|
||||
'{"section": false, "values": {"motionSmoothing": [false]}}']
|
||||
for content in invalid:
|
||||
for operation in ('apply', 'restore'):
|
||||
with self.subTest(content=content, operation=operation):
|
||||
backup.write_text(content)
|
||||
result = subprocess.run([sys.executable, str(helper), operation, str(settings), str(backup)],
|
||||
capture_output=True, text=True)
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn('repair the saved section/values and retry restore', result.stderr)
|
||||
self.assertEqual(backup.read_text(), content)
|
||||
self.assertEqual(settings.read_bytes(), applied)
|
||||
backup.write_bytes(valid_backup)
|
||||
subprocess.run([sys.executable, str(helper), 'restore', str(settings), str(backup)], check=True)
|
||||
self.assertEqual(json.loads(settings.read_text()), original)
|
||||
self.assertFalse(backup.exists())
|
||||
|
||||
def test_quest_update_preserves_previous_cvp_backup(self):
|
||||
self.environment['DROIDDECK_VR_PRESENT'] = 'questwsi'
|
||||
cvp = self.steamvr / 'drivers/cv/bin/linuxarm64/libArcturusPerception.so'
|
||||
cvp.parent.mkdir(parents=True)
|
||||
cvp.write_bytes(b'updated library')
|
||||
backup = Path(str(cvp) + '.droiddeck-disabled')
|
||||
backup.write_bytes(b'previous library')
|
||||
self.start()
|
||||
self.assertFalse(cvp.exists())
|
||||
self.assertEqual(backup.read_bytes(), b'previous library')
|
||||
self.assertEqual([p.read_bytes() for p in cvp.parent.glob('*.droiddeck-disabled.*')], [b'updated library'])
|
||||
|
||||
def test_start_failure_after_overrides_restores_preferences(self):
|
||||
self.environment['DROIDDECK_VR_PRESENT'] = 'questwsi'
|
||||
path = self.home / '.local/share/Steam/config/steamvr.vrsettings'
|
||||
path.parent.mkdir(parents=True)
|
||||
original = {'steamvr': {'enableLinuxVulkanAsync': False, 'motionSmoothing': True}}
|
||||
path.write_text(json.dumps(original))
|
||||
cvp = self.steamvr / 'drivers/cv/bin/linuxarm64/libArcturusPerception.so'
|
||||
cvp.parent.mkdir(parents=True)
|
||||
cvp.touch()
|
||||
self.executable(self.commands / 'mv', 'exit 1')
|
||||
result = subprocess.run(['sh', str(self.helper), 'start'], env=self.environment,
|
||||
capture_output=True, text=True, timeout=5)
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertEqual(json.loads(path.read_text()), original)
|
||||
|
||||
def test_explicit_quest_presenter_enables_the_lease(self):
|
||||
self.environment['DROIDDECK_VR_PRESENT'] = 'questframes'
|
||||
self.assertIn('present=questframes lease=1', self.lease_log())
|
||||
|
||||
def test_explicit_diagnostic_override_is_preserved(self):
|
||||
self.environment.update(DROIDDECK_VR_PRESENT='questframes', DROIDDECK_VR_PRODUCER_LEASE='0')
|
||||
self.assertIn('present=questframes lease=0', self.lease_log())
|
||||
|
||||
def test_flat_presenter_does_not_enable_the_producer_lease(self):
|
||||
self.assertIn('present=unset lease=unset', self.lease_log())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loaded 100 of 616 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user