]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common: Move exit related functions to a common/exit
authorNirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
Wed, 30 Apr 2025 12:45:22 +0000 (12:45 +0000)
committerZorro Lang <zlang@kernel.org>
Tue, 6 May 2025 09:27:57 +0000 (17:27 +0800)
Introduce a new file common/exit that will contain all the exit
related functions. This will remove the dependencies these functions
have on other non-related helper files and they can be indepedently
sourced. This was suggested by Dave Chinner[1].
While moving the exit related functions, remove _die() and die_now()
and replace die_now with _fatal(). It is of no use to keep the
unnecessary wrappers.

[1] https://lore.kernel.org/linux-xfs/Z_UJ7XcpmtkPRhTr@dread.disaster.area/

Suggested-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Nirjhar Roy (IBM) <nirjhar.roy.lists@gmail.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
check
common/config
common/exit [new file with mode: 0644]
common/preamble
common/punch
common/rc

diff --git a/check b/check
index 9451c350bd1d567f028057e97513dedfd1bdc1d5..bd84f2133088052e0038cb2aa832a60060cf6c47 100755 (executable)
--- a/check
+++ b/check
@@ -46,6 +46,8 @@ export DIFF_LENGTH=${DIFF_LENGTH:=10}
 
 # by default don't output timestamps
 timestamp=${TIMESTAMP:=false}
+. common/exit
+. common/test_names
 
 rm -f $tmp.list $tmp.tmp $tmp.grep $here/$iam.out $tmp.report.* $tmp.arglist
 
index eada3971788d87bfdcf425b4a7e06fb6e73282b1..22b5243283a02281946ec20f8bcdb2bf022fb659 100644 (file)
@@ -39,8 +39,6 @@
 #   validity or mountedness.
 #
 
-. common/test_names
-
 # all tests should use a common language setting to prevent golden
 # output mismatches.
 export LANG=C
@@ -96,15 +94,6 @@ export LOCAL_CONFIGURE_OPTIONS=${LOCAL_CONFIGURE_OPTIONS:=--enable-readline=yes}
 
 export RECREATE_TEST_DEV=${RECREATE_TEST_DEV:=false}
 
-# This functions sets the exit code to status and then exits. Don't use
-# exit directly, as it might not set the value of "$status" correctly, which is
-# used as an exit code in the trap handler routine set up by the check script.
-_exit()
-{
-       test -n "$1" && status="$1"
-       exit "$status"
-}
-
 # Handle mkfs.$fstyp which does (or does not) require -f to overwrite
 set_mkfs_prog_path_with_opts()
 {
@@ -121,12 +110,6 @@ set_mkfs_prog_path_with_opts()
        fi
 }
 
-_fatal()
-{
-    echo "$*"
-    _exit 1
-}
-
 export MKFS_PROG="$(type -P mkfs)"
 [ "$MKFS_PROG" = "" ] && _fatal "mkfs not found"
 
diff --git a/common/exit b/common/exit
new file mode 100644 (file)
index 0000000..222c79b
--- /dev/null
@@ -0,0 +1,39 @@
+##/bin/bash
+
+# This functions sets the exit code to status and then exits. Don't use
+# exit directly, as it might not set the value of "$status" correctly, which is
+# used as an exit code in the trap handler routine set up by the check script.
+_exit()
+{
+       test -n "$1" && status="$1"
+       exit "$status"
+}
+
+_fatal()
+{
+    echo "$*"
+    _exit 1
+}
+
+# just plain bail out
+#
+_fail()
+{
+    echo "$*" | tee -a $seqres.full
+    echo "(see $seqres.full for details)"
+    _exit 1
+}
+
+# bail out, setting up .notrun file. Need to kill the filesystem check files
+# here, otherwise they are set incorrectly for the next test.
+#
+_notrun()
+{
+    echo "$*" > $seqres.notrun
+    echo "$seq not run: $*"
+    rm -f ${RESULT_DIR}/require_test*
+    rm -f ${RESULT_DIR}/require_scratch*
+
+    _exit 0
+}
+
index ba029a347a4beea670a6a78e77f286e9eb12a53c..51d03396c9686438b3b325768bd8c2acb24a0605 100644 (file)
@@ -33,6 +33,9 @@ _register_cleanup()
 # explicitly as a member of the 'all' group.
 _begin_fstest()
 {
+       . common/exit
+       . common/test_names
+
        if [ -n "$seq" ]; then
                echo "_begin_fstest can only be called once!"
                _exit 1
index 64d665d8632204188f61dafa18558d22fdadbacd..ddbe757a9a76fb03d81410e5c289b77da973b6e6 100644 (file)
@@ -222,11 +222,6 @@ _filter_bmap()
        _coalesce_extents
 }
 
