xfs: race freeze and fsmap for a while to see if we livelock
[xfstests-dev.git] / check
diff --git a/check b/check
index d768d6e903589f47147457337f2e8871a2a9c77d..2e148e5776e56f8586087e0db96bd8877c7bf118 100755 (executable)
--- a/check
+++ b/check
@@ -1,24 +1,9 @@
 #!/bin/bash
-#
-# Control script for QA
-#
+# SPDX-License-Identifier: GPL-2.0
 # Copyright (c) 2000-2002,2006 Silicon Graphics, Inc.  All Rights Reserved.
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# Control script for QA
 #
-
 tmp=/tmp/$$
 status=0
 needwrap=true
@@ -37,6 +22,7 @@ have_test_arg=false
 randomize=false
 export here=`pwd`
 xfile=""
+subdir_xfile=""
 brief_test_summary=false
 do_report=false
 DUMP_OUTPUT=false
@@ -66,14 +52,15 @@ usage()
     echo "Usage: $0 [options] [testlist]"'
 
 check options
-    -nfs                test NFS
-    -glusterfs                test GlusterFS
-    -cifs               test CIFS
+    -nfs               test NFS
+    -glusterfs         test GlusterFS
+    -cifs              test CIFS
     -9p                        test 9p
+    -virtiofs          test virtiofs
     -overlay           test overlay
-    -pvfs2          test PVFS2
-    -tmpfs              test TMPFS
-    -ubifs              test ubifs
+    -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
@@ -144,6 +131,7 @@ get_group_list()
        local grp=$1
        local grpl=""
        local sub=$(dirname $grp)
+       local fsgroup="$FSTYP"
 
        if [ -n "$sub" -a "$sub" != "." -a -d "$SRC_DIR/$sub" ]; then
                # group is given as <subdir>/<group> (e.g. xfs/quick)
@@ -152,7 +140,10 @@ get_group_list()
                return
        fi
 
-       for d in $SRC_GROUPS $FSTYP; do
+       if [ "$FSTYP" = ext2 -o "$FSTYP" = ext3 ]; then
+           fsgroup=ext4
+       fi
+       for d in $SRC_GROUPS $fsgroup; do
                if ! test -d "$SRC_DIR/$d" ; then
                        continue
                fi
@@ -256,13 +247,17 @@ _prepare_test_list()
        done
 
        # sort the list of tests into numeric order
-       list=`sort -n $tmp.list | uniq`
-       rm -f $tmp.list
-
-       if $randomize
-       then
-               list=`echo $list | awk -f randomize.awk`
+       if $randomize; then
+               if type shuf >& /dev/null; then
+                       sorter="shuf"
+               else
+                       sorter="awk -v seed=$RANDOM -f randomize.awk"
+               fi
+       else
+               sorter="cat"
        fi
+       list=`sort -n $tmp.list | uniq | $sorter`
+       rm -f $tmp.list
 }
 
 # Process command arguments first.
@@ -274,6 +269,7 @@ while [ $# -gt 0 ]; do
        -glusterfs)     FSTYP=glusterfs ;;
        -cifs)          FSTYP=cifs ;;
        -9p)            FSTYP=9p ;;
+       -virtiofs)      FSTYP=virtiofs ;;
        -overlay)       FSTYP=overlay; export OVERLAY=true ;;
        -pvfs2)         FSTYP=pvfs2 ;;
        -tmpfs)         FSTYP=tmpfs ;;
@@ -287,13 +283,7 @@ while [ $# -gt 0 ]; do
                XGROUP_LIST="$XGROUP_LIST ${xgroup//,/ }"
                ;;
 
-       -X)     xfile=$2; shift ;
-               for d in $SRC_GROUPS $FSTYP; do
-                       [ -f $SRC_DIR/$d/$xfile ] || continue
-                       for f in `sed "s/#.*$//" $SRC_DIR/$d/$xfile`; do
-                               echo $d/$f >> $tmp.xlist
-                       done
-               done
+       -X)     subdir_xfile=$2; shift ;
                ;;
        -E)     xfile=$2; shift ;
                if [ -f $xfile ]; then
