s390x: upgrade status of KVM cores to "supported"
[qemu/ar7.git] / tests / qemu-iotests / check
blob895e1e3dcbd5bb1af9fada42a95dfa809fd45249
1 #!/bin/bash
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
22 status=0
23 needwrap=true
24 try=0
25 n_bad=0
26 bad=""
27 notrun=""
28 interrupt=true
30 # by default don't output timestamps
31 timestamp=${TIMESTAMP:=false}
33 _init_error()
35 echo "check: $1" >&2
36 exit 1
39 if [ -L "$0" ]
40 then
41 # called from the build tree
42 source_iotests=$(dirname "$(readlink "$0")")
43 if [ -z "$source_iotests" ]
44 then
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"
48 build_iotests=$PWD
49 else
50 # called from the source tree
51 source_iotests=$PWD
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
54 # actually exist)
55 build_iotests=$PWD
58 build_root="$build_iotests/../.."
60 # we need common.env
61 if ! . "$build_iotests/common.env"
62 then
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"
68 then
69 _init_error "failed to source common.config"
72 _full_imgfmt_details()
74 if [ -n "$IMGOPTS" ]; then
75 echo "$IMGFMT ($IMGOPTS)"
76 else
77 echo "$IMGFMT"
81 _full_platform_details()
83 os=$(uname -s)
84 host=$(hostname -s)
85 kernel=$(uname -r)
86 platform=$(uname -m)
87 echo "$os/$platform $host $kernel"
90 # $1 = prog to look for
91 set_prog_path()
93 p=$(command -v $1 2> /dev/null)
94 if [ -n "$p" -a -x "$p" ]; then
95 type -p "$p"
96 else
97 return 1
101 if [ -z "$TEST_DIR" ]; then
102 TEST_DIR=$PWD/scratch
105 if [ ! -e "$TEST_DIR" ]; then
106 mkdir "$TEST_DIR"
109 diff="diff -u"
110 verbose=false
111 debug=false
112 group=false
113 xgroup=false
114 imgopts=false
115 showme=false
116 sortme=false
117 expunge=true
118 have_test_arg=false
119 cachemode=false
121 tmp="${TEST_DIR}"/$$
122 rm -f $tmp.list $tmp.tmp $tmp.sed
124 export IMGFMT=raw
125 export IMGFMT_GENERIC=true
126 export IMGPROTO=file
127 export IMGOPTS=""
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=
134 export IMGKEYSECRET=
135 export IMGOPTSSYNTAX=false
137 # Save current tty settings, since an aborting qemu call may leave things
138 # screwed up
139 STTY_RESTORE=
140 if test -t 0; then
141 STTY_RESTORE=$(stty -g)
144 for r
147 if $group
148 then
149 # arg after -g
150 group_list=$(sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
151 s/ .*//p
153 if [ -z "$group_list" ]
154 then
155 echo "Group \"$r\" is empty or not defined?"
156 exit 1
158 [ ! -s $tmp.list ] && touch $tmp.list
159 for t in $group_list
161 if grep -s "^$t\$" $tmp.list >/dev/null
162 then
164 else
165 echo "$t" >>$tmp.list
167 done
168 group=false
169 continue
171 elif $xgroup
172 then
173 # arg after -x
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 /"'{
177 s/ .*//p
179 if [ -z "$group_list" ]
180 then
181 echo "Group \"$r\" is empty or not defined?"
182 exit 1
184 numsed=0
185 rm -f $tmp.sed
186 for t in $group_list
188 if [ $numsed -gt 100 ]
189 then
190 sed -f $tmp.sed <$tmp.list >$tmp.tmp
191 mv $tmp.tmp $tmp.list
192 numsed=0
193 rm -f $tmp.sed
195 echo "/^$t\$/d" >>$tmp.sed
196 numsed=$(expr $numsed + 1)
197 done
198 sed -f $tmp.sed <$tmp.list >$tmp.tmp
199 mv $tmp.tmp $tmp.list
200 xgroup=false
201 continue
203 elif $imgopts
204 then
205 IMGOPTS="$r"
206 imgopts=false
207 continue
208 elif $cachemode
209 then
210 CACHEMODE="$r"
211 CACHEMODE_IS_DEFAULT=false
212 cachemode=false
213 continue
216 xpand=true
217 case "$r"
220 -\? | -h | --help) # usage
221 echo "Usage: $0 [options] [testlist]"'
223 common options
224 -v verbose
225 -d debug
227 image format options
228 -raw test raw (default)
229 -bochs test bochs
230 -cloop test cloop
231 -parallels test parallels
232 -qcow test qcow
233 -qcow2 test qcow2
234 -qed test qed
235 -vdi test vdi
236 -vpc test vpc
237 -vhdx test vhdx
238 -vmdk test vmdk
239 -luks test luks
240 -dmg test dmg
242 image protocol options
243 -file test file (default)
244 -rbd test rbd
245 -sheepdog test sheepdog
246 -nbd test nbd
247 -ssh test ssh
248 -nfs test nfs
249 -vxhs test vxhs
251 other options
252 -xdiff graphical mode diff
253 -nocache use O_DIRECT on backing file
254 -misalign misalign memory allocations
255 -n show me, do not run tests
256 -o options -o options to pass to qemu-img create/convert
257 -T output timestamps
258 -c mode cache mode
260 testlist options
261 -g group[,group...] include tests from these groups
262 -x group[,group...] exclude tests from these groups
263 NNN include test NNN
264 NNN-NNN include test range (eg. 012-021)
266 exit 0
269 -raw)
270 IMGFMT=raw
271 xpand=false
274 -bochs)
275 IMGFMT=bochs
276 IMGFMT_GENERIC=false
277 xpand=false
280 -cloop)
281 IMGFMT=cloop
282 IMGFMT_GENERIC=false
283 xpand=false
286 -parallels)
287 IMGFMT=parallels
288 xpand=false
291 -qcow)
292 IMGFMT=qcow
293 xpand=false
296 -qcow2)
297 IMGFMT=qcow2
298 xpand=false
301 -luks)
302 IMGOPTSSYNTAX=true
303 IMGFMT=luks
304 IMGKEYSECRET=123456
305 xpand=false
308 -dmg)
309 IMGFMT=dmg
310 IMGFMT_GENERIC=false
311 xpand=false
314 -qed)
315 IMGFMT=qed
316 xpand=false
319 -vdi)
320 IMGFMT=vdi
321 xpand=false
324 -vmdk)
325 IMGFMT=vmdk
326 xpand=false
329 -vpc)
330 IMGFMT=vpc
331 xpand=false
334 -vhdx)
335 IMGFMT=vhdx
336 xpand=false
339 -file)
340 IMGPROTO=file
341 xpand=false
344 -rbd)
345 IMGPROTO=rbd
346 xpand=false
349 -sheepdog)
350 IMGPROTO=sheepdog
351 xpand=false
354 -nbd)
355 IMGPROTO=nbd
356 xpand=false
359 -vxhs)
360 IMGPROTO=vxhs
361 xpand=false
364 -ssh)
365 IMGPROTO=ssh
366 xpand=false
369 -nfs)
370 IMGPROTO=nfs
371 xpand=false
374 -nocache)
375 CACHEMODE="none"
376 CACHEMODE_IS_DEFAULT=false
377 xpand=false
380 -misalign)
381 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
382 xpand=false
385 -valgrind)
386 VALGRIND_QEMU='y'
387 xpand=false
390 -g) # -g group ... pick from group file
391 group=true
392 xpand=false
395 -xdiff) # graphical diff mode
396 xpand=false
398 if [ ! -z "$DISPLAY" ]
399 then
400 command -v xdiff >/dev/null 2>&1 && diff=xdiff
401 command -v gdiff >/dev/null 2>&1 && diff=gdiff
402 command -v tkdiff >/dev/null 2>&1 && diff=tkdiff
403 command -v xxdiff >/dev/null 2>&1 && diff=xxdiff
407 -n) # show me, don't do it
408 showme=true
409 xpand=false
412 imgopts=true
413 xpand=false
416 cachemode=true
417 xpand=false
419 -T) # turn on timestamp output
420 timestamp=true
421 xpand=false
425 verbose=true
426 xpand=false
429 debug=true
430 xpand=false
432 -x) # -x group ... exclude from group file
433 xgroup=true
434 xpand=false
436 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
437 echo "No tests?"
438 status=1
439 exit $status
442 [0-9]*-[0-9]*)
443 eval $(echo $r | sed -e 's/^/start=/' -e 's/-/ end=/')
446 [0-9]*-)
447 eval $(echo $r | sed -e 's/^/start=/' -e 's/-//')
448 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/.* //')
449 if [ -z "$end" ]
450 then
451 echo "No tests in range \"$r\"?"
452 status=1
453 exit $status
458 start=$r
459 end=$r
462 esac
464 # get rid of leading 0s as can be interpreted as octal
465 start=$(echo $start | sed 's/^0*//')
466 end=$(echo $end | sed 's/^0*//')
468 if $xpand
469 then
470 have_test_arg=true
471 awk </dev/null '
472 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
473 | while read id
475 if grep -s "^$id " "$source_iotests/group" >/dev/null
476 then
477 # in group file ... OK
478 echo $id >>$tmp.list
479 else
480 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
481 then
482 # expunged ... will be reported, but not run, later
483 echo $id >>$tmp.list
484 else
485 # oops
486 if [ "$start" == "$end" -a "$id" == "$end" ]
487 then
488 echo "$id - unknown test"
489 exit 1
490 else
491 echo "$id - unknown test, ignored"
495 done || exit 1
498 done
500 # Set qemu-io cache mode with $CACHEMODE we have
501 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE"
503 QEMU_IO_OPTIONS_NO_FMT="$QEMU_IO_OPTIONS"
504 if [ "$IMGOPTSSYNTAX" != "true" ]; then
505 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT"
508 # Set default options for qemu-img create -o if they were not specified
509 if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then
510 IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1")
512 if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null); then
513 IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10")
516 if [ -z "$SAMPLE_IMG_DIR" ]; then
517 SAMPLE_IMG_DIR="$source_iotests/sample_images"
520 export TEST_DIR
521 export SAMPLE_IMG_DIR
523 if [ -s $tmp.list ]
524 then
525 # found some valid test numbers ... this is good
527 else
528 if $have_test_arg
529 then
530 # had test numbers, but none in group file ... do nothing
531 touch $tmp.list
532 else
533 # no test numbers, do everything from group file
534 sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list
538 # should be sort -n, but this did not work for Linux when this
539 # was ported from IRIX
541 list=$(sort $tmp.list)
542 rm -f $tmp.list $tmp.tmp $tmp.sed
544 if [ -z "$QEMU_PROG" ]
545 then
546 if [ -x "$build_iotests/qemu" ]; then
547 export QEMU_PROG="$build_iotests/qemu"
548 elif [ -x "$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}" ]; then
549 export QEMU_PROG="$build_root/${qemu_arch}-softmmu/qemu-system-${qemu_arch}"
550 else
551 pushd "$build_root" > /dev/null
552 for binary in *-softmmu/qemu-system-*
554 if [ -x "$binary" ]
555 then
556 export QEMU_PROG="$build_root/$binary"
557 break
559 done
560 popd > /dev/null
561 [ "$QEMU_PROG" = "" ] && _init_error "qemu not found"
564 export QEMU_PROG="$(type -p "$QEMU_PROG")"
566 if [ -z "$QEMU_IMG_PROG" ]; then
567 if [ -x "$build_iotests/qemu-img" ]; then
568 export QEMU_IMG_PROG="$build_iotests/qemu-img"
569 elif [ -x "$build_root/qemu-img" ]; then
570 export QEMU_IMG_PROG="$build_root/qemu-img"
571 else
572 _init_error "qemu-img not found"
575 export QEMU_IMG_PROG="$(type -p "$QEMU_IMG_PROG")"
577 if [ -z "$QEMU_IO_PROG" ]; then
578 if [ -x "$build_iotests/qemu-io" ]; then
579 export QEMU_IO_PROG="$build_iotests/qemu-io"
580 elif [ -x "$build_root/qemu-io" ]; then
581 export QEMU_IO_PROG="$build_root/qemu-io"
582 else
583 _init_error "qemu-io not found"
586 export QEMU_IO_PROG="$(type -p "$QEMU_IO_PROG")"
588 if [ -z $QEMU_NBD_PROG ]; then
589 if [ -x "$build_iotests/qemu-nbd" ]; then
590 export QEMU_NBD_PROG="$build_iotests/qemu-nbd"
591 elif [ -x "$build_root/qemu-nbd" ]; then
592 export QEMU_NBD_PROG="$build_root/qemu-nbd"
593 else
594 _init_error "qemu-nbd not found"
597 export QEMU_NBD_PROG="$(type -p "$QEMU_NBD_PROG")"
599 if [ -z "$QEMU_VXHS_PROG" ]; then
600 export QEMU_VXHS_PROG="$(set_prog_path qnio_server)"
603 if [ -x "$build_iotests/socket_scm_helper" ]
604 then
605 export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper"
608 default_machine=$($QEMU_PROG -machine help | sed -n '/(default)/ s/ .*//p')
609 default_alias_machine=$($QEMU_PROG -machine help | \
610 sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }")
611 if [[ "$default_alias_machine" ]]; then
612 default_machine="$default_alias_machine"
615 export QEMU_DEFAULT_MACHINE="$default_machine"
617 TIMESTAMP_FILE=check.time-$IMGPROTO-$IMGFMT
619 _wallclock()
621 date "+%H %M %S" | awk '{ print $1*3600 + $2*60 + $3 }'
624 _timestamp()
626 now=$(date "+%T")
627 printf %s " [$now]"
630 _wrapup()
632 if $showme
633 then
635 elif $needwrap
636 then
637 if [ -f $TIMESTAMP_FILE -a -f $tmp.time ]
638 then
639 cat $TIMESTAMP_FILE $tmp.time \
640 | awk '
641 { t[$1] = $2 }
642 END { if (NR > 0) {
643 for (i in t) print i " " t[i]
645 }' \
646 | sort -n >$tmp.out
647 mv $tmp.out $TIMESTAMP_FILE
650 if [ -f $tmp.expunged ]
651 then
652 notrun=$(wc -l <$tmp.expunged | sed -e 's/ *//g')
653 try=$(expr $try - $notrun)
654 list=$(echo "$list" | sed -f $tmp.expunged)
657 echo "" >>check.log
658 date >>check.log
659 echo $list | fmt | sed -e 's/^/ /' >>check.log
660 $interrupt && echo "Interrupted!" >>check.log
662 if [ ! -z "$notrun" ]
663 then
664 echo "Not run:$notrun"
665 echo "Not run:$notrun" >>check.log
667 if [ ! -z "$n_bad" -a $n_bad != 0 ]
668 then
669 echo "Failures:$bad"
670 echo "Failed $n_bad of $try tests"
671 echo "Failures:$bad" | fmt >>check.log
672 echo "Failed $n_bad of $try tests" >>check.log
673 else
674 echo "Passed all $try tests"
675 echo "Passed all $try tests" >>check.log
677 needwrap=false
680 if test -n "$STTY_RESTORE"; then
681 stty $STTY_RESTORE
683 rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.time
684 rm -f "${TEST_DIR}"/check.pid "${TEST_DIR}"/check.sts
685 rm -f $tmp.*
688 trap "_wrapup; exit \$status" 0 1 2 3 15
690 [ -f $TIMESTAMP_FILE ] || touch $TIMESTAMP_FILE
692 FULL_IMGFMT_DETAILS=$(_full_imgfmt_details)
693 FULL_HOST_DETAILS=$(_full_platform_details)
695 cat <<EOF
696 QEMU -- "$QEMU_PROG" $QEMU_OPTIONS
697 QEMU_IMG -- "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS
698 QEMU_IO -- "$QEMU_IO_PROG" $QEMU_IO_OPTIONS
699 QEMU_NBD -- "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS
700 IMGFMT -- $FULL_IMGFMT_DETAILS
701 IMGPROTO -- $IMGPROTO
702 PLATFORM -- $FULL_HOST_DETAILS
703 TEST_DIR -- $TEST_DIR
704 SOCKET_SCM_HELPER -- $SOCKET_SCM_HELPER
708 seq="check"
710 [ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
712 for seq in $list
714 err=false
715 printf %s "$seq"
716 if [ -n "$TESTS_REMAINING_LOG" ] ; then
717 sed -e "s/$seq//" -e 's/ / /' -e 's/^ *//' $TESTS_REMAINING_LOG > $TESTS_REMAINING_LOG.tmp
718 mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG
719 sync
722 if $showme
723 then
724 echo
725 continue
726 elif [ -f expunged ] && $expunge && egrep "^$seq([ ]|\$)" expunged >/dev/null
727 then
728 echo " - expunged"
729 rm -f $seq.out.bad
730 echo "/^$seq\$/d" >>$tmp.expunged
731 elif [ ! -f "$source_iotests/$seq" ]
732 then
733 echo " - no such test?"
734 echo "/^$seq\$/d" >>$tmp.expunged
735 else
736 # really going to try and run this one
738 rm -f $seq.out.bad
739 lasttime=$(sed -n -e "/^$seq /s/.* //p" <$TIMESTAMP_FILE)
740 if [ "X$lasttime" != X ]; then
741 printf %s " ${lasttime}s ..."
742 else
743 printf " " # prettier output with timestamps.
745 rm -f core $seq.notrun
747 start=$(_wallclock)
748 $timestamp && printf %s " [$(date "+%T")]"
750 if [ "$(head -n 1 "$source_iotests/$seq")" == "#!/usr/bin/env python" ]; then
751 run_command="$PYTHON $seq"
752 else
753 run_command="./$seq"
755 export OUTPUT_DIR=$PWD
756 if $debug; then
757 (cd "$source_iotests";
758 MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
759 $run_command -d 2>&1 | tee $tmp.out)
760 else
761 (cd "$source_iotests";
762 MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
763 $run_command >$tmp.out 2>&1)
765 sts=$?
766 $timestamp && _timestamp
767 stop=$(_wallclock)
769 if [ -f core ]
770 then
771 printf " [dumped core]"
772 mv core $seq.core
773 err=true
776 if [ -f $seq.notrun ]
777 then
778 $timestamp || printf " [not run] "
779 $timestamp && echo " [not run]" && printf %s " $seq -- "
780 cat $seq.notrun
781 notrun="$notrun $seq"
782 else
783 if [ $sts -ne 0 ]
784 then
785 printf %s " [failed, exit status $sts]"
786 err=true
789 reference="$source_iotests/$seq.out"
790 reference_machine="$source_iotests/$seq.$QEMU_DEFAULT_MACHINE.out"
791 if [ -f "$reference_machine" ]; then
792 reference="$reference_machine"
795 reference_format="$source_iotests/$seq.out.$IMGFMT"
796 if [ -f "$reference_format" ]; then
797 reference="$reference_format"
800 if [ "$CACHEMODE" = "none" ]; then
801 [ -f "$source_iotests/$seq.out.nocache" ] && reference="$source_iotests/$seq.out.nocache"
804 if [ ! -f "$reference" ]
805 then
806 echo " - no qualified output"
807 err=true
808 else
809 if diff -w "$reference" $tmp.out >/dev/null 2>&1
810 then
811 echo ""
812 if $err
813 then
815 else
816 echo "$seq $(expr $stop - $start)" >>$tmp.time
818 else
819 echo " - output mismatch (see $seq.out.bad)"
820 mv $tmp.out $seq.out.bad
821 $diff -w "$reference" "$PWD"/$seq.out.bad
822 err=true
829 # come here for each test, except when $showme is true
831 if $err
832 then
833 bad="$bad $seq"
834 n_bad=$(expr $n_bad + 1)
835 quick=false
837 [ -f $seq.notrun ] || try=$(expr $try + 1)
839 seq="after_$seq"
840 done
842 interrupt=false
843 status=$(expr $n_bad)
844 exit