3 # Control script for QA
5 # Copyright (c) 2000-2002,2006 Silicon Graphics, Inc. All Rights Reserved.
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation.
11 # This program is distributed in the hope that it would be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write the Free Software Foundation,
18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
42 # start the initialisation work now
45 export MSGVERB="text:action"
46 export QA_CHECK_FS=${QA_CHECK_FS:=true}
48 # number of diff lines from a failed test, 0 for whole output
49 export DIFF_LENGTH=${DIFF_LENGTH:=10}
51 # by default don't output timestamps
52 timestamp=${TIMESTAMP:=false}
54 rm -f $tmp.list $tmp.tmp $tmp.grep $here/$iam.out $tmp.xlist
56 # we need common/config
57 if ! . ./common/config
59 echo "$iam: failed to source common/config"
63 SRC_GROUPS="generic shared"
64 export SRC_DIR="tests"
68 echo "Usage: $0 [options] [testlist]"'
75 -udiff show unified diff (default)
76 -n show me, do not run tests
78 -r randomize test order
79 -d dump test output to stdout
80 --large-fs optimise scratch device for large filesystems
81 -s section run only specified section from config file
84 -g group[,group...] include tests from these groups
85 -x group[,group...] exclude tests from these groups
86 -X file exclude individual tests
87 -E external_file exclude individual tests
88 [testlist] include tests matching names in testlist
97 for d in $SRC_GROUPS $FSTYP; do
98 l=$(sed -n < $SRC_DIR/$d/group \
101 -e "s;^\($VALID_TEST_NAME\).* $grp .*;$SRC_DIR/$d/\1;p")
107 # Find all tests, excluding files that are test metadata such as group files.
108 # It matches test names against $VALID_TEST_NAME defined in common/rc
112 for d in $SRC_GROUPS $FSTYP; do
115 grep "^$SRC_DIR/$d/$VALID_TEST_NAME"| \
116 grep -v "group\|Makefile" >> $tmp.list 2>/dev/null
120 # takes the list of tests to run in $tmp.list, and removes the tests passed to
121 # the function from that list.
130 if [ $numsed -gt 100 ]; then
131 grep -v -f $tmp.grep <$tmp.list >$tmp.tmp
132 mv $tmp.tmp $tmp.list
136 echo "^$t\$" >>$tmp.grep
137 numsed=`expr $numsed + 1`
139 grep -v -f $tmp.grep <$tmp.list >$tmp.tmp
140 mv $tmp.tmp $tmp.list
158 # Tests specified on the command line
159 if [ -s $tmp.arglist ]; then
160 cat $tmp.arglist > $tmp.list
165 # Specified groups to include
166 for group in $GROUP_LIST; do
167 list=$(get_group_list $group)
168 if [ -z "$list" ]; then
169 echo "Group \"$group\" is empty or not defined?"
174 grep -s "^$t\$" $tmp.list >/dev/null || \
175 echo "$t" >>$tmp.list
179 if ! $have_test_arg && [ -z "$GROUP_LIST" ]; then
180 # no test numbers, do everything
184 # Specified groups to exclude
185 for xgroup in $XGROUP_LIST; do
186 list=$(get_group_list $xgroup)
187 if [ -z "$list" ]; then
188 echo "Group \"$xgroup\" is empty or not defined?"
195 # sort the list of tests into numeric order
196 list=`sort -n $tmp.list | uniq`
197 rm -f $tmp.list $tmp.tmp $tmp.grep
201 list=`echo $list | awk -f randomize.awk`
205 # Process command arguments first.
206 while [ $# -gt 0 ]; do
208 -\? | -h | --help) usage ;;
212 -tmpfs) FSTYP=tmpfs ;;
214 -g) group=$2 ; shift ;
215 GROUP_LIST="$GROUP_LIST ${group//,/ }"
218 -x) xgroup=$2 ; shift ;
219 XGROUP_LIST="$XGROUP_LIST ${xgroup//,/ }"
222 -X) xfile=$2; shift ;
223 for d in $SRC_GROUPS $FSTYP; do
224 [ -f $SRC_DIR/$d/$xfile ] || continue
225 for f in `cat $SRC_DIR/$d/$xfile`; do
226 echo $d/$f >> $tmp.xlist
230 -E) xfile=$2; shift ;
231 if [ -f $xfile ]; then
232 cat "$xfile" >> $tmp.xlist
235 -s) RUN_SECTION="$RUN_SECTION $2"; shift ;;
237 -udiff) diff="$diff -u" ;;
240 -r) randomize=true ;;
242 -T) timestamp=true ;;
243 -d) DUMP_OUTPUT=true ;;
245 --large-fs) export LARGE_SCRATCH_DEV=yes ;;
246 --extra-space=*) export SCRATCH_DEV_EMPTY_SPACE=${r#*=} ;;
249 *) # not an argument, we've got tests now.
250 have_test_arg=true ;;
253 # if we've found a test specification, the break out of the processing
254 # loop before we shift the arguments so that this is the first argument
255 # that we process in the test arg loop below.
256 if $have_test_arg; then
263 # Process tests from command line now.
264 if $have_test_arg; then
265 while [ $# -gt 0 ]; do
267 -*) echo "Arguments before tests, please!"
271 *) test_dir=`dirname $1`
272 test_dir=${test_dir#$SRC_DIR/*}
273 test_name=`basename $1`
274 group_file=$SRC_DIR/$test_dir/group
276 if egrep "^$test_name" $group_file >/dev/null ; then
277 # in group file ... OK
278 echo $SRC_DIR/$test_dir/$test_name >>$tmp.arglist
281 echo "$1 - unknown test, ignored"
293 echo "check: failed to source common/rc"
299 echo "check: QA must be run as root"
313 check="$RESULT_BASE/check"
320 if [ -f $check.time -a -f $tmp.time ]
322 cat $check.time $tmp.time \
326 for (i in t) print i " " t[i]
330 mv $tmp.out $check.time
335 echo $list | fmt | sed -e 's/^/ /' -e "s;$SRC_DIR/;;g" >>$check.log
336 $interrupt && echo "Interrupted!" >>$check.log
338 echo "SECTION -- $section" >>$tmp.summary
339 echo "=========================" >>$tmp.summary
340 if [ ! -z "$n_try" -a $n_try != 0 ]
343 echo "Ran:$try" >>$tmp.summary
346 if [ ! -z "$notrun" ]
348 echo "Not run:$notrun"
349 echo "Not run:$notrun" >>$check.log
350 echo "Not run:$notrun" >>$tmp.summary
353 if [ ! -z "$n_bad" -a $n_bad != 0 ]
356 echo "Failed $n_bad of $n_try tests"
357 echo "Failures:$bad" | fmt >>$check.log
358 echo "Failed $n_bad of $n_try tests" >>$check.log
359 echo "Failures:$bad" >>$tmp.summary
360 echo "Failed $n_bad of $n_try tests" >>$tmp.summary
362 echo "Passed all $n_try tests"
363 echo "Passed all $n_try tests" >>$check.log
364 echo "Passed all $n_try tests" >>$tmp.summary
366 echo "" >>$tmp.summary
370 sum_bad=`expr $sum_bad + $n_bad`
372 rm -f /tmp/*.rawout /tmp/*.out /tmp/*.err /tmp/*.time
373 if ! $OPTIONS_HAVE_SECTIONS; then
384 count=`wc -L $tmp.summary | cut -f1 -d" "`
393 if [ -f ${RESULT_DIR}/require_test ]; then
394 _check_test_fs || err=true
395 rm -f ${RESULT_DIR}/require_test
397 if [ -f ${RESULT_DIR}/require_scratch ]; then
398 _check_scratch_fs || err=true
399 rm -f ${RESULT_DIR}/require_scratch
405 if $OPTIONS_HAVE_SECTIONS; then
406 trap "_summary; exit \$status" 0 1 2 3 15
408 trap "_wrapup; exit \$status" 0 1 2 3 15
411 for section in $HOST_OPTIONS_SECTIONS; do
413 OLD_MOUNT_OPTIONS=$MOUNT_OPTIONS
414 get_next_config $section
416 # Do we need to run only some sections ?
417 if [ ! -z "$RUN_SECTION" ]; then
419 for s in $RUN_SECTION; do
420 if [ $section == $s ]; then
429 mkdir -p $RESULT_BASE
430 if [ ! -d $RESULT_BASE ]; then
431 echo "failed to create results directory $RESULT_BASE"
436 if $OPTIONS_HAVE_SECTIONS; then
437 echo "SECTION -- $section"
440 if $RECREATE_TEST_DEV || [ "$OLD_FSTYP" != "$FSTYP" ]; then
441 echo "RECREATING -- $FSTYP on $TEST_DEV"
442 umount $TEST_DEV 2> /dev/null
443 if ! _test_mkfs >$tmp.err 2>&1
445 echo "our local _test_mkfs routine ..."
447 echo "check: failed to mkfs \$TEST_DEV using specified options"
451 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
452 if [ $? -ne 1 ]; then
458 elif [ "$OLD_MOUNT_OPTIONS" != "$MOUNT_OPTIONS" ]; then
459 umount $TEST_DEV 2> /dev/null
460 out=`_mount_or_remount_rw "$MOUNT_OPTIONS" $TEST_DEV $TEST_DIR`
461 if [ $? -ne 1 ]; then
471 check="$RESULT_BASE/check"
473 # don't leave old full output behind on a clean run
476 [ -f $check.time ] || touch $check.time
478 # print out our test configuration
479 echo "FSTYP -- `_full_fstyp_details`"
480 echo "PLATFORM -- `_full_platform_details`"
481 if [ ! -z "$SCRATCH_DEV" ]; then
482 echo "MKFS_OPTIONS -- `_scratch_mkfs_options`"
483 echo "MOUNT_OPTIONS -- `_scratch_mount_options`"
488 if [ ! -z "$SCRATCH_DEV" ]; then
489 umount $SCRATCH_DEV 2>/dev/null
490 # call the overridden mkfs - make sure the FS is built
491 # the same as we'll create it later.
493 if ! _scratch_mkfs >$tmp.err 2>&1
495 echo "our local _scratch_mkfs routine ..."
497 echo "check: failed to mkfs \$SCRATCH_DEV using specified options"
502 # call the overridden mount - make sure the FS mounts with
503 # the same options that we'll mount with later.
504 if ! _scratch_mount >$tmp.err 2>&1
506 echo "our local mount routine ..."
508 echo "check: failed to mount \$SCRATCH_DEV using specified options"
521 # the filename for the test and the name output are different.
522 # we don't include the tests/ directory in the name output.
523 export seqnum=`echo $seq | sed -e "s;$SRC_DIR/;;"`
525 # Similarly, the result directory needs to replace the tests/
526 # part of the test location.
528 if $OPTIONS_HAVE_SECTIONS; then
529 export RESULT_DIR=`echo $group | sed -e "s;$SRC_DIR;${RESULT_BASE}/$section;"`
530 seqres="$RESULT_BASE/$section/$seqnum"
532 export RESULT_DIR=`echo $group | sed -e "s;$SRC_DIR;$RESULT_BASE;"`
533 seqres="$RESULT_BASE/$seqnum"
543 elif [ ! -f $seq ]; then
544 # Try to get full name in case the user supplied only seq id
545 # and the test has a name. A bit of hassle to find really
546 # the test and not its sample output or helping files.
547 bname=$(basename $seq)
548 full_seq=$(find $(dirname $seq) -name $bname* -executable |
549 awk '(NR == 1 || length < length(shortest)) { shortest = $0 }\
550 END { print shortest }')
551 if [ -f $full_seq ] \
552 && [ x$(echo $bname | grep -o "^$VALID_TEST_ID") != x ]; then
554 seqnum=${full_seq#*/}
558 if [ ! -f $seq ]; then
559 echo " - no such test?"
561 # really going to try and run this one
563 rm -f $seqres.out.bad
565 # check if we really should run it
566 if [ -s $tmp.xlist ]; then
567 if grep $seqnum $tmp.xlist > /dev/null 2>&1 ; then
573 # slashes now in names, sed barfs on them so use grep
574 lasttime=`grep -w ^$seqnum $check.time | awk '// {print $2}'`
575 if [ "X$lasttime" != X ]; then
576 echo -n " ${lasttime}s ..."
578 echo -n " " # prettier output with timestamps.
580 rm -f core $seqres.notrun
583 $timestamp && echo -n " ["`date "+%T"`"]"
584 [ ! -x $seq ] && chmod u+x $seq # ensure we can run it
585 $LOGGER_PROG "run xfstest $seqnum"
586 if [ -w /dev/kmsg ]; then
587 export date_time=`date +"%F %T"`
588 echo "run fstests $seqnum at $date_time" > /dev/kmsg
589 # _check_dmesg depends on this log in dmesg
590 touch ${RESULT_DIR}/check_dmesg
592 if [ "$DUMP_OUTPUT" = true ]; then
593 ./$seq 2>&1 | tee $tmp.rawout
594 # Because $? would get tee's return code
597 ./$seq >$tmp.rawout 2>&1
600 $timestamp && _timestamp
603 _fix_malloc <$tmp.rawout >$tmp.out
608 echo -n " [dumped core]"
609 mv core $RESULT_BASE/$seqnum.core
613 if [ -f $seqres.notrun ]
615 $timestamp || echo -n " [not run] "
616 $timestamp && echo " [not run]" && echo -n " $seqnum -- "
618 notrun="$notrun $seqnum"
622 echo -n " [failed, exit status $sts]"
627 echo " - no qualified output"
631 # coreutils 8.16+ changed quote formats in error messages from
632 # `foo' to 'foo'. Filter old versions to match the new version.
633 sed -i "s/\`/\'/g" $tmp.out
634 if diff $seq.out $tmp.out >/dev/null 2>&1
640 echo "$seqnum `expr $stop - $start`" >>$tmp.time
641 echo -n " `expr $stop - $start`s"
645 echo " - output mismatch (see $seqres.out.bad)"
646 mv $tmp.out $seqres.out.bad
647 $diff $seq.out $seqres.out.bad | {
648 if test "$DIFF_LENGTH" -le 0; then
651 head -n "$DIFF_LENGTH"
653 echo "(Run '$diff $seq.out $seqres.out.bad'" \
654 " to see the entire diff)"
656 sed -e 's/^\(.\)/ \1/'
661 n_try=`expr $n_try + 1`
663 _check_dmesg || err=true
668 # come here for each test, except when $showme is true
673 n_bad=`expr $n_bad + 1`
682 umount $TEST_DEV 2> /dev/null
683 umount $SCRATCH_DEV 2> /dev/null
687 status=`expr $sum_bad`