fstests: Make ./new work for non-root user
[xfstests-dev.git] / check
diff --git a/check b/check
index 66a349a6a0b5f1449d9a0aaeb73b61011cdae1e2..a8cb7289b3208c9d16dd0c50cbc5ae9ae24f0ccd 100755 (executable)
--- a/check
+++ b/check
@@ -28,6 +28,7 @@ try=""
 n_bad=0
 sum_bad=0
 bad=""
+n_notrun=0
 notrun=""
 interrupt=true
 diff="diff -u"
@@ -37,7 +38,8 @@ randomize=false
 export here=`pwd`
 xfile=""
 brief_test_summary=false
-
+_err_msg=""
+do_report=false
 DUMP_OUTPUT=false
 
 # start the initialisation work now
@@ -52,7 +54,7 @@ export DIFF_LENGTH=${DIFF_LENGTH:=10}
 # by default don't output timestamps
 timestamp=${TIMESTAMP:=false}
 
-rm -f $tmp.list $tmp.tmp $tmp.grep $here/$iam.out $tmp.xlist
+rm -f $tmp.list $tmp.tmp $tmp.grep $here/$iam.out $tmp.xlist $tmp.report.*
 
 SRC_GROUPS="generic shared"
 export SRC_DIR="tests"
@@ -63,9 +65,13 @@ usage()
 
 check options
     -nfs                test NFS
+    -glusterfs                test GlusterFS
     -cifs               test CIFS
+    -9p                        test 9p
     -overlay           test overlay
+    -pvfs2          test PVFS2
     -tmpfs              test TMPFS
+    -ubifs              test ubifs
     -l                 line mode diff
     -udiff             show unified diff (default)
     -n                 show me, do not run tests
@@ -73,6 +79,7 @@ check options
     -r                 randomize test order
     -d                 dump test output to stdout
     -b                 brief test summary
+    -R fmt[,fmt]       generate report in formats specified. Supported format: [xunit]
     --large-fs         optimise scratch device for large filesystems
     -s section         run only specified section from config file
     -S section         exclude the specified section from the config file