-die_now()
-{
-       _exit 1
-}
-
 # test the different corner cases for zeroing a range:
 #
 #      1. into a hole
@@ -305,7 +300,7 @@ _test_generic_punch()
        $XFS_IO_PROG -f -c "truncate $_20k" \
                -c "$zero_cmd $_4k $_8k" \
                -c "$map_cmd -v" $testfile | $filter_cmd
-       [ $? -ne 0 ] && die_now
+       [ $? -ne 0 ] && _fatal
        _md5_checksum $testfile
 
        echo "  2. into allocated space"
@@ -316,7 +311,7 @@ _test_generic_punch()
                -c "pwrite 0 $_20k" $sync_cmd \
                -c "$zero_cmd $_4k $_8k" \
                -c "$map_cmd -v" $testfile | $filter_cmd
-       [ $? -ne 0 ] && die_now
+       [ $? -ne 0 ] && _fatal
        _md5_checksum $testfile
 
        if [ "$unwritten_tests" ]; then
@@ -328,7 +323,7 @@ _test_generic_punch()
                        -c "$alloc_cmd 0 $_20k" \
                        -c "$zero_cmd $_4k $_8k" \
                        -c "$map_cmd -v" $testfile | $filter_cmd
-               [ $? -ne 0 ] && die_now
+               [ $? -ne 0 ] && _fatal
                _md5_checksum $testfile
        fi
 
@@ -340,7 +335,7 @@ _test_generic_punch()
                -c "pwrite $_8k $_8k" $sync_cmd \
                -c "$zero_cmd $_4k $_8k" \
                -c "$map_cmd -v" $testfile | $filter_cmd
-       [ $? -ne 0 ] && die_now
+       [ $? -ne 0 ] && _fatal
        _md5_checksum $testfile
 
        if [ "$unwritten_tests" ]; then
@@ -352,7 +347,7 @@ _test_generic_punch()
                        -c "$alloc_cmd $_8k $_8k" \
                        -c "$zero_cmd $_4k $_8k" \
                        -c "$map_cmd -v" $testfile | $filter_cmd
-               [ $? -ne 0 ] && die_now
+               [ $? -ne 0 ] && _fatal
                _md5_checksum $testfile
        fi
 
@@ -364,7 +359,7 @@ _test_generic_punch()
                -c "pwrite 0 $_8k" $sync_cmd \
                 -c "$zero_cmd $_4k $_8k" \
                -c "$map_cmd -v" $testfile | $filter_cmd
-       [ $? -ne 0 ] && die_now
+       [ $? -ne 0 ] && _fatal
        _md5_checksum $testfile
 
        if [ "$unwritten_tests" ]; then
@@ -377,7 +372,7 @@ _test_generic_punch()
                        -c "$alloc_cmd $_8k $_8k" \
                        -c "$zero_cmd $_4k $_8k" \
                        -c "$map_cmd -v" $testfile | $filter_cmd
-               [ $? -ne 0 ] && die_now
+               [ $? -ne 0 ] && _fatal
                _md5_checksum $testfile
 
                echo "  8. unwritten -> hole"
@@ -388,7 +383,7 @@ _test_generic_punch()
                        -c "$alloc_cmd 0 $_8k" \
                        -c "$zero_cmd $_4k $_8k" \
                        -c "$map_cmd -v" $testfile | $filter_cmd
-               [ $? -ne 0 ] && die_now
+               [ $? -ne 0 ] && _fatal
                _md5_checksum $testfile
 
                echo "  9. unwritten -> data"
@@ -400,7 +395,7 @@ _test_generic_punch()
                        -c "pwrite $_8k $_8k" $sync_cmd \
                        -c "$zero_cmd $_4k $_8k" \
                        -c "$map_cmd -v" $testfile | $filter_cmd
-               [ $? -ne 0 ] && die_now
+               [ $? -ne 0 ] && _fatal
                _md5_checksum $testfile
        fi
 
