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