common 12.8 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# Copyright (C) 2009 Red Hat, Inc.
# Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# 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 20 21
#
#
# common procedures for QA scripts
#

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
_full_imgfmt_details()
{
    if [ -n "$IMGOPTS" ]; then
        echo "$IMGFMT ($IMGOPTS)"
    else
        echo "$IMGFMT"
    fi
}

_full_platform_details()
{
    os=`uname -s`
    host=`hostname -s`
    kernel=`uname -r`
    platform=`uname -m`
    echo "$os/$platform $host $kernel"
}

40 41 42 43 44 45 46 47 48 49 50
# $1 = prog to look for
set_prog_path()
{
    p=`command -v $1 2> /dev/null`
    if [ -n "$p" -a -x "$p" ]; then
        realpath -- "$(type -p "$p")"
    else
        return 1
    fi
}

51 52
diff="diff -u"
verbose=false
53
debug=false
54 55
group=false
xgroup=false
56
imgopts=false
57 58 59 60
showme=false
sortme=false
expunge=true
have_test_arg=false
61
cachemode=false
62 63 64
rm -f $tmp.list $tmp.tmp $tmp.sed

export IMGFMT=raw
65
export IMGFMT_GENERIC=true
66
export IMGPROTO=file
67
export IMGOPTS=""
68
export CACHEMODE="writeback"
69
export QEMU_IO_OPTIONS=""
70
export QEMU_IO_OPTIONS_NO_FMT=""
71
export CACHEMODE_IS_DEFAULT=true
72
export QEMU_OPTIONS="-nodefaults -machine accel=qtest"
73
export VALGRIND_QEMU=
74
export IMGKEYSECRET=
75
export IMGOPTSSYNTAX=false
76 77 78 79 80 81

for r
do

    if $group
    then
K
Kevin Wolf 已提交
82
        # arg after -g
M
Max Reitz 已提交
83
        group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
84 85
s/ .*//p
}'`
K
Kevin Wolf 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
        if [ -z "$group_list" ]
        then
            echo "Group \"$r\" is empty or not defined?"
            exit 1
        fi
        [ ! -s $tmp.list ] && touch $tmp.list
        for t in $group_list
        do
            if grep -s "^$t\$" $tmp.list >/dev/null
            then
                :
            else
                echo "$t" >>$tmp.list
            fi
        done
        group=false
        continue
103 104 105

    elif $xgroup
    then
K
Kevin Wolf 已提交
106
        # arg after -x
J
John Snow 已提交
107 108
        # Populate $tmp.list with all tests
        awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list 2>/dev/null
M
Max Reitz 已提交
109
        group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
110 111
s/ .*//p
}'`
K
Kevin Wolf 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
        if [ -z "$group_list" ]
        then
            echo "Group \"$r\" is empty or not defined?"
            exit 1
        fi
        numsed=0
        rm -f $tmp.sed
        for t in $group_list
        do
            if [ $numsed -gt 100 ]
            then
                sed -f $tmp.sed <$tmp.list >$tmp.tmp
                mv $tmp.tmp $tmp.list
                numsed=0
                rm -f $tmp.sed
            fi
            echo "/^$t\$/d" >>$tmp.sed
            numsed=`expr $numsed + 1`
        done
        sed -f $tmp.sed <$tmp.list >$tmp.tmp
        mv $tmp.tmp $tmp.list
        xgroup=false
        continue
135 136 137 138 139 140

    elif $imgopts
    then
        IMGOPTS="$r"
        imgopts=false
        continue
141 142 143 144 145 146
    elif $cachemode
    then
        CACHEMODE="$r"
        CACHEMODE_IS_DEFAULT=false
        cachemode=false
        continue
147 148 149 150 151 152
    fi

    xpand=true
    case "$r"
    in

K
Kevin Wolf 已提交
153 154
        -\? | -h | --help)        # usage
            echo "Usage: $0 [options] [testlist]"'
155 156

common options
157
    -v                  verbose
158
    -d                  debug
159

J
John Snow 已提交
160
image format options
161
    -raw                test raw (default)
162
    -bochs              test bochs
163
    -cloop              test cloop
164
    -parallels          test parallels
165 166
    -qcow               test qcow
    -qcow2              test qcow2
167
    -qed                test qed
168
    -vdi                test vdi
169
    -vpc                test vpc
170
    -vhdx               test vhdx
171
    -vmdk               test vmdk
J
John Snow 已提交
172 173 174
    -luks               test luks

image protocol options
175
    -file               test file (default)
176 177
    -rbd                test rbd
    -sheepdog           test sheepdog
178
    -nbd                test nbd
179
    -ssh                test ssh
180
    -nfs                test nfs
181
    -vxhs               test vxhs
J
John Snow 已提交
182 183

other options
184 185 186 187
    -xdiff              graphical mode diff
    -nocache            use O_DIRECT on backing file
    -misalign           misalign memory allocations
    -n                  show me, do not run tests
188
    -o options          -o options to pass to qemu-img create/convert
189
    -T                  output timestamps