@@ -340,6 +330,15 @@ if ! . ./common/rc; then
        exit 1
 fi
 
+if [ -n "$subdir_xfile" ]; then
+       for d in $SRC_GROUPS $FSTYP; do
+               [ -f $SRC_DIR/$d/$subdir_xfile ] || continue
+               for f in `sed "s/#.*$//" $SRC_DIR/$d/$subdir_xfile`; do
+                       echo $d/$f >> $tmp.xlist
+               done
+       done
+fi
+
 # Process tests from command line now.
 if $have_test_arg; then
        while [ $# -gt 0 ]; do
@@ -490,9 +489,8 @@ _check_filesystems()
        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
+       _scratch_unmount 2> /dev/null
 }
 
 _expunge_test()
@@ -507,7 +505,18 @@ _expunge_test()
        return 0
 }
 
-_init_kmemleak
+# Make the check script unattractive to the OOM killer...
+OOM_SCORE_ADJ="/proc/self/oom_score_adj"
+test -w ${OOM_SCORE_ADJ} && echo -1000 > ${OOM_SCORE_ADJ}
+
+# ...and make the tests themselves somewhat more attractive to it, so that if
+# the system runs out of memory it'll be the test that gets killed and not the
+# test framework.
+_run_seq() {
+       bash -c "test -w ${OOM_SCORE_ADJ} && echo 250 > ${OOM_SCORE_ADJ}; exec ./$seq"
+}
+
+_detect_kmemleak
 _prepare_test_list
 
 if $OPTIONS_HAVE_SECTIONS; then
@@ -625,13 +634,15 @@ for section in $HOST_OPTIONS_SECTIONS; do
 
          # call the overridden mount - make sure the FS mounts with
          # the same options that we'll mount with later.
-         if ! _scratch_mount >$tmp.err 2>&1
+         if ! _try_scratch_mount >$tmp.err 2>&1
          then
              echo "our local mount routine ..."
              cat $tmp.err
              echo "check: failed to mount \$SCRATCH_DEV using specified options"
              status=1
              exit
+         else
+             _scratch_unmount
          fi
        fi
 
@@ -744,12 +755,13 @@ for section in $HOST_OPTIONS_SECTIONS; do
                        # _check_dmesg depends on this log in dmesg
                        touch ${RESULT_DIR}/check_dmesg
                fi
+               _try_wipe_scratch_devs > /dev/null 2>&1
                if [ "$DUMP_OUTPUT" = true ]; then
-                       ./$seq 2>&1 | tee $tmp.out
+                       _run_seq 2>&1 | tee $tmp.out
                        # Because $? would get tee's return code
                        sts=${PIPESTATUS[0]}
                else
-                       ./$seq >$tmp.out 2>&1
+                       _run_seq >$tmp.out 2>&1
                        sts=$?
                fi
 
@@ -776,15 +788,20 @@ for section in $HOST_OPTIONS_SECTIONS; do
                        _dump_err_cont "[failed, exit status $sts]"
                        _test_unmount 2> /dev/null
                        _scratch_unmount 2> /dev/null
+                       rm -f ${RESULT_DIR}/require_test*
+                       rm -f ${RESULT_DIR}/require_scratch*
                        err=true
                else
                        # the test apparently passed, so check for corruption
                        # and log messages that shouldn't be there.
                        _check_filesystems
                        _check_dmesg || err=true
-                       _check_kmemleak || err=true
                fi
 
+               # Scan for memory leaks after every test so that associating
+               # a leak to a particular test will be as accurate as possible.
+               _check_kmemleak || err=true
+
                # test ends after all checks are done.
                $timestamp && _timestamp
                stop=`_wallclock`
@@ -814,7 +831,7 @@ for section in $HOST_OPTIONS_SECTIONS; do
                        else
                                head -n "$DIFF_LENGTH"
                                echo "..."
-                               echo "(Run '$diff $seq.out $seqres.out.bad'" \
+                               echo "(Run '$diff $here/$seq.out $seqres.out.bad'" \
                                        " to see the entire diff)"
                        fi; } | sed -e 's/^\(.\)/    \1/'
                        err=true