# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+prefix="@prefix@"
+exec_prefix="@exec_prefix@"
+initrd="@libdir@/initrd"
+
+arch="$(uname -m)"
+canonical_arch="$(uname -m | sed 's/i[456]86/i386/')"
+
+#timeout=10m
+
# Handle command line parsing.
function usage {
echo "qemu-sanity-check [options]"
echo "Options:"
- echo " --help Display this help"
- echo " --version Display version and exit"
+ echo " --help Display this help"
+ echo " -i|--initrd=initrd Set location of initramfs"
+ echo " -k|--kernel=vmlinuz Set location of kernel"
+ echo " -q|--qemu=qemu Set location of qemu/KVM binary"
+# echo " -t|--timeout=timeout Set the timeout"
+ echo " -V|--version Display version and exit"
exit 0
}
TEMP=$(getopt \
- -o v \
+ -o i:k:q:V \
--long help \
+ --long initrd: \
+ --long kernel: \
+ --long qemu: \
--long version \
-n 'qemu-sanity-check' -- "$@")
-if [ $? != 0 ]; then exit 1; fi
+if [ $? != 0 ]; then exit 2; fi
eval set -- "$TEMP"
while true; do
case "$1" in
- --help) usage ;;
- -v|--version) echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"; exit 0 ;;
- --) shift; break ;;
- *) fail "internal error ($1)" ;;
+ --help)
+ usage
+ ;;
+ -i|--initrd)
+ initrd="$2"
+ shift 2
+ ;;
+ -k|--kernel)
+ kernel="$2"
+ shift 2
+ ;;
+ -q|--qemu)
+ qemu="$2"
+ shift 2
+ ;;
+# -t|--timeout)
+# timeout="$2"
+# shift 2
+# ;;
+ -V|--version)
+ echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"
+ exit 0
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ echo "$0: internal error parsing options: $1"
+ exit 2
+ ;;
esac
done
+
+# Locate initrd.
+if [ ! -f "$initrd" ]; then
+ echo "$0: cannot find 'initrd', try using --initrd=/path/to/initrd"
+ echo "If you are running qemu-sanity-check without installing, then do:"
+ echo " $0 --initrd=./initrd $@"
+ echo "The default path is '@libdir@/initrd'."
+ exit 2
+fi
+
+# Locate kernel if not specified.
+if [ -z "$kernel" ]; then
+ kernel="$(ls -vr /boot/vmlinuz-*.$arch | head -1)"
+ if [ -z "$kernel" ]; then
+ echo "$0: cannot find a Linux kernel in /boot"
+ echo "Choose a kernel to test using --kernel=/path/to/vmlinuz"
+ exit 2
+ fi
+fi
+
+# Locate qemu if not specified.
+if [ -z "$qemu" ]; then
+ for q in qemu-kvm qemu-system-$canonical_arch qemu kvm; do
+ if "$q" --help >/dev/null 2>&1; then
+ qemu="$q"
+ break
+ fi
+ done
+ if [ -z "$qemu" ]; then
+ echo "$0: cannot find a qemu binary on the \$PATH"
+ echo "Choose a qemu binary to test using --qemu=/path/to/qemu"
+ exit 2
+ fi
+fi
+
+# Choose a temporary file for the output.
+test_output="$(mktemp --suff=.out)"
+
+# Run the command
+set -x
+#timeout "$timeout"
+"$qemu" \
+ -nographic -nodefconfig -nodefaults \
+ -no-reboot \
+ -serial stdio \
+ -kernel "$kernel" \
+ -initrd "$initrd" \
+ -append "console=ttyS0 panic=1" 2>&1 | tee "$test_output"
+r="${PIPESTATUS[0]}"
+set +x
+#if [ $r -eq 124 ]; then
+# cat "$test_output"
+# echo "$0: error: test $kernel on $qemu: timed out"
+# rm "$test_output"
+# exit 1
+if [ $r -ne 0 ]; then
+ cat "$test_output"
+ echo "$0: error: test $kernel on $qemu: failed"
+ rm "$test_output"
+ exit 1
+fi
+
+# Verify that userspace was reached.
+if ! grep -sq "initrd started up OK" "$test_output"; then
+ cat "$test_output"
+ echo "$0: error: test $kernel on $qemu: init process did not start up"
+ rm "$test_output"
+ exit 1
+fi
+
+# Successful.
+rm "$test_output"
+exit 0