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
155 if [ "$verbose" = "yes" ]; then
157 ls -1dvr /boot/vmlinuz-*.$arch*
159 kernel="$(ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen | head -1)"
160 if [ -z "$kernel" ]; then
161 echo "$0: cannot find a Linux kernel in /boot"
162 echo "Choose a kernel to test using --kernel=/path/to/vmlinuz"
166 if [ ! -r "$kernel" ]; then
167 echo "$0: kernel $kernel is not readable"
171 # Locate qemu if not specified.
172 if [ -z "$qemu" ]; then
173 if [ "$verbose" = "yes" ]; then
174 echo "all qemus:" @QEMU_LIST@
176 for q in @QEMU_LIST@; do
177 if "$q" --help >/dev/null 2>&1; then
182 if [ -z "$qemu" ]; then
183 echo "$0: cannot find a qemu binary on the \$PATH"
184 echo "Choose a qemu binary to test using --qemu=/path/to/qemu"
189 # Choose a temporary file for the output.
190 test_output="$(mktemp --suff=.out)"
192 # Generate the parameters for the qemu command.
195 argv[$((i++))]="$qemu"
196 argv[$((i++))]="-display"
197 argv[$((i++))]="none"
198 argv[$((i++))]="-no-user-config"
199 argv[$((i++))]="-nodefaults"
200 argv[$((i++))]="-machine"
201 argv[$((i++))]="$machine${machine:+,}accel=$accel"
202 if [ "$cpu" != "" ]; then
203 argv[$((i++))]="-cpu"
204 argv[$((i++))]="$cpu"
207 argv[$((i++))]="$memory"
208 argv[$((i++))]="-no-reboot"
209 argv[$((i++))]="-serial"
210 argv[$((i++))]="file:$test_output"
211 argv[$((i++))]="-kernel"
212 argv[$((i++))]="$kernel"
213 argv[$((i++))]="-initrd"
214 argv[$((i++))]="$initrd"
215 argv[$((i++))]="-append"
216 argv[$((i++))]="console=$console oops=panic panic=-1"
218 if [ "$verbose" = "yes" ]; then
223 timeout "$timeout" "${argv[@]}"
225 if [ $r -eq 124 ]; then
227 echo "$0: error: test $kernel on $qemu: timed out"
230 elif [ $r -ne 0 ]; then
232 echo "$0: error: test $kernel on $qemu: failed"
237 if [ "$verbose" = "yes" ]; then
241 # Check if there was a kernel panic. Note that oops=panic is set
242 # which will force a reboot for any oops condition.
243 if grep -sq "Kernel panic - not syncing" "$test_output"; then
245 echo "$0: error: test $kernel on $qemu: kernel panic seen"
250 # Verify that userspace was reached.
251 if ! grep -sq "initrd started up OK" "$test_output"; then
253 echo "$0: error: test $kernel on $qemu: init process did not start up"