From: Richard W.M. Jones Date: Tue, 20 Aug 2013 16:02:20 +0000 (+0100) Subject: Implement timeout, and add several tests. X-Git-Tag: v1.1.1~6 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=631427cddbf02bbee26b6933ae188f08868ab57f;p=qemu-sanity-check.git Implement timeout, and add several tests. --- diff --git a/Makefile.am b/Makefile.am index caf4011..38dd3cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -55,4 +55,10 @@ qemu-sanity-check.1: qemu-sanity-check.pod 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 diff --git a/qemu-sanity-check.in b/qemu-sanity-check.in index da4f59a..3fc9cea 100644 --- a/qemu-sanity-check.in +++ b/qemu-sanity-check.in @@ -24,7 +24,7 @@ initrd="@libdir@/initrd" arch="$(uname -m)" canonical_arch="$(uname -m | sed 's/i[456]86/i386/')" -#timeout=10m +timeout=10m # Handle command line parsing. @@ -35,17 +35,18 @@ function usage { 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 @@ -68,10 +69,10 @@ while true; do 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 @@ -88,7 +89,7 @@ while true; do 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 $@" @@ -105,6 +106,10 @@ if [ -z "$kernel" ]; then 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 @@ -124,24 +129,34 @@ 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" +# 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" diff --git a/qemu-sanity-check.pod.in b/qemu-sanity-check.pod.in index da3f237..f7629bb 100644 --- a/qemu-sanity-check.pod.in +++ b/qemu-sanity-check.pod.in @@ -81,6 +81,15 @@ kernel installed in C. Use the qemu (or KVM) binary C 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 is described in full in the man page for +L. + =item B<-V> =item B<--version> @@ -110,16 +119,6 @@ test that userspace has been reached. =back -=head1 BUGS - -=head2 TIMEOUTS - -Timeouts don't currently work because of some oddness with the -coreutils L program and qemu. Instead you should run the -whole script with a timeout, like this: - - timeout 10m qemu-sanity-check - =head1 SEE ALSO L, diff --git a/run-qemu-sanity-check b/run-qemu-sanity-check index 4553653..71184f7 100755 --- a/run-qemu-sanity-check +++ b/run-qemu-sanity-check @@ -17,4 +17,4 @@ # 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 "$@" diff --git a/sleeper b/sleeper new file mode 100755 index 0000000..d8f601a --- /dev/null +++ b/sleeper @@ -0,0 +1,21 @@ +#!/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 diff --git a/test-bad-kernel b/test-bad-kernel new file mode 100755 index 0000000..d5716d5 --- /dev/null +++ b/test-bad-kernel @@ -0,0 +1,25 @@ +#!/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 diff --git a/test-bad-options b/test-bad-options new file mode 100755 index 0000000..5e31ec6 --- /dev/null +++ b/test-bad-options @@ -0,0 +1,39 @@ +#!/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 diff --git a/test-bad-qemu b/test-bad-qemu new file mode 100755 index 0000000..f8ddcd2 --- /dev/null +++ b/test-bad-qemu @@ -0,0 +1,28 @@ +#!/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 diff --git a/test-bad-userspace b/test-bad-userspace new file mode 100755 index 0000000..cbd62f1 --- /dev/null +++ b/test-bad-userspace @@ -0,0 +1,27 @@ +#!/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 diff --git a/test-timeout b/test-timeout new file mode 100755 index 0000000..0cfb6f5 --- /dev/null +++ b/test-timeout @@ -0,0 +1,27 @@ +#!/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