"""EXPERIMENTAL prospective O1/O2 handler. No allocator or admission policy.""" import errno,re,time,subprocess from pathlib import Path import cases,oom from gate import sha,need from geometry import solid_point,exact,count from engine import COLORS def opening_before_map(raw,popup,parent): # WHY: native no-memory can precede configure/MAP. CONTRACT/INVARIANT: # validate actual serial/grab/parent wire, never await the failed popup MAP. rows=re.findall(rf'{popup} CREATE wl=(\d+) xdg=(\d+) role=(\d+) parent={parent} parent_xdg=(\d+)',raw) need(len(rows)==1,'unique failed popup identity');wl,xdg,role,parent_xdg=map(int,rows[0]) parent_ids=re.findall(rf'{parent} CREATE wl=(\d+) xdg=(\d+) role=(\d+)',raw) need(len(parent_ids)==1 and int(parent_ids[0][1])==parent_xdg,'failed popup exact parent') grabs=re.findall(rf'{popup} GRAB_REQUEST origin=wl_pointer.button target={parent} serial=(\d+) used=(\d+)',raw) need(len(grabs)==1 and grabs[0][0]==grabs[0][1] and int(grabs[0][0])>0,'failed popup real grab') serial=int(grabs[0][0]);button=raw.index(f'POINTER_BUTTON target={parent} serial={serial} button=272 state=1') wire=re.search(rf'wl_pointer#\d+\.button\({serial}, \d+, 272, 1\)',raw) create=re.search(rf'xdg_surface#{xdg}\.get_popup\(new id xdg_popup#{role}, xdg_surface#{parent_xdg}, xdg_positioner#\d+\)',raw) grab=re.search(rf'xdg_popup#{role}\.grab\(wl_seat#\d+, {serial}\)',raw) need(wire is not None and create is not None and grab is not None and wire.start()=6 and line.split()[-1].startswith('/') and 'libwlroots' in line.split()[-1]} need(paths=={s.auth['wlroots']} and sha(s.auth['wlroots'])==s.auth['wlroots_sha256'],'critical mapped wlroots changed') build=s.command_process(['readelf','-n',str(exe)]) ids=re.findall(r'Build ID: ([0-9a-f]+)',build.stdout) need(build.returncode==0 and len(ids)==1 and ids[0]==s.auth['build_id'],'actual availability BuildID mismatch') need(not any('libscenefx' in line for line in maps.splitlines()),'unexpected dynamic SceneFX in OOM binary') return dict(pid=s.comp.pid,exe=str(exe.resolve()),sha256=sha(exe),build_id=ids[0],wlroots=list(paths),maps=maps,scenefx_link='static',swaysock=str(s.sock),captured_before_cleanup=True) def availability_certificate(identity,expected,snapshot,neighbor_raw,buttons): # WHY: a final exit0 is not a post-injection live availability observation. # CONTRACT: exact surviving PID/exe/BuildID/maps + private IPC + fresh wire # press/release, saved before cleanup. INVARIANT: no superficial PASS receipt. need(identity.get('captured_before_cleanup') is True and identity['pid']==expected['pid'],'availability PID/time scope') need(identity['sha256']==expected['binary_sha256'] and identity['build_id']==expected['build_id'] and identity['exe']==expected['binary'],'availability ELF identity') need(identity['wlroots']==[expected['wlroots']] and expected['wlroots'] in identity['maps'] and 'libscenefx' not in identity['maps'],'availability mappings') sock=Path(identity['swaysock']);need(sock.parent.name.startswith('smx-') and sock.parent.parent in (Path('/tmp'),Path('/var/tmp')),'daily/foreign socket') need(snapshot['tree'].get('type')=='root' and snapshot['tree'].get('nodes') and len([o for o in snapshot['outputs'] if o.get('active')])==2,'live IPC tree/outputs absent') lines=buttons.get('reference',[]);events=[re.search(r'BUTTON ns=\d+ serial=(\d+) button=(\d+) state=(\d+)',line) for line in lines] need(len(events)==2 and all(events) and [list(map(int,e.groups()[1:])) for e in events]==[[273,1],[273,0]] and int(events[0][1])0 and count(pre[1],COLORS['POPUP_A'])==0,'nested precondition rootA sampled clip absent') s.save('oom-rootA-before-injection',dict(native_success=root_success,wire=proof,painted_H1=True,H2='EXACT',clip_scope='sampled; native generation NOT_PROVEN')) target='TOPLEVEL' if s.spec['id']=='OM-ROOT' else 'POPUP_A';popup='POPUP_A' if target=='TOPLEVEL' else 'POPUP_B' xy=solid_point(pre[0],COLORS[target],s.outputs[0],s.frames['HEADLESS-1']) stable=dict(startup=True,owner=True,neighbor=s.find('reference') is not None,reference_H2_twice=True,rootA=root_success is not None,rootA_native_success=root_success is not None) oom.arm(s,s.oom_env,s.auth['prospective'],stable) tails,buttons=s.click('owner',xy,'left',True) s.wait(lambda:'SMX_OOM ENOMEM ' in s.log('compositor')) wire=opening_before_map(s.log('owner'),popup,target) native=oom.native_failure(s.log('compositor'),s.oom_env,s.comp.pid) results=[line for line in s.log('compositor').splitlines() if 'SMX_OOM result ' in line and 'role='+s.oom_env['SMX_OOM_ROLE']+' ' in line] need(len(results)==1 and 'tree=(nil)' in results[0] and 'failures=1' in results[0],'native NULL caller outcome absent') ident=availability(s);s.save('oom-availability-identity',ident);after=s.snapshot('oom-after');s.save('oom-availability-ipc',dict(identity=ident,snapshot=after,captured_before_cleanup=True)) need(popup+' MAP ' not in s.log('owner'),'failed popup unexpectedly mapped') owner_raw_exit=s.proc['owner'].poll();disconnected=None if owner_raw_exit is None: time.sleep(.15);owner_raw_exit=s.proc['owner'].poll() if owner_raw_exit is not None:disconnected=retire_enomem(s) post=s.pair_capture('oom-post');post_pixels=popup_pixels(post,baseline,popup) old_root=dict(status='NOT_EXERCISED',reason='O1 has no old rootA' if root_success is None else ('EXPECTED_ENOMEM_DISCONNECT' if disconnected else 'ROOT_A_DISMISSED'),raw=s.log('owner')) if root_success is not None and disconnected is None and 'POPUP_A DESTROY ' not in s.log('owner') and 'POPUP_A POPUP_DONE ' not in s.log('owner'): need(count(post[0],COLORS['POPUP_A'])>0 and count(post[1],COLORS['POPUP_A'])==0,'surviving rootA sampled clipping') old_root=surviving_root_input(s,post);old_root['native_success']=root_success s.save('oom-rootA-post-input',old_root) neighbor=s.find('reference');need(neighbor is not None,'surviving neighbor absent') xy=solid_point(post[1],(48,48,56),s.outputs[1],s.frames['HEADLESS-2']) tails,buttons=s.click('reference',xy) # WHY/CONTRACT/INVARIANT: a surviving real popup grab may consume the # outside click to dismiss; only a measured dismissal permits a fresh # neighbor click. This does not claim universal click-through. if not buttons.get('reference'): need('POPUP_DONE ' in tails.get('owner',''),'neighbor input missing without measured outside dismissal') s.save('oom-neighbor-outside-dismissal',dict(tails=tails,buttons=buttons)) tails,buttons=s.click('reference',xy) lines=buttons.get('reference',[]) events=[re.search(r'BUTTON ns=\d+ serial=(\d+) button=(\d+) state=(\d+)',line) for line in lines] need(len(events)==2 and all(events) and [list(map(int,e.groups()[1:])) for e in events]==[[273,1],[273,0]],'fresh neighbor button pair') for e in events:need(re.search(rf'wl_pointer#\d+\.button\({e[1]}, \d+, 273, {e[3]}\)',tails['reference']) is not None,'neighbor real wire') need(not any(v for k,v in buttons.items() if k!='reference'),'neighbor button not exclusive') live=availability_certificate(ident,dict(s.auth,pid=s.comp.pid),after,tails['reference'],buttons) s.save('oom-availability-live',live) if disconnected is None:s.close_client('owner',scenario=s.closure_scenarios['owner']) final=s.pair_capture('oom-final');final_pixels=popup_pixels(final,baseline,final=True) s.save('oom-measurements',dict(post_pixels=post_pixels,final_pixels=final_pixels,native=native,wire=wire,rootA_success=root_success,old_rootA=old_root,before=before,after=after,availability=ident,owner_raw_exit=owner_raw_exit,owner_disconnect=disconnected,neighbor_buttons=buttons,H2_pre_post_final='EXACT',captures=8,closure_scenario=s.closure_scenarios['owner'],complete_damage='NOT_PROVEN',native_stale_listeners='NOT_PROVEN',native_no_partial_popup='NOT_PROVEN; IPC has no popup-node schema',atomic_generation='NOT_PROVEN')) return 'PARTIALLY_FEASIBLE'