]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests: ublk: move zero copy feature check into _add_ublk_dev()
authorMing Lei <ming.lei@redhat.com>
Mon, 3 Mar 2025 12:43:17 +0000 (20:43 +0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 10 Mar 2025 22:24:42 +0000 (16:24 -0600)
Move zero copy feature check into _add_ublk_dev() since we will have
more tests which requires to cover zero copy.

Then one check function of _check_add_dev() has to be added for dealing
with cleanup since '_add_ublk_dev()' is run in sub-shell, and we can't
exit from it to terminal shell.

Meantime always return error code from _add_ublk_dev().

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250303124324.3563605-8-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
tools/testing/selftests/ublk/test_common.sh
tools/testing/selftests/ublk/test_loop_01.sh
tools/testing/selftests/ublk/test_loop_02.sh
tools/testing/selftests/ublk/test_loop_03.sh
tools/testing/selftests/ublk/test_loop_04.sh
tools/testing/selftests/ublk/test_null_01.sh

index d70690281d14b7b668ee26183f3634ee09cc0293..40bf42f1bed25f9b5d6604addf7653b8148c716c 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
+UBLK_SKIP_CODE=4
+
 _create_backfile() {
        local my_size=$1
        local my_file
@@ -79,12 +81,37 @@ _prep_test() {
        echo "ublk $type: $*"
 }
 
+_remove_test_files()
+{
+       local files=$*
+
+       for file in ${files}; do
+               [ -f "${file}" ] && rm -f "${file}"
+       done
+}
+
 _show_result()
 {
-       if [ "$2" -ne 0 ]; then
-               echo "$1 : [FAIL]"
-       else
+       if [ "$2" -eq 0 ]; then
                echo "$1 : [PASS]"
+       elif [ "$2" -eq 4 ]; then
+               echo "$1 : [SKIP]"
+       else
+               echo "$1 : [FAIL]"
+       fi
+       [ "$2" -ne 0 ] && exit "$2"
+       return 0
+}
+
+# don't call from sub-shell, otherwise can't exit
+_check_add_dev()
+{
+       local tid=$1
+       local code=$2
+       shift 2
+       if [ "${code}" -ne 0 ]; then
+               _remove_test_files "$@"
+               _show_result "${tid}" "${code}"
        fi
 }
 
@@ -92,13 +119,28 @@ _cleanup_test() {
        "${UBLK_PROG}" del -a
 }
 
+_have_feature()
+{
+       if  $UBLK_PROG "features" | grep "$1" > /dev/null 2>&1; then
+               return 0
+       fi
+       return 1
+}
+
 _add_ublk_dev() {
        local kublk_temp;
        local dev_id;
 
+       if echo "$@" | grep -q "\-z"; then
+               if ! _have_feature "ZERO_COPY"; then
+                       return ${UBLK_SKIP_CODE}
+               fi
+       fi
+
        kublk_temp=$(mktemp /tmp/kublk-XXXXXX)
        if ! "${UBLK_PROG}" add "$@" > "${kublk_temp}" 2>&1; then
                echo "fail to add ublk dev $*"
+               rm -f "${kublk_temp}"
                return 255
        fi
 
@@ -108,13 +150,5 @@ _add_ublk_dev() {
        echo "${dev_id}"
 }
 
-_have_feature()
-{
-       if  "$UBLK_PROG" "features" | grep "$1" > /dev/null 2>&1; then
-               return 0
-       fi
-       return 1
-}
-
 UBLK_PROG=$(pwd)/kublk
 export UBLK_PROG
index 48a85796ca436c2b7b9908cd1088a4f84845a9cf..12bba9e5daa5925817bc5e23b645233dae5d93cc 100755 (executable)
@@ -11,6 +11,7 @@ _prep_test "loop" "write and verify test"
 backfile_0=$(_create_backfile 256M)
 
 dev_id=$(_add_ublk_dev -t loop "$backfile_0")
+_check_add_dev $TID $? "${backfile_0}"
 
 # run fio over the ublk disk
 fio --name=write_and_verify \
index 0a4b5fadbc73ad1c2d416cf126a63ee5c00d9543..9a163296ac83f7afb5842328402badf428659d2e 100755 (executable)
@@ -9,8 +9,8 @@ ERR_CODE=0
 _prep_test "loop" "mkfs & mount & umount"
 
 backfile_0=$(_create_backfile 256M)
-
 dev_id=$(_add_ublk_dev -t loop "$backfile_0")
+_check_add_dev $TID $? "$backfile_0"
 
 _mkfs_mount_test /dev/ublkb"${dev_id}"
 ERR_CODE=$?
index 5a11356e502c34dacac8dcb703d18f94acab17fb..72a1d072cfbd90b3d2a43699e0c57456b73020be 100755 (executable)
@@ -6,13 +6,11 @@
 TID="loop_03"
 ERR_CODE=0
 
-_have_feature "ZERO_COPY" || exit 4
-
 _prep_test "loop" "write and verify over zero copy"
 
 backfile_0=$(_create_backfile 256M)
-
 dev_id=$(_add_ublk_dev -t loop -z "$backfile_0")
+_check_add_dev $TID $? "$backfile_0"
 
 # run fio over the ublk disk
 fio --name=write_and_verify \
index 7e0d4dd8127e1a19a73fb4788d2367978be4a85b..676c4652d758d330304f9d7c84fdb7d0a35b8d67 100755 (executable)
@@ -9,8 +9,8 @@ ERR_CODE=0
 _prep_test "loop" "mkfs & mount & umount with zero copy"
 
 backfile_0=$(_create_backfile 256M)
-
 dev_id=$(_add_ublk_dev -t loop -z "$backfile_0")
+_check_add_dev $TID $? "$backfile_0"
 
 _mkfs_mount_test /dev/ublkb"${dev_id}"
 ERR_CODE=$?
index af11e73b7df6e26fdd2dd69de3796203fc6d33ef..e2847a50823a8c8251e78f09097b44ac2c08dc67 100755 (executable)
@@ -9,6 +9,7 @@ ERR_CODE=0
 _prep_test "null" "basic IO test"
 
 dev_id=$(_add_ublk_dev -t null)
+_check_add_dev $TID $?
 
 # run fio over the two disks
 fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio --rw=readwrite --iodepth=32 --size=256M > /dev/null 2>&1