qxl: check qxl_phys2virt return value
[qemu/ericb.git] / tests / qemu-iotests / check
blobaa94c6c7ea906e592a33fe53ab04c12de1cd7b00
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
241 image protocol options
242 -file test file (default)
243 -rbd test rbd
244 -sheepdog test sheepdog
245 -nbd test nbd
246 -ssh test ssh
247 -nfs test nfs
248 -vxhs test vxhs
250 other options
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
256 -T output timestamps
257 -c mode cache mode
259 testlist options
260 -g group[,group...] include tests from these groups
261 -x group[,group...] exclude tests from these groups
262 NNN include test NNN
263 NNN-NNN include test range (eg. 012-021)
265 exit 0
268 -raw)
269 IMGFMT=raw
270 xpand=false
273 -bochs)
274 IMGFMT=bochs
275 IMGFMT_GENERIC=false
276 xpand=false
279 -cloop)
280 IMGFMT=cloop
281 IMGFMT_GENERIC=false
282 xpand=false
285 -parallels)
286 IMGFMT=parallels
287 xpand=false
290 -qcow)
291 IMGFMT=qcow
292 xpand=false
295 -qcow2)
296 IMGFMT=qcow2
297 xpand=false
300 -luks)
301 IMGOPTSSYNTAX=true
302 IMGFMT=luks
303 IMGKEYSECRET=123456
304 xpand=false
307 -qed)
308 IMGFMT=qed
309 xpand=false
312 -vdi)
313 IMGFMT=vdi
314 xpand=false
317 -vmdk)
318 IMGFMT=vmdk
319 xpand=false
322 -vpc)
323 IMGFMT=vpc
324 xpand=false
327 -vhdx)
328 IMGFMT=vhdx
329 xpand=false
332 -file)
333 IMGPROTO=file
334 xpand=false
337 -rbd)
338 IMGPROTO=rbd
339 xpand=false
342 -sheepdog)
343 IMGPROTO=sheepdog
344 xpand=false
347 -nbd)
348 IMGPROTO=nbd
349 xpand=false
352 -vxhs)
353 IMGPROTO=vxhs
354 xpand=false
357 -ssh)
358 IMGPROTO=ssh
359 xpand=false
362 -nfs)
363 IMGPROTO=nfs
364 xpand=false
367 -nocache)
368 CACHEMODE="none"
369 CACHEMODE_IS_DEFAULT=false
370 xpand=false
373 -misalign)
374 QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign"
375 xpand=false
378 -valgrind)
379 VALGRIND_QEMU='y'
380 xpand=false
383 -g) # -g group ... pick from group file
384 group=true
385 xpand=false
388 -xdiff) # graphical diff mode
389 xpand=false
391 if [ ! -z "$DISPLAY" ]
392 then
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
401 showme=true
402 xpand=false
405 imgopts=true
406 xpand=false
409 cachemode=true
410 xpand=false
412 -T) # turn on timestamp output
413 timestamp=true
414 xpand=false
418 verbose=true
419 xpand=false
422 debug=true
423 xpand=false
425 -x) # -x group ... exclude from group file
426 xgroup=true
427 xpand=false
429 '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
430 echo "No tests?"
431 status=1
432 exit $status
435 [0-9]*-[0-9]*)
436 eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
439 [0-9]*-)
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/.* //'`
442 if [ -z "$end" ]
443 then
444 echo "No tests in range \"$r\"?"
445 status=1
446 exit $status
451 start=$r
452 end=$r
455 esac
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*//'`
461 if $xpand
462 then
463 have_test_arg=true
464 awk </dev/null '
465 BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
466 | while read id
468 if grep -s "^$id " "$source_iotests/group" >/dev/null
469 then
470 # in group file ... OK
471 echo $id >>$tmp.list
472 else
473 if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null
474 then
475 # expunged ... will be reported, but not run, later
476 echo $id >>$tmp.list
477 else
478 # oops
479 if [ "$start" == "$end" -a "$id" == "$end" ]
480 then
481 echo "$id - unknown test"
482 exit 1
483 else
484 echo "$id - unknown test, ignored"
488 done || exit 1
491 done
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"
513 export TEST_DIR
514 export SAMPLE_IMG_DIR
516 if [ -s $tmp.list ]
517 then
518 # found some valid test numbers ... this is good
520 else
521 if $have_test_arg
522 then
523 # had test numbers, but none in group file ... do nothing
524 touch $tmp.list
525 else
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" ]
538 then
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}"
543 else
544 pushd "$build_root" > /dev/null
545 for binary in *-softmmu/qemu-system-*
547 if [ -x "$binary" ]
548 then
549 export QEMU_PROG="$build_root/$binary"
550 break
552 done
553 popd > /dev/null
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"
564 else
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"
575 else
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"
586 else
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" ]
597 then
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
612 _wallclock()
614 date "+%H %M %S" | awk '{ print $1*3600 + $2*60 + $3 }'
617 _timestamp()
619 now=`date "+%T"`
620 printf %s " [$now]"
623 _wrapup()
625 if $showme
626 then
628 elif $needwrap
629 then
630 if [ -f $TIMESTAMP_FILE -a -f $tmp.time ]
631 then
632 cat $TIMESTAMP_FILE $tmp.time \
633 | awk '
634 { t[$1] = $2 }
635 END { if (NR > 0) {
636 for (i in t) print i " " t[i]
638 }' \
639 | sort -n >$tmp.out
640 mv $tmp.out $TIMESTAMP_FILE
643 if [ -f $tmp.expunged ]
644 then
645 notrun=`wc -l <$tmp.expunged | sed -e 's/ *//g'`
646 try=`expr $try - $notrun`
647 list=`echo "$list" | sed -f $tmp.expunged`
650 echo "" >>check.log
651 date >>check.log
652 echo $list | fmt | sed -e 's/^/ /' >>check.log
653 $interrupt && echo "Interrupted!" >>check.log
655 if [ ! -z "$notrun" ]
656 then
657 echo "Not run:$notrun"
658 echo "Not run:$notrun" >>check.log
660 if [ ! -z "$n_bad" -a $n_bad != 0 ]
661 then
662 echo "Failures:$bad"
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
666 else
667 echo "Passed all $try tests"
668 echo "Passed all $try tests" >>check.log
670 needwrap=false
673 if test -n "$STTY_RESTORE"; then
674 stty $STTY_RESTORE
676 rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.time
677 rm -f "${TEST_DIR}"/check.pid "${TEST_DIR}"/check.sts
678 rm -f $tmp.*
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`
688 cat <<EOF
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
701 seq="check"
703 [ -n "$TESTS_REMAINING_LOG" ] && echo $list > $TESTS_REMAINING_LOG
705 for seq in $list
707 err=false
708 printf %s "$seq"
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
712 sync
715 if $showme
716 then
717 echo
718 continue
719 elif [ -f expunged ] && $expunge && egrep "^$seq([ ]|\$)" expunged >/dev/null
720 then
721 echo " - expunged"
722 rm -f $seq.out.bad
723 echo "/^$seq\$/d" >>$tmp.expunged
724 elif [ ! -f "$source_iotests/$seq" ]
725 then
726 echo " - no such test?"
727 echo "/^$seq\$/d" >>$tmp.expunged
728 else
729 # really going to try and run this one
731 rm -f $seq.out.bad
732 lasttime=`sed -n -e "/^$seq /s/.* //p" <$TIMESTAMP_FILE`
733 if [ "X$lasttime" != X ]; then
734 printf %s " ${lasttime}s ..."
735 else
736 printf " " # prettier output with timestamps.
738 rm -f core $seq.notrun
740 start=`_wallclock`
741 $timestamp && printf %s " [$(date "+%T")]"
743 if [ "$(head -n 1 "$source_iotests/$seq")" == "#!/usr/bin/env python" ]; then
744 run_command="$PYTHON $seq"
745 else
746 run_command="./$seq"
748 export OUTPUT_DIR=$PWD
749 if $debug; then
750 (cd "$source_iotests";
751 MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
752 $run_command -d 2>&1 | tee $tmp.out)
753 else
754 (cd "$source_iotests";
755 MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(($RANDOM % 255 + 1))} \
756 $run_command >$tmp.out 2>&1)
758 sts=$?
759 $timestamp && _timestamp
760 stop=`_wallclock`
762 if [ -f core ]
763 then
764 printf " [dumped core]"
765 mv core $seq.core
766 err=true
769 if [ -f $seq.notrun ]
770 then
771 $timestamp || printf " [not run] "
772 $timestamp && echo " [not run]" && printf %s " $seq -- "
773 cat $seq.notrun
774 notrun="$notrun $seq"
775 else
776 if [ $sts -ne 0 ]
777 then
778 printf %s " [failed, exit status $sts]"
779 err=true
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" ]
798 then
799 echo " - no qualified output"
800 err=true
801 else
802 if diff -w "$reference" $tmp.out >/dev/null 2>&1
803 then
804 echo ""
805 if $err
806 then
808 else
809 echo "$seq `expr $stop - $start`" >>$tmp.time
811 else
812 echo " - output mismatch (see $seq.out.bad)"
813 mv $tmp.out $seq.out.bad
814 $diff -w "$reference" "$PWD"/$seq.out.bad
815 err=true
822 # come here for each test, except when $showme is true
824 if $err
825 then
826 bad="$bad $seq"
827 n_bad=`expr $n_bad + 1`
828 quick=false
830 [ -f $seq.notrun ] || try=`expr $try + 1`
832 seq="after_$seq"
833 done
835 interrupt=false
836 status=`expr $n_bad`
837 exit