#!/bin/sh
# DF-2212 rig - RUN on the FIXED kernel (ttm_module.c + fix.diff: the
# dead wait_event removed). Expected: trigger returns immediately,
# init/exit cycles work, nothing blocks, no behavior change elsewhere.
set -e
L=/tmp/poc/DF-2212/run_fixed.log

{
echo "===== DF-2212 FIXED run $(date) ====="
uname -a
sha256 -q /usr/src/sys/dev/drm/ttm/ttm_module.c
echo "--- control: boot check ---"
dmesg | grep 'df_ttm2212: BOOT CHECK' | tail -1
sysctl hw.df_ttm2212.status

echo "--- trigger: the sysctl command itself must COMPLETE now ---"
time sysctl -w hw.df_ttm2212.trigger=1
echo "trigger rc=$?"
cat /tmp/poc/DF-2212/trigger_fixed.out 2>/dev/null

echo "--- rig status after trigger ---"
sysctl hw.df_ttm2212.status

echo "--- 500 x (ttm_init; ttm_exit) cycles ---"
sysctl -w hw.df_ttm2212.cycle=500
sysctl hw.df_ttm2212.status

echo "--- a second trigger for good measure ---"
sysctl -w hw.df_ttm2212.trigger=1
sysctl hw.df_ttm2212.status

echo "--- no stuck sysctl processes ---"
ps -axo pid,stat,comm 2>/dev/null | grep '[s]ysctl' || echo "(none)"
echo "--- kernel log tail ---"
dmesg | grep 'df_ttm2212' | tail -10
echo "===== FIXED run complete $(date) ====="
} 2>&1 | tee $L
