4 # Copyright (C) 2013 Red Hat Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 exec_prefix="@exec_prefix@"
22 initrd="@libdir@/qemu-sanity-check/initrd"
25 canonical_arch="$(uname -m | sed 's/i[456]86/i386/')"
30 # Handle command line parsing.
33 echo "qemu-sanity-check [options]"
35 echo " --help Display this help"
36 echo " --accel=[kvm|tcg] Force KVM or software emulation"
37 echo " -i|--initrd=initrd Set location of initramfs"
38 echo " -k|--kernel=vmlinuz Set location of kernel"
39 echo " -q|--qemu=qemu Set location of qemu/KVM binary"
40 echo " -t|--timeout=timeout Set the timeout"
41 echo " -V|--version Display version and exit"
54 -n 'qemu-sanity-check' -- "$@")
55 if [ $? != 0 ]; then exit 2; fi
84 echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"
92 echo "$0: internal error parsing options: $1"
99 if [ ! -r "$initrd" ]; then
100 echo "$0: cannot find 'initrd', try using --initrd=/path/to/initrd"
101 echo "If you are running qemu-sanity-check without installing, then do:"
102 echo " $0 --initrd=./initrd $@"
103 echo "The default path is '@libdir@/initrd'."
107 # Locate kernel if not specified.
108 if [ -z "$kernel" ]; then
109 kernel="$(ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen | head -1)"
110 if [ -z "$kernel" ]; then
111 echo "$0: cannot find a Linux kernel in /boot"
112 echo "Choose a kernel to test using --kernel=/path/to/vmlinuz"
116 if [ ! -r "$kernel" ]; then
117 echo "$0: kernel $kernel is not readable"
121 # Locate qemu if not specified.
122 if [ -z "$qemu" ]; then
123 for q in @QEMU_LIST@; do
124 if "$q" --help >/dev/null 2>&1; then
129 if [ -z "$qemu" ]; then
130 echo "$0: cannot find a qemu binary on the \$PATH"
131 echo "Choose a qemu binary to test using --qemu=/path/to/qemu"
136 # Choose a temporary file for the output.
137 test_output="$(mktemp --suff=.out)"
139 # Generate the parameters for the qemu command.
142 argv[$((i++))]="$qemu"
143 argv[$((i++))]="-nographic"
144 argv[$((i++))]="-nodefconfig"
145 argv[$((i++))]="-nodefaults"
146 argv[$((i++))]="-machine"
147 argv[$((i++))]="accel=$accel"
148 argv[$((i++))]="-no-reboot"
149 argv[$((i++))]="-serial"
150 argv[$((i++))]="file:$test_output"
151 argv[$((i++))]="-kernel"
152 argv[$((i++))]="$kernel"
153 argv[$((i++))]="-initrd"
154 argv[$((i++))]="$initrd"
155 argv[$((i++))]="-append"
156 argv[$((i++))]="console=ttyS0 oops=panic panic=-1"
161 timeout "$timeout" "${argv[@]}"
163 if [ $r -eq 124 ]; then
165 echo "$0: error: test $kernel on $qemu: timed out"
168 elif [ $r -ne 0 ]; then
170 echo "$0: error: test $kernel on $qemu: failed"
175 # Verify that userspace was reached.
176 if ! grep -sq "initrd started up OK" "$test_output"; then
178 echo "$0: error: test $kernel on $qemu: init process did not start up"