xref: /openbmc/qemu/tests/qemu-iotests/check (revision e6e03dcf)
1#!/usr/bin/env 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
22status=0
23needwrap=true
24try=0
25n_bad=0
26bad=""
27notrun=""
28casenotrun=""
29interrupt=true
30makecheck=false
31
32_init_error()
33{
34    echo "check: $1" >&2
35    exit 1
36}
37
38if [ -L "$0" ]
39then
40    # called from the build tree
41    source_iotests=$(dirname "$(readlink "$0")")
42    if [ -z "$source_iotests" ]
43    then
44        _init_error "failed to obtain source tree name from check symlink"
45    fi
46    source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree"
47    build_iotests=$PWD
48else
49    # called from the source tree
50    source_iotests=$PWD
51    # this may be an in-tree build (note that in the following code we may not
52    # assume that it truly is and have to test whether the build results
53    # actually exist)
54    build_iotests=$PWD
55fi
56
57build_root="$build_iotests/../.."
58
59# we need common.env
60if ! . "$build_iotests/common.env"
61then
62    _init_error "failed to source common.env (make sure the qemu-iotests are run from tests/qemu-iotests in the build tree)"
63fi
64
65# we need common.config
66if ! . "$source_iotests/common.config"
67then
68    _init_error "failed to source common.config"
69fi
70
71_full_imgfmt_details()
72{
73    if [ -n "$IMGOPTS" ]; then
74        echo "$IMGFMT ($IMGOPTS)"
75    else
76        echo "$IMGFMT"
77    fi
78}
79
80_full_platform_details()
81{
82    os=$(uname -s)
83    host=$(hostname -s)
84    kernel=$(uname -r)
85    platform=$(uname -m)
86    echo "$os/$platform $host $kernel"
87}
88
89_full_env_details()
90{
91    cat <<EOF
92QEMU          -- "$QEMU_PROG" $QEMU_OPTIONS
93QEMU_IMG      -- "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS
94QEMU_IO       -- "$QEMU_IO_PROG" $QEMU_IO_OPTIONS
95QEMU_NBD      -- "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS
96IMGFMT        -- $FULL_IMGFMT_DETAILS
97IMGPROTO      -- $IMGPROTO
98PLATFORM      -- $FULL_HOST_DETAILS
99TEST_DIR      -- $TEST_DIR
100SOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER
101
102EOF
103}
104
105# $1 = prog to look for
106set_prog_path()
107{
108    p=$(command -v $1 2> /dev/null)
109    if [ -n "$p" -a -x "$p" ]; then
110        type -p "$p"
111    else
112        return 1
113    fi
114}
115
116if [ -z "$TEST_DIR" ]; then
117        TEST_DIR=$PWD/scratch
118fi
119
120if [ ! -e "$TEST_DIR" ]; then
121        mkdir "$TEST_DIR"
122fi
123
124diff="diff -u"
125verbose=false
126debug=false
127group=false
128xgroup=false
129imgopts=false
130showme=false
131sortme=false
132expunge=true
133have_test_arg=false
134cachemode=false
135
136tmp="${TEST_DIR}"/$$
137rm -f $tmp.list $tmp.tmp $tmp.sed
138
139export IMGFMT=raw
140export IMGFMT_GENERIC=true
141export IMGPROTO=file
142export IMGOPTS=""
143export CACHEMODE="writeback"
144export QEMU_IO_OPTIONS=""
145export QEMU_IO_OPTIONS_NO_FMT=""
146export CACHEMODE_IS_DEFAULT=true
147export VALGRIND_QEMU=
148export IMGKEYSECRET=
149export IMGOPTSSYNTAX=false
150
151# Save current tty settings, since an aborting qemu call may leave things
152# screwed up
153STTY_RESTORE=
154if test -t 0; then
155    STTY_RESTORE=$(stty -g)
156fi
157
158for r
159do
160
161    if $group
162    then
163        # arg after -g
164        group_list=$(sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
165s/ .*//p
166}')
167        if [ -z "$group_list" ]
168        then
169            echo "Group \"$r\" is empty or not defined?"
170            exit 1
171        fi
172        [ ! -s $tmp.list ] && touch $tmp.list
173        for t in $group_list
174        do
175            if grep -s "^$t\$" $tmp.list >/dev/null
176            then
177                :
178            else
179                echo "$t" >>$tmp.list
180            fi
181        done
182        group=false
183        continue
184
185    elif $xgroup
186    then
187        # arg after -x
188        # Populate $tmp.list with all tests
189        awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list 2>/dev/null
190        group_list=$(sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
191s/ .*//p
192}')
193        if [ -z "$group_list" ]
194        then
195            echo "Group \"$r\" is empty or not defined?"
196            exit 1
197        fi
198        numsed=0
199        rm -f $tmp.sed
200        for t in $group_list
201        do
202            if [ $numsed -gt 100 ]
203            then
204                sed -f $tmp.sed <$tmp.list >$tmp.tmp
205                mv $tmp.tmp $tmp.list
206                numsed=0
207                rm -f $tmp.sed
208            fi
209            echo "/^$t\$/d" >>$tmp.sed
210            numsed=$(expr $numsed + 1)
211        done
212        sed -f $tmp.sed <$tmp.list >$tmp.tmp
213        mv $tmp.tmp $tmp.list
214        xgroup=false
215        continue
216
217    elif $imgopts
218    then
219        IMGOPTS="$r"
220        imgopts=false
221        continue
222    elif $cachemode
223    then
224        CACHEMODE="$r"
225        CACHEMODE_IS_DEFAULT=false
226        cachemode=false
227        continue
228    fi
229
230    xpand=true
231    case "$r"
232    in
233
234        -\? | -h | --help)        # usage
235            echo "Usage: $0 [options] [testlist]"'
236
237common options
238    -v                  verbose
239    -d                  debug
240
241image format options
242    -raw                test raw (default)
243    -bochs              test bochs
244    -cloop              test cloop
245    -parallels          test parallels
246    -qcow               test qcow
247    -qcow2              test qcow2
248    -qed                test qed
249    -vdi                test vdi
250    -vpc                test vpc
251    -vhdx               test vhdx
252    -vmdk               test vmdk
253    -luks               test luks
254    -dmg                test dmg
255
256image protocol options
257    -file               test file (default)
258    -rbd                test rbd
259    -sheepdog           test sheepdog
260    -nbd                test nbd
261    -ssh                test ssh
262    -nfs                test nfs
263    -vxhs               test vxhs
264
265other options
266    -xdiff              graphical mode diff
267    -nocache            use O_DIRECT on backing file
268    -misalign           misalign memory allocations
269    -n                  show me, do not run tests
270    -o options          -o options to pass to qemu-img create/convert
271    -c mode             cache mode
272    -makecheck          pretty print output for make check
273
274testlist options
275    -g group[,group...]        include tests from these groups
276    -x group[,group...]        exclude tests from these groups
277    NNN                        include test NNN
278    NNN-NNN                    include test range (eg. 012-021)
279'
280            exit 0
281            ;;
282
283        -raw)
284            IMGFMT=raw
285            xpand=false
286            ;;
287
288        -bochs)
289            IMGFMT=bochs
290            IMGFMT_GENERIC=false
291            xpand=false
292            ;;
293
294        -cloop)
295            IMGFMT=cloop
296            IMGFMT_GENERIC=false
297            xpand=false
298            ;;
299
300        -parallels)
301            IMGFMT=parallels
302            xpand=false
303            ;;
304
305        -qcow)
306            IMGFMT=qcow
307            xpand=false
308            ;;
309
310        -qcow2)
311            IMGFMT=qcow2
312            xpand=false
313            ;;
314
315        -luks)
316            IMGOPTSSYNTAX=true
317            IMGFMT=luks
318            IMGKEYSECRET=123456
319            xpand=false
320            ;;
321
322        -dmg)
323            IMGFMT=dmg
324            IMGFMT_GENERIC=false
325            xpand=false
326            ;;
327
328        -qed)
329            IMGFMT=qed
330            xpand=false
331            ;;
332
333        -vdi)
334            IMGFMT=vdi
335            xpand=false
336            ;;
337
338        -vmdk)
339            IMGFMT=vmdk
340            xpand=false
341            ;;
342
343        -vpc)
344            IMGFMT=vpc
345            xpand=false
346            ;;
347
348        -vhdx)
349            IMGFMT=vhdx
350            xpand=false
351            ;;
352
353        -file)
354            IMGPROTO=file
355            xpand=false
356            ;;
357
358        -rbd)
359            IMGPROTO=rbd
360            xpand=false
361            ;;
362
363        -sheepdog)
364            IMGPROTO=sheepdog
365            xpand=false
366            ;;
367
368        -nbd)
369            IMGPROTO=nbd
370            xpand=false
371            ;;
372
373        -vxhs)
374            IMGPROTO=vxhs
375            xpand=false
376            ;;
377
378        -ssh)
379            IMGPROTO=ssh
380            xpand=false
381            ;;
382
383        -nfs)
384            IMGPROTO=nfs
385            xpand=false
386            ;;
387
388        -nocache)
389            CACHEMODE="none"
390            CACHEMODE_IS_DEFAULT=false
391            xpand=false
392            ;;
393
394        -misalign)
395            QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
396            xpand=false
397            ;;
398
399        -valgrind)
400            VALGRIND_QEMU='y'
401            xpand=false
402            ;;
403
404        -g)        # -g group ... pick from group file
405            group=true
406            xpand=false
407            ;;
408
409        -xdiff)        # graphical diff mode
410            xpand=false
411
412            if [ ! -z "$DISPLAY" ]
413            then
414                command -v xdiff >/dev/null 2>&1 && diff=xdiff
415                command -v gdiff >/dev/null 2>&1 && diff=gdiff
416                command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
417                command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
418            fi
419            ;;
420        -makecheck)   # makecheck friendly output
421            makecheck=true
422            xpand=false
423            ;;
424        -n)        # show me, don't do it
425            showme=true
426            xpand=false
427            ;;
428        -o)
429            imgopts=true
430            xpand=false
431            ;;
432        -c)
433            cachemode=true
434            xpand=false
435            ;;
436        -T)        # deprecated timestamp option
437            xpand=false
438            ;;
439
440        -v)
441            verbose=true
442            xpand=false
443            ;;
444        -d)
445            debug=true
446            xpand=false
447            ;;
448        -x)        # -x group ... exclude from group file
449            xgroup=true
450            xpand=false
451            ;;
452        '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
453            echo "No tests?"
454            status=1
455            exit $status
456            ;;
457
458        [0-9]*-[0-9]*)
459            eval $(echo $r | sed -e 's/^/start=/' -e 's/-/ end=/')
460            ;;
461
462        [0-9]*-)
463            eval $(echo $r | sed -e 's/^/start=/' -e 's/-//')
464            end=$(echo [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] | sed -e 's/\[0-9]//g' -e 's/  *$//' -e 's/.* //')
465            if [ -z "$end" ]
466            then
467                echo "No tests in range \"$r\"?"
468                status=1
469                exit $status
470            fi
471            ;;
472
473        *)
474            start=$r
475            end=$r
476            ;;
477
478    esac
479
480    # get rid of leading 0s as can be interpreted as octal
481    start=$(echo $start | sed 's/^0*//')
482    end=$(echo $end | sed 's/^0*//')
483
484    if $xpand
485    then
486        have_test_arg=true
487        awk </dev/null '
488BEGIN        { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
489        | while read id
490        do
491            if grep -s "^$id\( \|\$\)" "$source_iotests/group" >/dev/null
492            then
493                # in group file ... OK
494                echo $id >>$tmp.list
495            else
496                if [ -f expunged ] && $expunge && egrep "^$id([         ]|\$)" expunged >/dev/null
497                then
498                    # expunged ... will be reported, but not run, later
499                    echo $id >>$tmp.list
500                else
501                    # oops
502                    if [ "$start" == "$end" -a "$id" == "$end" ]
503                    then
504                        echo "$id - unknown test"
505                        exit 1
506                    else
507                        echo "$id - unknown test, ignored"
508                    fi
509                fi
510            fi
511        done || exit 1
512    fi
513
514done
515
516# Set qemu-io cache mode with $CACHEMODE we have
517QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
518
519QEMU_IO_OPTIONS_NO_FMT="$QEMU_IO_OPTIONS"
520if [ "$IMGOPTSSYNTAX" != "true" ]; then
521    QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT"
522fi
523
524# Set default options for qemu-img create -o if they were not specified
525if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then
526    IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1")
527fi
528if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null); then
529    IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10")
530fi
531
532if [ -z "$SAMPLE_IMG_DIR" ]; then
533        SAMPLE_IMG_DIR="$source_iotests/sample_images"
534fi
535
536export TEST_DIR
537export SAMPLE_IMG_DIR
538
539if [ -s $tmp.list ]
540then
541    # found some valid test numbers ... this is good
542    :
543else
544    if $have_test_arg
545    then
546        # had test numbers, but none in group file ... do nothing
547        touch $tmp.list
548    else
549        # no test numbers, do everything from group file
550        sed -n -e '/^[0-9][0-9][0-9]*/s/^\([0-9]*\).*/\1/p' <"$source_iotests/group" >$tmp.list
551    fi
552fi
553
554# should be sort -n, but this did not work for Linux when this
555# was ported from IRIX
556#
557list=$(sort $tmp.list)
558rm -f $tmp.list $tmp.tmp $tmp.sed
559
560if [ -z "$QEMU_PROG" ]
561then
562    if [ -x "$build_iotests/qemu" ]; then
563        export QEMU_PROG="$build_iotests/qemu"
564    elif [ -x "$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}" ]; then
565        export QEMU_PROG="$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}"
566    else
567        pushd "$build_root" > /dev/null
568        for binary in *-softmmu/qemu-system-*
569        do
570            if [ -x "$binary" ]
571            then
572                export QEMU_PROG="$build_root/$binary"
573                break
574            fi
575        done
576        popd > /dev/null
577        [ "$QEMU_PROG" = "" ] && _init_error "qemu not found"
578    fi
579fi
580export QEMU_PROG="$(type -p "$QEMU_PROG")"
581
582case "$QEMU_PROG" in
583    *qemu-system-arm|*qemu-system-aarch64)
584        export QEMU_OPTIONS="-nodefaults -display none -machine virt,accel=qtest"
585        ;;
586    *qemu-system-tricore)
587        export QEMU_OPTIONS="-nodefaults -display none -machine tricore_testboard,accel=qtest"
588        ;;
589    *)
590        export QEMU_OPTIONS="-nodefaults -display none -machine accel=qtest"
591        ;;
592esac
593
594if [ -z "$QEMU_IMG_PROG" ]; then
595    if [ -x "$build_iotests/qemu-img" ]; then
596        export QEMU_IMG_PROG="$build_iotests/qemu-img"
597    elif [ -x "$build_root/qemu-img" ]; then
598        export QEMU_IMG_PROG="$build_root/qemu-img"
599    else
600        _init_error "qemu-img not found"
601    fi
602fi
603export QEMU_IMG_PROG="$(type -p "$QEMU_IMG_PROG")"
604
605if [ -z "$QEMU_IO_PROG" ]; then
606    if [ -x "$build_iotests/qemu-io" ]; then
607        export QEMU_IO_PROG="$build_iotests/qemu-io"
608    elif [ -x "$build_root/qemu-io" ]; then
609        export QEMU_IO_PROG="$build_root/qemu-io"
610    else
611        _init_error "qemu-io not found"
612    fi
613fi
614export QEMU_IO_PROG="$(type -p "$QEMU_IO_PROG")"
615
616if [ -z $QEMU_NBD_PROG ]; then
617    if [ -x "$build_iotests/qemu-nbd" ]; then
618        export QEMU_NBD_PROG="$build_iotests/qemu-nbd"
619    elif [ -x "$build_root/qemu-nbd" ]; then
620        export QEMU_NBD_PROG="$build_root/qemu-nbd"
621    else
622        _init_error "qemu-nbd not found"
623    fi
624fi
625export QEMU_NBD_PROG="$(type -p "$QEMU_NBD_PROG")"
626
627if [ -z "$QEMU_VXHS_PROG" ]; then
628    export QEMU_VXHS_PROG="$(set_prog_path qnio_server)"
629fi
630
631if [ -x "$build_iotests/socket_scm_helper" ]
632then
633    export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper"
634fi
635
636python_usable=false
637if $PYTHON -c 'import sys; sys.exit(0 if sys.version_info >= (3,6) else 1)'
638then
639    python_usable=true
640fi
641
642default_machine=$($QEMU_PROG -machine help | sed -n '/(default)/ s/ .*//p')
643default_alias_machine=$($QEMU_PROG -machine help | \
644   sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }")
645if [[ "$default_alias_machine" ]]; then
646    default_machine="$default_alias_machine"
647fi
648
649export QEMU_DEFAULT_MACHINE="$default_machine"
650
651TIMESTAMP_FILE=check.time-$IMGPROTO-$IMGFMT
652
653_wallclock()
654{
655    date "+%H %M %S" | awk '{ print $1*3600 + $2*60 + $3 }'
656}
657
658_wrapup()
659{
660    if $showme
661    then
662        :
663    elif $needwrap
664    then
665        if [ -f $TIMESTAMP_FILE -a -f $tmp.time ]
666        then
667            cat $TIMESTAMP_FILE $tmp.time \
668            | awk '
669        { t[$1] = $2 }
670END        { if (NR > 0) {
671            for (i in t) print i " " t[i]
672          }
673        }' \
674            | sort -n >$tmp.out
675            mv $tmp.out $TIMESTAMP_FILE
676        fi
677
678        if [ -f $tmp.expunged ]
679        then
680            notrun=$(wc -l <$tmp.expunged | sed -e 's/  *//g')
681            try=$(expr $try - $notrun)
682            list=$(echo "$list" | sed -f $tmp.expunged)
683        fi
684
685        echo "" >>check.log
686        date >>check.log
687        echo $list | fmt | sed -e 's/^/    /' >>check.log
688        $interrupt && echo "Interrupted!" >>check.log
689
690        if [ ! -z "$notrun" ]
691        then
692            echo "Not run:$notrun"
693            echo "Not run:$notrun" >>check.log
694        fi
695        if [ ! -z "$casenotrun" ]
696        then
697            echo "Some cases not run in:$casenotrun"
698            echo "Some cases not run in:$casenotrun" >>check.log
699        fi
700        if [ ! -z "$n_bad" -a $n_bad != 0 ]
701        then
702            echo "Failures:$bad"
703            echo "Failed $n_bad of $try iotests"
704            echo "Failures:$bad" | fmt >>check.log
705            echo "Failed $n_bad of $try iotests" >>check.log
706        else
707            echo "Passed all $try iotests"
708            echo "Passed all $try iotests" >>check.log
709        fi
710        needwrap=false
711    fi
712
713    if test -n "$STTY_RESTORE"; then
714        stty $STTY_RESTORE
715    fi
716    rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.time
717    rm -f "${TEST_DIR}"/check.pid "${TEST_DIR}"/check.sts
718    rm -f $tmp.*
719}
720
721trap "_wrapup; exit \$status" 0 1 2 3 15
722
723# Report the test start and results. For makecheck we want to pretty
724# print the whole report at the end of the execution.
725# args: $seq, $starttime, $lasttime
726_report_test_start()
727{
728    if ! $makecheck; then
729        if [ -n "$3" ]; then
730            local lasttime=" (last: $3s)"
731        fi
732        printf "%-8s %-10s [%s]            %4s%-14s\r" "$1" "..." "$2" "..." "$lasttime"
733    fi
734}
735# args:$seq $status $starttime $lasttime $thistime $details
736_report_test_result()
737{
738    local status lasttime thistime
739    if $makecheck; then
740        if [ -n "$2" ] && [ "$2" != "pass" ]; then
741            status=" [$2]"
742        fi
743        printf "  TEST    iotest-$IMGFMT: %s%s\n" "$1" "$status"
744        return
745    fi
746
747    if [ -n "$4" ]; then
748        lasttime=" (last: $4s)"
749    fi
750    if [ -n "$5" ]; then
751        thistime=" $5s"
752    fi
753    case "$2" in
754        "pass")     status=$(printf "\e[32m%-10s\e[0m" "$2") ;;
755        "fail")     status=$(printf "\e[1m\e[31m%-10s\e[0m" "$2") ;;
756        "not run")  status=$(printf "\e[33m%-10s\e[0m" "$2") ;;
757        *)          status=$(printf "%-10s" "$2") ;;
758    esac
759
760    printf "%-8s %s [%s] [%s] %4s%-14s %s\n" "$1" "$status" "$3" "$(date '+%T')" "$thistime" "$lasttime" "$6"
761}
762
763[ -f $TIMESTAMP_FILE ] || touch $TIMESTAMP_FILE
764
765FULL_IMGFMT_DETAILS=$(_full_imgfmt_details)
766FULL_HOST_DETAILS=$(_full_platform_details)
767
768if ! $makecheck; then
769    _full_env_details
770fi
771
772seq="check"
773
774[ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
775
776for seq in $list
777do
778    err=false       # error flag
779    printdiff=false # show diff to reference output?
780    status=""       # test result summary
781    results=""      # test result details
782    thistime=""     # time the test took
783
784    if [ -n "$TESTS_REMAINING_LOG" ] ; then
785        sed -e "s/$seq//" -e 's/  / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
786        mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG
787        sync
788    fi
789
790    lasttime=$(sed -n -e "/^$seq /s/.* //p" <$TIMESTAMP_FILE)
791    starttime=$(date "+%T")
792    _report_test_start $seq $starttime $lasttime
793
794    if $showme
795    then
796        status="not run"
797    elif [ -f expunged ] && $expunge && egrep "^$seq([         ]|\$)" expunged >/dev/null
798    then
799        status="not run"
800        results="expunged"
801        rm -f $seq.out.bad
802        echo "/^$seq\$/d" >>$tmp.expunged
803    elif [ ! -f "$source_iotests/$seq" ]
804    then
805        status="not run"
806        results="no such test?"
807        echo "/^$seq\$/d" >>$tmp.expunged
808    else
809        # really going to try and run this one
810        #
811        rm -f $seq.out.bad
812        rm -f core $seq.notrun
813        rm -f $seq.casenotrun
814
815        start=$(_wallclock)
816
817        if [ "$(head -n 1 "$source_iotests/$seq")" == "#!/usr/bin/env python" ]; then
818            if $python_usable; then
819                run_command="$PYTHON $seq"
820            else
821                run_command="false"
822                echo "Unsupported Python version" > $seq.notrun
823            fi
824        else
825            run_command="./$seq"
826        fi
827        export OUTPUT_DIR=$PWD
828        if $debug; then
829            (cd "$source_iotests";
830            MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
831                    $run_command -d 2>&1 | tee $tmp.out)
832        else
833            (cd "$source_iotests";
834            MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
835                    $run_command >$tmp.out 2>&1)
836        fi
837        sts=$?
838        stop=$(_wallclock)
839
840        if [ -f core ]
841        then
842            mv core $seq.core
843            status="fail"
844            results="[dumped core] $seq.core"
845            err=true
846        fi
847
848        if [ -f $seq.notrun ]
849        then
850            # overwrites timestamp output
851            status="not run"
852            results="$(cat $seq.notrun)"
853        else
854            if [ $sts -ne 0 ]
855            then
856                status="fail"
857                results=$(printf %s "[failed, exit status $sts]")
858                err=true
859            fi
860
861            reference="$source_iotests/$seq.out"
862            reference_machine="$source_iotests/$seq.$QEMU_DEFAULT_MACHINE.out"
863            if [ -f "$reference_machine" ]; then
864                reference="$reference_machine"
865            fi
866
867            reference_format="$source_iotests/$seq.out.$IMGFMT"
868            if [ -f "$reference_format" ]; then
869                reference="$reference_format"
870            fi
871
872            if [ "$CACHEMODE" = "none" ]; then
873                [ -f "$source_iotests/$seq.out.nocache" ] && reference="$source_iotests/$seq.out.nocache"
874            fi
875
876            if [ ! -f "$reference" ]
877            then
878                status="fail"
879                reason="no qualified output"
880                err=true
881            else
882                if diff -w "$reference" $tmp.out >/dev/null 2>&1
883                then
884                    if ! $err; then
885                        status="pass"
886                        thistime=$(expr $stop - $start)
887                        echo "$seq $thistime" >>$tmp.time
888                    fi
889                else
890                    mv $tmp.out $seq.out.bad
891                    status="fail"
892                    results="output mismatch (see $seq.out.bad)"
893                    printdiff=true
894                    err=true
895                fi
896            fi
897        fi
898        if [ -f $seq.casenotrun ]
899        then
900            cat $seq.casenotrun
901            casenotrun="$casenotrun $seq"
902        fi
903    fi
904
905    # come here for each test, except when $showme is true
906    #
907    _report_test_result $seq "$status" "$starttime" "$lasttime" "$thistime" "$results"
908    case "$status" in
909        "pass")
910            try=$(expr $try + 1)
911            ;;
912        "fail")
913            try=$(expr $try + 1)
914            if $makecheck; then
915                _full_env_details
916            fi
917            if $printdiff; then
918                $diff -w "$reference" "$PWD"/$seq.out.bad
919            fi
920            bad="$bad $seq"
921            n_bad=$(expr $n_bad + 1)
922            quick=false
923            ;;
924        "not run")
925            notrun="$notrun $seq"
926            ;;
927    esac
928
929    seq="after_$seq"
930done
931
932interrupt=false
933status=$(expr $n_bad)
934exit
935