omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / tests / irqvfio_host.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | # HOST_ONLY: ptrace child-owned memfd, actual eventfd, no device opens. |
| 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 'irqvfio_host: INVALID compiler pin' >&2; exit 2; } |
| 10 | export R OMC |
| 11 | python3 - <<'PY' |
| 12 | import importlib.util, os, pathlib, platform, subprocess, tempfile |
| 13 | if platform.machine() != 'aarch64': |
| 14 | raise RuntimeError('NOT_RUN: native AArch64 ptrace fixture required') |
| 15 | r = pathlib.Path(os.environ['R']); omc = os.environ['OMC'] |
| 16 | spec = importlib.util.spec_from_file_location('irqvfio_ref', r/'tests/irqvfio_ref.py') |
| 17 | ref = importlib.util.module_from_spec(spec); spec.loader.exec_module(ref) |
| 18 | parts = {name:(r/name).read_text() for name in |
| 19 | ['gsp/irqtypes.om','gsp/irqvfio.om','gsp/irqprovider.om','gsp/irqlease.om','tests/irqvfio_trace.om']} |
| 20 | def build(t, sources, name): |
| 21 | z = subprocess.run([omc],input='\n'.join(sources.values()).encode(),capture_output=True) |
| 22 | if z.returncode: raise RuntimeError(f'INVALID compile {name}: {z.stderr.decode()}') |
| 23 | p=t/name; p.write_bytes(z.stdout); p.chmod(0o700); return p |
| 24 | mutants = [ |
| 25 | ('missing-mask-capability','gsp/irqvfio.om','if ne and flags 3 3','if false',[18]), |
| 26 | ('wrong-eventfd','gsp/irqvfio.om','viput 0 add 20 mul i 4 ulong e','viput 0 add 20 mul i 4 4294967295',[0]), |
| 27 | ('unacknowledged-disable','gsp/irqvfio.om','r = viset 33 0 0\nif ne r 0','r = viset 33 0 0\nif false',[6,11]), |
| 28 | ('ambiguous-close','gsp/irqvfio.om','r = fclose get viefd 0\nif ne r 0','r = fclose get viefd 0\nif false',[20]), |
| 29 | ('missing-unmask','gsp/irqvfio.om','r = viset 17 get vincount 0 get vistart 0','r = long 0',[0]), |
| 30 | ('missing-cancel-wake','gsp/irqvfio.om','r = write get viefd 0 viwake 0 8','r = long 8',[0]), |
| 31 | ('full-vector-boundary','gsp/irqvfio.om','if gt count sub n start','if ge count sub n start',[12]), |
| 32 | ('exact-page-boundary','gsp/irqvfio.om','if lt size 4096','if le size 4096',[0]), |
| 33 | ('returned-index','gsp/irqvfio.om','if or ne viget 1 0 16 ne viget 1 8 idx','if ne viget 1 0 16',[16]), |
| 34 | ('irq-idle-as-device-stop','gsp/irqprovider.om','if ne get pvmode 0 1\nret -95\nend\nif eq get pvbad 0 7','if false\nret -95\nend\nif eq get pvbad 0 7',[0]), |
| 35 | ] |
| 36 | with tempfile.TemporaryDirectory(prefix='irqvfio-') as td: |
| 37 | t=pathlib.Path(td); p=build(t,parts,'vfio') |
| 38 | for mode in range(21): |
| 39 | failures, records=ref.exercise(p,mode) |
| 40 | if failures: raise RuntimeError(f'FAIL fixture {mode}: {failures}') |
| 41 | print('irqvfio_host: PASS 21 independently checked UAPI/memfd/eventfd ownership cases') |
| 42 | for name,path,old,new,cases in mutants: |
| 43 | if old not in parts[path]: raise RuntimeError(f'INVALID missing mutation {name}') |
| 44 | changed=dict(parts); changed[path]=changed[path].replace(old,new,1) |
| 45 | p=build(t,changed,name) |
| 46 | if not any(ref.exercise(p,mode)[0] for mode in cases): |
| 47 | raise RuntimeError(f'FAIL undetected mutant {name}') |
| 48 | print(f'irqvfio_host: PASS {len(mutants)} compiling terminating behavior mutants; physical VFIO/GSP/GB10 NOT_RUN') |
| 49 | PY |