#!/bin/sh
# RUN-D: FIXED iicbus.ko (this pack's fix.diff) -- all four defects gone.
set -e
cd /root/df5632

echo "=== load FIXED chain ==="
kldload /usr/obj/root/df5632/mod_fixed/s/iicbus/iicbus.ko
kldload /boot/kernel/iicbb.ko
kldload /usr/obj/root/df5632/build_reg/iicbb_reg.ko
kldload /usr/obj/root/df5632/build_rig/df5632_rig.ko
sleep 1

echo "=== stat ==="
./dfctl stat
echo "=== addchild (BUS_ADD_CHILD must return a real device_t: no panic, real child) ==="
./dfctl addchild
echo "=== ivar round trip (write 0x42 -> read 0x42) ==="
./dfctl ivar
echo "=== create the controllable child, then cycle 2: trio must NOT grow ==="
./dfctl failchild
./dfctl cycle 2
./dfctl stat
echo "=== busy child must FAIL the bus detach (rc=16 EBUSY, bus stays attached) ==="
sysctl hw.df5632.childbusy=1
./dfctl detach_bus
./dfctl stat
echo "=== bus still healthy: request/release works (bus is ATTACHED) ==="
sysctl hw.df5632.childbusy=0
./dfctl reqbus
echo "=== teardown ==="
kldunload df5632_rig
kldunload iicbb_reg
kldunload iicbb
kldunload iicbus
sleep 1
kldstat | tail -4
echo RUN-D-DONE
