#!/bin/sh
# run.sh — Reproduce DF-0886 (autofs_node_vn create race panic).
#
# Prerequisites (run once as root):
#   kldload autofs
#   mkdir -p /autofs_test
#   mount_autofs -f autofs_race "" /autofs_test
#
# Then:
#   ./run.sh
#
# Expected on UNPATCHED kernel:
#   Kernel panic: "lost race" at autofs_node_vn+0xNNN
#   Guest drops to DDB (db> prompt)
#
# Expected on FIXED kernel (fix.diff applied):
#   All 4 racers print "autofs_node_vn rc=0 vp=<addr>" with the SAME vp
#   Module loads successfully, no panic, guest stays up.
#
echo "=== DF-0886: autofs_node_vn create race ==="
echo "Loading race harness (4 concurrent kthreads call autofs_node_vn)..."
echo "On UNPATCHED kernel: expect panic 'lost race'"
echo "On FIXED kernel: expect all racers to complete cleanly"
echo ""
kldload /root/df0886/df0886_race.ko 2>&1
rc=$?
echo ""
echo "kldload rc=$rc"
if [ $rc -eq 0 ]; then
    echo "RESULT: NO PANIC — fix is working (or check boot.log for racer output)"
    # Racer kprintf output goes to the serial console, check dmesg
    dmesg | grep "DF-0886 racer" | tail -5
else
    echo "RESULT: module load failed — check dmesg/boot.log"
fi
