Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-gpu-driver/blob/main/tests/irqlease_host.sh # omega-gpu-driver aien-dev/omega-gpu-driver Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-gpu-driver / tests / irqlease_host.sh` 107 lines ยท 5830 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 # HOST_ONLY. No VFIO open or GPU access. Anonymous map fixtures only. 4 set -eu 5 R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) 6 OMC=${IRQ_OMC:-$R/build/irq-omc} 7 . "$R/tools/irq-omc.pin" 8 a=$(sha256sum "$OMC"); a=${a%% *} 9 [ "$a" = "$OMC_SHA256" ] || { echo 'irqlease_host: INVALID compiler pin' >&2; exit 2; } 10 export R OMC 11 python3 - <<'PY' 12 import importlib.util, os, pathlib, random, struct, subprocess, tempfile 13 r = pathlib.Path(os.environ['R']); omc = os.environ['OMC'] 14 spec = importlib.util.spec_from_file_location('irqlease_ref', r/'tests/irqlease_ref.py') 15 ref = importlib.util.module_from_spec(spec); spec.loader.exec_module(ref) 16 parts = {name:(r/name).read_text() for name in 17 ['gsp/irqtypes.om','gsp/irqvfio.om','gsp/irqprovider.om','gsp/irqlease.om','tests/irqlease_trace.om']} 18 # Each named scenario is a distinct ownership/acknowledgement boundary, not a hardware claim. 19 named = { 20 'closed': [0,0,1,7,8,10,9,10,11,13,7], 21 'device-not-irq-idle': [0,0,1,6,9,7,8,10,11,9,10,9,10,11], 22 'queued-device-access': [0,0,1,6,7,8,10,9,10,9,10,9,10,11], 23 'active-owner': [0,0,1,2,7,8,13,3,8,9,10,11], 24 'snapshot-owned': [0,0,1,2,15,7,3,8,9,10,16,3,8,10,11], 25 'cancelled-wait': [0,0,1,4,7,8,5,8,9,10,11], 26 'duplicate-leave': [0,0,1,2,3,3,2,19,3,7,8,9,10,11], 27 'duplicate-enter': [0,0,1,2,2,3,19,7,8,9,10,11], 28 'sticky-lockdown': [0,0,1,2,14,12,13,14,7,13,3,8,9,10,11], 29 'late-entry': [0,0,1,7,2,4,6,8,9,10,6,11], 30 'late-peer-after-stop': [0,0,1,7,8,9,10,25,11], 31 'stale-generation': [0,0,1,2,20,21,22,23,24,3,7,8,9,10,11], 32 'rollback-ack': [1,0,1,2,7,8,9,10,11], 33 'rollback-uncertain': [2,0,1,2,7,8,9,10,11], 34 'disable-uncertain': [3,0,1,6,9,7,8,9,10,11], 35 'cancel-uncertain': [4,0,1,4,7,5,8,9,10,11], 36 'device-never-stops': [5,0,1,6,7,8,9,9,9,10,11], 37 'release-uncertain': [6,0,1,7,8,9,10,11,11], 38 'stop-uncertain': [7,0,1,7,8,9,10,11], 39 'enable-before-attach': [0,1,0,1,2,13,3,7,8,9,10,11], 40 'no-enable-after-lock': [0,0,12,1,2,13,7,8,9,10,11], 41 } 42 cases = [bytes(v) for v in named.values()] 43 rng = random.Random(`58017302`) 44 for bad in range(8): 45 for _ in range(12): 46 cases.append(bytes([bad,0,1]+[rng.choice(list(range(17))+[19,20,21,22,23]) for _ in range(32)])) 47 want = [ref.reference(x) for x in cases] 48 # Independent declarative facts additionally constrain the reference itself. 49 def rows(data): 50 out = [list(struct.unpack('<16Q',data[o:o+128])) for o in range(0,len(data),128)] 51 return [tuple([v[0]-128]+v[1:]) for v in out] 52 def at(name, step): return rows(want[list(named).index(name)])[step] 53 assert at('device-not-irq-idle',7)[0:2] == (-16,4), at('device-not-irq-idle',7) 54 assert at('snapshot-owned',7)[0] == -16 55 assert at('rollback-uncertain',0)[1:4] == (7,1,1) 56 assert at('release-uncertain',8)[1:4] == (7,1,1) 57 assert at('sticky-lockdown',7)[10] == 1 58 assert at('sticky-lockdown',9)[10] == 1 59 assert rows(want[0])[-3][1] == 6 60 61 def build(t, source, name): 62 z = subprocess.run([omc],input=source.encode(),capture_output=True) 63 if z.returncode: 64 raise RuntimeError(f'INVALID compile {name}: {z.stderr.decode()}') 65 p = t/name; p.write_bytes(z.stdout); p.chmod(0o700); return p 66 67 def run(p, data): 68 z = subprocess.run([str(p)],input=data,capture_output=True,timeout=5) 69 if z.returncode or len(z.stdout) != len(data)*128: 70 raise RuntimeError(f'INVALID runtime {p.name}: rc={z.returncode}, bytes={len(z.stdout)}: {z.stderr!r}') 71 return z.stdout 72 73 source = '\n'.join(parts.values()) 74 mutants = [ 75 ('revoke-order','gsp/irqlease.om','put ilstate 0 3','put ilstate 0 2'), 76 ('irq-idle-is-not-stop','gsp/irqprovider.om','put pvenable 0 0\nput pvmasks','put pvwork 0 0\nput pvenable 0 0\nput pvmasks'), 77 ('old-owner','gsp/irqlease.om','or eq open owner 0 ne open owner get ilowner 0','eq open owner 0'), 78 ('snapshot-owner','gsp/irqlease.om','if ne get ilsnap 0 0\nret -16\nend','if false\nret -16\nend'), 79 ('lock-read','gsp/irqprovider.om','if ne get pvlocked 0 0\nret -14\nend','if false\nret -14\nend'), 80 ('generation','gsp/irqprovider.om','eq gen get pvgen 0','eq gen gen'), 81 ('span-bound','gsp/irqprovider.om','if or gt off sub get pvbytes 0 4 ne rem off 4 0','if or ge off sub get pvbytes 0 4 ne rem off 4 0'), 82 ('device-attestation','gsp/irqlease.om','if not pvattest get ilepoch 0 get ilback 0','if false'), 83 ('release-ack','gsp/irqprovider.om','if eq get pvbad 0 6','if false'), 84 ('late-peer','gsp/irqprovider.om','fn pvpeer to long\nif ne get pvstopr 0 0','fn pvpeer to long\nif false'), 85 ('cancel-ack','gsp/irqprovider.om','if eq get pvbad 0 4','if false'), 86 ('rollback-ack','gsp/irqprovider.om','if ne get pvbad 0 2','if true'), 87 ] 88 with tempfile.TemporaryDirectory(prefix='irqlease-') as td: 89 t=pathlib.Path(td); p=build(t,source,'lease') 90 for i,case in enumerate(cases): 91 got=run(p,case) 92 if got != want[i]: 93 actual, expected = rows(got), rows(want[i]) 94 step=next(j for j,(a,b) in enumerate(zip(actual,expected)) if a!=b) 95 raise RuntimeError(f'FAIL case{i} {list(named)[i] if i