4 # Copyright (C) 2013-2020 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/')"
34 # Both libguestfs and virt-manager choose cpu=host when we think that
35 # KVM is available, and default otherwise. Although testing for KVM
36 # is hairy, I found that on aarch64 it can fail unless we choose
38 if test -r /dev/kvm; then
42 # Default machine and CPU type depends on arch. You can override this
43 # using -m|--machine and --cpu options.
44 case "$canonical_arch" in
48 if [ "$cpu" = "" ]; then cpu=cortex-a57; fi
52 # Handle command line parsing.
55 echo "qemu-sanity-check [options]"
57 echo " --help Display this help"
58 echo " --accel=[kvm|tcg] Force KVM or software emulation"
59 echo " --cpu=cpu Set CPU"
60 echo " -i|--initrd=initrd Set location of initramfs"
61 echo " -k|--kernel=vmlinuz Set location of kernel"
62 echo " -m|--machine=machine Set machine type"
63 echo " -q|--qemu=qemu Set location of qemu/KVM binary"
64 echo " -t|--timeout=timeout Set the timeout"
65 echo " -v|--verbose Verbose output"
66 echo " -V|--version Display version and exit"
82 -n 'qemu-sanity-check' -- "$@")
83 if [ $? != 0 ]; then exit 2; fi
124 echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"
132 echo "$0: internal error parsing options: $1"
139 if [ ! -r "$initrd" ]; then
140 echo "$0: cannot find 'initrd', try using --initrd=/path/to/initrd"
141 echo "If you are running qemu-sanity-check without installing, then do:"
142 echo " $0 --initrd=./initrd $@"
143 echo "The default path is '@libdir@/initrd'."
147 # Locate kernel if not specified.
148 if [ -z "$kernel" ]; then
149 kernel="$(ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen | head -1)"
150 if [ -z "$kernel" ]; then
151 echo "$0: cannot find a Linux kernel in /boot"
152 echo "Choose a kernel to test using --kernel=/path/to/vmlinuz"
156 if [ ! -r "$kernel" ]; then
157 echo "$0: kernel $kernel is not readable"
161 # Locate qemu if not specified.
162 if [ -z "$qemu" ]; then
163 for q in @QEMU_LIST@; do
164 if "$q" --help >/dev/null 2>&1; then
169 if [ -z "$qemu" ]; then
170 echo "$0: cannot find a qemu binary on the \$PATH"
171 echo "Choose a qemu binary to test using --qemu=/path/to/qemu"
176 # Choose a temporary file for the output.
177 test_output="$(mktemp --suff=.out)"
179 # Generate the parameters for the qemu command.
182 argv[$((i++))]="$qemu"
183 argv[$((i++))]="-display"
184 argv[$((i++))]="none"
185 argv[$((i++))]="-no-user-config"
186 argv[$((i++))]="-nodefaults"
187 argv[$((i++))]="-machine"
188 argv[$((i++))]="$machine${machine:+,}accel=$accel"
189 if [ "$cpu" != "" ]; then
190 argv[$((i++))]="-cpu"
191 argv[$((i++))]="$cpu"
194 argv[$((i++))]="$memory"
195 argv[$((i++))]="-no-reboot"
196 argv[$((i++))]="-serial"
197 argv[$((i++))]="file:$test_output"
198 argv[$((i++))]="-kernel"
199 argv[$((i++))]="$kernel"
200 argv[$((i++))]="-initrd"
201 argv[$((i++))]="$initrd"
202 argv[$((i++))]="-append"
203 argv[$((i++))]="console=ttyS0 oops=panic panic=-1"
205 if [ "$verbose" = "yes" ]; then
210 timeout "$timeout" "${argv[@]}"
212 if [ $r -eq 124 ]; then
214 echo "$0: error: test $kernel on $qemu: timed out"
217 elif [ $r -ne 0 ]; then
219 echo "$0: error: test $kernel on $qemu: failed"
224 # Verify that userspace was reached.
225 if ! grep -sq "initrd started up OK" "$test_output"; then
227 echo "$0: error: test $kernel on $qemu: init process did not start up"