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