omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / tests / transport_host.sh
| 1 | #!/bin/sh |
| 2 | # HOST ONLY. No GPU/VFIO fd. Python coordinates explicit anonymous-map peers and mutants. |
| 3 | set -eu |
| 4 | R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) |
| 5 | OMC=${OMC:-$R/build/omc} |
| 6 | a=$(sha256sum "$OMC"); a=${a%% *} |
| 7 | [ "$a" = bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6 ] || exit 2 |
| 8 | export R OMC |
| 9 | python3 - <<'PY' |
| 10 | import os,pathlib,subprocess,tempfile,hashlib,re |
| 11 | r=pathlib.Path(os.environ['R']); omc=os.environ['OMC'] |
| 12 | parts=['tests/dma_replay.om','gsp/mmio.om','gsp/sim.om','gsp/seq.om','chan/gmmu.om','chan/mem.om','chan/chan.om','chan/sim.om','tests/dma_check.om','gsp/rpc.om','gsp/sysinfo.om','chan/params.om','gsp/boot.om','gsp/arena.om','gsp/connect.om','gsp/owned.om','gsp/profile.om','gsp/dispatch.om','chan/complete.om','chan/rmchan.om','tests/arena_trace.om','tests/rpc_trace.om'] |
| 13 | base=[] |
| 14 | for i,p in enumerate(parts): |
| 15 | s=(r/p).read_text() |
| 16 | if p.startswith('tests/'): |
| 17 | s=s.replace('fn main to int',f'fn zzmain{i} to int') |
| 18 | base.append(s) |
| 19 | transport=(r/'gsp/transport.om').read_text(); trace=(r/'tests/transport_trace.om').read_text() |
| 20 | service=(r/'gsp/service.om').read_text() |
| 21 | notify=(r/'gsp/notify.om').read_text(); failnotify='note Explicit HOST TEST ONLY failed notification model.\nfn qtbell h long to long\nret -5\nend\n' |
| 22 | with tempfile.TemporaryDirectory(prefix='gsp-transport-') as td: |
| 23 | t=pathlib.Path(td) |
| 24 | def build(body,nt=notify,name='trace',svc=service): |
| 25 | src='\n'.join(base+[body,nt,svc,trace]); p=t/name |
| 26 | c=subprocess.run([omc],input=src.encode(),stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
| 27 | if c.returncode: |
| 28 | m=re.search(r'line (\d+)',c.stderr.decode(errors='replace')) |
| 29 | lines=src.splitlines(); n=int(m[1]) if m else 1 |
| 30 | excerpt='\n'.join(f'{i+1}: {lines[i]}' for i in range(max(0,n-3),min(len(lines),n+2))) |
| 31 | raise RuntimeError('INVALID compile '+name+': '+c.stderr.decode(errors='replace')+'\n'+excerpt) |
| 32 | p.write_bytes(c.stdout);p.chmod(0o700) |
| 33 | return p,src |
| 34 | def check(p,mode,expected=0): |
| 35 | z=subprocess.run([str(p)],input=bytes([mode]),capture_output=True) |
| 36 | if z.returncode!=expected: |
| 37 | raise RuntimeError(f'{p.name} mode{mode}: observed{z.returncode}, expected{expected}: '+repr(z.stderr)) |
| 38 | p,src=build(transport) |
| 39 | for mode in [106,100,105,97,119,102,103,98,120,118,101,114,99,109,104,116,115]:check(p,mode) |
| 40 | print('transport_host: PASS 17 composed mapped boot/RM hierarchy/schedule/submit/semaphore/drain/free/dispatch and queue refusal controls; hardware NOT_RUN') |
| 41 | print('transport source sha256',hashlib.sha256(src.encode()).hexdigest()) |
| 42 | print('transport binary sha256',hashlib.sha256(p.read_bytes()).hexdigest()) |
| 43 | p,_=build(transport,failnotify,'notify-failure');check(p,112) |
| 44 | print('transport_host: PASS postpublication notification failure retains identity and quarantines; hardware NOT_RUN') |
| 45 | mutants=[ |
| 46 | ('slotcopy','r = mapwrite h o rqtmp mul i RQSLOT RQSLOT','r = long RQSLOT',97,notify), |
| 47 | ('publish','p = rem add wr e RQCOUNT','p = wr',97,notify), |
| 48 | ('ack','x = mapset get mmwh 0 add get qtcmd 0 32 4 rqget32 0 32','x = mapset get mmwh 0 add get qtcmd 0 32 4 0',116,notify), |
| 49 | ('token','if or ne get qtpend 0 1 ne token get qttok 0','if false',116,notify), |
| 50 | ('snapshot','r = rqrecv','rqput32 1 16 mapget get mmwh 0 add get qtstat 0 16 4\nr = rqrecv',115,notify), |
| 51 | ('notifyloss','r = qtbell get qtbar 0\nif ne r 0\nqtlose','r = qtbell get qtbar 0\nif ne r 0',112,failnotify), |
| 52 | ('reset','ret eq get qtstate 0 0','ret true',98,notify), |
| 53 | ('generation','ret eq get qtboot 0 get bgen 0','ret true',103,notify), |
| 54 | ] |
| 55 | if service.count('d = dspauto')!=1:raise RuntimeError('INVALID sequencer service mutant anchor') |
| 56 | p,_=build(transport,notify,'false-sequencer',service.replace('d = dspauto','d = long 0')) |
| 57 | check(p,100,1) |
| 58 | print('DETECTED fabricated-sequencer-completion') |
| 59 | if notify.count('GPNOTIF 4 0')!=1:raise RuntimeError('INVALID notification mutant anchor') |
| 60 | p,_=build(transport,notify.replace('GPNOTIF 4 0','GPNOTIF 4 1'),'wrong-notification') |
| 61 | check(p,97,1) |
| 62 | print('DETECTED wrong-notification-value') |
| 63 | for name,old,new,mode,nt in mutants: |
| 64 | if transport.count(old)!=1:raise RuntimeError('INVALID mutant anchor '+name) |
| 65 | p,_=build(transport.replace(old,new),nt,name) |
| 66 | check(p,mode,1) |
| 67 | print('DETECTED',name) |
| 68 | # Ordering is a code-generation check, NOT a claim serialized peers prove fence necessity. |
| 69 | probe='fn main to int\nh = mapnew -1 0 4096 3 33\nr = mapset h 0 4 9\nv = mapget h 0 4\nif ne v 9\nret 1\nend\nr = mapdrop h\nret int r\nend\n' |
| 70 | z=subprocess.run([omc],input=probe.encode(),capture_output=True) |
| 71 | if z.returncode:raise RuntimeError('INVALID ordering probe compile') |
| 72 | p=t/'ordering';p.write_bytes(z.stdout);p.chmod(0o700) |
| 73 | if subprocess.run([str(p)]).returncode:raise RuntimeError('ordering probe behavior') |
| 74 | text=subprocess.check_output(['objdump','-D','-b','binary','-m','aarch64',str(p)],text=True) |
| 75 | ins=[] |
| 76 | for line in text.splitlines(): |
| 77 | m=re.match(r'\s*[0-9a-f]+:\s+[0-9a-f]{8}\s+(.+)',line) |
| 78 | if m:ins.append(m.group(1).strip()) |
| 79 | def ordered(xs): |
| 80 | hits=[] |
| 81 | for i,x in enumerate(xs): |
| 82 | if x.startswith('dsb') and x.split()[-1]=='sy' and i+2<len(xs): |
| 83 | if xs[i+2].startswith('dsb') and xs[i+2].split()[-1]=='sy': |
| 84 | hits.append(xs[i+1].split()[0]) |
| 85 | return hits==['str','ldr'] |
| 86 | if not ordered(ins):raise RuntimeError('INVALID generated DSB/store/load ordering: '+repr(ins)) |
| 87 | bad=ins.copy();bad[next(i for i,x in enumerate(bad) if x.startswith('dsb'))]='nop' |
| 88 | if ordered(bad):raise RuntimeError('SURVIVED missing-fence disassembly mutant') |
| 89 | print('transport_host: PASS generated DSB SY/store/DSB SY and DSB SY/load/DSB SY; missing-fence checker mutant detected. Device coherency NOT_RUN') |
| 90 | print('ordering probe binary sha256',hashlib.sha256(z.stdout).hexdigest()) |
| 91 | print('transport_host: PASS 10 behavior mutants; hardware/kernel execution NOT_RUN') |
| 92 | PY |