feat: add Quest SteamVR to the standard app

This commit is contained in:
XxJSONDeruloxX committed 2026-10-15 12:09:25 -04:00
1 parent d301148881
commit 389bef5ad3
48 files changed
+3367 -266

No files matched your search

+85
View File
@@ -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()
+105
View File
@@ -0,0 +1,105 @@
import os
import shutil
import socket
import subprocess
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):
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.helper.write_text(SOURCE.read_text(), 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()
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'),
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_automatically_enables_retained_producer_ownership(self):
self.runtime.mkdir()
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as receiver:
receiver.bind(str(self.runtime / 'droiddeck-xr-frames'))
self.assertIn('present=questframes lease=1', self.lease_log())
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()
+45
View File
@@ -0,0 +1,45 @@
import ctypes.util
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
@unittest.skipUnless(shutil.which("gcc"), "needs gcc on a Linux host")
class VrProducerLeaseTest(unittest.TestCase):
def compile_and_run(self, source, headers=None, gpu=False):
repository = Path(__file__).resolve().parents[2]
with tempfile.TemporaryDirectory() as directory:
executable = Path(directory) / "producer-test"
command = ["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror", "-Wno-unused-parameter", "-pthread"]
if headers:
command += ["-I" + str(headers)]
command += [str(repository / "tools/vr/tests" / source), "-ldl"]
if gpu:
command += ["-l:libvulkan.so.1"]
subprocess.run(command + ["-o", str(executable)], check=True)
environment = dict(os.environ)
if gpu:
manifests = sorted(Path("/usr/share/vulkan/icd.d").glob("lvp_icd*.json"))
environment["VK_DRIVER_FILES"] = str(manifests[0])
environment["VK_ICD_FILENAMES"] = str(manifests[0])
result = subprocess.run([str(executable)], env=environment, capture_output=True, text=True, timeout=20)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
return result.stdout
def test_protocol_and_retained_ownership(self):
self.assertIn("disconnect quarantine passed", self.compile_and_run("test_producer_lease.c"))
def test_real_gpu_completion_and_frozen_overwrite(self):
if not ctypes.util.find_library("vulkan") or not list(Path("/usr/share/vulkan/icd.d").glob("lvp_icd*.json")):
self.skipTest("needs Vulkan loader and Lavapipe")
repository = Path(__file__).resolve().parents[2]
candidates = [os.environ.get("VK_INCLUDE", ""), "/usr/include", repository / "build/vr/include"]
candidates += [path for root in (os.environ.get("ANDROID_HOME"), os.environ.get("ANDROID_SDK_ROOT")) if root
for path in Path(root).glob("ndk/*/toolchains/llvm/prebuilt/*/sysroot/usr/include")]
headers = next((Path(path) for path in candidates if path and (Path(path) / "vulkan/vk_layer.h").is_file()), None)
if headers is None:
self.skipTest("needs Vulkan headers")
self.assertIn("1024 buffer values passed", self.compile_and_run("test_producer_gpu.c", headers=headers, gpu=True))
+26
View File
@@ -0,0 +1,26 @@
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
@unittest.skipUnless(shutil.which("gcc"), "needs gcc on a Linux host")
class VrSemaphoreLayerTest(unittest.TestCase):
def test_waits_are_never_fabricated(self):
repository = Path(__file__).resolve().parents[2]
candidates = [os.environ.get("VK_INCLUDE", ""), "/usr/include", repository / "build/vr/include"]
candidates += [path for root in (os.environ.get("ANDROID_HOME"), os.environ.get("ANDROID_SDK_ROOT")) if root
for path in Path(root).glob("ndk/*/toolchains/llvm/prebuilt/*/sysroot/usr/include")]
headers = next((Path(path) for path in candidates if path and (Path(path) / "vulkan/vk_layer.h").is_file()), None)
if headers is None:
self.skipTest("needs Vulkan headers")
with tempfile.TemporaryDirectory() as directory:
executable = Path(directory) / "semaphore-layer-test"
subprocess.run(["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror", "-Wno-unused-parameter",
"-pthread", "-I" + str(headers), str(repository / "tools/vr/tests/test_semaphore_layer.c"),
"-ldl", "-o", str(executable)], check=True)
result = subprocess.run([str(executable)], capture_output=True, text=True, timeout=20)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertIn("fd ownership passed", result.stdout)