omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / tests / mutants-sysinfo.sh
| 1 | #!/bin/sh |
| 2 | # mutants-sysinfo.sh: single-line mutants of gsp/sysinfo.om; each must make tests/sysinfo_diff.sh go red. |
| 3 | # The test driver and the C reference are never mutated. A mutant must change exactly the named line and still |
| 4 | # compile; otherwise it is INVALID and the run fails. |
| 5 | set -u |
| 6 | here=$(cd "$(dirname "$0")/.." && pwd) |
| 7 | src=$here/gsp/sysinfo.om |
| 8 | diff_sh=$here/tests/sysinfo_diff.sh |
| 9 | t=$(mktemp -d /tmp/mutants-sysinfo.XXXXXX) || exit 2 |
| 10 | trap 'rm -rf "$t"' EXIT |
| 11 | |
| 12 | if ! sh "$diff_sh" > "$t/base.log" 2>&1; then |
| 13 | cat "$t/base.log"; echo "mutants-sysinfo: FAIL baseline is not green"; exit 2 |
| 14 | fi |
| 15 | |
| 16 | # desc|old line|new line[|old line 2|new line 2] (whole-line matches, each exactly once) |
| 17 | cat > "$t/list" <<'EOF' |
| 18 | oorArch offset 104 -> 105|put sioff 16 104|put sioff 16 105 |
| 19 | capsMethodData.status offset 828 -> 832|put sioff 44 828|put sioff 44 832 |
| 20 | FHBBusInfo.revisionID size 1 -> 2|put sisz 34 1|put sisz 34 2 |
| 21 | fit check shifts 7 bits per byte|ret eq shr v mul sz 8 0|ret eq shr v mul sz 7 0 |
| 22 | fit check skips 4-byte fields|if lt sz 8|if lt sz 4 |
| 23 | three tokens accepted (k != 2 check dropped)|if ne get sipos 0 b|if gt get sipos 0 b |
| 24 | 0X prefix not taken as hex|if or eq x 120 eq x 88|if eq x 120 |
| 25 | leading 0 read as decimal, not octal|base = 8|base = 10 |
| 26 | bytes not little endian (7-bit shift)|put siout add o b uchar and shr v mul b 8 255|put siout add o b uchar and shr v mul b 7 255 |
| 27 | line limit 512 -> 513|const SILINE ulong 512|const SILINE ulong 513 |
| 28 | comment cut on $ not #|if eq get sitxt h 35|if eq get sitxt h 36 |
| 29 | overflow test ignores the digit|if gt v div sub SIMAX64 d base|if gt v div SIMAX64 base |
| 30 | text not cut at NUL|if eq get sitxt i 0|if eq get sitxt i 1 |
| 31 | name lookup matches prefixes|if eq sub i s n|if ge sub i s n |
| 32 | token width 127 -> 128|while and lt p b lt n 127 bound 600|while and lt p b lt n 128 bound 600 |
| 33 | does-not-fit value shown to 41 chars|siwval 40|siwval 41 |
| 34 | lower-case hex digit value off by one|ret sub ulong c 87|ret sub ulong c 86 |
| 35 | leading + not skipped|if eq get sivb 0 43|if eq get sivb 0 44 |
| 36 | CR (13) not whitespace|ret or eq c 32 and ge c 9 le c 13|ret or eq c 32 and ge c 9 le c 12 |
| 37 | text limit refuses exactly 65536 bytes|if gt n SITXMAX|if ge n SITXMAX |
| 38 | EOF |
| 39 | |
| 40 | killed=0; survived=0; invalid=0 |
| 41 | while IFS='|' read -r desc o1 n1 o2 n2; do |
| 42 | m=$t/sysinfo.om |
| 43 | awk -v o1="$o1" -v n1="$n1" -v o2="${o2:-}" -v n2="${n2:-}" ' |
| 44 | $0 == o1 && !d1 { print n1; c1++; d1 = 1; next } |
| 45 | o2 != "" && $0 == o2 && !d2 { print n2; c2++; d2 = 1; next } |
| 46 | $0 == o1 { c1++ } o2 != "" && $0 == o2 { c2++ } |
| 47 | { print } |
| 48 | END { if (c1 != 1 || (o2 != "" && c2 != 1)) exit 1 }' "$src" > "$m" |
| 49 | if [ $? -ne 0 ] || cmp -s "$src" "$m"; then |
| 50 | echo "mutant INVALID (pattern not matched exactly once): $desc"; invalid=$((invalid + 1)); continue |
| 51 | fi |
| 52 | SYSINFO_OM=$m sh "$diff_sh" > "$t/m.log" 2>&1 |
| 53 | rc=$? |
| 54 | case $rc in |
| 55 | 0) echo "mutant SURVIVED: $desc"; survived=$((survived + 1)) ;; |
| 56 | 1) echo "mutant killed: $desc"; killed=$((killed + 1)) ;; |
| 57 | *) echo "mutant INVALID (exit $rc: $(cat "$t/m.log")): $desc"; invalid=$((invalid + 1)) ;; |
| 58 | esac |
| 59 | done < "$t/list" |
| 60 | echo "mutants-sysinfo: $killed killed, $survived survived, $invalid invalid" |
| 61 | [ "$survived" -eq 0 ] && [ "$invalid" -eq 0 ] && [ "$killed" -ge 10 ] |