#!/bin/sh
# DF-1927 harness run script.
# Runs both variants and prints a clear PASS/FAIL verdict.
cd "$(dirname "$0")"

echo "==================================================================="
echo "DF-1927: UAF race in drm_sched_entity_fini via broken kthread_park"
echo "==================================================================="
echo ""
echo "=== BUGGY model (faithful to DFly linux_kthread.c:104-110) ==="
echo "Expected: race fires in most/all iterations (Race A: spsc_queue"
echo "          double-pop -> job UAF)."
echo ""
./df1927_race
buggy_rc=$?
echo ""
echo "=== FIXED model (synchronous kthread_park, upstream Linux semantics) ==="
echo "Expected: race NEVER fires (the kthread_park barrier is now a true"
echo "          synchronization point; fini cannot proceed until the"
echo "          scheduler has parked at drm_sched_blocked)."
echo ""
./df1927_race_fixed
fixed_rc=$?
echo ""
echo "==================================================================="
if [ "$buggy_rc" -eq 0 ] && [ "$fixed_rc" -eq 0 ]; then
    echo "VERDICT: BUG confirmed in buggy model, CLOSED in fixed model."
    echo "         (DF-1927 race condition exists; fix.diff closes it.)"
else
    echo "VERDICT: UNEXPECTED -- buggy_rc=$buggy_rc fixed_rc=$fixed_rc"
    echo "  (buggy should exit 0 = race detected; fixed should exit 0 = none)"
fi
echo "==================================================================="