190
    -c mode             cache mode
K
Kevin Wolf 已提交
191

192
testlist options
K
Kevin Wolf 已提交
193 194 195
    -g group[,group...]        include tests from these groups
    -x group[,group...]        exclude tests from these groups
    NNN                        include test NNN
196
    NNN-NNN                    include test range (eg. 012-021)
197
'
K
Kevin Wolf 已提交
198 199 200 201 202 203 204 205
            exit 0
            ;;

        -raw)
            IMGFMT=raw
            xpand=false
            ;;

206 207 208 209 210 211
        -bochs)
            IMGFMT=bochs
            IMGFMT_GENERIC=false
            xpand=false
            ;;

212 213 214 215 216 217
        -cloop)
            IMGFMT=cloop
            IMGFMT_GENERIC=false
            xpand=false
            ;;

218 219 220 221 222 223
        -parallels)
            IMGFMT=parallels
            IMGFMT_GENERIC=false
            xpand=false
            ;;

K
Kevin Wolf 已提交
224 225 226 227 228 229 230 231 232 233
        -qcow)
            IMGFMT=qcow
            xpand=false
            ;;

        -qcow2)
            IMGFMT=qcow2
            xpand=false
            ;;

234 235 236 237 238 239 240
        -luks)
            IMGOPTSSYNTAX=true
            IMGFMT=luks
            IMGKEYSECRET=123456
            xpand=false
            ;;

K
Kevin Wolf 已提交
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
        -qed)
            IMGFMT=qed
            xpand=false
            ;;

        -vdi)
            IMGFMT=vdi
            xpand=false
            ;;

        -vmdk)
            IMGFMT=vmdk
            xpand=false
            ;;

        -vpc)
            IMGFMT=vpc
            xpand=false
            ;;

261 262 263 264 265
        -vhdx)
            IMGFMT=vhdx
            xpand=false
            ;;

266 267 268 269 270
        -file)
            IMGPROTO=file
            xpand=false
            ;;

K
Kevin Wolf 已提交
271 272 273 274
        -rbd)
            IMGPROTO=rbd
            xpand=false
            ;;
275

K
Kevin Wolf 已提交
276 277 278 279
        -sheepdog)
            IMGPROTO=sheepdog
            xpand=false
            ;;
280

K
Kevin Wolf 已提交
281 282 283 284
        -nbd)
            IMGPROTO=nbd
            xpand=false
            ;;
285

286 287 288 289 290
        -vxhs)
            IMGPROTO=vxhs
            xpand=false
            ;;

291 292 293 294
        -ssh)
            IMGPROTO=ssh
            xpand=false
            ;;
295 296 297 298 299 300

        -nfs)
            IMGPROTO=nfs
            xpand=false
            ;;

K
Kevin Wolf 已提交
301
        -nocache)
302 303
            CACHEMODE="none"
            CACHEMODE_IS_DEFAULT=false
K
Kevin Wolf 已提交
304 305
            xpand=false
            ;;
306

K
Kevin Wolf 已提交
307 308 309 310
        -misalign)
            QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
            xpand=false
            ;;
311

312
        -valgrind)
313
            VALGRIND_QEMU='y'
K
Kevin Wolf 已提交
314
            xpand=false
315
            ;;
K
Kevin Wolf 已提交
316

K
Kevin Wolf 已提交
317 318 319 320 321 322 323 324 325 326
        -g)        # -g group ... pick from group file
            group=true
            xpand=false
            ;;

        -xdiff)        # graphical diff mode
            xpand=false

            if [ ! -z "$DISPLAY" ]
            then
327 328 329 330
                command -v xdiff >/dev/null 2>&1 && diff=xdiff
                command -v gdiff >/dev/null 2>&1 && diff=gdiff
                command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
                command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
K
Kevin Wolf 已提交
331 332 333 334 335 336 337
            fi
            ;;

        -n)        # show me, don't do it
            showme=true
            xpand=false
            ;;
338 339 340 341
        -o)
            imgopts=true
            xpand=false
            ;;
342 343 344 345
        -c)
            cachemode=true
            xpand=false
            ;;
K
Kevin Wolf 已提交
346 347 348 349 350 351 352 353 354
        -T)        # turn on timestamp output
            timestamp=true
            xpand=false
            ;;

        -v)
            verbose=true
            xpand=false
            ;;
355 356 357 358
        -d)
            debug=true
            xpand=false
            ;;
K
Kevin Wolf 已提交
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
        -x)        # -x group ... exclude from group file
            xgroup=true
            xpand=false
            ;;
        '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
            echo "No tests?"
            status=1
            exit $status
            ;;

        [0-9]*-[0-9]*)
            eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
            ;;

        [0-9]*-)
            eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
            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/.* //'`
            if [ -z "$end" ]
            then
                echo "No tests in range \"$r\"?"
                status=1
                exit $status
            fi
            ;;

        *)
            start=$r
            end=$r
            ;;
388 389 390 391 392 393 394 395 396

    esac

    # get rid of leading 0s as can be interpreted as octal
    start=`echo $start | sed 's/^0*//'`
    end=`echo $end | sed 's/^0*//'`

    if $xpand
    then
