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 / dma_host.sh

68 lines · 3505 bytes Raw Blame History
1#!/bin/sh
2# Host verification only. No device open, VFIO release/reset, DMA or hardware MMIO.
3# Production .om is tested with anonymous memory + invalid fd; DMA success/error is explicit replay.
4set -u
5here=$(cd "$(dirname "$0")/.." && pwd)
6OMC=${OMC:-$here/build/omc}
7want=bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6
8got=$(sha256sum "$OMC" | cut -d' ' -f1)
9[ "$got" = "$want" ] || { echo "dma_host: wrong compiler $got"; exit 2; }
10t=$(mktemp -d /tmp/dma_host.XXXXXX) || exit 2
11trap 'rm -rf "$t"' EXIT
12run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; }
13build() {
14 transport=$1; gmmu=$2; mem=$3; main=$4; out=$5
15 cat "$transport" "$gmmu" "$mem" "$here/chan/chan.om" "$here/chan/sim.om" "$main" | run "$OMC" > "$out" || return 2
16 chmod +x "$out"
17}
18check() {
19 prog=$1; mode=$2; expected=$3
20 run "$prog" "$mode" > "$t/run.log" 2>&1; rc=$?
21 if [ "$rc" -ne "$expected" ]; then
22 echo "dma_host: mode $mode returned $rc, expected $expected"
23 cat "$t/run.log"
24 return 1
25 fi
26}
27build "$here/tests/dma_replay.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/tests/dma_check.om" "$t/replay" || exit 2
28for mode in a b c d e f g h i j k l s t u w x; do
29 check "$t/replay" "$mode" 0 || exit 1
30done
31for mode in m n o q r; do check "$t/replay" "$mode" 103 || exit 1; done
32for mode in v; do check "$t/replay" "$mode" 109 || exit 1; done
33build "$here/chan/dma.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/tests/dma_badfd.om" "$t/badfd" || exit 2
34run "$t/badfd" || { echo 'dma_host: real invalid-fd refusal failed'; exit 1; }
35sha256sum "$here/chan/dma.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/chan/chan.om" "$here/tests/dma_check.om" "$t/replay" "$t/badfd"
36echo 'dma_host: 23 replay/boundary cases and real invalid-fd retry/drop PASS'
37# Scoped whole-line mutants must still compile and must break the same behavior check.
38cat > "$t/mutants" <<'EOF'
39gmmu|mmrd64|ret mapget get mmwh 0 o 8|ret 0|a|0
40gmmu|mmwdmap|r = mmdmaop 1 fd get mmwh 0 get mmwb 0 get mmws 0|r = mmdmaop 1 fd get mmwh 0 add get mmwb 0 4096 get mmws 0|b|0
41gmmu|mmwclose|if eq get mmwst 0 MMWDMA|if eq get mmwst 0 MMWPUB|b|0
42gmmu|mmwclose|if or ne r 0 ne get mmduout 0 get mmws 0|if ne r 0|f|0
43gmmu|mmwpublish|if ne get mmwst 0 MMWDMA|if eq get mmwst 0 MMWNONE|b|0
44gmmu|mmwclose|if not mmwmutable|if eq get mmwst 0 MMWNONE|j|0
45gmmu|mmwoff|if gt n sub s o|if eq n 0|m|103
46mem|gmretire|if not mmwmutable|if eq get mmwst 0 MMWNONE|j|0
47gmmu|mminval|r = mmwquar get mmwgen 0|r = MMOK|k|0
48gmmu|mmwdmap|if not mmwepoch gen|if eq gen 0|b|0
49gmmu|mmwclose|if ne r 0|if eq r 1|i|0
50EOF
51killed=0
52while IFS='|' read -r unit fn old new mode expected; do
53 src=$here/chan/$unit.om
54 awk -v fn="$fn" -v old="$old" -v new="$new" '
55 /^fn / { active = ($2 == fn) }
56 active && $0 == old { print new; count++; next }
57 { print }
58 END { if (count != 1) exit 1 }
59 ' "$src" > "$t/mutant.om" || { echo "dma_host: INVALID mutant $fn:$old"; exit 2; }
60 gmmu=$here/chan/gmmu.om; mem=$here/chan/mem.om
61 case $unit in gmmu) gmmu=$t/mutant.om ;; mem) mem=$t/mutant.om ;; esac
62 build "$here/tests/dma_replay.om" "$gmmu" "$mem" "$here/tests/dma_check.om" "$t/mutant" || { echo "dma_host: INVALID noncompiling mutant $fn"; exit 2; }
63 if check "$t/mutant" "$mode" "$expected" > "$t/mutant.log" 2>&1; then
64 echo "dma_host: SURVIVED mutant $fn:$old"; exit 1
65 fi
66 killed=$((killed + 1))
67done < "$t/mutants"
68echo "dma_host: $killed compiled ownership/order/range/error mutants killed; hardware NOT_RUN"