omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / tests / mmio_diff.sh
| 1 | #!/bin/sh |
| 2 | # mmio_diff.sh: builds the .om GSP start-up trace (gsp/mmio.om + gsp/sim.om + tests/mmio_trace.om) and the |
| 3 | # C reference trace (aienux PR #441 tests/gsp_boot_trace.c + gpu/gsp_mmio.c + gpu/gsp_sim.c, compiled |
| 4 | # fresh into a temp dir as a test-only referee) and requires byte-identical stdout. Host only. |
| 5 | # Env: AIENUX (aienux checkout), OMC (pinned omc), MMIO_OM (driver file to test; mutants use this). |
| 6 | set -u |
| 7 | here=$(cd "$(dirname "$0")/.." && pwd) |
| 8 | AIENUX=${AIENUX:-/home/drakestapleton/work/OwnDriver/aienux} |
| 9 | OMC=${OMC:-$here/build/omc} |
| 10 | MMIO_OM=${MMIO_OM:-$here/gsp/mmio.om} |
| 11 | OMC_SHA=$(sed -n 's/^OMC_SHA256=//p' "$here/tools/omc.pin") |
| 12 | run() { nice -n 19 taskset -c "${AIEN_TEST_CPUS:-0-9,15-19}" "$@"; } |
| 13 | |
| 14 | got=$(sha256sum "$OMC" | cut -d' ' -f1) |
| 15 | if [ "$got" != "$OMC_SHA" ]; then |
| 16 | echo "mmio_diff: FAIL omc sha256 $got, pinned $OMC_SHA"; exit 2 |
| 17 | fi |
| 18 | # The host trace must stay on the simulator: mode 0 only, no device words in the test driver, |
| 19 | # while the BAR0 (mode 1) branch stays present in the driver. |
| 20 | if grep -n 'gspmode [0-9]* [1-9]\|gspbar\|vfio\|mapnew\|/dev/\|/sys/' "$here/tests/mmio_trace.om"; then |
| 21 | echo "mmio_diff: FAIL test driver leaves simulator mode or names a device"; exit 2 |
| 22 | fi |
| 23 | for w in 'ret mapget get gspbar 0 off 4' 'r = mapset get gspbar 0 off 4 v' 'r = sleepns get gsppns 0'; do |
| 24 | if ! grep -qxF "$w" "$here/gsp/mmio.om"; then |
| 25 | echo "mmio_diff: FAIL BAR0 branch line missing from gsp/mmio.om: $w"; exit 2 |
| 26 | fi |
| 27 | done |
| 28 | |
| 29 | t=$(mktemp -d /tmp/mmio_diff.XXXXXX) || exit 2 |
| 30 | trap 'rm -rf "$t"' EXIT |
| 31 | k=$AIENUX/native/kernel |
| 32 | if ! run cc -std=c11 -O1 -Wall -Werror -I"$k/gpu" -o "$t/ctrace" \ |
| 33 | "$k/tests/gsp_boot_trace.c" "$k/gpu/gsp_mmio.c" "$k/gpu/gsp_sim.c"; then |
| 34 | echo "mmio_diff: FAIL C reference build"; exit 2 |
| 35 | fi |
| 36 | run "$t/ctrace" > "$t/c.txt" || { echo "mmio_diff: FAIL C reference run"; exit 2; } |
| 37 | if ! cat "$MMIO_OM" "$here/gsp/sim.om" "$here/tests/mmio_trace.om" | run "$OMC" > "$t/omtrace"; then |
| 38 | echo "mmio_diff: FAIL omc build"; exit 3 |
| 39 | fi |
| 40 | chmod +x "$t/omtrace" |
| 41 | run "$t/omtrace" > "$t/om.txt" |
| 42 | rc=$? |
| 43 | if [ "$rc" -ne 0 ]; then |
| 44 | echo "mmio_diff: FAIL om trace exit $rc"; exit 1 |
| 45 | fi |
| 46 | n=$(wc -l < "$t/c.txt") |
| 47 | if [ "$n" -eq 0 ]; then |
| 48 | echo "mmio_diff: FAIL empty C trace"; exit 2 |
| 49 | fi |
| 50 | if ! cmp -s "$t/c.txt" "$t/om.txt"; then |
| 51 | echo "mmio_diff: FAIL traces differ ($(diff "$t/c.txt" "$t/om.txt" | grep -c '^[<>]') differing lines; C $n lines, om $(wc -l < "$t/om.txt"))" |
| 52 | exit 1 |
| 53 | fi |
| 54 | echo "mmio_diff: PASS ($n lines identical, $(grep -c '^==' "$t/c.txt") scenarios, .om vs C reference)" |