@@ -95,6 +102,8 @@ a test file name match pattern (e.g. xfs/*).
 group argument is either a name of a tests group to collect from all
 the test dirs (e.g. quick) or a name of a tests group to collect from
 a specific tests dir in the form of <test dir>/<group name> (e.g. xfs/quick).
+If you want to run all the tests in the test suite, use "-g all" to specify all
+groups.
 
 exclude_file argument refers to a name of a file inside each test directory.
 for every test dir where this file is found, the listed test names are
@@ -187,6 +196,7 @@ trim_test_list()
        done
        grep -v -f $tmp.grep <$tmp.list >$tmp.tmp
        mv $tmp.tmp $tmp.list
+       rm -f $tmp.grep
 }
 
 
@@ -212,22 +222,24 @@ _prepare_test_list()
        fi
 
        # Specified groups to include
-       for group in $GROUP_LIST; do
-               list=$(get_group_list $group)
-               if [ -z "$list" ]; then
-                       echo "Group \"$group\" is empty or not defined?"
-                       exit 1
-               fi
+       # Note that the CLI processing adds a leading space to the first group
+       # parameter, so we have to catch that here checking for "all"
+       if ! $have_test_arg && [ "$GROUP_LIST" == " all" ]; then
+               # no test numbers, do everything
+               get_all_tests
+       else
+               for group in $GROUP_LIST; do
+                       list=$(get_group_list $group)
+                       if [ -z "$list" ]; then
+                               echo "Group \"$group\" is empty or not defined?"
+                               exit 1
+                       fi
 
-               for t in $list; do
-                       grep -s "^$t\$" $tmp.list >/dev/null || \
+                       for t in $list; do
+                               grep -s "^$t\$" $tmp.list >/dev/null || \
                                                        echo "$t" >>$tmp.list
+                       done
                done
-       done
-
-       if ! $have_test_arg && [ -z "$GROUP_LIST" ]; then
-               # no test numbers, do everything
-               get_all_tests
        fi
 
        # Specified groups to exclude
@@ -243,7 +255,7 @@ _prepare_test_list()
 
        # sort the list of tests into numeric order
        list=`sort -n $tmp.list | uniq`
-       rm -f $tmp.list $tmp.tmp $tmp.grep
+       rm -f $tmp.list
 
        if $randomize
        then
@@ -257,9 +269,13 @@ while [ $# -gt 0 ]; do
        -\? | -h | --help) usage ;;
 
        -nfs)           FSTYP=nfs ;;
+       -glusterfs)     FSTYP=glusterfs ;;
        -cifs)          FSTYP=cifs ;;
+       -9p)            FSTYP=9p ;;
        -overlay)       FSTYP=overlay; export OVERLAY=true ;;
+       -pvfs2)         FSTYP=pvfs2 ;;
        -tmpfs)         FSTYP=tmpfs ;;
+       -ubifs)         FSTYP=ubifs ;;
 
        -g)     group=$2 ; shift ;
                GROUP_LIST="$GROUP_LIST ${group//,/ }"
@@ -293,7 +309,10 @@ while [ $# -gt 0 ]; do
        -T)     timestamp=true ;;
        -d)     DUMP_OUTPUT=true ;;
        -b)     brief_test_summary=true;;
-
+       -R)     report_fmt=$2 ; shift ;
+               REPORT_LIST="$REPORT_LIST ${report_fmt//,/ }"
+               do_report=true
+               ;;
        --large-fs) export LARGE_SCRATCH_DEV=yes ;;
        --extra-space=*) export SCRATCH_DEV_EMPTY_SPACE=${r#*=} ;;
 
@@ -312,10 +331,10 @@ while [ $# -gt 0 ]; do
        shift
 done
 
-# we need common/config, source it after processing args, overlay needs FSTYP
-# set before sourcing common/config
-if ! . ./common/config; then
-       echo "$iam: failed to source common/config"
+# we need common/rc, that also sources common/config. We need to source it
+# after processing args, overlay needs FSTYP set before sourcing common/config
+if ! . ./common/rc; then
+       echo "check: failed to source common/rc"
        exit 1
 fi
 
@@ -349,13 +368,10 @@ if $have_test_arg; then
 
                shift
        done
-fi
-
-# we need common/rc
-if ! . ./common/rc
-then
-    echo "check: failed to source common/rc"
-    exit 1
+elif [ -z "$GROUP_LIST" ]; then
+       # default group list is the auto group. If any other group or test is
+       # specified, we use that instead.
+       GROUP_LIST="auto"
 fi
 
 if [ `id -u` -ne 0 ]
@@ -368,6 +384,7 @@ _wipe_counters()
 {
        n_try="0"
        n_bad="0"
+       n_notrun="0"
        unset try notrun bad
 }
 
@@ -377,7 +394,12 @@ _wrapup()
        check="$RESULT_BASE/check"
 
        if $showme; then
-       :
+               if $needwrap; then
+                       if $do_report; then
+                               _make_section_report
+                       fi
+                       needwrap=false
+               fi
        elif $needwrap; then
                if [ -f $check.time -a -f $tmp.time ]; then
                        cat $check.time $tmp.time  \
@@ -428,6 +450,9 @@ _wrapup()
                        echo "Passed all $n_try tests" >>$tmp.summary
                fi
                echo "" >>$tmp.summary
+               if $do_report; then
+                       _make_section_report
+               fi
                needwrap=false
        fi
 
@@ -457,13 +482,30 @@ _check_filesystems()
        if [ -f ${RESULT_DIR}/require_test ]; then
                _check_test_fs || err=true
                rm -f ${RESULT_DIR}/require_test*
+       else
+               _test_unmount 2> /dev/null
        fi
        if [ -f ${RESULT_DIR}/require_scratch ]; then
                _check_scratch_fs || err=true
                rm -f ${RESULT_DIR}/require_scratch*
+       else
+               _scratch_unmount 2> /dev/null
        fi
 }
 
+_expunge_test()
+{
+       local TEST_ID="$1"
+       if [ -s $tmp.xlist ]; then
+               if grep -q $TEST_ID $tmp.xlist; then
+                       echo "       [expunged]"
+                       return 1
+               fi
+       fi
+       return 0
+}
+
+_init_kmemleak
 _prepare_test_list
 
 if $OPTIONS_HAVE_SECTIONS; then
@@ -516,6 +558,7 @@ for section in $HOST_OPTIONS_SECTIONS; do
                echo "SECTION       -- $section"
        fi
 
+       sect_start=`_wallclock`
        if $RECREATE_TEST_DEV || [ "$OLD_FSTYP" != "$FSTYP" ]; then
                echo "RECREATING    -- $FSTYP on $TEST_DEV"
                _test_unmount 2> /dev/null
@@ -596,6 +639,7 @@ for section in $HOST_OPTIONS_SECTIONS; do
        for seq in $list
        do
            err=false
+           _err_msg=""
            if [ ! -f $seq ]; then
                # Try to get full name in case the user supplied only seq id
                # and the test has a name. A bit of hassle to find really
@@ -619,34 +663,43 @@ for section in $HOST_OPTIONS_SECTIONS; do
            group=`dirname $seq`
            if $OPTIONS_HAVE_SECTIONS; then
                export RESULT_DIR=`echo $group | sed -e "s;$SRC_DIR;${RESULT_BASE}/$section;"`
-               seqres="$RESULT_BASE/$section/$seqnum"
+               REPORT_DIR="$RESULT_BASE/$section"
            else
                export RESULT_DIR=`echo $group | sed -e "s;$SRC_DIR;$RESULT_BASE;"`
-               seqres="$RESULT_BASE/$seqnum"
+               REPORT_DIR="$RESULT_BASE"
            fi
+           seqres="$REPORT_DIR/$seqnum"
 
            mkdir -p $RESULT_DIR
 
            echo -n "$seqnum"
 
-               if $showme; then
-                       echo
+           if $showme; then
+               _expunge_test $seqnum
+               if [ $? -eq 1 ]; then
                        continue
                fi
-
-               if [ ! -f $seq ]; then
-                       echo " - no such test?"
-               else
+               echo
+               start=0
+               stop=0
+               n_notrun=`expr $n_notrun + 1`
+               if $do_report; then
+                       _make_testcase_report "list"
+               fi
+               continue
+           fi
+           tc_status="pass"
+           if [ ! -f $seq ]; then
+               echo " - no such test?"
+           else
                # really going to try and run this one
                #
                rm -f $seqres.out.bad
 
                # check if we really should run it
-               if [ -s $tmp.xlist ]; then
-                       if grep $seqnum $tmp.xlist > /dev/null 2>&1 ; then
-                               echo "       [expunged]"
-                               continue
-                       fi
+               _expunge_test $seqnum
+               if [ $? -eq 1 ]; then
+                       continue
                fi
 
                # slashes now in names, sed barfs on them so use grep
@@ -669,22 +722,20 @@ for section in $HOST_OPTIONS_SECTIONS; do
                        touch ${RESULT_DIR}/check_dmesg
                fi
                if [ "$DUMP_OUTPUT" = true ]; then
-                       ./$seq 2>&1 | tee $tmp.rawout
+                       ./$seq 2>&1 | tee $tmp.out
                        # Because $? would get tee's return code
                        sts=${PIPESTATUS[0]}
                else
-                       ./$seq >$tmp.rawout 2>&1
+                       ./$seq >$tmp.out 2>&1
                        sts=$?
                fi
                $timestamp && _timestamp
                stop=`_wallclock`
 
-               _fix_malloc <$tmp.rawout >$tmp.out
-               rm -f $tmp.rawout
-
                if [ -f core ]
                then
-                   echo -n " [dumped core]"
+                   _err_msg="[dumped core]"
+                   echo -n " $_err_msg"
                    mv core $RESULT_BASE/$seqnum.core
                    err=true
                fi
@@ -695,15 +746,18 @@ for section in $HOST_OPTIONS_SECTIONS; do
                    $timestamp && echo " [not run]" && echo -n "        $seqnum -- "
                    cat $seqres.notrun
                    notrun="$notrun $seqnum"
+                   n_notrun=`expr $n_notrun + 1`
+                   tc_status="notrun"
                else
                    if [ $sts -ne 0 ]
                    then
-                       echo -n " [failed, exit status $sts]"
+                       _err_msg="[failed, exit status $sts]"
+                       echo -n " $_err_msg"
                        err=true
                    fi
                    if [ ! -f $seq.out ]
                    then
-                       echo " - no qualified output"
+                       _dump_err "no qualified output"
                        err=true
                    else
 
@@ -733,6 +787,7 @@ for section in $HOST_OPTIONS_SECTIONS; do
                                                " to see the entire diff)"
                                fi; } | \
                                sed -e 's/^\(.\)/    \1/'
+                           _err_msg="output mismatch (see $diff $seq.out $seqres.out.bad)"
                            err=true
                        fi
                    fi
@@ -740,6 +795,7 @@ for section in $HOST_OPTIONS_SECTIONS; do
                    n_try=`expr $n_try + 1`
                    _check_filesystems
                    _check_dmesg || err=true
+                   _check_kmemleak || err=true
                fi
 
            fi
@@ -750,11 +806,14 @@ for section in $HOST_OPTIONS_SECTIONS; do
            then
                bad="$bad $seqnum"
                n_bad=`expr $n_bad + 1`
-               quick=false
+               tc_status="fail"
+           fi
+           if $do_report; then
+               _make_testcase_report "$tc_status"
            fi
-
            seq="after_$seqnum"
        done
+       sect_stop=`_wallclock`
        interrupt=false
        _wrapup
        interrupt=true
@@ -765,5 +824,5 @@ for section in $HOST_OPTIONS_SECTIONS; do
 done
 
 interrupt=false
-status=`expr $sum_bad`
+status=`expr $sum_bad != 0`
 exit