aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / evidence / own-gpu-driver / rung1 / gsp_contract_mutants.sh
| 1 | #!/usr/bin/env bash |
| 2 | # gsp_contract_mutants.sh DEVC KERNEL_DIR: wrong-but-well-formed edits of gpu/contract/gb10_gsp.devc (offsets, bits, |
| 3 | # constants). The checker may accept them (they break no ordering rule); the generated twin must then FAIL |
| 4 | # test_gsp_mmio or differ from the hand twin in gsp_boot_trace. A mutant that survives = a hole. Exit 0 only if all die. |
| 5 | set -u |
| 6 | DEVC=$1 K=$2 |
| 7 | CC=${CC:-cc} |
| 8 | src=$K/gpu/contract/gb10_gsp.devc |
| 9 | work=$(mktemp -d); trap 'rm -rf "$work"' EXIT |
| 10 | cc_() { $CC -std=c11 -O1 -I"$K/gpu" -I"$K/tests" -o "$1" "${@:2}" "$K/gpu/gsp_sim.c" > "$work/cc.log" 2>&1; } |
| 11 | cc_ "$work/trace_hand" "$K/tests/gsp_boot_trace.c" "$K/gpu/gsp_mmio.c" && "$work/trace_hand" > "$work/h.txt" || { echo "BASELINE FAILS"; exit 2; } |
| 12 | "$DEVC" gen "$src" "$work/gen" > /dev/null && cc_ "$work/t" "$K/tests/test_gsp_mmio.c" "$work/gen/gsb_contract.c" && "$work/t" > /dev/null && |
| 13 | cc_ "$work/tr" "$K/tests/gsp_boot_trace.c" "$work/gen/gsb_contract.c" && "$work/tr" | cmp -s - "$work/h.txt" || { echo "BASELINE CONTRACT FAILS"; exit 2; } |
| 14 | muts=( |
| 15 | "reg sec2 QTAIL0 0xc04|reg sec2 QTAIL0 0xc0c" |
| 16 | "reg sec2 EMEMD0 0xac4|reg sec2 EMEMD0 0xacc" |
| 17 | "reg sec2 SEC2_MAILBOX0 0x040|reg sec2 SEC2_MAILBOX0 0x048" |
| 18 | "reg gsp GSP_MAILBOX1 0x044|reg gsp GSP_MAILBOX1 0x04c" |
| 19 | "reg gsp FALCON_OS 0x080|reg gsp FALCON_OS 0x084" |
| 20 | "reg gsp HWCFG2 0x0f4|reg gsp HWCFG2 0x0f8" |
| 21 | "reg gsp CPUCTL 0x1388|reg gsp CPUCTL 0x1384" |
| 22 | "reg gsp GSP_QHEAD0 0xc00|reg gsp GSP_QHEAD0 0xc08" |
| 23 | "window sec2 bar 0 base 0x840000|window sec2 bar 0 base 0x841000" |
| 24 | "window gsp bar 0 base 0x110000|window gsp bar 0 base 0x114000" |
| 25 | "bit LOCKDOWN HWCFG2 13|bit LOCKDOWN HWCFG2 12" |
| 26 | "bit ACTIVE CPUCTL 7|bit ACTIVE CPUCTL 6" |
| 27 | "bit AINCW EMEMC0 24|bit AINCW EMEMC0 25" |
| 28 | "const SEC2_CMD_BUSY 0xc001cafe|const SEC2_CMD_BUSY 0xc001caff" |
| 29 | "const PRIV_LOCKED_MASK 0xFFFFFF00|const PRIV_LOCKED_MASK 0xFFFFFFF0" |
| 30 | "const EMEM_CHANNEL_BYTES 1024|const EMEM_CHANNEL_BYTES 1020" |
| 31 | "budget polls_can_send else E_BUSY|budget polls_can_send else E_EMEM" |
| 32 | "write FALCON_OS app_version|write FALCON_OS 0" |
| 33 | "write GSP_QHEAD0 0|write GSP_QHEAD0 1" |
| 34 | "into sec2_mb0 timeout-read SEC2_MAILBOX1 sec2_mb1|into sec2_mb0" |
| 35 | ) |
| 36 | killed=0 total=0 |
| 37 | for m in "${muts[@]}"; do |
| 38 | from=${m%%|*} to=${m#*|}; total=$((total + 1)) |
| 39 | F=$from T=$to perl -0777 -ne '$i = index($_, $ENV{F}); exit 3 if $i < 0; substr($_, $i, length $ENV{F}) = $ENV{T}; print' \ |
| 40 | "$src" > "$work/gb10_gsp.devc" || { echo "MUTANT TEXT MISSING: $from"; exit 2; } |
| 41 | rm -rf "$work/gen" |
| 42 | if ! "$DEVC" gen "$work/gb10_gsp.devc" "$work/gen" > "$work/gen.log" 2>&1; then |
| 43 | echo "mutant killed (checker): $from -> $to"; killed=$((killed + 1)); continue |
| 44 | fi |
| 45 | if ! cc_ "$work/t" "$K/tests/test_gsp_mmio.c" "$work/gen/gsb_contract.c" || ! cc_ "$work/tr" "$K/tests/gsp_boot_trace.c" "$work/gen/gsb_contract.c"; then |
| 46 | echo "mutant killed (does not compile): $from -> $to"; killed=$((killed + 1)); continue |
| 47 | fi |
| 48 | if ! "$work/t" > /dev/null 2>&1; then echo "mutant killed (test_gsp_mmio): $from -> $to"; killed=$((killed + 1)); continue; fi |
| 49 | "$work/tr" > "$work/c.txt" |
| 50 | if ! cmp -s "$work/h.txt" "$work/c.txt"; then echo "mutant killed (trace differs): $from -> $to"; killed=$((killed + 1)); continue; fi |
| 51 | echo "MUTANT SURVIVED: $from -> $to" |
| 52 | done |
| 53 | echo "gsp contract mutants: $killed of $total killed" |
| 54 | test "$killed" -eq "$total" |