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 10/11] selftests: ublk: add stress test for covering IO vs. killing ublk server
Date: Mon, 3 Mar 2025 20:43:20 +0800 [thread overview]
Message-ID: <20250303124324.3563605-11-ming.lei@redhat.com> (raw)
In-Reply-To: <20250303124324.3563605-1-ming.lei@redhat.com>
Add stress_test_01 for running IO vs. killing ublk server, so io_uring exit &
cancel code path can be covered, same with ublk's cancel code path.
Especially IO buffer lifetime is one big thing for ublk zero copy, the added
test can verify if this area works as expected.
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
tools/testing/selftests/ublk/Makefile | 1 +
tools/testing/selftests/ublk/test_common.sh | 29 ++++++++++++
.../testing/selftests/ublk/test_stress_01.sh | 2 +-
.../testing/selftests/ublk/test_stress_02.sh | 47 +++++++++++++++++++
4 files changed, 78 insertions(+), 1 deletion(-)
create mode 100755 tools/testing/selftests/ublk/test_stress_02.sh
diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile
index 40af938cd277..5d8d5939f051 100644
--- a/tools/testing/selftests/ublk/Makefile
+++ b/tools/testing/selftests/ublk/Makefile
@@ -10,6 +10,7 @@ TEST_PROGS += test_loop_03.sh
TEST_PROGS += test_loop_04.sh
TEST_PROGS += test_stress_01.sh
+TEST_PROGS += test_stress_02.sh
TEST_GEN_PROGS_EXTENDED = kublk
diff --git a/tools/testing/selftests/ublk/test_common.sh b/tools/testing/selftests/ublk/test_common.sh
index 89244a7e275c..92596d0d0013 100755
--- a/tools/testing/selftests/ublk/test_common.sh
+++ b/tools/testing/selftests/ublk/test_common.sh
@@ -155,6 +155,26 @@ _add_ublk_dev() {
echo "${dev_id}"
}
+# kill the ublk daemon and return ublk device state
+__ublk_kill_daemon()
+{
+ local dev_id=$1
+ local exp_state=$2
+ local daemon_pid
+ local state
+
+ daemon_pid=$(_get_ublk_daemon_pid "${dev_id}")
+ state=$(_get_ublk_dev_state "${dev_id}")
+
+ for ((j=0;j<50;j++)); do
+ [ "$state" == "$exp_state" ] && break
+ kill -9 "$daemon_pid" > /dev/null 2>&1
+ sleep 1
+ state=$(_get_ublk_dev_state "${dev_id}")
+ done
+ echo "$state"
+}
+
__remove_ublk_dev_return() {
local dev_id=$1
@@ -168,11 +188,20 @@ __run_io_and_remove()
{
local dev_id=$1
local size=$2
+ local kill_server=$3
fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \
--rw=readwrite --iodepth=64 --size="${size}" --numjobs=4 \
--runtime=20 --time_based > /dev/null 2>&1 &
sleep 2
+ if [ "${kill_server}" = "yes" ]; then
+ local state
+ state=$(__ublk_kill_daemon "${dev_id}" "DEAD")
+ if [ "$state" != "DEAD" ]; then
+ echo "device isn't dead($state) after killing daemon"
+ return 255
+ fi
+ fi
if ! __remove_ublk_dev_return "${dev_id}"; then
echo "delete dev ${dev_id} failed"
return 255
diff --git a/tools/testing/selftests/ublk/test_stress_01.sh b/tools/testing/selftests/ublk/test_stress_01.sh
index 2dfd01cfd265..c1cdde3e79f7 100755
--- a/tools/testing/selftests/ublk/test_stress_01.sh
+++ b/tools/testing/selftests/ublk/test_stress_01.sh
@@ -18,7 +18,7 @@ ublk_io_and_remove()
_check_add_dev $TID $? "${backfile}"
echo "run ublk IO vs. remove device(ublk add $*)"
- if ! __run_io_and_remove "${DEV_ID}" "${size}"; then
+ if ! __run_io_and_remove "${DEV_ID}" "${size}" "no"; then
echo "/dev/ublkc${DEV_ID} isn't removed"
_remove_backfile "${backfile}"
exit 255
diff --git a/tools/testing/selftests/ublk/test_stress_02.sh b/tools/testing/selftests/ublk/test_stress_02.sh
new file mode 100755
index 000000000000..ec758f649a97
--- /dev/null
+++ b/tools/testing/selftests/ublk/test_stress_02.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+. test_common.sh
+TID="stress_02"
+ERR_CODE=0
+DEV_ID=-1
+
+ublk_io_and_kill_daemon()
+{
+ local size=$1
+ shift 1
+ local backfile=""
+ if echo "$@" | grep -q "loop"; then
+ backfile=${*: -1}
+ fi
+ DEV_ID=$(_add_ublk_dev "$@")
+ _check_add_dev $TID $? "${backfile}"
+
+ echo "run ublk IO vs kill ublk server(ublk add $*)"
+ if ! __run_io_and_remove "${DEV_ID}" "${size}" "yes"; then
+ echo "/dev/ublkc${DEV_ID} isn't removed res ${res}"
+ _remove_backfile "${backfile}"
+ exit 255
+ fi
+}
+
+_prep_test "stress" "run IO and kill ublk server"
+
+ublk_io_and_kill_daemon 8G -t null
+ERR_CODE=$?
+if [ ${ERR_CODE} -ne 0 ]; then
+ _show_result $TID $ERR_CODE
+fi
+
+BACK_FILE=$(_create_backfile 256M)
+ublk_io_and_kill_daemon 256M -t loop "${BACK_FILE}"
+ERR_CODE=$?
+if [ ${ERR_CODE} -ne 0 ]; then
+ _show_result $TID $ERR_CODE
+fi
+
+ublk_io_and_kill_daemon 256M -t loop -z "${BACK_FILE}"
+ERR_CODE=$?
+_cleanup_test "stress"
+_remove_backfile "${BACK_FILE}"
+_show_result $TID $ERR_CODE
--
2.47.0
next prev 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 ` [PATCH 07/11] selftests: ublk: move zero copy feature check into _add_ublk_dev() Ming Lei
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 ` Ming Lei [this message]
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-11-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