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
31 # by default don't output timestamps
32 timestamp
=${TIMESTAMP:=false}
42 # called from the build tree
43 source_iotests
=$
(dirname "$(readlink "$0")")
44 if [ -z "$source_iotests" ]
46 _init_error
"failed to obtain source tree name from check symlink"
48 source_iotests
=$
(cd "$source_iotests"; pwd) || _init_error
"failed to enter source tree"
51 # called from the source tree
53 # this may be an in-tree build (note that in the following code we may not
54 # assume that it truly is and have to test whether the build results
59 build_root
="$build_iotests/../.."
62 if ! .
"$build_iotests/common.env"
64 _init_error
"failed to source common.env (make sure the qemu-iotests are run from tests/qemu-iotests in the build tree)"
67 # we need common.config
68 if ! .
"$source_iotests/common.config"
70 _init_error
"failed to source common.config"
73 _full_imgfmt_details
()
75 if [ -n "$IMGOPTS" ]; then
76 echo "$IMGFMT ($IMGOPTS)"
82 _full_platform_details
()
88 echo "$os/$platform $host $kernel"
91 # $1 = prog to look for
94 p
=$
(command -v $1 2> /dev
/null
)
95 if [ -n "$p" -a -x "$p" ]; then
102 if [ -z "$TEST_DIR" ]; then
103 TEST_DIR
=$PWD/scratch
106 if [ ! -e "$TEST_DIR" ]; then
123 rm -f $tmp.list
$tmp.tmp
$tmp.
sed
126 export IMGFMT_GENERIC
=true
129 export CACHEMODE
="writeback"
130 export QEMU_IO_OPTIONS
=""
131 export QEMU_IO_OPTIONS_NO_FMT
=""
132 export CACHEMODE_IS_DEFAULT
=true
133 export QEMU_OPTIONS
="-nodefaults -machine accel=qtest"
134 export VALGRIND_QEMU
=
136 export IMGOPTSSYNTAX
=false
138 # Save current tty settings, since an aborting qemu call may leave things
142 STTY_RESTORE
=$
(stty
-g)
151 group_list
=$
(sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
154 if [ -z "$group_list" ]
156 echo "Group \"$r\" is empty or not defined?"
159 [ ! -s $tmp.list
] && touch $tmp.list
162 if grep -s "^$t\$" $tmp.list
>/dev
/null
166 echo "$t" >>$tmp.list
175 # Populate $tmp.list with all tests
176 awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list
2>/dev
/null
177 group_list
=$
(sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
180 if [ -z "$group_list" ]
182 echo "Group \"$r\" is empty or not defined?"
189 if [ $numsed -gt 100 ]
191 sed -f $tmp.
sed <$tmp.list
>$tmp.tmp
192 mv $tmp.tmp
$tmp.list
196 echo "/^$t\$/d" >>$tmp.
sed
197 numsed
=$
(expr $numsed + 1)
199 sed -f $tmp.
sed <$tmp.list
>$tmp.tmp
200 mv $tmp.tmp
$tmp.list
212 CACHEMODE_IS_DEFAULT
=false
221 -\? |
-h |
--help) # usage
222 echo "Usage: $0 [options] [testlist]"'
229 -raw test raw (default)
232 -parallels test parallels
243 image protocol options
244 -file test file (default)
246 -sheepdog test sheepdog
253 -xdiff graphical mode diff
254 -nocache use O_DIRECT on backing file
255 -misalign misalign memory allocations
256 -n show me, do not run tests
257 -o options -o options to pass to qemu-img create/convert
262 -g group[,group...] include tests from these groups
263 -x group[,group...] exclude tests from these groups
265 NNN-NNN include test range (eg. 012-021)
377 CACHEMODE_IS_DEFAULT
=false
382 QEMU_IO_OPTIONS
="$QEMU_IO_OPTIONS --misalign"
391 -g) # -g group ... pick from group file
396 -xdiff) # graphical diff mode
399 if [ ! -z "$DISPLAY" ]
401 command -v xdiff
>/dev
/null
2>&1 && diff=xdiff
402 command -v gdiff
>/dev
/null
2>&1 && diff=gdiff
403 command -v tkdiff
>/dev
/null
2>&1 && diff=tkdiff
404 command -v xxdiff
>/dev
/null
2>&1 && diff=xxdiff
408 -n) # show me, don't do it
420 -T) # turn on timestamp output
433 -x) # -x group ... exclude from group file
437 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
444 eval $
(echo $r |
sed -e 's/^/start=/' -e 's/-/ end=/')
448 eval $
(echo $r |
sed -e 's/^/start=/' -e 's/-//')
449 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/.* //')
452 echo "No tests in range \"$r\"?"
465 # get rid of leading 0s as can be interpreted as octal
466 start
=$
(echo $start |
sed 's/^0*//')
467 end
=$
(echo $end |
sed 's/^0*//')
473 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
476 if grep -s "^$id " "$source_iotests/group" >/dev
/null
478 # in group file ... OK
481 if [ -f expunged
] && $expunge && egrep "^$id([ ]|\$)" expunged
>/dev
/null
483 # expunged ... will be reported, but not run, later
487 if [ "$start" == "$end" -a "$id" == "$end" ]
489 echo "$id - unknown test"
492 echo "$id - unknown test, ignored"
501 # Set qemu-io cache mode with $CACHEMODE we have
502 QEMU_IO_OPTIONS
="$QEMU_IO_OPTIONS --cache $CACHEMODE"
504 QEMU_IO_OPTIONS_NO_FMT
="$QEMU_IO_OPTIONS"
505 if [ "$IMGOPTSSYNTAX" != "true" ]; then
506 QEMU_IO_OPTIONS
="$QEMU_IO_OPTIONS -f $IMGFMT"
509 # Set default options for qemu-img create -o if they were not specified
510 if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" |
grep "compat=" > /dev
/null
); then
511 IMGOPTS
=$
(_optstr_add
"$IMGOPTS" "compat=1.1")
513 if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" |
grep "iter-time=" > /dev
/null
); then
514 IMGOPTS
=$
(_optstr_add
"$IMGOPTS" "iter-time=10")
517 if [ -z "$SAMPLE_IMG_DIR" ]; then
518 SAMPLE_IMG_DIR
="$source_iotests/sample_images"
522 export SAMPLE_IMG_DIR
526 # found some valid test numbers ... this is good
531 # had test numbers, but none in group file ... do nothing
534 # no test numbers, do everything from group file
535 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
539 # should be sort -n, but this did not work for Linux when this
540 # was ported from IRIX
542 list
=$
(sort $tmp.list
)
543 rm -f $tmp.list
$tmp.tmp
$tmp.
sed
545 if [ -z "$QEMU_PROG" ]
547 if [ -x "$build_iotests/qemu" ]; then
548 export QEMU_PROG
="$build_iotests/qemu"
549 elif [ -x "$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}" ]; then
550 export QEMU_PROG
="$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}"
552 pushd "$build_root" > /dev
/null
553 for binary
in *-softmmu/qemu-system-
*
557 export QEMU_PROG
="$build_root/$binary"
562 [ "$QEMU_PROG" = "" ] && _init_error
"qemu not found"
565 export QEMU_PROG
="$(type -p "$QEMU_PROG")"
567 if [ -z "$QEMU_IMG_PROG" ]; then
568 if [ -x "$build_iotests/qemu-img" ]; then
569 export QEMU_IMG_PROG
="$build_iotests/qemu-img"
570 elif [ -x "$build_root/qemu-img" ]; then
571 export QEMU_IMG_PROG
="$build_root/qemu-img"
573 _init_error
"qemu-img not found"
576 export QEMU_IMG_PROG
="$(type -p "$QEMU_IMG_PROG")"
578 if [ -z "$QEMU_IO_PROG" ]; then
579 if [ -x "$build_iotests/qemu-io" ]; then
580 export QEMU_IO_PROG
="$build_iotests/qemu-io"
581 elif [ -x "$build_root/qemu-io" ]; then
582 export QEMU_IO_PROG
="$build_root/qemu-io"
584 _init_error
"qemu-io not found"
587 export QEMU_IO_PROG
="$(type -p "$QEMU_IO_PROG")"
589 if [ -z $QEMU_NBD_PROG ]; then
590 if [ -x "$build_iotests/qemu-nbd" ]; then
591 export QEMU_NBD_PROG
="$build_iotests/qemu-nbd"
592 elif [ -x "$build_root/qemu-nbd" ]; then
593 export QEMU_NBD_PROG
="$build_root/qemu-nbd"
595 _init_error
"qemu-nbd not found"
598 export QEMU_NBD_PROG
="$(type -p "$QEMU_NBD_PROG")"
600 if [ -z "$QEMU_VXHS_PROG" ]; then
601 export QEMU_VXHS_PROG
="$(set_prog_path qnio_server)"
604 if [ -x "$build_iotests/socket_scm_helper" ]
606 export SOCKET_SCM_HELPER
="$build_iotests/socket_scm_helper"
609 default_machine
=$
($QEMU_PROG -machine help |
sed -n '/(default)/ s/ .*//p')
610 default_alias_machine
=$
($QEMU_PROG -machine help | \
611 sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }")
612 if [[ "$default_alias_machine" ]]; then
613 default_machine
="$default_alias_machine"
616 export QEMU_DEFAULT_MACHINE
="$default_machine"
618 TIMESTAMP_FILE
=check.time-
$IMGPROTO-$IMGFMT
622 date "+%H %M %S" |
awk '{ print $1*3600 + $2*60 + $3 }'
638 if [ -f $TIMESTAMP_FILE -a -f $tmp.
time ]
640 cat $TIMESTAMP_FILE $tmp.
time \
644 for (i in t) print i " " t[i]
648 mv $tmp.out
$TIMESTAMP_FILE
651 if [ -f $tmp.expunged
]
653 notrun
=$
(wc -l <$tmp.expunged |
sed -e 's/ *//g')
654 try
=$
(expr $try - $notrun)
655 list
=$
(echo "$list" |
sed -f $tmp.expunged
)
660 echo $list |
fmt |
sed -e 's/^/ /' >>check.log
661 $interrupt && echo "Interrupted!" >>check.log
663 if [ ! -z "$notrun" ]
665 echo "Not run:$notrun"
666 echo "Not run:$notrun" >>check.log
668 if [ ! -z "$casenotrun" ]
670 echo "Some cases not run in:$casenotrun"
671 echo "Some cases not run in:$casenotrun" >>check.log
673 if [ ! -z "$n_bad" -a $n_bad != 0 ]
676 echo "Failed $n_bad of $try tests"
677 echo "Failures:$bad" |
fmt >>check.log
678 echo "Failed $n_bad of $try tests" >>check.log
680 echo "Passed all $try tests"
681 echo "Passed all $try tests" >>check.log
686 if test -n "$STTY_RESTORE"; then
689 rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.
time
690 rm -f "${TEST_DIR}"/check.pid
"${TEST_DIR}"/check.sts
694 trap "_wrapup; exit \$status" 0 1 2 3 15
696 [ -f $TIMESTAMP_FILE ] ||
touch $TIMESTAMP_FILE
698 FULL_IMGFMT_DETAILS
=$
(_full_imgfmt_details
)
699 FULL_HOST_DETAILS
=$
(_full_platform_details
)
702 QEMU -- "$QEMU_PROG" $QEMU_OPTIONS
703 QEMU_IMG -- "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS
704 QEMU_IO -- "$QEMU_IO_PROG" $QEMU_IO_OPTIONS
705 QEMU_NBD -- "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS
706 IMGFMT -- $FULL_IMGFMT_DETAILS
707 IMGPROTO -- $IMGPROTO
708 PLATFORM -- $FULL_HOST_DETAILS
709 TEST_DIR -- $TEST_DIR
710 SOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER
716 [ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
722 if [ -n "$TESTS_REMAINING_LOG" ] ; then
723 sed -e "s/$seq//" -e 's/ / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
724 mv $TESTS_REMAINING_LOG.tmp
$TESTS_REMAINING_LOG
732 elif [ -f expunged
] && $expunge && egrep "^$seq([ ]|\$)" expunged
>/dev
/null
736 echo "/^$seq\$/d" >>$tmp.expunged
737 elif [ ! -f "$source_iotests/$seq" ]
739 echo " - no such test?"
740 echo "/^$seq\$/d" >>$tmp.expunged
742 # really going to try and run this one
745 lasttime
=$
(sed -n -e "/^$seq /s/.* //p" <$TIMESTAMP_FILE)
746 if [ "X$lasttime" != X
]; then
747 printf %s
" ${lasttime}s ..."
749 printf " " # prettier output with timestamps.
751 rm -f core
$seq.notrun
752 rm -f $seq.casenotrun
755 $timestamp && printf %s
" [$(date "+%T
")]"
757 if [ "$(head -n 1 "$source_iotests/$seq")" == "#!/usr/bin/env python" ]; then
758 run_command
="$PYTHON $seq"
762 export OUTPUT_DIR
=$PWD
764 (cd "$source_iotests";
765 MALLOC_PERTURB_
=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
766 $run_command -d 2>&1 |
tee $tmp.out
)
768 (cd "$source_iotests";
769 MALLOC_PERTURB_
=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
770 $run_command >$tmp.out
2>&1)
773 $timestamp && _timestamp
778 printf " [dumped core]"
783 if [ -f $seq.notrun
]
785 $timestamp ||
printf " [not run] "
786 $timestamp && echo " [not run]" && printf %s
" $seq -- "
788 notrun
="$notrun $seq"
792 printf %s
" [failed, exit status $sts]"
796 reference
="$source_iotests/$seq.out"
797 reference_machine
="$source_iotests/$seq.$QEMU_DEFAULT_MACHINE.out"
798 if [ -f "$reference_machine" ]; then
799 reference
="$reference_machine"
802 reference_format
="$source_iotests/$seq.out.$IMGFMT"
803 if [ -f "$reference_format" ]; then
804 reference
="$reference_format"
807 if [ "$CACHEMODE" = "none" ]; then
808 [ -f "$source_iotests/$seq.out.nocache" ] && reference
="$source_iotests/$seq.out.nocache"
811 if [ ! -f "$reference" ]
813 echo " - no qualified output"
816 if diff -w "$reference" $tmp.out
>/dev
/null
2>&1
823 echo "$seq $(expr $stop - $start)" >>$tmp.
time
826 echo " - output mismatch (see $seq.out.bad)"
827 mv $tmp.out
$seq.out.bad
828 $diff -w "$reference" "$PWD"/$seq.out.bad
833 if [ -f $seq.casenotrun
]
836 casenotrun
="$casenotrun $seq"
840 # come here for each test, except when $showme is true
845 n_bad
=$
(expr $n_bad + 1)
848 [ -f $seq.notrun
] || try
=$
(expr $try + 1)
854 status
=$
(expr $n_bad)