#!/bin/bash -

set -e
set -x

# A git clone of the watchdog test framework:
# http://git.annexia.org/?p=watchdog-test-framework.git;a=summary
# compiled on the host.
tf=/home/rjones/d/watchdog-test-framework

# The qemu binary we want to test.
qemu=/home/rjones/d/qemu/x86_64-softmmu/qemu-system-x86_64

# Build a CentOS 7.1 VM which will run the tests.
cd /tmp
virt-builder centos-7.1 \
    --upload $tf/watchdog-test:/root

for timeout in 60 120 250 270 500 520 1010 1030 2046 2500
do
    # Install a firstboot script which will run the test and
    # display output on the serial console.
    virt-customize -a centos-7.1.img \
        --firstboot-command "
            /root/watchdog-test --timeout $timeout --yes
    "

    # Boot the guest.
    $qemu -nodefconfig -nodefaults -display none \
          -machine pc,accel=kvm:tcg \
          -cpu host \
          -m 1024 \
          -hda centos-7.1.img \
          -watchdog i6300esb \
          -watchdog-action poweroff \
          -serial stdio
    echo
    echo === qemu exited ===
done
