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
40 # called from the build tree
41 source_iotests
=$
(dirname "$(readlink "$0")")
42 if [ -z "$source_iotests" ]
44 _init_error
"failed to obtain source tree name from check symlink"
46 source_iotests
=$
(cd "$source_iotests"; pwd) || _init_error
"failed to enter source tree"
49 # called from the source tree
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
57 build_root
="$build_iotests/../.."
60 if ! .
"$build_iotests/common.env"
62 _init_error
"failed to source common.env (make sure the qemu-iotests are run from tests/qemu-iotests in the build tree)"
65 # we need common.config
66 if ! .
"$source_iotests/common.config"
68 _init_error
"failed to source common.config"
71 _full_imgfmt_details
()
73 if [ -n "$IMGOPTS" ]; then
74 echo "$IMGFMT ($IMGOPTS)"
80 _full_platform_details
()
86 echo "$os/$platform $host $kernel"
92 QEMU -- "$QEMU_PROG" $QEMU_OPTIONS
93 QEMU_IMG -- "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS
94 QEMU_IO -- "$QEMU_IO_PROG" $QEMU_IO_OPTIONS
95 QEMU_NBD -- "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS
96 IMGFMT -- $FULL_IMGFMT_DETAILS
98 PLATFORM -- $FULL_HOST_DETAILS
100 SOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER
105 # $1 = prog to look for
108 p
=$
(command -v $1 2> /dev
/null
)
109 if [ -n "$p" -a -x "$p" ]; then
116 if [ -z "$TEST_DIR" ]; then
117 TEST_DIR
=$PWD/scratch
120 if [ ! -e "$TEST_DIR" ]; then
137 rm -f $tmp.list
$tmp.tmp
$tmp.
sed
140 export IMGFMT_GENERIC
=true
143 export CACHEMODE
="writeback"
144 export QEMU_IO_OPTIONS
=""
145 export QEMU_IO_OPTIONS_NO_FMT
=""
146 export CACHEMODE_IS_DEFAULT
=true
147 export VALGRIND_QEMU
=
149 export IMGOPTSSYNTAX
=false
151 # Save current tty settings, since an aborting qemu call may leave things
155 STTY_RESTORE
=$
(stty
-g)
164 group_list
=$
(sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
167 if [ -z "$group_list" ]
169 echo "Group \"$r\" is empty or not defined?"
172 [ ! -s $tmp.list
] && touch $tmp.list
175 if grep -s "^$t\$" $tmp.list
>/dev
/null
179 echo "$t" >>$tmp.list
188 # Populate $tmp.list with all tests
189 awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list
2>/dev
/null
190 group_list
=$
(sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
193 if [ -z "$group_list" ]
195 echo "Group \"$r\" is empty or not defined?"
202 if [ $numsed -gt 100 ]
204 sed -f $tmp.
sed <$tmp.list
>$tmp.tmp
205 mv $tmp.tmp
$tmp.list
209 echo "/^$t\$/d" >>$tmp.
sed
210 numsed
=$
(expr $numsed + 1)
212 sed -f $tmp.
sed <$tmp.list
>$tmp.tmp
213 mv $tmp.tmp
$tmp.list
225 CACHEMODE_IS_DEFAULT
=false
234 -\? |
-h |
--help) # usage
235 echo "Usage: $0 [options] [testlist]"'
242 -raw test raw (default)
245 -parallels test parallels
256 image protocol options
257 -file test file (default)
259 -sheepdog test sheepdog
266 -xdiff graphical mode diff
267 -nocache use O_DIRECT on backing file
268 -misalign misalign memory allocations
269 -n show me, do not run tests
270 -o options -o options to pass to qemu-img create/convert
272 -makecheck pretty print output for make check
275 -g group[,group...] include tests from these groups
276 -x group[,group...] exclude tests from these groups
278 NNN-NNN include test range (eg. 012-021)
390 CACHEMODE_IS_DEFAULT
=false
395 QEMU_IO_OPTIONS
="$QEMU_IO_OPTIONS --misalign"
404 -g) # -g group ... pick from group file
409 -xdiff) # graphical diff mode
412 if [ ! -z "$DISPLAY" ]
414 command -v xdiff
>/dev
/null
2>&1 && diff=xdiff
415 command -v gdiff
>/dev
/null
2>&1 && diff=gdiff
416 command -v tkdiff
>/dev
/null
2>&1 && diff=tkdiff
417 command -v xxdiff
>/dev
/null
2>&1 && diff=xxdiff
420 -makecheck) # makecheck friendly output
424 -n) # show me, don't do it
436 -T) # deprecated timestamp option
448 -x) # -x group ... exclude from group file
452 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
459 eval $
(echo $r |
sed -e 's/^/start=/' -e 's/-/ end=/')
463 eval $
(echo $r |
sed -e 's/^/start=/' -e 's/-//')
464 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/.* //')
467 echo "No tests in range \"$r\"?"
480 # get rid of leading 0s as can be interpreted as octal
481 start
=$
(echo $start |
sed 's/^0*//')
482 end
=$
(echo $end |
sed 's/^0*//')
488 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
491 if grep -s "^$id " "$source_iotests/group" >/dev
/null
493 # in group file ... OK
496 if [ -f expunged
] && $expunge && egrep "^$id([ ]|\$)" expunged
>/dev
/null
498 # expunged ... will be reported, but not run, later
502 if [ "$start" == "$end" -a "$id" == "$end" ]
504 echo "$id - unknown test"
507 echo "$id - unknown test, ignored"
516 # Set qemu-io cache mode with $CACHEMODE we have
517 QEMU_IO_OPTIONS
="$QEMU_IO_OPTIONS --cache $CACHEMODE"
519 QEMU_IO_OPTIONS_NO_FMT
="$QEMU_IO_OPTIONS"
520 if [ "$IMGOPTSSYNTAX" != "true" ]; then
521 QEMU_IO_OPTIONS
="$QEMU_IO_OPTIONS -f $IMGFMT"
524 # Set default options for qemu-img create -o if they were not specified
525 if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" |
grep "compat=" > /dev
/null
); then
526 IMGOPTS
=$
(_optstr_add
"$IMGOPTS" "compat=1.1")
528 if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" |
grep "iter-time=" > /dev
/null
); then
529 IMGOPTS
=$
(_optstr_add
"$IMGOPTS" "iter-time=10")
532 if [ -z "$SAMPLE_IMG_DIR" ]; then
533 SAMPLE_IMG_DIR
="$source_iotests/sample_images"
537 export SAMPLE_IMG_DIR
541 # found some valid test numbers ... this is good
546 # had test numbers, but none in group file ... do nothing
549 # no test numbers, do everything from group file
550 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
554 # should be sort -n, but this did not work for Linux when this
555 # was ported from IRIX
557 list
=$
(sort $tmp.list
)
558 rm -f $tmp.list
$tmp.tmp
$tmp.
sed
560 if [ -z "$QEMU_PROG" ]
562 if [ -x "$build_iotests/qemu" ]; then
563 export QEMU_PROG
="$build_iotests/qemu"
564 elif [ -x "$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}" ]; then
565 export QEMU_PROG
="$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}"
567 pushd "$build_root" > /dev
/null
568 for binary
in *-softmmu/qemu-system-
*
572 export QEMU_PROG
="$build_root/$binary"
577 [ "$QEMU_PROG" = "" ] && _init_error
"qemu not found"
580 export QEMU_PROG
="$(type -p "$QEMU_PROG")"
583 *qemu-system-arm|
*qemu-system-aarch64
)
584 export QEMU_OPTIONS
="-nodefaults -machine virt,accel=qtest"
586 *qemu-system-tricore
)
587 export QEMU_OPTIONS
="-nodefaults -machine tricore_testboard,accel=qtest"
590 export QEMU_OPTIONS
="-nodefaults -machine accel=qtest"
594 if [ -z "$QEMU_IMG_PROG" ]; then
595 if [ -x "$build_iotests/qemu-img" ]; then
596 export QEMU_IMG_PROG
="$build_iotests/qemu-img"
597 elif [ -x "$build_root/qemu-img" ]; then
598 export QEMU_IMG_PROG
="$build_root/qemu-img"
600 _init_error
"qemu-img not found"
603 export QEMU_IMG_PROG
="$(type -p "$QEMU_IMG_PROG")"
605 if [ -z "$QEMU_IO_PROG" ]; then
606 if [ -x "$build_iotests/qemu-io" ]; then
607 export QEMU_IO_PROG
="$build_iotests/qemu-io"
608 elif [ -x "$build_root/qemu-io" ]; then
609 export QEMU_IO_PROG
="$build_root/qemu-io"
611 _init_error
"qemu-io not found"
614 export QEMU_IO_PROG
="$(type -p "$QEMU_IO_PROG")"
616 if [ -z $QEMU_NBD_PROG ]; then
617 if [ -x "$build_iotests/qemu-nbd" ]; then
618 export QEMU_NBD_PROG
="$build_iotests/qemu-nbd"
619 elif [ -x "$build_root/qemu-nbd" ]; then
620 export QEMU_NBD_PROG
="$build_root/qemu-nbd"
622 _init_error
"qemu-nbd not found"
625 export QEMU_NBD_PROG
="$(type -p "$QEMU_NBD_PROG")"
627 if [ -z "$QEMU_VXHS_PROG" ]; then
628 export QEMU_VXHS_PROG
="$(set_prog_path qnio_server)"
631 if [ -x "$build_iotests/socket_scm_helper" ]
633 export SOCKET_SCM_HELPER
="$build_iotests/socket_scm_helper"
636 default_machine
=$
($QEMU_PROG -machine help |
sed -n '/(default)/ s/ .*//p')
637 default_alias_machine
=$
($QEMU_PROG -machine help | \
638 sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }")
639 if [[ "$default_alias_machine" ]]; then
640 default_machine
="$default_alias_machine"
643 export QEMU_DEFAULT_MACHINE
="$default_machine"
645 TIMESTAMP_FILE
=check.time-
$IMGPROTO-$IMGFMT
649 date "+%H %M %S" |
awk '{ print $1*3600 + $2*60 + $3 }'
659 if [ -f $TIMESTAMP_FILE -a -f $tmp.
time ]
661 cat $TIMESTAMP_FILE $tmp.
time \
665 for (i in t) print i " " t[i]
669 mv $tmp.out
$TIMESTAMP_FILE
672 if [ -f $tmp.expunged
]
674 notrun
=$
(wc -l <$tmp.expunged |
sed -e 's/ *//g')
675 try
=$
(expr $try - $notrun)
676 list
=$
(echo "$list" |
sed -f $tmp.expunged
)
681 echo $list |
fmt |
sed -e 's/^/ /' >>check.log
682 $interrupt && echo "Interrupted!" >>check.log
684 if [ ! -z "$notrun" ]
686 echo "Not run:$notrun"
687 echo "Not run:$notrun" >>check.log
689 if [ ! -z "$casenotrun" ]
691 echo "Some cases not run in:$casenotrun"
692 echo "Some cases not run in:$casenotrun" >>check.log
694 if [ ! -z "$n_bad" -a $n_bad != 0 ]
697 echo "Failed $n_bad of $try tests"
698 echo "Failures:$bad" |
fmt >>check.log
699 echo "Failed $n_bad of $try tests" >>check.log
701 echo "Passed all $try tests"
702 echo "Passed all $try tests" >>check.log
707 if test -n "$STTY_RESTORE"; then
710 rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.
time
711 rm -f "${TEST_DIR}"/check.pid
"${TEST_DIR}"/check.sts
715 trap "_wrapup; exit \$status" 0 1 2 3 15
717 # Report the test start and results. For makecheck we want to pretty
718 # print the whole report at the end of the execution.
719 # args: $seq, $starttime, $lasttime
722 if ! $makecheck; then
724 local lasttime
=" (last: $3s)"
726 printf "%-8s %-10s [%s] %4s%-14s\r" "$1" "..." "$2" "..." "$lasttime"
729 # args:$seq $status $starttime $lasttime $thistime $details
730 _report_test_result
()
732 local status lasttime thistime
734 if [ -n "$2" ] && [ "$2" != "pass" ]; then
737 printf " TEST iotest-$IMGFMT: %s%s\n" "$1" "$status"
742 lasttime
=" (last: $4s)"
748 "pass") status
=$
(printf "\e[32m%-10s\e[0m" "$2") ;;
749 "fail") status
=$
(printf "\e[1m\e[31m%-10s\e[0m" "$2") ;;
750 "not run") status
=$
(printf "\e[33m%-10s\e[0m" "$2") ;;
751 *) status
=$
(printf "%-10s" "$2") ;;
754 printf "%-8s %s [%s] [%s] %4s%-14s %s\n" "$1" "$status" "$3" "$(date '+%T')" "$thistime" "$lasttime" "$6"
757 [ -f $TIMESTAMP_FILE ] ||
touch $TIMESTAMP_FILE
759 FULL_IMGFMT_DETAILS
=$
(_full_imgfmt_details
)
760 FULL_HOST_DETAILS
=$
(_full_platform_details
)
762 if ! $makecheck; then
768 [ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
772 err
=false
# error flag
773 printdiff
=false
# show diff to reference output?
774 status
="" # test result summary
775 results
="" # test result details
777 if [ -n "$TESTS_REMAINING_LOG" ] ; then
778 sed -e "s/$seq//" -e 's/ / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
779 mv $TESTS_REMAINING_LOG.tmp
$TESTS_REMAINING_LOG
783 lasttime
=$
(sed -n -e "/^$seq /s/.* //p" <$TIMESTAMP_FILE)
784 starttime
=$
(date "+%T")
785 _report_test_start
$seq $starttime $lasttime
790 elif [ -f expunged
] && $expunge && egrep "^$seq([ ]|\$)" expunged
>/dev
/null
795 echo "/^$seq\$/d" >>$tmp.expunged
796 elif [ ! -f "$source_iotests/$seq" ]
799 results
="no such test?"
800 echo "/^$seq\$/d" >>$tmp.expunged
802 # really going to try and run this one
805 rm -f core
$seq.notrun
806 rm -f $seq.casenotrun
810 if [ "$(head -n 1 "$source_iotests/$seq")" == "#!/usr/bin/env python" ]; then
811 run_command
="$PYTHON $seq"
815 export OUTPUT_DIR
=$PWD
817 (cd "$source_iotests";
818 MALLOC_PERTURB_
=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
819 $run_command -d 2>&1 |
tee $tmp.out
)
821 (cd "$source_iotests";
822 MALLOC_PERTURB_
=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
823 $run_command >$tmp.out
2>&1)
832 results
="[dumped core] $seq.core"
836 if [ -f $seq.notrun
]
838 # overwrites timestamp output
840 results
="$(cat $seq.notrun)"
845 results
=$
(printf %s
"[failed, exit status $sts]")
849 reference
="$source_iotests/$seq.out"
850 reference_machine
="$source_iotests/$seq.$QEMU_DEFAULT_MACHINE.out"
851 if [ -f "$reference_machine" ]; then
852 reference
="$reference_machine"
855 reference_format
="$source_iotests/$seq.out.$IMGFMT"
856 if [ -f "$reference_format" ]; then
857 reference
="$reference_format"
860 if [ "$CACHEMODE" = "none" ]; then
861 [ -f "$source_iotests/$seq.out.nocache" ] && reference
="$source_iotests/$seq.out.nocache"
864 if [ ! -f "$reference" ]
867 reason
="no qualified output"
870 if diff -w "$reference" $tmp.out
>/dev
/null
2>&1
874 thistime
=$
(expr $stop - $start)
875 echo "$seq $thistime" >>$tmp.
time
878 mv $tmp.out
$seq.out.bad
879 $diff -w "$reference" "$PWD"/$seq.out.bad
881 results
="output mismatch (see $seq.out.bad)"
887 if [ -f $seq.casenotrun
]
890 casenotrun
="$casenotrun $seq"
894 # come here for each test, except when $showme is true
896 _report_test_result
$seq "$status" "$starttime" "$lasttime" "$thistime" "$results"
907 $diff -w "$reference" "$PWD"/$seq.out.bad
910 n_bad
=$
(expr $n_bad + 1)
914 notrun
="$notrun $seq"
922 status
=$
(expr $n_bad)