3 # Copyright (C) 2009 Red Hat, Inc.
4 # Copyright (c) 2000-2002,2006 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 # Control script for QA
30 # by default don't output timestamps
31 timestamp
=${TIMESTAMP:=false}
41 # called from the build tree
42 source_iotests
=$
(dirname "$(readlink "$0")")
43 if [ -z "$source_iotests" ]
45 _init_error
"failed to obtain source tree name from check symlink"
47 source_iotests
=$
(cd "$source_iotests"; pwd) || _init_error
"failed to enter source tree"
50 # called from the source tree
52 # this may be an in-tree build (note that in the following code we may not
53 # assume that it truly is and have to test whether the build results
58 build_root
="$build_iotests/../.."
61 if ! .
"$build_iotests/common.env"
63 _init_error
"failed to source common.env (make sure the qemu-iotests are run from tests/qemu-iotests in the build tree)"
66 # we need common.config
67 if ! .
"$source_iotests/common.config"
69 _init_error
"failed to source common.config"
72 _full_imgfmt_details
()
74 if [ -n "$IMGOPTS" ]; then
75 echo "$IMGFMT ($IMGOPTS)"
81 _full_platform_details
()
87 echo "$os/$platform $host $kernel"
90 # $1 = prog to look for
93 p
=`command -v $1 2> /dev/null`
94 if [ -n "$p" -a -x "$p" ]; then
101 if [ -z "$TEST_DIR" ]; then
102 TEST_DIR
=`pwd`/scratch
105 if [ ! -e "$TEST_DIR" ]; then
122 rm -f $tmp.list
$tmp.tmp
$tmp.
sed
125 export IMGFMT_GENERIC
=true
128 export CACHEMODE
="writeback"
129 export QEMU_IO_OPTIONS
=""
130 export QEMU_IO_OPTIONS_NO_FMT
=""
131 export CACHEMODE_IS_DEFAULT
=true
132 export QEMU_OPTIONS
="-nodefaults -machine accel=qtest"
133 export VALGRIND_QEMU
=
135 export IMGOPTSSYNTAX
=false
137 # Save current tty settings, since an aborting qemu call may leave things
141 STTY_RESTORE
=$
(stty
-g)
150 group_list
=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
153 if [ -z "$group_list" ]
155 echo "Group \"$r\" is empty or not defined?"
158 [ ! -s $tmp.list
] && touch $tmp.list
161 if grep -s "^$t\$" $tmp.list
>/dev
/null
165 echo "$t" >>$tmp.list
174 # Populate $tmp.list with all tests
175 awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list
2>/dev
/null
176 group_list
=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
179 if [ -z "$group_list" ]
181 echo "Group \"$r\" is empty or not defined?"
188 if [ $numsed -gt 100 ]
190 sed -f $tmp.
sed <$tmp.list
>$tmp.tmp
191 mv $tmp.tmp
$tmp.list
195 echo "/^$t\$/d" >>$tmp.
sed
196 numsed
=`expr $numsed + 1`
198 sed -f $tmp.
sed <$tmp.list
>$tmp.tmp
199 mv $tmp.tmp
$tmp.list
211 CACHEMODE_IS_DEFAULT
=false
220 -\? |
-h |
--help) # usage
221 echo "Usage: $0 [options] [testlist]"'
228 -raw test raw (default)
231 -parallels test parallels
241 image protocol options
242 -file test file (default)
244 -sheepdog test sheepdog
251 -xdiff graphical mode diff
252 -nocache use O_DIRECT on backing file
253 -misalign misalign memory allocations
254 -n show me, do not run tests
255 -o options -o options to pass to qemu-img create/convert
260 -g group[,group...] include tests from these groups
261 -x group[,group...] exclude tests from these groups
263 NNN-NNN include test range (eg. 012-021)
369 CACHEMODE_IS_DEFAULT
=false
374 QEMU_IO_OPTIONS
="$QEMU_IO_OPTIONS --misalign"
383 -g) # -g group ... pick from group file
388 -xdiff) # graphical diff mode
391 if [ ! -z "$DISPLAY" ]
393 command -v xdiff
>/dev
/null
2>&1 && diff=xdiff
394 command -v gdiff
>/dev
/null
2>&1 && diff=gdiff
395 command -v tkdiff
>/dev
/null
2>&1 && diff=tkdiff
396 command -v xxdiff
>/dev
/null
2>&1 && diff=xxdiff
400 -n) # show me, don't do it
412 -T) # turn on timestamp output
425 -x) # -x group ... exclude from group file
429 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
436 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
440 eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
441 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/.* //'`
444 echo "No tests in range \"$r\"?"
457 # get rid of leading 0s as can be interpreted as octal
458 start
=`echo $start | sed 's/^0*//'`
459 end
=`echo $end | sed 's/^0*//'`
465 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
468 if grep -s "^$id " "$source_iotests/group" >/dev
/null
470 # in group file ... OK
473 if [ -f expunged
] && $expunge && egrep "^$id([ ]|\$)" expunged
>/dev
/null
475 # expunged ... will be reported, but not run, later
479 if [ "$start" == "$end" -a "$id" == "$end" ]
481 echo "$id - unknown test"
484 echo "$id - unknown test, ignored"
493 # Set qemu-io cache mode with $CACHEMODE we have
494 QEMU_IO_OPTIONS
="$QEMU_IO_OPTIONS --cache $CACHEMODE"
496 QEMU_IO_OPTIONS_NO_FMT
="$QEMU_IO_OPTIONS"
497 if [ "$IMGOPTSSYNTAX" != "true" ]; then
498 QEMU_IO_OPTIONS
="$QEMU_IO_OPTIONS -f $IMGFMT"
501 # Set default options for qemu-img create -o if they were not specified
502 if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" |
grep "compat=" > /dev
/null
); then
503 IMGOPTS
=$
(_optstr_add
"$IMGOPTS" "compat=1.1")
505 if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" |
grep "iter-time=" > /dev
/null
); then
506 IMGOPTS
=$
(_optstr_add
"$IMGOPTS" "iter-time=10")
509 if [ -z "$SAMPLE_IMG_DIR" ]; then
510 SAMPLE_IMG_DIR
="$source_iotests/sample_images"
514 export SAMPLE_IMG_DIR
518 # found some valid test numbers ... this is good
523 # had test numbers, but none in group file ... do nothing
526 # no test numbers, do everything from group file
527 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
531 # should be sort -n, but this did not work for Linux when this
532 # was ported from IRIX
534 list
=`sort $tmp.list`
535 rm -f $tmp.list
$tmp.tmp
$tmp.
sed
537 if [ -z "$QEMU_PROG" ]
539 if [ -x "$build_iotests/qemu" ]; then
540 export QEMU_PROG
="$build_iotests/qemu"
541 elif [ -x "$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}" ]; then
542 export QEMU_PROG
="$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}"
544 pushd "$build_root" > /dev
/null
545 for binary
in *-softmmu/qemu-system-
*
549 export QEMU_PROG
="$build_root/$binary"
554 [ "$QEMU_PROG" = "" ] && _init_error
"qemu not found"
557 export QEMU_PROG
="$(type -p "$QEMU_PROG")"
559 if [ -z "$QEMU_IMG_PROG" ]; then
560 if [ -x "$build_iotests/qemu-img" ]; then
561 export QEMU_IMG_PROG
="$build_iotests/qemu-img"
562 elif [ -x "$build_root/qemu-img" ]; then
563 export QEMU_IMG_PROG
="$build_root/qemu-img"
565 _init_error
"qemu-img not found"
568 export QEMU_IMG_PROG
="$(type -p "$QEMU_IMG_PROG")"
570 if [ -z "$QEMU_IO_PROG" ]; then
571 if [ -x "$build_iotests/qemu-io" ]; then
572 export QEMU_IO_PROG
="$build_iotests/qemu-io"
573 elif [ -x "$build_root/qemu-io" ]; then
574 export QEMU_IO_PROG
="$build_root/qemu-io"
576 _init_error
"qemu-io not found"
579 export QEMU_IO_PROG
="$(type -p "$QEMU_IO_PROG")"
581 if [ -z $QEMU_NBD_PROG ]; then
582 if [ -x "$build_iotests/qemu-nbd" ]; then
583 export QEMU_NBD_PROG
="$build_iotests/qemu-nbd"
584 elif [ -x "$build_root/qemu-nbd" ]; then
585 export QEMU_NBD_PROG
="$build_root/qemu-nbd"
587 _init_error
"qemu-nbd not found"
590 export QEMU_NBD_PROG
="$(type -p "$QEMU_NBD_PROG")"
592 if [ -z "$QEMU_VXHS_PROG" ]; then
593 export QEMU_VXHS_PROG
="`set_prog_path qnio_server`"
596 if [ -x "$build_iotests/socket_scm_helper" ]
598 export SOCKET_SCM_HELPER
="$build_iotests/socket_scm_helper"
601 default_machine
=$
($QEMU_PROG -machine help |
sed -n '/(default)/ s/ .*//p')
602 default_alias_machine
=$
($QEMU_PROG -machine help | \
603 sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }")
604 if [[ "$default_alias_machine" ]]; then
605 default_machine
="$default_alias_machine"
608 export QEMU_DEFAULT_MACHINE
="$default_machine"
610 TIMESTAMP_FILE
=check.time-
$IMGPROTO-$IMGFMT
614 date "+%H %M %S" |
awk '{ print $1*3600 + $2*60 + $3 }'
630 if [ -f $TIMESTAMP_FILE -a -f $tmp.
time ]
632 cat $TIMESTAMP_FILE $tmp.
time \
636 for (i in t) print i " " t[i]
640 mv $tmp.out
$TIMESTAMP_FILE
643 if [ -f $tmp.expunged
]
645 notrun
=`wc -l <$tmp.expunged | sed -e 's/ *//g'`
646 try
=`expr $try - $notrun`
647 list
=`echo "$list" | sed -f $tmp.expunged`
652 echo $list |
fmt |
sed -e 's/^/ /' >>check.log
653 $interrupt && echo "Interrupted!" >>check.log
655 if [ ! -z "$notrun" ]
657 echo "Not run:$notrun"
658 echo "Not run:$notrun" >>check.log
660 if [ ! -z "$n_bad" -a $n_bad != 0 ]
663 echo "Failed $n_bad of $try tests"
664 echo "Failures:$bad" |
fmt >>check.log
665 echo "Failed $n_bad of $try tests" >>check.log
667 echo "Passed all $try tests"
668 echo "Passed all $try tests" >>check.log
673 if test -n "$STTY_RESTORE"; then
676 rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.
time
677 rm -f "${TEST_DIR}"/check.pid
"${TEST_DIR}"/check.sts
681 trap "_wrapup; exit \$status" 0 1 2 3 15
683 [ -f $TIMESTAMP_FILE ] ||
touch $TIMESTAMP_FILE
685 FULL_IMGFMT_DETAILS
=`_full_imgfmt_details`
686 FULL_HOST_DETAILS
=`_full_platform_details`
689 QEMU -- "$QEMU_PROG" $QEMU_OPTIONS
690 QEMU_IMG -- "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS
691 QEMU_IO -- "$QEMU_IO_PROG" $QEMU_IO_OPTIONS
692 QEMU_NBD -- "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS
693 IMGFMT -- $FULL_IMGFMT_DETAILS
694 IMGPROTO -- $IMGPROTO
695 PLATFORM -- $FULL_HOST_DETAILS
696 TEST_DIR -- $TEST_DIR
697 SOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER
703 [ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
709 if [ -n "$TESTS_REMAINING_LOG" ] ; then
710 sed -e "s/$seq//" -e 's/ / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
711 mv $TESTS_REMAINING_LOG.tmp
$TESTS_REMAINING_LOG
719 elif [ -f expunged
] && $expunge && egrep "^$seq([ ]|\$)" expunged
>/dev
/null
723 echo "/^$seq\$/d" >>$tmp.expunged
724 elif [ ! -f "$source_iotests/$seq" ]
726 echo " - no such test?"
727 echo "/^$seq\$/d" >>$tmp.expunged
729 # really going to try and run this one
732 lasttime
=`sed -n -e "/^$seq /s/.* //p" <$TIMESTAMP_FILE`
733 if [ "X$lasttime" != X
]; then
734 printf %s
" ${lasttime}s ..."
736 printf " " # prettier output with timestamps.
738 rm -f core
$seq.notrun
741 $timestamp && printf %s
" [$(date "+%T
")]"
743 if [ "$(head -n 1 "$source_iotests/$seq")" == "#!/usr/bin/env python" ]; then
744 run_command
="$PYTHON $seq"
748 export OUTPUT_DIR
=$PWD
750 (cd "$source_iotests";
751 MALLOC_PERTURB_
=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
752 $run_command -d 2>&1 |
tee $tmp.out
)
754 (cd "$source_iotests";
755 MALLOC_PERTURB_
=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
756 $run_command >$tmp.out
2>&1)
759 $timestamp && _timestamp
764 printf " [dumped core]"
769 if [ -f $seq.notrun
]
771 $timestamp ||
printf " [not run] "
772 $timestamp && echo " [not run]" && printf %s
" $seq -- "
774 notrun
="$notrun $seq"
778 printf %s
" [failed, exit status $sts]"
782 reference
="$source_iotests/$seq.out"
783 reference_machine
="$source_iotests/$seq.$QEMU_DEFAULT_MACHINE.out"
784 if [ -f "$reference_machine" ]; then
785 reference
="$reference_machine"
788 reference_format
="$source_iotests/$seq.out.$IMGFMT"
789 if [ -f "$reference_format" ]; then
790 reference
="$reference_format"
793 if [ "$CACHEMODE" = "none" ]; then
794 [ -f "$source_iotests/$seq.out.nocache" ] && reference
="$source_iotests/$seq.out.nocache"
797 if [ ! -f "$reference" ]
799 echo " - no qualified output"
802 if diff -w "$reference" $tmp.out
>/dev
/null
2>&1
809 echo "$seq `expr $stop - $start`" >>$tmp.
time
812 echo " - output mismatch (see $seq.out.bad)"
813 mv $tmp.out
$seq.out.bad
814 $diff -w "$reference" "$PWD"/$seq.out.bad
822 # come here for each test, except when $showme is true
827 n_bad
=`expr $n_bad + 1`
830 [ -f $seq.notrun
] || try
=`expr $try + 1`