#!/bin/sh
# DF-2005 — module-build validation of fix.diff
# (HW-gated finding: no AMD GPU on guest, so runtime PoC is impossible.
#  Instead we validate the fix by applying it to in-guest /usr/src/sys and
#  building amdgpu.ko with -Werror; rc=0 means the fix compiles & links.)
set -e

# 1. push fix.diff to guest (assumes dfbsd-qemu/config ssh alias)
scp -F dfbsd-qemu/config fix.diff dfbsd:/root/fix.diff

# 2. apply & build, sh-forced over ssh
ssh -F dfbsd-qemu/config dfbsd /bin/sh <<'EOF'
set -e
cd /usr/src
patch -p1 --forward < /root/fix.diff
echo "--- patched check_powerplay_tables: ---"
sed -n '64,90p' sys/dev/drm/amd/powerplay/hwmgr/vega12_processpptables.c
echo "--- building amdgpu.ko with -Werror ---"
cd sys/dev/drm/amd/amdgpu
make -DWERROR WERROR=-Werror COPTS=-Werror 2>&1 | tail -30
echo "AMDGPU_KMOD_MAKE_RC=${PIPESTATUS[0]:-$?}"
ls -l amdgpu.ko
EOF
