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/')"
30 # Default machine type depends on arch. You can override this using
31 # -m|--machine option.
32 case "$canonical_arch" in
33 arm*|aarch*) machine=virt ;;
34 # On non-ARM let qemu pick the default.
38 # Handle command line parsing.
41 echo "qemu-sanity-check [options]"
43 echo " --help Display this help"
44 echo " --accel=[kvm|tcg] Force KVM or software emulation"
45 echo " -i|--initrd=initrd Set location of initramfs"
46 echo " -k|--kernel=vmlinuz Set location of kernel"
47 echo " -m|--machine=machine Set machine type"
48 echo " -q|--qemu=qemu Set location of qemu/KVM binary"
49 echo " -t|--timeout=timeout Set the timeout"
50 echo " -V|--version Display version and exit"
64 -n 'qemu-sanity-check' -- "$@")
65 if [ $? != 0 ]; then exit 2; fi
98 echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"
106 echo "$0: internal error parsing options: $1"
113 if [ ! -r "$initrd" ]; then
114 echo "$0: cannot find 'initrd', try using --initrd=/path/to/initrd"
115 echo "If you are running qemu-sanity-check without installing, then do:"
116 echo " $0 --initrd=./initrd $@"
117 echo "The default path is '@libdir@/initrd'."
121 # Locate kernel if not specified.
122 if [ -z "$kernel" ]; then
123 kernel="$(ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen | head -1)"
124 if [ -z "$kernel" ]; then
125 echo "$0: cannot find a Linux kernel in /boot"
126 echo "Choose a kernel to test using --kernel=/path/to/vmlinuz"
130 if [ ! -r "$kernel" ]; then
131 echo "$0: kernel $kernel is not readable"
135 # Locate qemu if not specified.
136 if [ -z "$qemu" ]; then
137 for q in @QEMU_LIST@; do
138 if "$q" --help >/dev/null 2>&1; then
143 if [ -z "$qemu" ]; then
144 echo "$0: cannot find a qemu binary on the \$PATH"
145 echo "Choose a qemu binary to test using --qemu=/path/to/qemu"
150 # Choose a temporary file for the output.
151 test_output="$(mktemp --suff=.out)"
153 # Generate the parameters for the qemu command.
156 argv[$((i++))]="$qemu"
157 argv[$((i++))]="-display"
158 argv[$((i++))]="none"
159 argv[$((i++))]="-no-user-config"
160 argv[$((i++))]="-nodefaults"
161 argv[$((i++))]="-machine"
162 argv[$((i++))]="$machine${machine:+,}accel=$accel"
163 argv[$((i++))]="-no-reboot"
164 argv[$((i++))]="-serial"
165 argv[$((i++))]="file:$test_output"
166 argv[$((i++))]="-kernel"
167 argv[$((i++))]="$kernel"
168 argv[$((i++))]="-initrd"
169 argv[$((i++))]="$initrd"
170 argv[$((i++))]="-append"
171 argv[$((i++))]="console=ttyS0 oops=panic panic=-1"
176 timeout "$timeout" "${argv[@]}"
178 if [ $r -eq 124 ]; then
180 echo "$0: error: test $kernel on $qemu: timed out"
183 elif [ $r -ne 0 ]; then
185 echo "$0: error: test $kernel on $qemu: failed"
190 # Verify that userspace was reached.
191 if ! grep -sq "initrd started up OK" "$test_output"; then
193 echo "$0: error: test $kernel on $qemu: init process did not start up"