interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / tests / irqqueue_host.sh

101 lines · 5861 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# HOST_MODEL mapped GSP transport. No VFIO/device open. Independent declarative wire outcomes.
4set -eu
5R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
6OMC=${IRQ_OMC:-$R/build/irq-omc}
7. "$R/tools/irq-omc.pin"
8a=$(sha256sum "$OMC"); a=${a%% *}
9[ "$a" = "$OMC_SHA256" ] || { echo 'irqqueue_host: INVALID compiler pin' >&2; exit 2; }
10export R OMC
11python3 - <<'PY'
12import os, pathlib, struct, subprocess, tempfile
13r=pathlib.Path(os.environ['R']); omc=os.environ['OMC']
14files=['tests/dma_replay.om','gsp/mmio.om','gsp/sim.om','gsp/seq.om',
15 'chan/gmmu.om','chan/mem.om','chan/chan.om','chan/sim.om','tests/dma_check.om',
16 'gsp/rpc.om','gsp/sysinfo.om','chan/params.om','gsp/boot.om','gsp/arena.om',
17 'gsp/connect.om','gsp/owned.om','gsp/profile.om','gsp/dispatch.om',
18 'chan/complete.om','chan/rmchan.om','tests/arena_trace.om','tests/rpc_trace.om',
19 'gsp/transport.om','gsp/notify.om','gsp/service.om','gsp/irqqueue.om',
20 'tests/transport_trace.om','tests/irqqueue_trace.om']
21parts={}
22for i,name in enumerate(files):
23 s=(r/name).read_text()
24 if name.startswith('tests/') and name!='tests/irqqueue_trace.om':
25 s=s.replace('fn main to int',f'fn qrfixture{i} to int')
26 parts[name]=s
27# Exact field expectations constrain behavior independently of the transport and adapter implementations.
28# capture,handler,initial-consumer,captured-consumer,final-consumer,local-consumer,
29# pending,transport-state,boot-state,adapter-state,lockdown,rx-sequence,delay-count,delay-value,probe,dead.
30def expected(**kw):
31 v=dict(c=1,h=1,initial=0,captured=0,final=1,local=1,pending=0,transport=1,
32 boot=5,adapter=0,lock=0,rx=1,delay_count=0,delay_value=0,probe=-6,dead=0)
33 v.update(kw)
34 out=list(v.values()); out[0]+=32; out[1]+=32; out[14]+=32
35 return struct.pack('<16Q',*out)
36want={i:expected() for i in (0,7,9,10,11)}
37want.update({
38 1:expected(boot=4,delay_count=1,delay_value=5),
39 2:expected(h=2,final=0,pending=2,boot=4,adapter=2,lock=1),
40 3:expected(c=-3,h=0,final=0,local=0,pending=2,transport=2,boot=12,adapter=3,rx=0,dead=1),
41 4:expected(h=-13,final=0,pending=2,transport=2,boot=12,adapter=3,dead=1),
42 5:expected(h=-6,transport=2,boot=12,adapter=3,dead=1),
43 6:expected(h=-13,final=0,pending=2,transport=2,boot=12,adapter=3,dead=1),
44 8:expected(boot=4,delay_count=1,delay_value=5),
45 13:expected(c=0,h=0,final=0,local=0,boot=4,rx=0),
46 14:expected(c=-6,h=0,final=0,local=0,transport=2,boot=12,adapter=3,rx=0,dead=1),
47 15:expected(c=-1,h=0,final=0,local=0,pending=2,transport=2,boot=12,adapter=3,rx=0,dead=1),
48})
49def build(t,pieces,name):
50 source='\n'.join(pieces.values())
51 z=subprocess.run([omc],input=source.encode(),capture_output=True)
52 if z.returncode: raise RuntimeError(f'INVALID compile {name}: {z.stderr.decode()}')
53 p=t/name; p.write_bytes(z.stdout); p.chmod(0o700); return p
54
55def run(p,mode):
56 z=subprocess.run([str(p)],input=bytes([mode]),capture_output=True,timeout=10)
57 if z.returncode or len(z.stdout)!=128:
58 raise RuntimeError(f'INVALID runtime {p.name} mode{mode}: rc={z.returncode} bytes={len(z.stdout)} stderr={z.stderr!r}')
59 return z.stdout
60
61def change(path,old,new):
62 if old not in parts[path]: raise RuntimeError(f'INVALID missing mutation {old}')
63 p=dict(parts); p[path]=p[path].replace(old,new,1); return p
64
65store='x = mapset get mmwh 0 add get qtcmd 0 32 4 rqget32 0 32'
66mutants=[
67 ('early-consumer','gsp/transport.om','ret 1\nend\nfn qthandled',
68 'early = mapset get mmwh 0 add get qtcmd 0 32 4 rqget32 0 32\nret 1\nend\nfn qthandled'),
69 ('missing-publication','gsp/transport.om',store,'x = long 0'),
70 ('completion-proof','gsp/transport.om','if ne get qthand 0 1\nret -6\nend','if false\nret -6\nend'),
71 ('stale-completion','gsp/transport.om','if or ne get qtpend 0 2 ne token get qttok 0','if false'),
72 ('semantic-skipped','gsp/irqqueue.om','r = drvstep ne get qruse 0 0','r = long 1'),
73 ('sequencer-is-not-lockdown','gsp/irqqueue.om','put qthold 0 0\nif lt r 0',
74 'put qthold 0 0\nif eq r 2\nret 2\nend\nif lt r 0'),
75 ('capture-is-immutable','gsp/irqqueue.om','r = drvstep ne get qruse 0 0',
76 'late = mapread get mmwh 0 add get qtstat 0 RQSLOT rqout 0 RQSLOT\nr = drvstep ne get qruse 0 0'),
77 ('no-publish-after-lockdown','gsp/irqqueue.om','put qrlock 0 1',
78 'late = mapset get mmwh 0 add get qtcmd 0 32 4 rqget32 0 32\nput qrlock 0 1'),
79 ('peer-error-is-not-empty','gsp/irqqueue.om','ret qrfail r','ret 0'),
80 ('no-cursor-rollback','gsp/irqqueue.om','fn qrfail r long to long\nqtlose',
81 'fn qrfail r long to long\nrqput32 0 32 get qtrd 0\nqtlose'),
82]
83with tempfile.TemporaryDirectory(prefix='irqqueue-') as td:
84 t=pathlib.Path(td); p=build(t,parts,'queue')
85 for mode,target in sorted(want.items()):
86 if mode==5: continue
87 got=run(p,mode)
88 if got!=target: raise RuntimeError(f'FAIL mode{mode}: {struct.unpack("<16Q",got)} != {struct.unpack("<16Q",target)}')
89 # A provider may report failure AFTER the store. Cursor publication is uncertain/advanced, never rolled back.
90 p=build(t,change('gsp/transport.om',store,'actual = mapset get mmwh 0 add get qtcmd 0 32 4 rqget32 0 32\nx = long -5'),'postpublish-error')
91 if run(p,5)!=want[5]: raise RuntimeError('FAIL post-publication error handling')
92 print(f'irqqueue_host: PASS {len(want)} independent mapped wire/semantic/order cases')
93 for name,path,old,new in mutants:
94 p=build(t,change(path,old,new),name)
95 detected=False
96 for mode,target in sorted(want.items()):
97 if mode==5: continue
98 if run(p,mode)!=target: detected=True; break
99 if not detected: raise RuntimeError(f'FAIL undetected mutant {name}')
100 print(f'irqqueue_host: PASS {len(mutants)} compiling terminating behavior mutants; physical transport/firmware/GB10 NOT_RUN')
101PY