omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / tests / ogd_host.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # HOST/QEMU_USER only. No physical provider adoption or device access. |
| 4 | set -eu |
| 5 | R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) |
| 6 | cd "$R" |
| 7 | sh tools/buildogd.sh |
| 8 | export R |
| 9 | python3 - <<'PY' |
| 10 | import os, pathlib, shutil, struct, subprocess, tempfile |
| 11 | r=pathlib.Path(os.environ['R']); p=r/'build/ogd' |
| 12 | units=(r/'tools/ogd.units').read_text().splitlines() |
| 13 | parts={name:(r/name).read_text() for name in units} |
| 14 | expected=(131,3,1,1,3,2,1,5,128,128,112,2,128,128,4,114) |
| 15 | def run(command,arg,rc=0): |
| 16 | z=subprocess.run([*command,arg],capture_output=True,timeout=10) |
| 17 | if z.returncode!=rc: raise RuntimeError(f'INVALID {command} {arg}: rc={z.returncode} {z.stderr!r}') |
| 18 | return z |
| 19 | |
| 20 | def check(command): |
| 21 | if run(command,'modes').stdout!=b'model\nmodel-trace\n': raise RuntimeError('FAIL advertised hardware mode') |
| 22 | for denied in ('physical','ident','boot','hello','exec','', 'model-tracex'): |
| 23 | z=run(command,denied,95) |
| 24 | if z.stdout or b'physical VFIO/GSP launch refused' not in z.stderr: raise RuntimeError('FAIL physical refusal') |
| 25 | z=run(command,'model-trace') |
| 26 | if len(z.stdout)!=128 or struct.unpack('<16Q',z.stdout)!=expected: |
| 27 | raise RuntimeError(f'FAIL composed trace: {z.stdout.hex()}') |
| 28 | z=run(command,'model') |
| 29 | if not z.stdout.startswith(b'ogd MODEL PASS:') or b'published DMA retained' not in z.stdout: |
| 30 | raise RuntimeError('FAIL model lifecycle report') |
| 31 | |
| 32 | check([str(p)]) |
| 33 | print('ogd_host: PASS native composed sequencer/INIT_DONE/lockdown, ordered consumer, revoke/sync/device-stop; 7 physical-mode refusals') |
| 34 | qemu=os.environ.get('QEMU_AARCH64') or shutil.which('qemu-aarch64') |
| 35 | if not qemu: raise RuntimeError('NOT_RUN: qemu-aarch64 is required for composed model acceptance') |
| 36 | check([qemu,str(p)]) |
| 37 | print('ogd_host: PASS QEMU-user composed model and physical-mode refusals; NOT a system/device/chip qualification') |
| 38 | mutants=[ |
| 39 | ('snapshot-retirement','gsp/irqctl.om','put ilsnap 0 0\nend\nend\nfn iqpm','put ilsnap 0 1\nend\nend\nfn iqpm'), |
| 40 | ('missing-clear-effect','gsp/irqctl.om','r = pvwrite get icspan 0 get icowner 0 get icgen 0 4 value','r = long 0'), |
| 41 | ('lockdown-mmio','gsp/irqprovider.om','if ne get pvlocked 0 0\nret -14\nend','if false\nret -14\nend'), |
| 42 | ('sequencer-is-lockdown','gsp/irqqueue.om','put qthold 0 0\nif lt r 0','put qthold 0 0\nif eq r 2\nret 2\nend\nif lt r 0'), |
| 43 | ('premature-device-idle','gsp/irqlease.om','if not pvattest get ilepoch 0 get ilback 0','if false'), |
| 44 | ('old-handler-accepted','gsp/irqlease.om','if or not irvalid cap gen or ne get ilstate 0 2 ne get pvlocked 0 0','if or not irvalid cap gen ne get ilstate 0 2'), |
| 45 | ] |
| 46 | with tempfile.TemporaryDirectory(prefix='ogd-host-') as td: |
| 47 | for name,path,old,new in mutants: |
| 48 | if old not in parts[path]: raise RuntimeError(f'INVALID missing mutation {name}') |
| 49 | changed=dict(parts); changed[path]=changed[path].replace(old,new,1) |
| 50 | z=subprocess.run([str(r/'build/irq-omc')],input='\n'.join(changed.values()).encode(),capture_output=True) |
| 51 | if z.returncode: raise RuntimeError(f'INVALID compile {name}: {z.stderr.decode()}') |
| 52 | m=pathlib.Path(td)/name; m.write_bytes(z.stdout); m.chmod(0o700) |
| 53 | z=run([str(m)],'model-trace') |
| 54 | if len(z.stdout)!=128: raise RuntimeError(f'INVALID output {name}') |
| 55 | if struct.unpack('<16Q',z.stdout)==expected: raise RuntimeError(f'FAIL undetected mutant {name}') |
| 56 | print(f'ogd_host: PASS {len(mutants)} compiling terminating composed behavior mutants; physical VFIO/GSP/GB10 NOT_RUN') |
| 57 | PY |