4 # Copyright (C) 2013-2024 Red Hat Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 exec_prefix="@exec_prefix@"
23 initrd="@libdir@/qemu-sanity-check/initrd"
26 canonical_arch="$(uname -m | sed 's/i[456]86/i386/')"
36 # Both libguestfs and virt-manager choose cpu=host when we think that
37 # KVM is available, and default otherwise. Although testing for KVM
38 # is hairy, I found that on aarch64 it can fail unless we choose
40 if test -r /dev/kvm; then
44 # Default machine and CPU type depends on arch. You can override this
45 # using -m|--machine and --cpu options.
46 case "$canonical_arch" in
52 if [ "$cpu" = "" ]; then cpu=cortex-a57; fi
58 # Handle command line parsing.
61 echo "qemu-sanity-check [options]"
63 echo " --help Display this help"
64 echo " --accel=[kvm|tcg] Force KVM or software emulation"
65 echo " --cpu=cpu Set CPU"
66 echo " -i|--initrd=initrd Set location of initramfs"
67 echo " -k|--kernel=vmlinuz Set location of kernel"
68 echo " -m|--machine=machine Set machine type"
69 echo " -q|--qemu=qemu Set location of qemu/KVM binary"
70 echo " -t|--timeout=timeout Set the timeout"
71 echo " -v|--verbose Verbose output"
72 echo " -V|--version Display version and exit"
88 -n 'qemu-sanity-check' -- "$@")
89 if [ $? != 0 ]; then exit 2; fi
130 echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"
138 echo "$0: internal error parsing options: $1"
145 if [ ! -r "$initrd" ]; then
146 echo "$0: cannot find 'initrd', try using --initrd=/path/to/initrd"
147 echo "If you are running qemu-sanity-check without installing, then do:"
148 echo " $0 --initrd=./initrd $@"
149 echo "The default path is '@libdir@/initrd'."
153 # Locate kernel if not specified.
154 if [ -z "$kernel" ]; then
156 if [ "$verbose" = "yes" ]; then
158 ls -1dvr /lib/modules/*/vmlinuz /boot/vmlinuz-*.$arch*
160 kernel="$(ls -1dvr /lib/modules/*/vmlinuz /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen | head -1)"
161 if [ -z "$kernel" ]; then
162 echo "$0: cannot find a Linux kernel in /boot"
163 echo "Choose a kernel to test using --kernel=/path/to/vmlinuz"
168 if [ ! -r "$kernel" ]; then
169 echo "$0: kernel $kernel is not readable"
173 # Locate qemu if not specified.
174 if [ -z "$qemu" ]; then
175 if [ "$verbose" = "yes" ]; then
176 echo "all qemus:" @QEMU_LIST@
178 for q in @QEMU_LIST@; do
179 if "$q" --help >/dev/null 2>&1; then
184 if [ -z "$qemu" ]; then
185 echo "$0: cannot find a qemu binary on the \$PATH"
186 echo "Choose a qemu binary to test using --qemu=/path/to/qemu"
191 # Choose a temporary file for the output.
192 test_output="$(mktemp --suff=.out)"
194 # Generate the parameters for the qemu command.
197 argv[$((i++))]="$qemu"
198 argv[$((i++))]="-display"
199 argv[$((i++))]="none"
200 argv[$((i++))]="-no-user-config"
201 argv[$((i++))]="-nodefaults"
202 argv[$((i++))]="-machine"
203 argv[$((i++))]="$machine${machine:+,}accel=$accel"
204 if [ "$cpu" != "" ]; then
205 argv[$((i++))]="-cpu"
206 argv[$((i++))]="$cpu"
209 argv[$((i++))]="$memory"
210 argv[$((i++))]="-no-reboot"
211 argv[$((i++))]="-serial"
212 argv[$((i++))]="file:$test_output"
213 argv[$((i++))]="-kernel"
214 argv[$((i++))]="$kernel"
215 argv[$((i++))]="-initrd"
216 argv[$((i++))]="$initrd"
217 argv[$((i++))]="-append"
218 argv[$((i++))]="console=$console oops=panic panic=-1"
220 if [ "$verbose" = "yes" ]; then
225 timeout "$timeout" "${argv[@]}"
227 if [ $r -eq 124 ]; then
229 echo "$0: error: test $kernel on $qemu: timed out"
232 elif [ $r -ne 0 ]; then
234 echo "$0: error: test $kernel on $qemu: failed"
239 if [ "$verbose" = "yes" ]; then
243 # Check if there was a kernel panic. Note that oops=panic is set
244 # which will force a reboot for any oops condition.
245 if grep -sq "Kernel panic - not syncing" "$test_output"; then
247 echo "$0: error: test $kernel on $qemu: kernel panic seen"
252 # Verify that userspace was reached.
253 if ! grep -sq "initrd started up OK" "$test_output"; then
255 echo "$0: error: test $kernel on $qemu: init process did not start up"