endif
# Tests.
-TESTS = run-qemu-sanity-check
+TESTS = \
+ run-qemu-sanity-check \
+ test-timeout \
+ test-bad-options \
+ test-bad-kernel \
+ test-bad-qemu \
+ test-bad-userspace
arch="$(uname -m)"
canonical_arch="$(uname -m | sed 's/i[456]86/i386/')"
-#timeout=10m
+timeout=10m
# Handle command line parsing.
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 " -t|--timeout=timeout Set the timeout"
echo " -V|--version Display version and exit"
exit 0
}
TEMP=$(getopt \
- -o i:k:q:V \
+ -o i:k:q:t:V \
--long help \
--long initrd: \
--long kernel: \
--long qemu: \
+ --long timeout: \
--long version \
-n 'qemu-sanity-check' -- "$@")
if [ $? != 0 ]; then exit 2; fi
qemu="$2"
shift 2
;;
-# -t|--timeout)
-# timeout="$2"
-# shift 2
-# ;;
+ -t|--timeout)
+ timeout="$2"
+ shift 2
+ ;;
-V|--version)
echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"
exit 0
done
# Locate initrd.
-if [ ! -f "$initrd" ]; then
+if [ ! -r "$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 $@"
exit 2
fi
fi
+if [ ! -r "$kernel" ]; then
+ echo "$0: kernel $kernel is not readable"
+ exit 2
+fi
# Locate qemu if not specified.
if [ -z "$qemu" ]; then
# 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"
+# Generate the parameters for the qemu command.
+declare -a argv
+i=0
+argv[$((i++))]="$qemu"
+argv[$((i++))]="-nographic"
+argv[$((i++))]="-nodefconfig"
+argv[$((i++))]="-nodefaults"
+argv[$((i++))]="-no-reboot"
+argv[$((i++))]="-serial"
+argv[$((i++))]="file:$test_output"
+argv[$((i++))]="-kernel"
+argv[$((i++))]="$kernel"
+argv[$((i++))]="-initrd"
+argv[$((i++))]="$initrd"
+argv[$((i++))]="-append"
+argv[$((i++))]="console=ttyS0 panic=1"
+
+#echo "${argv[@]}"
+
+# Run the command.
+timeout "$timeout" "${argv[@]}"
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
+if [ $r -eq 124 ]; then
+ cat "$test_output"
+ echo "$0: error: test $kernel on $qemu: timed out"
+ rm "$test_output"
+ exit 1
+elif [ $r -ne 0 ]; then
cat "$test_output"
echo "$0: error: test $kernel on $qemu: failed"
rm "$test_output"
Use the qemu (or KVM) binary C<QEMU> instead of searching C<$PATH> for
a suitable binary.
+=item B<-t> TIMEOUT
+
+=item B<--timeout>=TIMEOUT
+
+Specify a timeout instead of the default which is C<10m> (10 minutes).
+
+The syntax for the C<TIMEOUT> is described in full in the man page for
+L<timeout(1)>.
+
=item B<-V>
=item B<--version>
=back
-=head1 BUGS
-
-=head2 TIMEOUTS
-
-Timeouts don't currently work because of some oddness with the
-coreutils L<timeout(1)> program and qemu. Instead you should run the
-whole script with a timeout, like this:
-
- timeout 10m qemu-sanity-check
-
=head1 SEE ALSO
L<http://qemu.org>,
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-./qemu-sanity-check --initrd=./initrd
+./qemu-sanity-check --initrd=./initrd "$@"
--- /dev/null
+#!/bin/bash
+# -*- shell-script -*-
+# sleeper
+# Copyright (C) 2013 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# This script is used by the tests as a fake qemu. It just sleeps forever.
+while true; do sleep 1000000; done
--- /dev/null
+#!/bin/bash
+# -*- shell-script -*-
+# test-bad-kernel
+# Copyright (C) 2013 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+./run-qemu-sanity-check --kernel=/dev/null
+r=$?
+if [ $r -ne 1 ]; then
+ echo "$0: unexpected exit code $r (expecting 1)"
+ exit 1
+fi
--- /dev/null
+#!/bin/bash
+# -*- shell-script -*-
+# test-bad-options
+# Copyright (C) 2013 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+./qemu-sanity-check --foobar
+r=$?
+if [ $r -ne 2 ]; then
+ echo "$0: bad argument: unexpected exit code $r (expecting 2)"
+ exit 1
+fi
+
+./qemu-sanity-check --kernel=/nosuchfile
+r=$?
+if [ $r -ne 2 ]; then
+ echo "$0: missing kernel: unexpected exit code $r (expecting 2)"
+ exit 1
+fi
+
+./qemu-sanity-check --initrd=/nosuchfile
+r=$?
+if [ $r -ne 2 ]; then
+ echo "$0: missing initrd: unexpected exit code $r (expecting 2)"
+ exit 1
+fi
--- /dev/null
+#!/bin/bash
+# -*- shell-script -*-
+# test-bad-qemu
+# Copyright (C) 2013 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# Choose a fake qemu which won't immediately fail, but also won't work
+# properly when it's run for real.
+
+./run-qemu-sanity-check --qemu=true
+r=$?
+if [ $r -ne 1 ]; then
+ echo "$0: unexpected exit code $r (expecting 1)"
+ exit 1
+fi
--- /dev/null
+#!/bin/bash
+# -*- shell-script -*-
+# test-bad-userspace
+# Copyright (C) 2013 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# Test what happens if the userspace (ie. initrd) is bad.
+
+./qemu-sanity-check --initrd=/dev/null
+r=$?
+if [ $r -ne 1 ]; then
+ echo "$0: unexpected exit code $r (expecting 1)"
+ exit 1
+fi
--- /dev/null
+#!/bin/bash
+# -*- shell-script -*-
+# test-timeout
+# Copyright (C) 2013 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# Check the --timeout option is functional.
+
+./run-qemu-sanity-check --timeout=10 --qemu=./sleeper
+r=$?
+if [ $r -ne 1 ]; then
+ echo "$0: unexpected exit code $r (expecting 1)"
+ exit 1
+fi