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/')"
29 # Handle command line parsing.
32 echo "qemu-sanity-check [options]"
34 echo " --help Display this help"
35 echo " -i|--initrd=initrd Set location of initramfs"
36 echo " -k|--kernel=vmlinuz Set location of kernel"
37 echo " -q|--qemu=qemu Set location of qemu/KVM binary"
38 echo " -t|--timeout=timeout Set the timeout"
39 echo " -V|--version Display version and exit"
51 -n 'qemu-sanity-check' -- "$@")
52 if [ $? != 0 ]; then exit 2; fi
77 echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"
85 echo "$0: internal error parsing options: $1"
92 if [ ! -r "$initrd" ]; then
93 echo "$0: cannot find 'initrd', try using --initrd=/path/to/initrd"
94 echo "If you are running qemu-sanity-check without installing, then do:"
95 echo " $0 --initrd=./initrd $@"
96 echo "The default path is '@libdir@/initrd'."
100 # Locate kernel if not specified.
101 if [ -z "$kernel" ]; then
102 kernel="$(ls -vr /boot/vmlinuz-*.$arch | head -1)"
103 if [ -z "$kernel" ]; then
104 echo "$0: cannot find a Linux kernel in /boot"
105 echo "Choose a kernel to test using --kernel=/path/to/vmlinuz"
109 if [ ! -r "$kernel" ]; then
110 echo "$0: kernel $kernel is not readable"
114 # Locate qemu if not specified.
115 if [ -z "$qemu" ]; then
116 for q in qemu-kvm qemu-system-$canonical_arch qemu kvm; do
117 if "$q" --help >/dev/null 2>&1; then
122 if [ -z "$qemu" ]; then
123 echo "$0: cannot find a qemu binary on the \$PATH"
124 echo "Choose a qemu binary to test using --qemu=/path/to/qemu"
129 # Choose a temporary file for the output.
130 test_output="$(mktemp --suff=.out)"
132 # Generate the parameters for the qemu command.
135 argv[$((i++))]="$qemu"
136 argv[$((i++))]="-nographic"
137 argv[$((i++))]="-nodefconfig"
138 argv[$((i++))]="-nodefaults"
139 argv[$((i++))]="-no-reboot"
140 argv[$((i++))]="-serial"
141 argv[$((i++))]="file:$test_output"
142 argv[$((i++))]="-kernel"
143 argv[$((i++))]="$kernel"
144 argv[$((i++))]="-initrd"
145 argv[$((i++))]="$initrd"
146 argv[$((i++))]="-append"
147 argv[$((i++))]="console=ttyS0 panic=1"
152 timeout "$timeout" "${argv[@]}"
154 if [ $r -eq 124 ]; then
156 echo "$0: error: test $kernel on $qemu: timed out"
159 elif [ $r -ne 0 ]; then
161 echo "$0: error: test $kernel on $qemu: failed"
166 # Verify that userspace was reached.
167 if ! grep -sq "initrd started up OK" "$test_output"; then
169 echo "$0: error: test $kernel on $qemu: init process did not start up"