xref: /openbmc/qemu/tests/qemu-iotests/check (revision 8f1e884b)
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
22tmp=/tmp/$$
23status=0
24needwrap=true
25try=0
26n_bad=0
27bad=""
28notrun=""
29interrupt=true
30
31# by default don't output timestamps
32timestamp=${TIMESTAMP:=false}
33
34# generic initialization
35iam=check
36
37# we need common.env
38if ! . ./common.env
39then
40    echo "$iam: failed to source common.env"
41    exit 1
42fi
43
44# we need common.config
45if ! . ./common.config
46then
47    echo "$iam: failed to source common.config"
48    exit 1
49fi
50
51# we need common.rc
52if ! . ./common.rc
53then
54    echo "check: failed to source common.rc"
55    exit 1
56fi
57
58# we need common
59. ./common
60
61#if [ `id -u` -ne 0 ]
62#then
63#    echo "check: QA must be run as root"
64#    exit 1
65#fi
66
67_wallclock()
68{
69    date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }'
70}
71
72_timestamp()
73{
74    now=`date "+%T"`
75    echo -n " [$now]"
76}
77
78_wrapup()
79{
80    # for hangcheck ...
81    # remove files that were used by hangcheck
82    #
83    [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid
84    [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts
85
86    if $showme
87    then
88        :
89    elif $needwrap
90    then
91        if [ -f check.time -a -f $tmp.time ]
92        then
93            cat check.time $tmp.time \
94            | $AWK_PROG '
95        { t[$1] = $2 }
96END        { if (NR > 0) {
97            for (i in t) print i " " t[i]
98          }
99        }' \
100            | sort -n >$tmp.out
101            mv $tmp.out check.time
102        fi
103
104        if [ -f $tmp.expunged ]
105        then
106            notrun=`wc -l <$tmp.expunged | sed -e 's/  *//g'`
107            try=`expr $try - $notrun`
108            list=`echo "$list" | sed -f $tmp.expunged`
109        fi
110
111        echo "" >>check.log
112        date >>check.log
113        echo $list | fmt | sed -e 's/^/    /' >>check.log
114        $interrupt && echo "Interrupted!" >>check.log
115
116        if [ ! -z "$notrun" ]
117        then
118            echo "Not run:$notrun"
119            echo "Not run:$notrun" >>check.log
120        fi
121        if [ ! -z "$n_bad" -a $n_bad != 0 ]
122        then
123            echo "Failures:$bad"
124            echo "Failed $n_bad of $try tests"
125            echo "Failures:$bad" | fmt >>check.log
126            echo "Failed $n_bad of $try tests" >>check.log
127        else
128            echo "Passed all $try tests"
129            echo "Passed all $try tests" >>check.log
130        fi
131        needwrap=false
132    fi
133
134    rm -f /tmp/*.out /tmp/*.err /tmp/*.time
135    rm -f /tmp/check.pid /tmp/check.sts
136    rm -f $tmp.*
137}
138
139trap "_wrapup; exit \$status" 0 1 2 3 15
140
141# for hangcheck ...
142# Save pid of check in a well known place, so that hangcheck can be sure it
143# has the right pid (getting the pid from ps output is not reliable enough).
144#
145rm -rf /tmp/check.pid
146echo $$ >/tmp/check.pid
147
148# for hangcheck ...
149# Save the status of check in a well known place, so that hangcheck can be
150# sure to know where check is up to (getting test number from ps output is
151# not reliable enough since the trace stuff has been introduced).
152#
153rm -rf /tmp/check.sts
154echo "preamble" >/tmp/check.sts
155
156# don't leave old full output behind on a clean run
157rm -f check.full
158
159[ -f check.time ] || touch check.time
160
161FULL_IMGFMT_DETAILS=`_full_imgfmt_details`
162FULL_IMGPROTO_DETAILS=`_full_imgproto_details`
163FULL_HOST_DETAILS=`_full_platform_details`
164#FULL_MKFS_OPTIONS=`_scratch_mkfs_options`
165#FULL_MOUNT_OPTIONS=`_scratch_mount_options`
166
167cat <<EOF
168QEMU          -- $QEMU
169QEMU_IMG      -- $QEMU_IMG
170QEMU_IO       -- $QEMU_IO
171QEMU_NBD      -- $QEMU_NBD
172IMGFMT        -- $FULL_IMGFMT_DETAILS
173IMGPROTO      -- $FULL_IMGPROTO_DETAILS
174PLATFORM      -- $FULL_HOST_DETAILS
175SOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER
176
177EOF
178#MKFS_OPTIONS  -- $FULL_MKFS_OPTIONS
179#MOUNT_OPTIONS -- $FULL_MOUNT_OPTIONS
180
181seq="check"
182
183[ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
184
185for seq in $list
186do
187    err=false
188    echo -n "$seq"
189    if [ -n "$TESTS_REMAINING_LOG" ] ; then
190        sed -e "s/$seq//" -e 's/  / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
191        mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG
192        sync
193    fi
194
195    if $showme
196    then
197        echo
198        continue
199    elif [ -f expunged ] && $expunge && egrep "^$seq([         ]|\$)" expunged >/dev/null
200    then
201        echo " - expunged"
202        rm -f $seq.out.bad
203        echo "/^$seq\$/d" >>$tmp.expunged
204    elif [ ! -f $seq ]
205    then
206        echo " - no such test?"
207        echo "/^$seq\$/d" >>$tmp.expunged
208    else
209        # really going to try and run this one
210        #
211        rm -f $seq.out.bad
212        lasttime=`sed -n -e "/^$seq /s/.* //p" <check.time`
213        if [ "X$lasttime" != X ]; then
214                echo -n " ${lasttime}s ..."
215        else
216                echo -n "        "        # prettier output with timestamps.
217        fi
218        rm -f core $seq.notrun
219
220        # for hangcheck ...
221        echo "$seq" >/tmp/check.sts
222
223        start=`_wallclock`
224        $timestamp && echo -n "        ["`date "+%T"`"]"
225
226        if [ "$(head -n 1 $seq)" == "#!/usr/bin/env python" ]; then
227            run_command="$PYTHON $seq"
228        else
229            [ ! -x $seq ] && chmod u+x $seq # ensure we can run it
230            run_command="./$seq"
231        fi
232
233        MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
234                $run_command >$tmp.out 2>&1
235        sts=$?
236        $timestamp && _timestamp
237        stop=`_wallclock`
238
239        if [ -f core ]
240        then
241            echo -n " [dumped core]"
242            mv core $seq.core
243            err=true
244        fi
245
246        if [ -f $seq.notrun ]
247        then
248            $timestamp || echo -n " [not run] "
249            $timestamp && echo " [not run]" && echo -n "        $seq -- "
250            cat $seq.notrun
251            notrun="$notrun $seq"
252        else
253            if [ $sts -ne 0 ]
254            then
255                echo -n " [failed, exit status $sts]"
256                err=true
257            fi
258
259            reference=$seq.out
260            if [ "$CACHEMODE" = "none" ]; then
261                [ -f $seq.out.nocache ] && reference=$seq.out.nocache
262            fi
263
264            if [ ! -f $reference ]
265            then
266                echo " - no qualified output"
267                err=true
268            else
269                if diff -w $reference $tmp.out >/dev/null 2>&1
270                then
271                    echo ""
272                    if $err
273                    then
274                        :
275                    else
276                        echo "$seq `expr $stop - $start`" >>$tmp.time
277                    fi
278                else
279                    echo " - output mismatch (see $seq.out.bad)"
280                    mv $tmp.out $seq.out.bad
281                    $diff -w $reference $seq.out.bad
282                    err=true
283                fi
284            fi
285        fi
286
287    fi
288
289    # come here for each test, except when $showme is true
290    #
291    if $err
292    then
293        bad="$bad $seq"
294        n_bad=`expr $n_bad + 1`
295        quick=false
296    fi
297    [ -f $seq.notrun ] || try=`expr $try + 1`
298
299    seq="after_$seq"
300done
301
302interrupt=false
303status=`expr $n_bad`
304exit
305