public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org, Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 07/11] selftests: ublk: move zero copy feature check into _add_ublk_dev()
Date: Mon,  3 Mar 2025 20:43:17 +0800	[thread overview]
Message-ID: <20250303124324.3563605-8-ming.lei@redhat.com> (raw)
In-Reply-To: <20250303124324.3563605-1-ming.lei@redhat.com>

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>
---
 tools/testing/selftests/ublk/test_common.sh  | 56 ++++++++++++++++----
 tools/testing/selftests/ublk/test_loop_01.sh |  1 +
 tools/testing/selftests/ublk/test_loop_02.sh |  2 +-
 tools/testing/selftests/ublk/test_loop_03.sh |  4 +-
 tools/testing/selftests/ublk/test_loop_04.sh |  2 +-
 tools/testing/selftests/ublk/test_null_01.sh |  1 +
 6 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/ublk/test_common.sh b/tools/testing/selftests/ublk/test_common.sh
index d70690281d14..40bf42f1bed2 100755
--- a/tools/testing/selftests/ublk/test_common.sh
+++ b/tools/testing/selftests/ublk/test_common.sh
@@ -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
diff --git a/tools/testing/selftests/ublk/test_loop_01.sh b/tools/testing/selftests/ublk/test_loop_01.sh
index 48a85796ca43..12bba9e5daa5 100755
--- a/tools/testing/selftests/ublk/test_loop_01.sh
+++ b/tools/testing/selftests/ublk/test_loop_01.sh
@@ -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 \
diff --git a/tools/testing/selftests/ublk/test_loop_02.sh b/tools/testing/selftests/ublk/test_loop_02.sh
index 0a4b5fadbc73..9a163296ac83 100755
--- a/tools/testing/selftests/ublk/test_loop_02.sh
+++ b/tools/testing/selftests/ublk/test_loop_02.sh
@@ -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=$?
diff --git a/tools/testing/selftests/ublk/test_loop_03.sh b/tools/testing/selftests/ublk/test_loop_03.sh
index 5a11356e502c..72a1d072cfbd 100755
--- a/tools/testing/selftests/ublk/test_loop_03.sh
+++ b/tools/testing/selftests/ublk/test_loop_03.sh
@@ -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 \
diff --git a/tools/testing/selftests/ublk/test_loop_04.sh b/tools/testing/selftests/ublk/test_loop_04.sh
index 7e0d4dd8127e..676c4652d758 100755
--- a/tools/testing/selftests/ublk/test_loop_04.sh
+++ b/tools/testing/selftests/ublk/test_loop_04.sh
@@ -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=$?
diff --git a/tools/testing/selftests/ublk/test_null_01.sh b/tools/testing/selftests/ublk/test_null_01.sh
index af11e73b7df6..e2847a50823a 100755
--- a/tools/testing/selftests/ublk/test_null_01.sh
+++ b/tools/testing/selftests/ublk/test_null_01.sh
@@ -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
-- 
2.47.0


  parent reply	other threads:[~2025-03-03 12:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03 12:43 [PATCH 00/11] selftests: ublk: bug fixes & consolidation Ming Lei
2025-03-03 12:43 ` [PATCH 01/11] selftests: ublk: make ublk_stop_io_daemon() more reliable Ming Lei
2025-03-03 21:31   ` Keith Busch
2025-03-03 12:43 ` [PATCH 02/11] selftests: ublk: fix build failure Ming Lei
2025-03-03 21:31   ` Keith Busch
2025-03-03 12:43 ` [PATCH 03/11] selftests: ublk: add --foreground command line Ming Lei
2025-03-03 21:31   ` Keith Busch
2025-03-03 12:43 ` [PATCH 04/11] selftests: ublk: fix parsing '-a' argument Ming Lei
2025-03-03 21:32   ` Keith Busch
2025-03-03 12:43 ` [PATCH 05/11] selftests: ublk: support shellcheck and fix all warning Ming Lei
2025-03-03 12:43 ` [PATCH 06/11] selftests: ublk: don't pass ${dev_id} to _cleanup_test() Ming Lei
2025-03-03 12:43 ` Ming Lei [this message]
2025-03-03 12:43 ` [PATCH 08/11] selftests: ublk: load/unload ublk_drv when preparing & cleaning up tests Ming Lei
2025-03-03 12:43 ` [PATCH 09/11] selftests: ublk: add one stress test for covering IO vs. removing device Ming Lei
2025-03-03 12:43 ` [PATCH 10/11] selftests: ublk: add stress test for covering IO vs. killing ublk server Ming Lei
2025-03-03 12:43 ` [PATCH 11/11] selftests: ublk: improve test usability Ming Lei
2025-03-10 15:09 ` [PATCH 00/11] selftests: ublk: bug fixes & consolidation Ming Lei
2025-03-10 15:17   ` Jens Axboe
2025-03-11  4:35     ` Ming Lei
2025-03-11 13:28       ` Jens Axboe
2025-03-10 15:18 ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250303124324.3563605-8-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox