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