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

66 lines · 3098 bytes Raw Blame History
1#!/bin/sh
2# chan_diff.sh: builds the .om channel trace (chan/gmmu.om + chan/mem.om + chan/chan.om + chan/sim.om +
3# tests/chan_trace.om) and the C reference trace (aienux PR #441 tests/gpu_chan_trace.c + gpu/gmmu.c +
4# gpu/gpu_mem.c + gpu/gpu_chan.c + gpu/gpu_sim.c, compiled fresh into a temp dir as a test-only referee)
5# and requires byte-identical stdout. Host only: the trace runs on the simulator (mmmode 0).
6# Env: AIENUX (aienux checkout), OMC (pinned omc), GMMU_OM / MEM_OM / CHAN_OM / GSIM_OM (unit files to
7# test; mutants use these), CHAN_REF (a C trace already produced by this script's referee build, so a
8# mutant run skips the rebuild; the file must be non-empty).
9set -u
10here=$(cd "$(dirname "$0")/.." && pwd)
11AIENUX=${AIENUX:-/home/drakestapleton/work/OwnDriver/aienux}
12OMC=${OMC:-$here/build/omc}
13GMMU_OM=${GMMU_OM:-$here/chan/gmmu.om}
14MEM_OM=${MEM_OM:-$here/chan/mem.om}
15CHAN_OM=${CHAN_OM:-$here/chan/chan.om}
16GSIM_OM=${GSIM_OM:-$here/chan/sim.om}
17CHAN_REF=${CHAN_REF:-}
18OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$here/tools/omc.pin")
19run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; }
20
21got=$(sha256sum "$OMC" | cut -d' ' -f1)
22if [ "$got" != "$OMC_SHA" ]; then
23 echo "chan_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2
24fi
25# The host trace must stay on the simulator: mode 0 only, no device words in the test driver,
26# while the BAR0 (mode 1) branch stays present in the register seam.
27if grep -n 'mmmode [0-9]* [1-9]\|mmbar\|vfio\|mapnew\|/dev/\|/sys/' "$here/tests/chan_trace.om"; then
28 echo "chan_diff: FAIL test driver leaves simulator mode or names a device"; exit 2
29fi
30for w in 'ret mapget get mmbar 0 off 4' 'r = mapset get mmbar 0 off 4 v'; do
31 if ! grep -qxF "$w" "$GMMU_OM"; then
32 echo "chan_diff: FAIL BAR0 branch line missing from chan/gmmu.om: $w"; exit 2
33 fi
34done
35
36t=$(mktemp -d /tmp/chan_diff.XXXXXX) || exit 2
37trap 'rm -rf "$t"' EXIT
38if [ -n "$CHAN_REF" ]; then
39 [ -s "$CHAN_REF" ] || { echo "chan_diff: FAIL CHAN_REF $CHAN_REF missing or empty"; exit 2; }
40 cp "$CHAN_REF" "$t/c.txt" || exit 2
41else
42 k=$AIENUX/native/kernel
43 if ! run cc -std=c11 -O1 -Wall -Werror -I"$k/gpu" -o "$t/ctrace" \
44 "$k/tests/gpu_chan_trace.c" "$k/gpu/gmmu.c" "$k/gpu/gpu_mem.c" "$k/gpu/gpu_chan.c" "$k/gpu/gpu_sim.c"; then
45 echo "chan_diff: FAIL C reference build"; exit 2
46 fi
47 run "$t/ctrace" > "$t/c.txt" || { echo "chan_diff: FAIL C reference run"; exit 2; }
48fi
49if ! cat "$here/chan/dma.om" "$GMMU_OM" "$MEM_OM" "$CHAN_OM" "$GSIM_OM" "$here/tests/chan_trace.om" | run "$OMC" > "$t/omtrace"; then
50 echo "chan_diff: FAIL omc build"; exit 3
51fi
52chmod +x "$t/omtrace"
53run "$t/omtrace" > "$t/om.txt"
54rc=$?
55if [ "$rc" -ne 0 ]; then
56 echo "chan_diff: FAIL om trace exit $rc"; exit 1
57fi
58n=$(wc -l < "$t/c.txt")
59if [ "$n" -eq 0 ]; then
60 echo "chan_diff: FAIL empty C trace"; exit 2
61fi
62if ! cmp -s "$t/c.txt" "$t/om.txt"; then
63 echo "chan_diff: FAIL traces differ ($(diff "$t/c.txt" "$t/om.txt" | grep -c '^[<>]') differing lines; C $n lines, om $(wc -l < "$t/om.txt"))"
64 exit 1
65fi
66echo "chan_diff: PASS ($n lines identical, .om vs C reference)"