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-uvm.sh

76 lines · 2802 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Deliberately broken variants of the UVM units. A mutant must still compile
4# and must make the independent checker fail. A corrupted good trace must
5# also fail the checker. Surviving a mutant, or accepting a corrupted trace,
6# is a failed test.
7set -eu
8here=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
9repo=$(CDPATH= cd -- "$here/.." && pwd)
10omc=/home/drakestapleton/work/cudastack/omega-mv/seed/out/omc
11tmp=$(mktemp -d)
12trap 'rm -rf "$tmp"' EXIT
13
14echo "mutants-uvm: baseline"
15if ! sh "$here/uvm_diff.sh" > "$tmp/base.log" 2>&1; then
16 echo "mutants-uvm: baseline is not green" >&2
17 cat "$tmp/base.log" >&2
18 exit 2
19fi
20cat "$tmp/base.log"
21
22# Rebuild the good trace once so the gate negative control has bytes to flip.
23cat "$repo/uvm/fmt.om" "$repo/uvm/pt.om" "$repo/uvm/fault.om" "$repo/tests/uvm_trace.om" > "$tmp/good.om"
24taskset -c 10-14 nice -n 10 "$omc" < "$tmp/good.om" > "$tmp/good.bin"
25chmod +x "$tmp/good.bin"
26taskset -c 10-14 nice -n 10 "$tmp/good.bin" > "$tmp/good.txt"
27python3 - "$tmp/good.txt" "$tmp/bad.txt" <<'PY'
28import sys
29text = open(sys.argv[1], "r", encoding="utf-8").read()
30old = "W 0 0000000080001014"
31new = "W 0 0000000080001015"
32if old not in text:
33 sys.stderr.write("gate line missing\n")
34 sys.exit(1)
35open(sys.argv[2], "w", encoding="utf-8").write(text.replace(old, new, 1))
36PY
37if python3 "$here/uvm_check.py" "$tmp/bad.txt" > "$tmp/gate.log" 2>&1; then
38 echo "mutants-uvm: corrupted trace was accepted" >&2
39 exit 1
40fi
41echo "mutants-uvm: gate negative control killed"
42
43run_mutant() {
44 name=$1
45 file=$2
46 old=$3
47 new=$4
48 n=$(grep -F -c "$old" "$file" || true)
49 if [ "$n" != "1" ]; then
50 echo "mutants-uvm: $name pattern found $n times" >&2
51 exit 1
52 fi
53 mkdir -p "$tmp/$name"
54 sed "s|$old|$new|" "$file" > "$tmp/$name/$(basename "$file")"
55 FMT_OM=$repo/uvm/fmt.om
56 PT_OM=$repo/uvm/pt.om
57 FAULT_OM=$repo/uvm/fault.om
58 case $(basename "$file") in
59 fmt.om) FMT_OM=$tmp/$name/fmt.om ;;
60 pt.om) PT_OM=$tmp/$name/pt.om ;;
61 fault.om) FAULT_OM=$tmp/$name/fault.om ;;
62 esac
63 if FMT_OM=$FMT_OM PT_OM=$PT_OM FAULT_OM=$FAULT_OM sh "$here/uvm_diff.sh" > "$tmp/$name.log" 2>&1; then
64 echo "mutants-uvm: $name SURVIVED" >&2
65 exit 1
66 fi
67 echo "mutants-uvm: $name killed"
68}
69
70run_mutant aperture "$repo/uvm/fmt.om" 'v = or ulong 1 shl and ap 3 1' 'v = or ulong 1 shl and ap 3 2'
71run_mutant align "$repo/uvm/pt.om" 'if ne and va sub page 1 0' 'if ne ulong 0 0'
72run_mutant overlap "$repo/uvm/pt.om" 'if or eq r UVMAPPED eq r UVCONF' 'if eq r UVCONF'
73run_mutant replay "$repo/uvm/fault.om" 'if eq get uvfrep 0 0' 'if eq get uvfrep 0 2'
74run_mutant alloc "$repo/uvm/pt.om" 'if uvoverlap va sz' 'if eq ulong 0 1'
75
76echo "mutants-uvm: PASS (baseline green, gate killed, 5 mutants killed)"