check: don't leave the scratch filesystem mounted after _notrun
[xfstests-dev.git] / check
diff --git a/check b/check
index e51cbeded353ae3dedaffee0d081bc07bd8e2d2a..242cb8c1e6f71004e5fb531e7b79e1cada2e8431 100755 (executable)
--- a/check
+++ b/check
@@ -20,6 +20,7 @@ diff="diff -u"
 showme=false
 have_test_arg=false
 randomize=false
+exact_order=false
 export here=`pwd`
 xfile=""
 subdir_xfile=""
@@ -27,6 +28,7 @@ brief_test_summary=false
 do_report=false
 DUMP_OUTPUT=false
 iterations=1
+istop=false
 
 # This is a global variable used to pass test failure text to reporting gunk
 _err_msg=""
@@ -67,7 +69,9 @@ check options
     -n                 show me, do not run tests
     -T                 output timestamps
     -r                 randomize test order
+    --exact-order      run tests in the exact order specified
     -i <n>             iterate the test list <n> times
+    -I <n>             iterate the test list <n> times, but stops iterating further in case of any test failure
     -d                 dump test output to stdout
     -b                 brief test summary
     -R fmt[,fmt]       generate report in formats specified. Supported format: [xunit]
@@ -112,7 +116,7 @@ examples:
  check -X .exclude -g auto
  check -E ~/.xfstests.exclude
 '
-           exit 0
+           exit 1
 }
 
 get_sub_group_list()
@@ -120,9 +124,9 @@ get_sub_group_list()
        local d=$1
        local grp=$2
 
-       test -s "$SRC_DIR/$d/group" || return 1
+       test -s "$SRC_DIR/$d/group.list" || return 1
 
-       local grpl=$(sed -n < $SRC_DIR/$d/group \
+       local grpl=$(sed -n < $SRC_DIR/$d/group.list \
                -e 's/#.*//' \
                -e 's/$/ /' \
                -e "s;^\($VALID_TEST_NAME\).* $grp .*;$SRC_DIR/$d/\1;p")
@@ -243,23 +247,28 @@ _prepare_test_list()
                list=$(get_group_list $xgroup)
                if [ -z "$list" ]; then
                        echo "Group \"$xgroup\" is empty or not defined?"
-                       exit 1
+                       continue
                fi
 
                trim_test_list $list
        done
 
-       # sort the list of tests into numeric order
-       if $randomize; then
-               if type shuf >& /dev/null; then
-                       sorter="shuf"
+       # sort the list of tests into numeric order unless we're running tests
+       # in the exact order specified
+       if ! $exact_order; then
+               if $randomize; then
+                       if type shuf >& /dev/null; then
+                               sorter="shuf"
+                       else
+                               sorter="awk -v seed=$RANDOM -f randomize.awk"
+                       fi
                else
-                       sorter="awk -v seed=$RANDOM -f randomize.awk"
+                       sorter="cat"
                fi
+               list=`sort -n $tmp.list | uniq | $sorter`
        else
-               sorter="cat"
+               list=`cat $tmp.list`
        fi
-       list=`sort -n $tmp.list | uniq | $sorter`
        rm -f $tmp.list
 }
 
@@ -304,8 +313,22 @@ while [ $# -gt 0 ]; do
        -udiff) diff="$diff -u" ;;
 
        -n)     showme=true ;;
-        -r)    randomize=true ;;
+       -r)
+               if $exact_order; then
+                       echo "Cannot specify -r and --exact-order."
+                       exit 1
+               fi
+               randomize=true
+               ;;
+       --exact-order)
+               if $randomize; then
+                       echo "Cannnot specify --exact-order and -r."
+                       exit 1
+               fi
+               exact_order=true
+               ;;
        -i)     iterations=$2; shift ;;
+       -I)     iterations=$2; istop=true; shift ;;
        -T)     timestamp=true ;;
        -d)     DUMP_OUTPUT=true ;;
        -b)     brief_test_summary=true;;
@@ -361,7 +384,7 @@ if $have_test_arg; then
                                test_dir=`dirname $t`
                                test_dir=${test_dir#$SRC_DIR/*}
                                test_name=`basename $t`
-                               group_file=$SRC_DIR/$test_dir/group
+                               group_file=$SRC_DIR/$test_dir/group.list
 
                                if egrep -q "^$test_name" $group_file; then
                                        # in group file ... OK
@@ -502,17 +525,20 @@ _summary()
 
 _check_filesystems()
 {
+       local ret=0
+
        if [ -f ${RESULT_DIR}/require_test ]; then
-               _check_test_fs || err=true
+               _check_test_fs || ret=1
                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
+               _check_scratch_fs || ret=1
                rm -f ${RESULT_DIR}/require_scratch*
        fi
        _scratch_unmount 2> /dev/null
+       return $ret
 }
 
 _expunge_test()
@@ -535,11 +561,15 @@ test $? -eq 77 && HAVE_SYSTEMD_SCOPES=yes
 
 # 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}
+function _adjust_oom_score() {
+       test -w "${OOM_SCORE_ADJ}" && echo "$1" > "${OOM_SCORE_ADJ}"
+}
+_adjust_oom_score -1000
 
 # ...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.
+# test framework.  The test is run in a separate process without any of our
+# functions, so we open-code adjusting the OOM score.
 #
 # If systemd is available, run the entire test script in a scope so that we can
 # kill all subprocesses of the test if it fails to clean up after itself.  This
@@ -841,6 +871,10 @@ function run_section()
                        notrun="$notrun $seqnum"
                        n_notrun=`expr $n_notrun + 1`
                        tc_status="notrun"
+
+                       # Unmount the scratch fs so that we can wipe the scratch
+                       # dev state prior to the next test run.
+                       _scratch_unmount 2> /dev/null
                        continue;
                fi
 
@@ -852,9 +886,12 @@ function run_section()
                        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
+                       # The test apparently passed, so check for corruption
+                       # and log messages that shouldn't be there.  Run the
+                       # checking tools from a subshell with adjusted OOM
+                       # score so that the OOM killer will target them instead
+                       # of the check script itself.
+                       (_adjust_oom_score 250; _check_filesystems) || err=true
                        _check_dmesg || err=true
                fi
 
@@ -932,6 +969,11 @@ function run_section()
 for ((iters = 0; iters < $iterations; iters++)) do
        for section in $HOST_OPTIONS_SECTIONS; do
                run_section $section
+               if [ "$sum_bad" != 0 ] && [ "$istop" = true ]; then
+                       interrupt=false
+                       status=`expr $sum_bad != 0`
+                       exit
+               fi
        done
 done