Files
DroidDeck/tools/tests/test_frame_acquire_peer_gate.py
T

67 lines
3.7 KiB
Python

"""Focused worker-grant contract; no Android or guest boot required."""
import os
import sys
from pathlib import Path
import subprocess
import tempfile
import unittest
ROOT=Path(__file__).resolve().parents[2]
SRC=ROOT/'app/src/main/cpp/waylandcomp/src'
JAVA=ROOT/'app/src/main/java/com/droiddeck/launcher'
class FrameAcquirePeerGateTest(unittest.TestCase):
def test_app_issued_identity_and_executable_mapping(self):
with tempfile.TemporaryDirectory() as tmp:
image=Path(tmp)/'probe'
subprocess.run([os.environ.get('CC','cc'), '-std=c11','-Wall','-Wextra','-Werror',
'-I',str(SRC),str(Path(__file__).with_name('frame_worker_peer_test.c')),
'-o',str(image)],check=True)
subprocess.run([str(image)],check=True,timeout=10)
@unittest.skipUnless(sys.platform.startswith("linux"), "Requires Linux procfs and pidfd")
def test_live_worker_mapping_starttime_and_revocation(self):
with tempfile.TemporaryDirectory() as tmp:
image = Path(tmp) / "probe"
subprocess.run([os.environ.get("CC", "cc"), "-std=c11", "-Wall", "-Wextra", "-Werror",
"-I", str(SRC), str(Path(__file__).with_name("frame_worker_peer_live_test.c")),
"-o", str(image)], check=True)
subprocess.run([str(image)], check=True, timeout=10)
def test_publish_before_worker_go_and_require_map_at_bind(self):
workers=(JAVA/'runtime/GuestWorkers.kt').read_text()
match=workers.index('val testWorker = FrameAcquireWorkerProbe.match')
confirmation=workers.index('}, confirmed = {',match)
publish=workers.index('FrameAcquireWorkerProbe.publish',confirmation)
self.assertLess(publish,workers.index('}, commit = { started ->',confirmation))
self.assertIn('confirmed() && Os.write(go[1]',workers)
self.assertIn('if (pid <= 0 && testWorker != null && worker > 1) FrameAcquireWorkerProbe.revoke',workers)
comp=(SRC/'compositor.c').read_text()
bind=comp.split('static void bind_frame_acquire',1)[1].split('#endif',1)[0]
self.assertIn('frame_acquire_peer_allowed(client, true)',bind)
self.assertIn('poll(&alive, 1, 0) == 0',comp)
def test_admission_diagnostics_are_coarse_bounded_and_probe_only(self):
kt=(JAVA/'runtime/FrameAcquireWorkerProbe.kt').read_text()
comp=(SRC/'compositor.c').read_text()
jni=(SRC/'waylandcomp_jni.c').read_text()
arm=kt.split('fun arm(',1)[1].split('fun exactGamescopeArgs',1)[0]
match=kt.split('fun match(',1)[1].split('fun publish(',1)[0]
self.assertLess(arm.index('!WaylandCompositor.frameWorkerProbeEnabled()'),
arm.index('breadcrumb(Stage.ARM'))
self.assertLess(match.index('?: return null'),match.index('breadcrumb('))
self.assertIn('"--version" !in argv',match)
self.assertIn('if (reported.add(stage))',kt)
self.assertIn('"worker_admission=" + reason.name',kt)
for name in ('ARM_FILE','MATCH_ACK','MATCH_OWNER','MATCH_EXPIRED','MATCH_PATH','MATCH_ROOT',
'MATCH_ARGV','MATCH_FILE','MATCH_DIGEST','QUALIFIED','PUBLISH_TICKET',
'PUBLISH_RESTAT','PUBLISH_NATIVE','RESERVED'):
self.assertIn('Reason.'+name,kt)
self.assertIn(' return JNI_FALSE;\n#endif',jni.split('frameWorkerProbeEnabled(',1)[1])
self.assertIn('if (!frame_worker_map_reported)',comp)
for name in ('NATIVE_FILE','NATIVE_PIDFD','NATIVE_STARTTIME','NATIVE_ALREADY_RESERVED',
'MAP_STARTTIME','MAP_OPEN','MAP_IDENTITY'):
self.assertIn('"worker_admission='+name+'"',comp)