omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / tests / dma_host.sh
| 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. |
| 4 | set -u |
| 5 | here=$(cd "$(dirname "$0")/.." && pwd) |
| 6 | OMC=${OMC:-$here/build/omc} |
| 7 | want=bcfa582892afca8f65e551fe56867d918d86e84540c7381be8fa9ef18d0cf0f6 |
| 8 | got=$(sha256sum "$OMC" | cut -d' ' -f1) |
| 9 | [ "$got" = "$want" ] || { echo "dma_host: wrong compiler $got"; exit 2; } |
| 10 | t=$(mktemp -d /tmp/dma_host.XXXXXX) || exit 2 |
| 11 | trap 'rm -rf "$t"' EXIT |
| 12 | run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } |
| 13 | build() { |
| 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 | } |
| 18 | check() { |
| 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 | } |
| 27 | build "$here/tests/dma_replay.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/tests/dma_check.om" "$t/replay" || exit 2 |
| 28 | for 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 |
| 30 | done |
| 31 | for mode in m n o q r; do check "$t/replay" "$mode" 103 || exit 1; done |
| 32 | for mode in v; do check "$t/replay" "$mode" 109 || exit 1; done |
| 33 | build "$here/chan/dma.om" "$here/chan/gmmu.om" "$here/chan/mem.om" "$here/tests/dma_badfd.om" "$t/badfd" || exit 2 |
| 34 | run "$t/badfd" || { echo 'dma_host: real invalid-fd refusal failed'; exit 1; } |
| 35 | sha256sum "$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" |
| 36 | echo '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. |
| 38 | cat > "$t/mutants" <<'EOF' |
| 39 | gmmu|mmrd64|ret mapget get mmwh 0 o 8|ret 0|a|0 |
| 40 | gmmu|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 |
| 41 | gmmu|mmwclose|if eq get mmwst 0 MMWDMA|if eq get mmwst 0 MMWPUB|b|0 |
| 42 | gmmu|mmwclose|if or ne r 0 ne get mmduout 0 get mmws 0|if ne r 0|f|0 |
| 43 | gmmu|mmwpublish|if ne get mmwst 0 MMWDMA|if eq get mmwst 0 MMWNONE|b|0 |
| 44 | gmmu|mmwclose|if not mmwmutable|if eq get mmwst 0 MMWNONE|j|0 |
| 45 | gmmu|mmwoff|if gt n sub s o|if eq n 0|m|103 |
| 46 | mem|gmretire|if not mmwmutable|if eq get mmwst 0 MMWNONE|j|0 |
| 47 | gmmu|mminval|r = mmwquar get mmwgen 0|r = MMOK|k|0 |
| 48 | gmmu|mmwdmap|if not mmwepoch gen|if eq gen 0|b|0 |
| 49 | gmmu|mmwclose|if ne r 0|if eq r 1|i|0 |
| 50 | EOF |
| 51 | killed=0 |
| 52 | while 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)) |
| 67 | done < "$t/mutants" |
| 68 | echo "dma_host: $killed compiled ownership/order/range/error mutants killed; hardware NOT_RUN" |