#!/usr/bin/env python3 import datetime,json,os,pathlib,socket,struct,subprocess,time,sys FORCE='--force-pixman' in sys.argv OUT=pathlib.Path('/run/gpu-padded-'+('pixman' if FORCE else 'gpu'));OUT.mkdir(exist_ok=True) PYTHON='/nix/store/v189xydz6qkcd4cbkixcmv91w8hbc560-python3-riscv64-unknown-linux-gnu-3.14.7/bin/python3' SWAY='/nix/store/26mglvlajp14a7yc3ami5kwavzsks1bi-sway-unwrapped-riscv64-unknown-linux-gnu-1.12/bin/sway' CLIENT='/nix/store/bxiz9zkb33m4v97gkgzx91aswfm7cf9f-card-composition-probe-client-riscv64-unknown-linux-gnu-0.1/bin/card-composition-probe-client' result={'at_utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'evidence_class':'board synthetic scene diagnostic; no real finger or optical claim','forced_pixman':FORCE,'source_revision':'ead54046b786a073f6ac880dde0f4838a6d78dee','compositor':SWAY,'client':CLIENT,'boot_id':pathlib.Path('/proc/sys/kernel/random/boot_id').read_text().strip(),'normal_system':os.path.realpath('/run/current-system'),'captures':[]} def ipc(path,kind=4): with socket.socket(socket.AF_UNIX) as s: s.settimeout(2);s.connect(str(path));s.sendall(b'i3-ipc'+struct.pack('=II',0,kind)) def read(n): data=b'' while len(data)g>r and g>20 for r,g,b in samples)>=6:ready=True;break time.sleep(.2) result['visible_frame_prerequisite']=ready if not ready: subprocess.run(['grim',str(OUT/'no-visible-scene.png')],env=env,check=True,timeout=8) result['captures'].append('no-visible-scene');raise RuntimeError('recognizable scene never reached native capture') for name in ['scene-first','scene-later']: subprocess.run(['grim',str(OUT/(name+'.png'))],env=env,check=True,timeout=8);result['captures'].append(name);time.sleep(1) state=pathlib.Path('/sys/kernel/debug/dri/0/state').read_text();result['scanout_format']=[s.strip() for s in state.splitlines() if 'format=' in s] result['sway_processes']=subprocess.check_output(['pgrep','-x','sway'],text=True).split() else:result['scene_mapped']=False result['trial_exit']=proc.wait(timeout=45) finally: if proc.poll() is None: proc.terminate() try:proc.wait(timeout=40) except subprocess.TimeoutExpired:result['controller_still_running']=True log.close() result['normal_shell_active']=subprocess.run(['systemctl','is-active','--quiet','shell']).returncode==0 result['seatd_active']=subprocess.run(['systemctl','is-active','--quiet','seatd']).returncode==0 raw=(OUT/'raw-private.log').read_text() records=[line[line.index('VG-Lite '):] for line in raw.splitlines() if 'VG-Lite decision v=1 ' in line or 'VG-Lite operation v=1 ' in line] (OUT/'decisions.log').write_text('\n'.join(records)+'\n') result['gpu_full_frames']=raw.count('VG-Lite full frame submitted') result['pixman_replayed_frames']=raw.count('VG-Lite full pass replayed with Pixman') result['restoration_marker']='RESTORED shell.service active; diagnostic compositor cgroup stopped' in raw (OUT/'result.json').write_text(json.dumps(result,indent=2)+'\n') print(json.dumps(result,indent=2),flush=True)