interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / tests / mutants-seq.sh

72 lines · 3731 bytes Raw Blame History
1#!/bin/sh
2# mutants-seq.sh: single-line mutants of gsp/seq.om; each must make tests/seq_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.
5set -u
6here=$(cd "$(dirname "$0")/.." && pwd)
7src=$here/gsp/seq.om
8diff_sh=$here/tests/seq_diff.sh
9t=$(mktemp -d /tmp/mutants-seq.XXXXXX) || exit 2
10trap 'rm -rf "$t"' EXIT
11
12if ! sh "$diff_sh" > "$t/base.log" 2>&1; then
13 cat "$t/base.log"; echo "mutants-seq: FAIL baseline is not green"; exit 2
14fi
15
16# desc|old line|new line[|old line 2|new line 2] (whole-line matches, each exactly once)
17cat > "$t/list" <<'EOF'
18WRITE opcode 0 -> 9|const SQWR ulong 0|const SQWR ulong 9
19MODIFY opcode 1 -> 10|const SQMOD ulong 1|const SQMOD ulong 10
20POLL opcode 2 -> 11|const SQPOLL ulong 2|const SQPOLL ulong 11
21DELAY opcode 3 -> 12|const SQDLY ulong 3|const SQDLY ulong 12
22STORE opcode 4 -> 13|const SQSTO ulong 4|const SQSTO ulong 13
23core opcodes start at 6, not 5|const SQCRST ulong 5|const SQCRST ulong 6
24core opcodes end at 7, not 8|const SQCRES ulong 8|const SQCRES ulong 7
25WRITE/STORE payload 2 -> 3|ret 2|ret 3
26MODIFY payload 3 -> 2|ret 3|ret 2
27POLL payload 5 -> 4|ret 5|ret 4
28DELAY payload 1 -> 2|ret 1|ret 2
29poll ignores the mask|while ne and v a1 a2 bound 999999|while ne v a2 bound 999999
30poll compares with <, not ==|while ne and v a1 a2 bound 999999|while lt and v a1 a2 bound 999999
31poll budget 0 gives 2 extra reads, not 1|left = 1|left = 2
32poll spends 2 per retry|left = sub left 1|left = sub left 2
33poll budget cap 999998 -> 999997|const SQBMAX ulong 999998|const SQBMAX ulong 999997
34delay microseconds not summed|put sqdly 1 add get sqdly 1 us|put sqdly 1 us
35delay calls not counted|put sqdly 0 add get sqdly 0 1|put sqdly 0 1
36overrun check > -> >=|if gt add i n ci|if ge add i n ci
37cmdIndex check >= -> >|if ge ci nw|if gt ci nw
38empty buffer not refused|if eq nw 0|if lt nw 0
39save index 8 accepted|if ge k SQSAVE|if gt k SQSAVE
40save index read from the address dword|k = sqw add i 1|k = sqw i
41MODIFY keeps masked bits (~mask dropped)|gspwr a or and v xor sqw add i 1 M32 sqw add i 2|gspwr a or and v sqw add i 1 sqw add i 2
42MODIFY ignores the value dword|gspwr a or and v xor sqw add i 1 M32 sqw add i 2|gspwr a and v xor sqw add i 1 M32
43WRITE writes the address as value|gspwr sqw i sqw add i 1|gspwr sqw i sqw i
44core opcode runs with no callback|if eq get sqcore 0 0|if eq get sqcore 0 2
45core failure (-1) not refused|if ne c 0|if gt c 0
46walk steps 2, not the payload|i = add i n|i = add i 2
47nwords cap 16384 -> 16383|const SQMAX ulong 16384|const SQMAX ulong 16383
48why text off by one|k = ulong sub 0 add e 1|k = ulong sub 0 e
49EOF
50
51killed=0; survived=0; invalid=0
52while IFS='|' read -r desc o1 n1 o2 n2; do
53 m=$t/seq.om
54 awk -v o1="$o1" -v n1="$n1" -v o2="${o2:-}" -v n2="${n2:-}" '
55 $0 == o1 && !d1 { print n1; c1++; d1 = 1; next }
56 o2 != "" && $0 == o2 && !d2 { print n2; c2++; d2 = 1; next }
57 $0 == o1 { c1++ } o2 != "" && $0 == o2 { c2++ }
58 { print }
59 END { if (c1 != 1 || (o2 != "" && c2 != 1)) exit 1 }' "$src" > "$m"
60 if [ $? -ne 0 ] || cmp -s "$src" "$m"; then
61 echo "mutant INVALID (pattern not matched exactly once): $desc"; invalid=$((invalid + 1)); continue
62 fi
63 SEQ_OM=$m sh "$diff_sh" > "$t/m.log" 2>&1
64 rc=$?
65 case $rc in
66 0) echo "mutant SURVIVED: $desc"; survived=$((survived + 1)) ;;
67 1) echo "mutant killed: $desc"; killed=$((killed + 1)) ;;
68 *) echo "mutant INVALID (exit $rc: $(cat "$t/m.log")): $desc"; invalid=$((invalid + 1)) ;;
69 esac
70done < "$t/list"
71echo "mutants-seq: $killed killed, $survived survived, $invalid invalid"
72[ "$survived" -eq 0 ] && [ "$invalid" -eq 0 ] && [ "$killed" -ge 10 ]