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