#!/bin/sh
# cycle usb-kbd unplug/replug while kbdspam hammers console ioctls
i=0
while [ $i -lt ${1:-40} ]; do
  i=$((i+1))
  python3 /tmp/opencode/monrun.py "device_del k1" 0.8 >/dev/null 2>&1
  sleep 0.6
  python3 /tmp/opencode/monrun.py "device_add usb-kbd,id=k1" 0.8 >/dev/null 2>&1
  sleep 1.2
  ssh -F dfbsd-qemu/config -o ConnectTimeout=6 -o BatchMode=yes dfbsd-maxx "sh /tmp/rebind.sh" 2>/dev/null
  if ! dfbsd-qemu/vm.sh status >/dev/null 2>&1; then echo "GUEST DOWN at cycle $i"; exit 1; fi
done
echo "done $i cycles"
