omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / tests / mutants-fw.sh
| 1 | #!/bin/sh |
| 2 | # mutants-fw.sh: single-line mutants of the firmware units (gsp/fw.om, gsp/inflate.om, gsp/sha2.om, |
| 3 | # gsp/bindata.om, fwprep.om); each must make tests/fw_diff.sh go red (exit 1). A mutant must change |
| 4 | # exactly the named line and still compile; otherwise it is INVALID and the run fails. |
| 5 | set -u |
| 6 | here=$(cd "$(dirname "$0")/.." && pwd) |
| 7 | diff_sh=$here/tests/fw_diff.sh |
| 8 | t=$(mktemp -d /tmp/mutants-fw.XXXXXX) || exit 2 |
| 9 | trap 'rm -rf "$t"' EXIT |
| 10 | |
| 11 | if ! sh "$diff_sh" > "$t/base.log" 2>&1; then |
| 12 | cat "$t/base.log"; echo "mutants-fw: FAIL baseline is not green"; exit 2 |
| 13 | fi |
| 14 | |
| 15 | # unit|desc|old line|new line (whole-line match, exactly once in the unit) |
| 16 | cat > "$t/list" <<'EOF' |
| 17 | fw|ELF magic byte 1 'E' (69) taken as 68|if ne get fwhd 1 69|if ne get fwhd 1 68 |
| 18 | fw|e_machine RISC-V (243) replaced by x86-64 (62)|if ne fwh16 18 243|if ne fwh16 18 62 |
| 19 | fw|EI_VERSION check inverted|if ne get fwhd 6 1|if eq get fwhd 6 1 |
| 20 | fw|e_shentsize 64 replaced by 40|if ne fwh16 58 64|if ne fwh16 58 40 |
| 21 | fw|signature section matched by the build-id note name|if eq fwnmeq o 50 1|if eq fwnmeq o 49 1 |
| 22 | inflate|CRC-32 polynomial low bit set|c = xor shr c 1 and 3988292384 m|c = xor shr c 1 and 3988292385 m |
| 23 | inflate|CRC-32 check compares the trailer with itself|if ne infle32 sub inlen 8 infcrc outlen|if ne infle32 sub inlen 8 infle32 sub inlen 8 |
| 24 | inflate|ISIZE read from the CRC word|if ne infle32 sub inlen 4 outlen|if ne infle32 sub inlen 8 outlen |
| 25 | inflate|length base for symbol 257 is 4|put inflb 0 3|put inflb 0 4 |
| 26 | sha2|SHA-256 K[63] off by one|put shk 63 3329325298|put shk 63 3329325299 |
| 27 | sha2|SHA-384 IV word 0 off by one|put sh5h 0 14680500436340154072|put sh5h 0 14680500436340154073 |
| 28 | bindata|lowercase hex digit base 87 ('a'-10) taken as 86|ret sub ulong c 87|ret sub ulong c 86 |
| 29 | bindata|descriptor version 5 taken as 6|if ne bdw32 i 0 5|if ne bdw32 i 0 6 |
| 30 | bindata|UCODE_HASH length 48 taken as 47|if ne get bdpn i 48|if ne get bdpn i 47 |
| 31 | bindata|descriptor region alignment check inverted|if ne rem off 256 0|if eq rem off 256 0 |
| 32 | fwprep|fmc.pubkey takes UCODE_SIG|e = fwpslot 10 4 2|e = fwpslot 11 4 2 |
| 33 | fwprep|descriptor word stride 3 bytes|p = add get fwpdo 0 mul w 4|p = add get fwpdo 0 mul w 3 |
| 34 | fwprep|stale fw.manifest not unlinked|u = unlink fwpp 0 get fwppn 0|u = long 0 |
| 35 | fwprep|function-name check disabled|if eq m 0|if eq m 2 |
| 36 | fwprep|manifest signature offset taken from .fwimage|fwodec get fwsof get fwsx 0|fwodec get fwsof get fwimx 0 |
| 37 | EOF |
| 38 | |
| 39 | killed=0; survived=0; invalid=0 |
| 40 | while IFS='|' read -r unit desc o1 n1; do |
| 41 | case $unit in |
| 42 | fw) var=FW_OM; src=$here/gsp/fw.om ;; |
| 43 | inflate) var=INFL_OM; src=$here/gsp/inflate.om ;; |
| 44 | sha2) var=SHA2_OM; src=$here/gsp/sha2.om ;; |
| 45 | bindata) var=BD_OM; src=$here/gsp/bindata.om ;; |
| 46 | fwprep) var=FWPREP_OM; src=$here/fwprep.om ;; |
| 47 | *) echo "mutant INVALID (unknown unit $unit): $desc"; invalid=$((invalid + 1)); continue ;; |
| 48 | esac |
| 49 | m=$t/$unit.om |
| 50 | awk -v o1="$o1" -v n1="$n1" ' |
| 51 | $0 == o1 && !d1 { print n1; c1++; d1 = 1; next } |
| 52 | $0 == o1 { c1++ } |
| 53 | { print } |
| 54 | END { if (c1 != 1) exit 1 }' "$src" > "$m" |
| 55 | if [ $? -ne 0 ] || cmp -s "$src" "$m"; then |
| 56 | echo "mutant INVALID (pattern not matched exactly once): $unit: $desc"; invalid=$((invalid + 1)); continue |
| 57 | fi |
| 58 | env "$var=$m" sh "$diff_sh" > "$t/m.log" 2>&1 |
| 59 | rc=$? |
| 60 | case $rc in |
| 61 | 0) echo "mutant SURVIVED: $unit: $desc"; survived=$((survived + 1)) ;; |
| 62 | 1) echo "mutant killed: $unit: $desc ($(grep 'FAIL' "$t/m.log" | head -n 1))"; killed=$((killed + 1)) ;; |
| 63 | *) echo "mutant INVALID (exit $rc: $(tail -n 1 "$t/m.log")): $unit: $desc"; invalid=$((invalid + 1)) ;; |
| 64 | esac |
| 65 | done < "$t/list" |
| 66 | echo "mutants-fw: $killed killed, $survived survived, $invalid invalid" |
| 67 | [ "$survived" -eq 0 ] && [ "$invalid" -eq 0 ] && [ "$killed" -ge 12 ] |