]> Git Repo - qemu.git/blob - tests/qemu-iotests/check
iotests: Allow out-of-tree run
[qemu.git] / tests / qemu-iotests / check
1 #!/bin/bash
2 #
3 # Copyright (C) 2009 Red Hat, Inc.
4 # Copyright (c) 2000-2002,2006 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 #
19 # Control script for QA
20 #
21
22 tmp=/tmp/$$
23 status=0
24 needwrap=true
25 try=0
26 n_bad=0
27 bad=""
28 notrun=""
29 interrupt=true
30
31 # by default don't output timestamps
32 timestamp=${TIMESTAMP:=false}
33
34 # generic initialization
35 iam=check
36
37 _init_error()
38 {
39     echo "$iam: $1" >&2
40     exit 1
41 }
42
43 if [ -L "$0" ]
44 then
45     # called from the build tree
46     source_iotests=$(dirname "$(readlink "$0")")
47     if [ -z "$source_iotests" ]
48     then
49         _init_error "failed to obtain source tree name from check symlink"
50     fi
51     source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree"
52     build_iotests=$PWD
53 else
54     # called from the source tree
55     source_iotests=$PWD
56     # this may be an in-tree build (note that in the following code we may not
57     # assume that it truly is and have to test whether the build results
58     # actually exist)
59     build_iotests=$PWD
60 fi
61
62 build_root="$build_iotests/../.."
63
64 if [ -x "$build_iotests/socket_scm_helper" ]
65 then
66     export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper"
67 fi
68
69 # if ./qemu exists, it should be prioritized and will be chosen by common.config
70 if [[ -z "$QEMU_PROG" && ! -x './qemu' ]]
71 then
72     arch=$(uname -m 2> /dev/null)
73
74     if [[ -n $arch && -x "$build_root/$arch-softmmu/qemu-system-$arch" ]]
75     then
76         export QEMU_PROG="$build_root/$arch-softmmu/qemu-system-$arch"
77     else
78         pushd "$build_root" > /dev/null
79         for binary in *-softmmu/qemu-system-*
80         do
81             if [ -x "$binary" ]
82             then
83                 export QEMU_PROG="$build_root/$binary"
84                 break
85             fi
86         done
87         popd > /dev/null
88     fi
89 fi
90
91 if [[ -z $QEMU_IMG_PROG && -x "$build_root/qemu-img" && ! -x './qemu-img' ]]
92 then
93     export QEMU_IMG_PROG="$build_root/qemu-img"
94 fi
95
96 if [[ -z $QEMU_IO_PROG && -x "$build_root/qemu-io" && ! -x './qemu-io' ]]
97 then
98     export QEMU_IO_PROG="$build_root/qemu-io"
99 fi
100
101 if [[ -z $QEMU_NBD_PROG && -x "$build_root/qemu-nbd" && ! -x './qemu-nbd' ]]
102 then
103     export QEMU_NBD_PROG="$build_root/qemu-nbd"
104 fi
105
106 # we need common.config
107 if ! . "$source_iotests/common.config"
108 then
109     _init_error "failed to source common.config"
110 fi
111
112 # we need common.rc
113 if ! . "$source_iotests/common.rc"
114 then
115     _init_error "failed to source common.rc"
116 fi
117
118 # we need common
119 . "$source_iotests/common"
120
121 #if [ `id -u` -ne 0 ]
122 #then
123 #    echo "check: QA must be run as root"
124 #    exit 1
125 #fi
126
127 _wallclock()
128 {
129     date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }'
130 }
131
132 _timestamp()
133 {
134     now=`date "+%T"`
135     echo -n " [$now]"
136 }
137
138 _wrapup()
139 {
140     # for hangcheck ...
141     # remove files that were used by hangcheck
142     #
143     [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid
144     [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts
145
146     if $showme
147     then
148         :
149     elif $needwrap
150     then
151         if [ -f check.time -a -f $tmp.time ]
152         then
153             cat check.time $tmp.time \
154             | $AWK_PROG '
155         { t[$1] = $2 }
156 END        { if (NR > 0) {
157             for (i in t) print i " " t[i]
158           }
159         }' \
160             | sort -n >$tmp.out
161             mv $tmp.out check.time
162         fi
163
164         if [ -f $tmp.expunged ]
165         then
166             notrun=`wc -l <$tmp.expunged | sed -e 's/  *//g'`
167             try=`expr $try - $notrun`
168             list=`echo "$list" | sed -f $tmp.expunged`
169         fi
170
171         echo "" >>check.log
172         date >>check.log
173         echo $list | fmt | sed -e 's/^/    /' >>check.log
174         $interrupt && echo "Interrupted!" >>check.log
175
176         if [ ! -z "$notrun" ]
177         then
178             echo "Not run:$notrun"
179             echo "Not run:$notrun" >>check.log
180         fi
181         if [ ! -z "$n_bad" -a $n_bad != 0 ]
182         then
183             echo "Failures:$bad"
184             echo "Failed $n_bad of $try tests"
185             echo "Failures:$bad" | fmt >>check.log
186             echo "Failed $n_bad of $try tests" >>check.log
187         else
188             echo "Passed all $try tests"
189             echo "Passed all $try tests" >>check.log
190         fi
191         needwrap=false
192     fi
193
194     rm -f /tmp/*.out /tmp/*.err /tmp/*.time
195     rm -f /tmp/check.pid /tmp/check.sts
196     rm -f $tmp.*
197 }
198
199 trap "_wrapup; exit \$status" 0 1 2 3 15
200
201 # for hangcheck ...
202 # Save pid of check in a well known place, so that hangcheck can be sure it
203 # has the right pid (getting the pid from ps output is not reliable enough).
204 #
205 rm -rf /tmp/check.pid
206 echo $$ >/tmp/check.pid
207
208 # for hangcheck ...
209 # Save the status of check in a well known place, so that hangcheck can be
210 # sure to know where check is up to (getting test number from ps output is
211 # not reliable enough since the trace stuff has been introduced).
212 #
213 rm -rf /tmp/check.sts
214 echo "preamble" >/tmp/check.sts
215
216 # don't leave old full output behind on a clean run
217 rm -f check.full
218
219 [ -f check.time ] || touch check.time
220
221 FULL_IMGFMT_DETAILS=`_full_imgfmt_details`
222 FULL_IMGPROTO_DETAILS=`_full_imgproto_details`
223 FULL_HOST_DETAILS=`_full_platform_details`
224 #FULL_MKFS_OPTIONS=`_scratch_mkfs_options`
225 #FULL_MOUNT_OPTIONS=`_scratch_mount_options`
226
227 cat <<EOF
228 QEMU          -- $QEMU
229 QEMU_IMG      -- $QEMU_IMG
230 QEMU_IO       -- $QEMU_IO
231 QEMU_NBD      -- $QEMU_NBD
232 IMGFMT        -- $FULL_IMGFMT_DETAILS
233 IMGPROTO      -- $FULL_IMGPROTO_DETAILS
234 PLATFORM      -- $FULL_HOST_DETAILS
235 SOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER
236
237 EOF
238 #MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS
239 #MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS
240
241 seq="check"
242
243 [ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
244
245 for seq in $list
246 do
247     err=false
248     echo -n "$seq"
249     if [ -n "$TESTS_REMAINING_LOG" ] ; then
250         sed -e "s/$seq//" -e 's/  / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
251         mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG
252         sync
253     fi
254
255     if $showme
256     then
257         echo
258         continue
259     elif [ -f expunged ] && $expunge && egrep "^$seq([         ]|\$)" expunged >/dev/null
260     then
261         echo " - expunged"
262         rm -f $seq.out.bad
263         echo "/^$seq\$/d" >>$tmp.expunged
264     elif [ ! -f "$source_iotests/$seq" ]
265     then
266         echo " - no such test?"
267         echo "/^$seq\$/d" >>$tmp.expunged
268     else
269         # really going to try and run this one
270         #
271         rm -f $seq.out.bad
272         lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time`
273         if [ "X$lasttime" != X ]; then
274                 echo -n " ${lasttime}s ..."
275         else
276                 echo -n "        "        # prettier output with timestamps.
277         fi
278         rm -f core $seq.notrun
279
280         # for hangcheck ...
281         echo "$seq" >/tmp/check.sts
282
283         start=`_wallclock`
284         $timestamp && echo -n "        ["`date "+%T"`"]"
285         export OUTPUT_DIR=$PWD
286         (cd "$source_iotests";
287         MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
288                 ./$seq >$tmp.out 2>&1)
289         sts=$?
290         $timestamp && _timestamp
291         stop=`_wallclock`
292
293         if [ -f core ]
294         then
295             echo -n " [dumped core]"
296             mv core $seq.core
297             err=true
298         fi
299
300         if [ -f $seq.notrun ]
301         then
302             $timestamp || echo -n " [not run] "
303             $timestamp && echo " [not run]" && echo -n "        $seq -- "
304             cat $seq.notrun
305             notrun="$notrun $seq"
306         else
307             if [ $sts -ne 0 ]
308             then
309                 echo -n " [failed, exit status $sts]"
310                 err=true
311             fi
312
313             reference="$source_iotests/$seq.out"
314             if [ "$CACHEMODE" = "none" ]; then
315                 [ -f "$source_iotests/$seq.out.nocache" ] && reference="$source_iotests/$seq.out.nocache"
316             fi
317
318             if [ ! -f "$reference" ]
319             then
320                 echo " - no qualified output"
321                 err=true
322             else
323                 if diff -w "$reference" $tmp.out >/dev/null 2>&1
324                 then
325                     echo ""
326                     if $err
327                     then
328                         :
329                     else
330                         echo "$seq `expr $stop - $start`" >>$tmp.time
331                     fi
332                 else
333                     echo " - output mismatch (see $seq.out.bad)"
334                     mv $tmp.out $seq.out.bad
335                     $diff -w "$reference" $seq.out.bad
336                     err=true
337                 fi
338             fi
339         fi
340
341     fi
342
343     # come here for each test, except when $showme is true
344     #
345     if $err
346     then
347         bad="$bad $seq"
348         n_bad=`expr $n_bad + 1`
349         quick=false
350     fi
351     [ -f $seq.notrun ] || try=`expr $try + 1`
352
353     seq="after_$seq"
354 done
355
356 interrupt=false
357 status=`expr $n_bad`
358 exit
This page took 0.043821 seconds and 4 git commands to generate.