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/')"
35 # Both libguestfs and virt-manager choose cpu=host when we think that
36 # KVM is available, and default otherwise. Although testing for KVM
37 # is hairy, I found that on aarch64 it can fail unless we choose
39 if test -r /dev/kvm; then
43 # Default machine and CPU type depends on arch. You can override this
44 # using -m|--machine and --cpu options.
45 case "$canonical_arch" in
51 if [ "$cpu" = "" ]; then cpu=cortex-a57; fi
57 # Handle command line parsing.
60 echo "qemu-sanity-check [options]"
62 echo " --help Display this help"
63 echo " --accel=[kvm|tcg] Force KVM or software emulation"
64 echo " --cpu=cpu Set CPU"
65 echo " -i|--initrd=initrd Set location of initramfs"
66 echo " -k|--kernel=vmlinuz Set location of kernel"
67 echo " -m|--machine=machine Set machine type"
68 echo " -q|--qemu=qemu Set location of qemu/KVM binary"
69 echo " -t|--timeout=timeout Set the timeout"
70 echo " -v|--verbose Verbose output"
71 echo " -V|--version Display version and exit"
87 -n 'qemu-sanity-check' -- "$@")
88 if [ $? != 0 ]; then exit 2; fi
129 echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"
137 echo "$0: internal error parsing options: $1"
144 if [ ! -r "$initrd" ]; then
145 echo "$0: cannot find 'initrd', try using --initrd=/path/to/initrd"
146 echo "If you are running qemu-sanity-check without installing, then do:"
147 echo " $0 --initrd=./initrd $@"
148 echo "The default path is '@libdir@/initrd'."
152 # Locate kernel if not specified.
153 if [ -z "$kernel" ]; then
154 kernel="$(ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen | head -1)"
155 if [ -z "$kernel" ]; then
156 echo "$0: cannot find a Linux kernel in /boot"
157 echo "Choose a kernel to test using --kernel=/path/to/vmlinuz"
161 if [ ! -r "$kernel" ]; then
162 echo "$0: kernel $kernel is not readable"
166 # Locate qemu if not specified.
167 if [ -z "$qemu" ]; then
168 for q in @QEMU_LIST@; do
169 if "$q" --help >/dev/null 2>&1; then
174 if [ -z "$qemu" ]; then
175 echo "$0: cannot find a qemu binary on the \$PATH"
176 echo "Choose a qemu binary to test using --qemu=/path/to/qemu"
181 # Choose a temporary file for the output.
182 test_output="$(mktemp --suff=.out)"
184 # Generate the parameters for the qemu command.
187 argv[$((i++))]="$qemu"
188 argv[$((i++))]="-display"
189 argv[$((i++))]="none"
190 argv[$((i++))]="-no-user-config"
191 argv[$((i++))]="-nodefaults"
192 argv[$((i++))]="-machine"
193 argv[$((i++))]="$machine${machine:+,}accel=$accel"
194 if [ "$cpu" != "" ]; then
195 argv[$((i++))]="-cpu"
196 argv[$((i++))]="$cpu"
199 argv[$((i++))]="$memory"
200 argv[$((i++))]="-no-reboot"
201 argv[$((i++))]="-serial"
202 argv[$((i++))]="file:$test_output"
203 argv[$((i++))]="-kernel"
204 argv[$((i++))]="$kernel"
205 argv[$((i++))]="-initrd"
206 argv[$((i++))]="$initrd"
207 argv[$((i++))]="-append"
208 argv[$((i++))]="console=$console oops=panic panic=-1"
210 if [ "$verbose" = "yes" ]; then
215 timeout "$timeout" "${argv[@]}"
217 if [ $r -eq 124 ]; then
219 echo "$0: error: test $kernel on $qemu: timed out"
222 elif [ $r -ne 0 ]; then
224 echo "$0: error: test $kernel on $qemu: failed"
229 # Verify that userspace was reached.
230 if ! grep -sq "initrd started up OK" "$test_output"; then
232 echo "$0: error: test $kernel on $qemu: init process did not start up"