K
Kevin Wolf 已提交
397
        have_test_arg=true
P
Paolo Bonzini 已提交
398
        awk </dev/null '
K
Kevin Wolf 已提交
399 400 401
BEGIN        { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
        | while read id
        do
M
Max Reitz 已提交
402
            if grep -s "^$id " "$source_iotests/group" >/dev/null
K
Kevin Wolf 已提交
403 404 405 406 407 408 409 410 411 412
            then
                # in group file ... OK
                echo $id >>$tmp.list
            else
                if [ -f expunged ] && $expunge && egrep "^$id([         ]|\$)" expunged >/dev/null
                then
                    # expunged ... will be reported, but not run, later
                    echo $id >>$tmp.list
                else
                    # oops
413 414 415 416 417 418 419
                    if [ "$start" == "$end" -a "$id" == "$end" ]
                    then
                        echo "$id - unknown test"
                        exit 1
                    else
                        echo "$id - unknown test, ignored"
                    fi
K
Kevin Wolf 已提交
420 421
                fi
            fi
422
        done || exit 1
423 424 425 426
    fi

done

427
# Set qemu-io cache mode with $CACHEMODE we have
428 429 430 431 432
QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"

QEMU_IO_OPTIONS_NO_FMT="$QEMU_IO_OPTIONS"
if [ "$IMGOPTSSYNTAX" != "true" ]; then
    QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT"
433
fi
434

435
# Set default options for qemu-img create -o if they were not specified
436 437 438 439 440 441
if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then
    IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1")
fi
if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null); then
    IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10")
fi
442

443 444 445 446 447 448 449
if [ -s $tmp.list ]
then
    # found some valid test numbers ... this is good
    :
else
    if $have_test_arg
    then
K
Kevin Wolf 已提交
450 451
        # had test numbers, but none in group file ... do nothing
        touch $tmp.list
452
    else
K
Kevin Wolf 已提交
453
        # no test numbers, do everything from group file
M
Max Reitz 已提交
454
        sed -n -e '/^[0-9][0-9][0-9]*/s/[         ].*//p' <"$source_iotests/group" >$tmp.list
455 456 457 458 459 460 461 462 463
    fi
fi

# should be sort -n, but this did not work for Linux when this
# was ported from IRIX
#
list=`sort $tmp.list`
rm -f $tmp.list $tmp.tmp $tmp.sed

464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
if [ -z "$QEMU_PROG" ]
then
    if [ -x "$build_iotests/qemu" ]; then
        export QEMU_PROG="$build_iotests/qemu"
    elif [ -x "$build_root/$arch-softmmu/qemu-system-$arch" ]; then
        export QEMU_PROG="$build_root/$arch-softmmu/qemu-system-$arch"
    else
        pushd "$build_root" > /dev/null
        for binary in *-softmmu/qemu-system-*
        do
            if [ -x "$binary" ]
            then
                export QEMU_PROG="$build_root/$binary"
                break
            fi
        done
        popd > /dev/null
        [ "$QEMU_PROG" = "" ] && _init_error "qemu not found"
    fi
fi
export QEMU_PROG=$(realpath -- "$(type -p "$QEMU_PROG")")

if [ -z "$QEMU_IMG_PROG" ]; then
    if [ -x "$build_iotests/qemu-img" ]; then
        export QEMU_IMG_PROG="$build_iotests/qemu-img"
    elif [ -x "$build_root/qemu-img" ]; then
        export QEMU_IMG_PROG="$build_root/qemu-img"
    else
        _init_error "qemu-img not found"
    fi
fi
export QEMU_IMG_PROG=$(realpath -- "$(type -p "$QEMU_IMG_PROG")")

if [ -z "$QEMU_IO_PROG" ]; then
    if [ -x "$build_iotests/qemu-io" ]; then
        export QEMU_IO_PROG="$build_iotests/qemu-io"
    elif [ -x "$build_root/qemu-io" ]; then
        export QEMU_IO_PROG="$build_root/qemu-io"
    else
        _init_error "qemu-io not found"
    fi
fi
export QEMU_IO_PROG=$(realpath -- "$(type -p "$QEMU_IO_PROG")")
507

508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
if [ -z $QEMU_NBD_PROG ]; then
    if [ -x "$build_iotests/qemu-nbd" ]; then
        export QEMU_NBD_PROG="$build_iotests/qemu-nbd"
    elif [ -x "$build_root/qemu-nbd" ]; then
        export QEMU_NBD_PROG="$build_root/qemu-nbd"
    else
        _init_error "qemu-nbd not found"
    fi
fi
export QEMU_NBD_PROG=$(realpath -- "$(type -p "$QEMU_NBD_PROG")")

if [ -z "$QEMU_VXHS_PROG" ]; then
  export QEMU_VXHS_PROG="`set_prog_path qnio_server`"
fi

if [ -x "$build_iotests/socket_scm_helper" ]
then
    export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper"
526
fi