#!/bin/sh
#
# Reproduce PR 47720 in qemu, without the use of raidframe
#
# When the VM panics, it will reboot and be stuck at the
# login prompt for a one-hour timeout.  Scroll back past the
# boot messages to see the panic message.
#

mirror=ftp.netbsd.org
release=ftp://$mirror/pub/NetBSD/NetBSD-6.1.5/amd64/
workdir=./pr47720-work

mkdir -p $workdir/root

cat <<\EOF | sed -e "s!@RELEASE@!$release!" >$workdir/root/install-xen.sh
#!/bin/sh

set -ex

export PKG_PATH=ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/$(uname -m)/6.0/All

dhcpcd

pkg_add xenkernel42
cp /usr/pkg/xen*-kernel/xen.gz /

pkg_add xentools42
cp /usr/pkg/share/examples/rc.d/xendomains /etc/rc.d/
cp /usr/pkg/share/examples/rc.d/xend /etc/rc.d/
cp /usr/pkg/share/examples/rc.d/xencommons /etc/rc.d/
cp /usr/pkg/share/examples/rc.d/xen-watchdog /etc/rc.d/

cd /
for dom in 0 U
do
  ftp @RELEASE@binary/kernel/netbsd-XEN3_DOM${dom}.gz
done

ed /boot.cfg <<END
1
i
menu=Xen:load /netbsd-XEN3_DOM0.gz console=com0c;multiboot /xen.gz dom0_mem=256M console=com1 com1=9600,8n1
.
w
q
END

cat >>/etc/rc.conf <<END
xencommons=YES
END

halt -p
EOF

makefs -M 1m $workdir/img $workdir/root

anita --workdir $workdir --disk-size 4G install $release

anita --persist --workdir $workdir --memory-size 1G \
    --run "mount /dev/wd1a /mnt && sh /mnt/install-xen.sh" --vmm-args "--hdb $workdir/img" \
    boot $release
echo "Python EOF exception and stack trace above are expected, please ignore"

anita --persist --workdir $workdir --memory-size 1G --run "halt -p" boot $release
echo "Timeout above is expected, scroll back past boot messages for panic message"
