qemu: Use oops=panic panic=-1
[qemu-sanity-check.git] / qemu-sanity-check.in
1 #!/bin/bash
2 # -*- shell-script -*-
3 # qemu-sanity-check
4 # Copyright (C) 2013 Red Hat Inc.
5 #
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.
10 #
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.
15 #
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.
19
20 prefix="@prefix@"
21 exec_prefix="@exec_prefix@"
22 initrd="@libdir@/qemu-sanity-check/initrd"
23
24 arch="$(uname -m)"
25 canonical_arch="$(uname -m | sed 's/i[456]86/i386/')"
26
27 timeout=10m
28
29 # Handle command line parsing.
30
31 function usage {
32     echo "qemu-sanity-check [options]"
33     echo "Options:"
34     echo "  --help               Display this help"
35     echo "  -i|--initrd=initrd   Set location of initramfs"
36     echo "  -k|--kernel=vmlinuz  Set location of kernel"
37     echo "  -q|--qemu=qemu       Set location of qemu/KVM binary"
38     echo "  -t|--timeout=timeout Set the timeout"
39     echo "  -V|--version         Display version and exit"
40     exit 0
41 }
42
43 TEMP=$(getopt \
44     -o i:k:q:t:V \
45     --long help \
46     --long initrd: \
47     --long kernel: \
48     --long qemu: \
49     --long timeout: \
50     --long version \
51     -n 'qemu-sanity-check' -- "$@")
52 if [ $? != 0 ]; then exit 2; fi
53 eval set -- "$TEMP"
54
55 while true; do
56     case "$1" in
57         --help)
58             usage
59             ;;
60         -i|--initrd)
61             initrd="$2"
62             shift 2
63             ;;
64         -k|--kernel)
65             kernel="$2"
66             shift 2
67             ;;
68         -q|--qemu)
69             qemu="$2"
70             shift 2
71             ;;
72         -t|--timeout)
73             timeout="$2"
74             shift 2
75             ;;
76         -V|--version)
77             echo "@PACKAGE_NAME@ @PACKAGE_VERSION@"
78             exit 0
79             ;;
80         --)
81             shift
82             break
83             ;;
84         *)
85             echo "$0: internal error parsing options: $1"
86             exit 2
87             ;;
88     esac
89 done
90
91 # Locate initrd.
92 if [ ! -r "$initrd" ]; then
93     echo "$0: cannot find 'initrd', try using --initrd=/path/to/initrd"
94     echo "If you are running qemu-sanity-check without installing, then do:"
95     echo "    $0 --initrd=./initrd $@"
96     echo "The default path is '@libdir@/initrd'."
97     exit 2
98 fi
99
100 # Locate kernel if not specified.
101 if [ -z "$kernel" ]; then
102     kernel="$(ls -vr /boot/vmlinuz-*.$arch | head -1)"
103     if [ -z "$kernel" ]; then
104         echo "$0: cannot find a Linux kernel in /boot"
105         echo "Choose a kernel to test using --kernel=/path/to/vmlinuz"
106         exit 2
107     fi
108 fi
109 if [ ! -r "$kernel" ]; then
110     echo "$0: kernel $kernel is not readable"
111     exit 2
112 fi
113
114 # Locate qemu if not specified.
115 if [ -z "$qemu" ]; then
116     for q in @QEMU_LIST@; do
117         if "$q" --help >/dev/null 2>&1; then
118             qemu="$q"
119             break
120         fi
121     done
122     if [ -z "$qemu" ]; then
123         echo "$0: cannot find a qemu binary on the \$PATH"
124         echo "Choose a qemu binary to test using --qemu=/path/to/qemu"
125         exit 2
126     fi
127 fi
128
129 # Choose a temporary file for the output.
130 test_output="$(mktemp --suff=.out)"
131
132 # Generate the parameters for the qemu command.
133 declare -a argv
134 i=0
135 argv[$((i++))]="$qemu"
136 argv[$((i++))]="-nographic"
137 argv[$((i++))]="-nodefconfig"
138 argv[$((i++))]="-nodefaults"
139 argv[$((i++))]="-machine"
140 argv[$((i++))]="accel=kvm:tcg"
141 argv[$((i++))]="-no-reboot"
142 argv[$((i++))]="-serial"
143 argv[$((i++))]="file:$test_output"
144 argv[$((i++))]="-kernel"
145 argv[$((i++))]="$kernel"
146 argv[$((i++))]="-initrd"
147 argv[$((i++))]="$initrd"
148 argv[$((i++))]="-append"
149 argv[$((i++))]="console=ttyS0 oops=panic panic=-1"
150
151 #echo "${argv[@]}"
152
153 # Run the command.
154 timeout "$timeout" "${argv[@]}"
155 r="${PIPESTATUS[0]}"
156 if [ $r -eq 124 ]; then
157     cat "$test_output"
158     echo "$0: error: test $kernel on $qemu: timed out"
159     rm "$test_output"
160     exit 1
161 elif [ $r -ne 0 ]; then
162     cat "$test_output"
163     echo "$0: error: test $kernel on $qemu: failed"
164     rm "$test_output"
165     exit 1
166 fi
167
168 # Verify that userspace was reached.
169 if ! grep -sq "initrd started up OK" "$test_output"; then
170     cat "$test_output"
171     echo "$0: error: test $kernel on $qemu: init process did not start up"
172     rm "$test_output"
173     exit 1
174 fi
175
176 # Successful.
177 rm "$test_output"
178 exit 0