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