@@ -412,7 +407,7 @@ _test_generic_punch()
                -c "pwrite $_8k $_4k" $sync_cmd \
                -c "$zero_cmd $_4k $_12k" \
                -c "$map_cmd -v" $testfile | $filter_cmd
-       [ $? -ne 0 ] && die_now
+       [ $? -ne 0 ] && _fatal
        _md5_checksum $testfile
 
        echo "  11. data -> hole -> data"
@@ -426,7 +421,7 @@ _test_generic_punch()
                -c "$punch_cmd $_8k $_4k" \
                -c "$zero_cmd $_4k $_12k" \
                -c "$map_cmd -v" $testfile | $filter_cmd
-       [ $? -ne 0 ] && die_now
+       [ $? -ne 0 ] && _fatal
        _md5_checksum $testfile
 
        if [ "$unwritten_tests" ]; then
@@ -439,7 +434,7 @@ _test_generic_punch()
                        -c "pwrite $_8k $_4k" $sync_cmd \
                        -c "$zero_cmd $_4k $_12k" \
                        -c "$map_cmd -v" $testfile | $filter_cmd
-               [ $? -ne 0 ] && die_now
+               [ $? -ne 0 ] && _fatal
                _md5_checksum $testfile
 
                echo "  13. data -> unwritten -> data"
@@ -452,7 +447,7 @@ _test_generic_punch()
                        -c "pwrite $_12k $_8k" -c "fsync" \
                        -c "$zero_cmd $_4k $_12k" \
                        -c "$map_cmd -v" $testfile | $filter_cmd
-               [ $? -ne 0 ] && die_now
+               [ $? -ne 0 ] && _fatal
                _md5_checksum $testfile
        fi
 
@@ -466,7 +461,7 @@ _test_generic_punch()
                        -c "pwrite 0 $_20k" $sync_cmd \
                        -c "$zero_cmd $_12k $_8k" \
                        -c "$map_cmd -v" $testfile | $filter_cmd
-               [ $? -ne 0 ] && die_now
+               [ $? -ne 0 ] && _fatal
                _md5_checksum $testfile
        fi
 
@@ -483,7 +478,7 @@ _test_generic_punch()
                -c "pwrite 0 $_20k" $sync_cmd \
                -c "$zero_cmd 0 $_8k" \
                -c "$map_cmd -v" $testfile | $filter_cmd
-       [ $? -ne 0 ] && die_now
+       [ $? -ne 0 ] && _fatal
        _md5_checksum $testfile
 
        # If zero_cmd is fcollpase, don't check unaligned offsets
@@ -512,7 +507,7 @@ _test_generic_punch()
                -c "fadvise -d" \
                -c "$map_cmd -v" $testfile | $filter_cmd
        diff $testfile $testfile.2
-       [ $? -ne 0 ] && die_now
+       [ $? -ne 0 ] && _fatal
        rm -f $testfile.2
        _md5_checksum $testfile
 
@@ -532,7 +527,7 @@ _test_generic_punch()
                -c "$zero_cmd 128 128" \
                -c "$map_cmd -v" $testfile | $filter_cmd | \
                         sed -e "s/\.\.[0-9]*\]/..7\]/"
-       [ $? -ne 0 ] && die_now
+       [ $? -ne 0 ] && _fatal
        od -x $testfile | head -n -1
 }
 
index 9bed6dad9303db6f368dda126fbd36ae18da0898..fac9b6da77c2005fc5cc406f3c2832557681cf55 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -1798,28 +1798,6 @@ _do()
     return $ret
 }
 
-# bail out, setting up .notrun file. Need to kill the filesystem check files
-# here, otherwise they are set incorrectly for the next test.
-#
-_notrun()
-{
-    echo "$*" > $seqres.notrun
-    echo "$seq not run: $*"
-    rm -f ${RESULT_DIR}/require_test*
-    rm -f ${RESULT_DIR}/require_scratch*
-
-    _exit 0
-}
-
-# just plain bail out
-#
-_fail()
-{
-    echo "$*" | tee -a $seqres.full
-    echo "(see $seqres.full for details)"
-    _exit 1
-}
-
 #
 # Tests whether $FSTYP should be exclude from this test.
 #
@@ -3835,12 +3813,6 @@ _link_out_file()
        _link_out_file_named $seqfull.out "$features"
 }
 
-_die()
-{
-        echo $@
-        _exit 1
-}
-
 # convert urandom incompressible data to compressible text data
 _ddt()
 {