3 # Copyright (C) 2009 Red Hat, Inc.
4 # Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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/>.
19 # common procedures for QA scripts
28 rm -f "$OUTPUT_DIR/$iam.out"
45 rm -f $tmp.list $tmp.tmp $tmp.sed
48 export IMGFMT_GENERIC=true
51 export CACHEMODE="writeback"
52 export QEMU_IO_OPTIONS=""
53 export QEMU_IO_OPTIONS_NO_FMT=""
54 export CACHEMODE_IS_DEFAULT=true
55 export QEMU_OPTIONS="-nodefaults -machine accel=qtest"
58 export IMGOPTSSYNTAX=false
66 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
69 if [ -z "$group_list" ]
71 echo "Group \"$r\" is empty or not defined?"
74 [ ! -s $tmp.list ] && touch $tmp.list
77 if grep -s "^$t\$" $tmp.list >/dev/null
90 # Populate $tmp.list with all tests
91 awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list 2>/dev/null
92 group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
95 if [ -z "$group_list" ]
97 echo "Group \"$r\" is empty or not defined?"
104 if [ $numsed -gt 100 ]
106 sed -f $tmp.sed <$tmp.list >$tmp.tmp
107 mv $tmp.tmp $tmp.list
111 echo "/^$t\$/d" >>$tmp.sed
112 numsed=`expr $numsed + 1`
114 sed -f $tmp.sed <$tmp.list >$tmp.tmp
115 mv $tmp.tmp $tmp.list
127 CACHEMODE_IS_DEFAULT=false
136 -\? | -h | --help) # usage
137 echo "Usage: $0 [options] [testlist]"'
144 -raw test raw (default)
147 -parallels test parallels
157 image protocol options
158 -file test file (default)
160 -sheepdog test sheepdog
167 -xdiff graphical mode diff
168 -nocache use O_DIRECT on backing file
169 -misalign misalign memory allocations
170 -n show me, do not run tests
171 -o options -o options to pass to qemu-img create/convert
173 -r randomize test order
177 -g group[,group...] include tests from these groups
178 -x group[,group...] exclude tests from these groups
180 NNN-NNN include test range (eg. 012-021)
287 CACHEMODE_IS_DEFAULT=false
292 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
301 -g) # -g group ... pick from group file
306 -xdiff) # graphical diff mode
309 if [ ! -z "$DISPLAY" ]
311 command -v xdiff >/dev/null 2>&1 && diff=xdiff
312 command -v gdiff >/dev/null 2>&1 && diff=gdiff
313 command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
314 command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
318 -n) # show me, don't do it
330 -r) # randomize test order
335 -T) # turn on timestamp output
348 -x) # -x group ... exclude from group file
352 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
359 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
363 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
364 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/.* //'`
367 echo "No tests in range \"$r\"?"
380 # get rid of leading 0s as can be interpreted as octal
381 start=`echo $start | sed 's/^0*//'`
382 end=`echo $end | sed 's/^0*//'`
387 $AWK_PROG </dev/null '
388 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
391 if grep -s "^$id " "$source_iotests/group" >/dev/null
393 # in group file ... OK
396 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
398 # expunged ... will be reported, but not run, later
402 if [ "$start" == "$end" -a "$id" == "$end" ]
404 echo "$id - unknown test"
407 echo "$id - unknown test, ignored"
416 # Set qemu-io cache mode with $CACHEMODE we have
417 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
419 QEMU_IO_OPTIONS_NO_FMT="$QEMU_IO_OPTIONS"
420 if [ "$IMGOPTSSYNTAX" != "true" ]; then
421 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT"
424 # Set default options for qemu-img create -o if they were not specified
429 # found some valid test numbers ... this is good
434 # had test numbers, but none in group file ... do nothing
437 # no test numbers, do everything from group file
438 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
442 # should be sort -n, but this did not work for Linux when this
443 # was ported from IRIX
445 list=`sort $tmp.list`
446 rm -f $tmp.list $tmp.tmp $tmp.sed
450 list=`echo $list | awk -f randomize.awk`
453 [ "$QEMU" = "" ] && _fatal "qemu not found"
454 [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found"
455 [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found"
457 if [ "$IMGPROTO" = "nbd" ] ; then
458 [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found"