xref: /openbmc/qemu/tests/qemu-iotests/check (revision 9ee4b6f803335d23e3b6fe21c139707918c3eb24)
1908eaf68SStefan Hajnoczi#!/bin/bash
26bf19c94SChristoph Hellwig#
36bf19c94SChristoph Hellwig# Copyright (C) 2009 Red Hat, Inc.
46bf19c94SChristoph Hellwig# Copyright (c) 2000-2002,2006 Silicon Graphics, Inc.  All Rights Reserved.
56bf19c94SChristoph Hellwig#
66bf19c94SChristoph Hellwig# This program is free software; you can redistribute it and/or
76bf19c94SChristoph Hellwig# modify it under the terms of the GNU General Public License as
86bf19c94SChristoph Hellwig# published by the Free Software Foundation.
96bf19c94SChristoph Hellwig#
106bf19c94SChristoph Hellwig# This program is distributed in the hope that it would be useful,
116bf19c94SChristoph Hellwig# but WITHOUT ANY WARRANTY; without even the implied warranty of
126bf19c94SChristoph Hellwig# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
136bf19c94SChristoph Hellwig# GNU General Public License for more details.
146bf19c94SChristoph Hellwig#
156bf19c94SChristoph Hellwig# You should have received a copy of the GNU General Public License
16e8c212d6SChristoph Hellwig# along with this program.  If not, see <http://www.gnu.org/licenses/>.
176bf19c94SChristoph Hellwig#
186bf19c94SChristoph Hellwig#
196bf19c94SChristoph Hellwig# Control script for QA
206bf19c94SChristoph Hellwig#
216bf19c94SChristoph Hellwig
226bf19c94SChristoph Hellwigstatus=0
236bf19c94SChristoph Hellwigneedwrap=true
246bf19c94SChristoph Hellwigtry=0
256bf19c94SChristoph Hellwign_bad=0
266bf19c94SChristoph Hellwigbad=""
276bf19c94SChristoph Hellwignotrun=""
286bf19c94SChristoph Hellwiginterrupt=true
296bf19c94SChristoph Hellwig
306bf19c94SChristoph Hellwig# by default don't output timestamps
316bf19c94SChristoph Hellwigtimestamp=${TIMESTAMP:=false}
326bf19c94SChristoph Hellwig
336bf19c94SChristoph Hellwig# generic initialization
346bf19c94SChristoph Hellwigiam=check
356bf19c94SChristoph Hellwig
36e8f8624dSMax Reitz_init_error()
37e8f8624dSMax Reitz{
38e8f8624dSMax Reitz    echo "$iam: $1" >&2
396bf19c94SChristoph Hellwig    exit 1
40e8f8624dSMax Reitz}
41e8f8624dSMax Reitz
42e8f8624dSMax Reitzif [ -L "$0" ]
43e8f8624dSMax Reitzthen
44e8f8624dSMax Reitz    # called from the build tree
45e8f8624dSMax Reitz    source_iotests=$(dirname "$(readlink "$0")")
46e8f8624dSMax Reitz    if [ -z "$source_iotests" ]
47e8f8624dSMax Reitz    then
48e8f8624dSMax Reitz        _init_error "failed to obtain source tree name from check symlink"
49e8f8624dSMax Reitz    fi
50e8f8624dSMax Reitz    source_iotests=$(cd "$source_iotests"; pwd) || _init_error "failed to enter source tree"
51e8f8624dSMax Reitz    build_iotests=$PWD
52e8f8624dSMax Reitzelse
53e8f8624dSMax Reitz    # called from the source tree
54e8f8624dSMax Reitz    source_iotests=$PWD
55e8f8624dSMax Reitz    # this may be an in-tree build (note that in the following code we may not
56e8f8624dSMax Reitz    # assume that it truly is and have to test whether the build results
57e8f8624dSMax Reitz    # actually exist)
58e8f8624dSMax Reitz    build_iotests=$PWD
59e8f8624dSMax Reitzfi
60e8f8624dSMax Reitz
61e8f8624dSMax Reitzbuild_root="$build_iotests/../.."
62e8f8624dSMax Reitz
63e8f8624dSMax Reitzif [ -x "$build_iotests/socket_scm_helper" ]
64e8f8624dSMax Reitzthen
65e8f8624dSMax Reitz    export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper"
66e8f8624dSMax Reitzfi
67e8f8624dSMax Reitz
68e8f8624dSMax Reitzif [[ -z "$QEMU_PROG" && ! -x './qemu' ]]
69e8f8624dSMax Reitzthen
70e8f8624dSMax Reitz    arch=$(uname -m 2> /dev/null)
71e8f8624dSMax Reitz
72e8f8624dSMax Reitz    if [[ -n $arch && -x "$build_root/$arch-softmmu/qemu-system-$arch" ]]
73e8f8624dSMax Reitz    then
74e8f8624dSMax Reitz        export QEMU_PROG="$build_root/$arch-softmmu/qemu-system-$arch"
75e8f8624dSMax Reitz    else
76e8f8624dSMax Reitz        pushd "$build_root" > /dev/null
77e8f8624dSMax Reitz        for binary in *-softmmu/qemu-system-*
78e8f8624dSMax Reitz        do
79e8f8624dSMax Reitz            if [ -x "$binary" ]
80e8f8624dSMax Reitz            then
81e8f8624dSMax Reitz                export QEMU_PROG="$build_root/$binary"
82e8f8624dSMax Reitz                break
83e8f8624dSMax Reitz            fi
84e8f8624dSMax Reitz        done
85e8f8624dSMax Reitz        popd > /dev/null
86e8f8624dSMax Reitz    fi
87e8f8624dSMax Reitzfi
88e8f8624dSMax Reitz
89e8f8624dSMax Reitzif [[ -z $QEMU_IMG_PROG && -x "$build_root/qemu-img" && ! -x './qemu-img' ]]
90e8f8624dSMax Reitzthen
91e8f8624dSMax Reitz    export QEMU_IMG_PROG="$build_root/qemu-img"
92e8f8624dSMax Reitzfi
93e8f8624dSMax Reitz
94e8f8624dSMax Reitzif [[ -z $QEMU_IO_PROG && -x "$build_root/qemu-io" && ! -x './qemu-io' ]]
95e8f8624dSMax Reitzthen
96e8f8624dSMax Reitz    export QEMU_IO_PROG="$build_root/qemu-io"
97e8f8624dSMax Reitzfi
98e8f8624dSMax Reitz
99e8f8624dSMax Reitzif [[ -z $QEMU_NBD_PROG && -x "$build_root/qemu-nbd" && ! -x './qemu-nbd' ]]
100e8f8624dSMax Reitzthen
101e8f8624dSMax Reitz    export QEMU_NBD_PROG="$build_root/qemu-nbd"
102e8f8624dSMax Reitzfi
103e8f8624dSMax Reitz
1047fed1a49SMax Reitz# we need common.env
1057fed1a49SMax Reitzif ! . "$build_iotests/common.env"
1067fed1a49SMax Reitzthen
1077fed1a49SMax Reitz    _init_error "failed to source common.env (make sure the qemu-iotests are run from tests/qemu-iotests in the build tree)"
1087fed1a49SMax Reitzfi
1097fed1a49SMax Reitz
110e8f8624dSMax Reitz# we need common.config
111e8f8624dSMax Reitzif ! . "$source_iotests/common.config"
112e8f8624dSMax Reitzthen
113e8f8624dSMax Reitz    _init_error "failed to source common.config"
1146bf19c94SChristoph Hellwigfi
1156bf19c94SChristoph Hellwig
1166bf19c94SChristoph Hellwig# we need common.rc
117e8f8624dSMax Reitzif ! . "$source_iotests/common.rc"
1186bf19c94SChristoph Hellwigthen
119e8f8624dSMax Reitz    _init_error "failed to source common.rc"
1206bf19c94SChristoph Hellwigfi
1216bf19c94SChristoph Hellwig
12289004368SKevin Wolf# we need common
123e8f8624dSMax Reitz. "$source_iotests/common"
12489004368SKevin Wolf
12536bd4228SDaniel P. BerrangeTIMESTAMP_FILE=check.time-$IMGPROTO-$IMGFMT
12636bd4228SDaniel P. Berrange
1270145b4e1SSascha Silbetmp="${TEST_DIR}"/$$
1280145b4e1SSascha Silbe
1296bf19c94SChristoph Hellwig_wallclock()
1306bf19c94SChristoph Hellwig{
131*9ee4b6f8SPaolo Bonzini    date "+%H %M %S" | awk '{ print $1*3600 + $2*60 + $3 }'
1326bf19c94SChristoph Hellwig}
1336bf19c94SChristoph Hellwig
1346bf19c94SChristoph Hellwig_timestamp()
1356bf19c94SChristoph Hellwig{
1366bf19c94SChristoph Hellwig    now=`date "+%T"`
137b43671f8SEric Blake    printf %s " [$now]"
1386bf19c94SChristoph Hellwig}
1396bf19c94SChristoph Hellwig
1406bf19c94SChristoph Hellwig_wrapup()
1416bf19c94SChristoph Hellwig{
1426bf19c94SChristoph Hellwig    if $showme
1436bf19c94SChristoph Hellwig    then
1446bf19c94SChristoph Hellwig        :
1456bf19c94SChristoph Hellwig    elif $needwrap
1466bf19c94SChristoph Hellwig    then
14736bd4228SDaniel P. Berrange        if [ -f $TIMESTAMP_FILE -a -f $tmp.time ]
1486bf19c94SChristoph Hellwig        then
14936bd4228SDaniel P. Berrange            cat $TIMESTAMP_FILE $tmp.time \
150*9ee4b6f8SPaolo Bonzini            | awk '
1516bf19c94SChristoph Hellwig        { t[$1] = $2 }
1526bf19c94SChristoph HellwigEND        { if (NR > 0) {
1536bf19c94SChristoph Hellwig            for (i in t) print i " " t[i]
1546bf19c94SChristoph Hellwig          }
1556bf19c94SChristoph Hellwig        }' \
1566bf19c94SChristoph Hellwig            | sort -n >$tmp.out
15736bd4228SDaniel P. Berrange            mv $tmp.out $TIMESTAMP_FILE
1586bf19c94SChristoph Hellwig        fi
1596bf19c94SChristoph Hellwig
1606bf19c94SChristoph Hellwig        if [ -f $tmp.expunged ]
1616bf19c94SChristoph Hellwig        then
1626bf19c94SChristoph Hellwig            notrun=`wc -l <$tmp.expunged | sed -e 's/  *//g'`
1636bf19c94SChristoph Hellwig            try=`expr $try - $notrun`
1646bf19c94SChristoph Hellwig            list=`echo "$list" | sed -f $tmp.expunged`
1656bf19c94SChristoph Hellwig        fi
1666bf19c94SChristoph Hellwig
1676bf19c94SChristoph Hellwig        echo "" >>check.log
1686bf19c94SChristoph Hellwig        date >>check.log
1696bf19c94SChristoph Hellwig        echo $list | fmt | sed -e 's/^/    /' >>check.log
1706bf19c94SChristoph Hellwig        $interrupt && echo "Interrupted!" >>check.log
1716bf19c94SChristoph Hellwig
1726bf19c94SChristoph Hellwig        if [ ! -z "$notrun" ]
1736bf19c94SChristoph Hellwig        then
1746bf19c94SChristoph Hellwig            echo "Not run:$notrun"
1756bf19c94SChristoph Hellwig            echo "Not run:$notrun" >>check.log
1766bf19c94SChristoph Hellwig        fi
1776bf19c94SChristoph Hellwig        if [ ! -z "$n_bad" -a $n_bad != 0 ]
1786bf19c94SChristoph Hellwig        then
1796bf19c94SChristoph Hellwig            echo "Failures:$bad"
1806bf19c94SChristoph Hellwig            echo "Failed $n_bad of $try tests"
1816bf19c94SChristoph Hellwig            echo "Failures:$bad" | fmt >>check.log
1826bf19c94SChristoph Hellwig            echo "Failed $n_bad of $try tests" >>check.log
1836bf19c94SChristoph Hellwig        else
1846bf19c94SChristoph Hellwig            echo "Passed all $try tests"
1856bf19c94SChristoph Hellwig            echo "Passed all $try tests" >>check.log
1866bf19c94SChristoph Hellwig        fi
1876bf19c94SChristoph Hellwig        needwrap=false
1886bf19c94SChristoph Hellwig    fi
1896bf19c94SChristoph Hellwig
1900145b4e1SSascha Silbe    rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.time
1910145b4e1SSascha Silbe    rm -f "${TEST_DIR}"/check.pid "${TEST_DIR}"/check.sts
1926bf19c94SChristoph Hellwig    rm -f $tmp.*
1936bf19c94SChristoph Hellwig}
1946bf19c94SChristoph Hellwig
1956bf19c94SChristoph Hellwigtrap "_wrapup; exit \$status" 0 1 2 3 15
1966bf19c94SChristoph Hellwig
19736bd4228SDaniel P. Berrange[ -f $TIMESTAMP_FILE ] || touch $TIMESTAMP_FILE
1986bf19c94SChristoph Hellwig
1996bf19c94SChristoph HellwigFULL_IMGFMT_DETAILS=`_full_imgfmt_details`
2006bf19c94SChristoph HellwigFULL_HOST_DETAILS=`_full_platform_details`
2016bf19c94SChristoph Hellwig
2026bf19c94SChristoph Hellwigcat <<EOF
203934659c4SMax ReitzQEMU          -- "$QEMU_PROG" $QEMU_OPTIONS
204934659c4SMax ReitzQEMU_IMG      -- "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS
205934659c4SMax ReitzQEMU_IO       -- "$QEMU_IO_PROG" $QEMU_IO_OPTIONS
206934659c4SMax ReitzQEMU_NBD      -- "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS
2076bf19c94SChristoph HellwigIMGFMT        -- $FULL_IMGFMT_DETAILS
208657c572aSCleber RosaIMGPROTO      -- $IMGPROTO
2096bf19c94SChristoph HellwigPLATFORM      -- $FULL_HOST_DETAILS
210b8aff7d6SFam ZhengTEST_DIR      -- $TEST_DIR
21130b005d9SWenchao XiaSOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER
2126bf19c94SChristoph Hellwig
2136bf19c94SChristoph HellwigEOF
2146bf19c94SChristoph Hellwig
2156bf19c94SChristoph Hellwigseq="check"
2166bf19c94SChristoph Hellwig
2176bf19c94SChristoph Hellwig[ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
2186bf19c94SChristoph Hellwig
2196bf19c94SChristoph Hellwigfor seq in $list
2206bf19c94SChristoph Hellwigdo
2216bf19c94SChristoph Hellwig    err=false
222b43671f8SEric Blake    printf %s "$seq"
2236bf19c94SChristoph Hellwig    if [ -n "$TESTS_REMAINING_LOG" ] ; then
2246bf19c94SChristoph Hellwig        sed -e "s/$seq//" -e 's/  / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
2256bf19c94SChristoph Hellwig        mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG
2266bf19c94SChristoph Hellwig        sync
2276bf19c94SChristoph Hellwig    fi
2286bf19c94SChristoph Hellwig
2296bf19c94SChristoph Hellwig    if $showme
2306bf19c94SChristoph Hellwig    then
2316bf19c94SChristoph Hellwig        echo
2326bf19c94SChristoph Hellwig        continue
2336bf19c94SChristoph Hellwig    elif [ -f expunged ] && $expunge && egrep "^$seq([         ]|\$)" expunged >/dev/null
2346bf19c94SChristoph Hellwig    then
2356bf19c94SChristoph Hellwig        echo " - expunged"
2366bf19c94SChristoph Hellwig        rm -f $seq.out.bad
2376bf19c94SChristoph Hellwig        echo "/^$seq\$/d" >>$tmp.expunged
238e8f8624dSMax Reitz    elif [ ! -f "$source_iotests/$seq" ]
2396bf19c94SChristoph Hellwig    then
2406bf19c94SChristoph Hellwig        echo " - no such test?"
2416bf19c94SChristoph Hellwig        echo "/^$seq\$/d" >>$tmp.expunged
2426bf19c94SChristoph Hellwig    else
2436bf19c94SChristoph Hellwig        # really going to try and run this one
2446bf19c94SChristoph Hellwig        #
2456bf19c94SChristoph Hellwig        rm -f $seq.out.bad
24636bd4228SDaniel P. Berrange        lasttime=`sed -n -e "/^$seq /s/.* //p" <$TIMESTAMP_FILE`
2476bf19c94SChristoph Hellwig        if [ "X$lasttime" != X ]; then
248b43671f8SEric Blake                printf %s " ${lasttime}s ..."
2496bf19c94SChristoph Hellwig        else
250b43671f8SEric Blake                printf "        "        # prettier output with timestamps.
2516bf19c94SChristoph Hellwig        fi
2526bf19c94SChristoph Hellwig        rm -f core $seq.notrun
2536bf19c94SChristoph Hellwig
2546bf19c94SChristoph Hellwig        start=`_wallclock`
255b43671f8SEric Blake        $timestamp && printf %s "        [$(date "+%T")]"
256ea81ca9dSMax Reitz
257ea81ca9dSMax Reitz        if [ "$(head -n 1 "$source_iotests/$seq")" == "#!/usr/bin/env python" ]; then
258ea81ca9dSMax Reitz            run_command="$PYTHON $seq"
259ea81ca9dSMax Reitz        else
260ea81ca9dSMax Reitz            run_command="./$seq"
261ea81ca9dSMax Reitz        fi
262e8f8624dSMax Reitz        export OUTPUT_DIR=$PWD
263aa4f592aSFam Zheng        if $debug; then
264aa4f592aSFam Zheng            (cd "$source_iotests";
265aa4f592aSFam Zheng            MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
266aa4f592aSFam Zheng                    $run_command -d 2>&1 | tee $tmp.out)
267aa4f592aSFam Zheng        else
268e8f8624dSMax Reitz            (cd "$source_iotests";
26904129606SStefan Hajnoczi            MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
270ea81ca9dSMax Reitz                    $run_command >$tmp.out 2>&1)
271aa4f592aSFam Zheng        fi
2726bf19c94SChristoph Hellwig        sts=$?
2736bf19c94SChristoph Hellwig        $timestamp && _timestamp
2746bf19c94SChristoph Hellwig        stop=`_wallclock`
2756bf19c94SChristoph Hellwig
2766bf19c94SChristoph Hellwig        if [ -f core ]
2776bf19c94SChristoph Hellwig        then
278b43671f8SEric Blake            printf " [dumped core]"
2796bf19c94SChristoph Hellwig            mv core $seq.core
2806bf19c94SChristoph Hellwig            err=true
2816bf19c94SChristoph Hellwig        fi
2826bf19c94SChristoph Hellwig
2836bf19c94SChristoph Hellwig        if [ -f $seq.notrun ]
2846bf19c94SChristoph Hellwig        then
285b43671f8SEric Blake            $timestamp || printf " [not run] "
286b43671f8SEric Blake            $timestamp && echo " [not run]" && printf %s "        $seq -- "
2876bf19c94SChristoph Hellwig            cat $seq.notrun
2886bf19c94SChristoph Hellwig            notrun="$notrun $seq"
2896bf19c94SChristoph Hellwig        else
2906bf19c94SChristoph Hellwig            if [ $sts -ne 0 ]
2916bf19c94SChristoph Hellwig            then
292b43671f8SEric Blake                printf %s " [failed, exit status $sts]"
2936bf19c94SChristoph Hellwig                err=true
2946bf19c94SChristoph Hellwig            fi
2958f94b077SKevin Wolf
296e8f8624dSMax Reitz            reference="$source_iotests/$seq.out"
297e166b414SBo Tu            reference_machine="$source_iotests/$seq.$QEMU_DEFAULT_MACHINE.out"
298e166b414SBo Tu            if [ -f "$reference_machine" ]; then
299e166b414SBo Tu                reference="$reference_machine"
300e166b414SBo Tu            fi
301e166b414SBo Tu
302217a0683SStefan Hajnoczi            reference_format="$source_iotests/$seq.out.$IMGFMT"
303217a0683SStefan Hajnoczi            if [ -f "$reference_format" ]; then
304217a0683SStefan Hajnoczi                reference="$reference_format"
305217a0683SStefan Hajnoczi            fi
306217a0683SStefan Hajnoczi
3073baa8449SFam Zheng            if [ "$CACHEMODE" = "none" ]; then
308e8f8624dSMax Reitz                [ -f "$source_iotests/$seq.out.nocache" ] && reference="$source_iotests/$seq.out.nocache"
3098f94b077SKevin Wolf            fi
3108f94b077SKevin Wolf
311e8f8624dSMax Reitz            if [ ! -f "$reference" ]
3126bf19c94SChristoph Hellwig            then
3136bf19c94SChristoph Hellwig                echo " - no qualified output"
3146bf19c94SChristoph Hellwig                err=true
3156bf19c94SChristoph Hellwig            else
316e8f8624dSMax Reitz                if diff -w "$reference" $tmp.out >/dev/null 2>&1
3176bf19c94SChristoph Hellwig                then
3186bf19c94SChristoph Hellwig                    echo ""
3196bf19c94SChristoph Hellwig                    if $err
3206bf19c94SChristoph Hellwig                    then
3216bf19c94SChristoph Hellwig                        :
3226bf19c94SChristoph Hellwig                    else
3236bf19c94SChristoph Hellwig                        echo "$seq `expr $stop - $start`" >>$tmp.time
3246bf19c94SChristoph Hellwig                    fi
3256bf19c94SChristoph Hellwig                else
3266bf19c94SChristoph Hellwig                    echo " - output mismatch (see $seq.out.bad)"
3276bf19c94SChristoph Hellwig                    mv $tmp.out $seq.out.bad
32893e53fb6SFam Zheng                    $diff -w "$reference" $(realpath $seq.out.bad)
3296bf19c94SChristoph Hellwig                    err=true
3306bf19c94SChristoph Hellwig                fi
3316bf19c94SChristoph Hellwig            fi
3326bf19c94SChristoph Hellwig        fi
3336bf19c94SChristoph Hellwig
3346bf19c94SChristoph Hellwig    fi
3356bf19c94SChristoph Hellwig
3366bf19c94SChristoph Hellwig    # come here for each test, except when $showme is true
3376bf19c94SChristoph Hellwig    #
3386bf19c94SChristoph Hellwig    if $err
3396bf19c94SChristoph Hellwig    then
3406bf19c94SChristoph Hellwig        bad="$bad $seq"
3416bf19c94SChristoph Hellwig        n_bad=`expr $n_bad + 1`
3426bf19c94SChristoph Hellwig        quick=false
3436bf19c94SChristoph Hellwig    fi
3446bf19c94SChristoph Hellwig    [ -f $seq.notrun ] || try=`expr $try + 1`
3456bf19c94SChristoph Hellwig
3466bf19c94SChristoph Hellwig    seq="after_$seq"
3476bf19c94SChristoph Hellwigdone
3486bf19c94SChristoph Hellwig
3496bf19c94SChristoph Hellwiginterrupt=false
3506bf19c94SChristoph Hellwigstatus=`expr $n_bad`
3516bf19c94SChristoph Hellwigexit
352