"""Physical test against the separately started disposable logind session. FERESE_TEST_DRM=1 python3 scripts/tests/test_rime_drm_isolated.py Never starts/switches sessions itself. Requires its prepared lock-cycle binary. """ import importlib.util import json import os from pathlib import Path import subprocess import time import unittest ROOT=Path(__file__).resolve().parents[2] spec=importlib.util.spec_from_file_location("drm",ROOT/"scripts/rime-drm-validation.py") d=importlib.util.module_from_spec(spec);spec.loader.exec_module(d) @unittest.skipUnless(os.environ.get("FERESE_TEST_DRM")=="1","explicit physical-session validation") class PhysicalRime(unittest.TestCase): def test_three_outputs_and_lock_cycle(self): for _ in range(100): if (d.DATA/"context.json").exists() and (d.DATA/"entry-state.json").exists():break time.sleep(.1) c=json.loads((d.DATA/"context.json").read_text()) self.assertTrue(Path(f"/proc/{c['compositor_pid']}").exists()) self.assertNotEqual(subprocess.check_output(["loginctl","show-seat","seat0","-p","ActiveSession","--value"],text=True).strip(),d.original()) env={**os.environ,"XDG_RUNTIME_DIR":str(d.RUNTIME),"WAYLAND_DISPLAY":c["wayland"], "DBUS_SESSION_BUS_ADDRESS":c["bus"],"FERESE_SOCKET":c["socket"],"GDK_BACKEND":"wayland", "GTK_IM_MODULE":"wayland","FERESE_TEST_INPUT":"1","FERESE_TEST_DRM_PID":str(c["compositor_pid"]), "FERESE_RIME_CONTROL":str(d.RUNTIME/"rime-control.sock"),"GTK_A11Y":"none","GSETTINGS_BACKEND":"keyfile"} env["GSK_RENDERER"]=os.environ.get("FERESE_TEST_GSK","vulkan") control=[str(ROOT/"target/debug/feresectl"),"--socket",c["socket"]] def run(args):return subprocess.check_output(args,env=env,text=True,stderr=subprocess.PIPE).strip() def ctl(*args):return json.loads(run([str(ROOT/"target/debug/ferese-rime"),*args]))["state"] def wait(fn,message,timeout=5): until=time.monotonic()+timeout while time.monotonic()