Skip to content

Commit af83ccc

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add stress test for covering IO vs. killing ublk server
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> Link: https://lore.kernel.org/r/20250303124324.3563605-11-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c60ac48 commit af83ccc

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

tools/testing/selftests/ublk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ TEST_PROGS += test_loop_03.sh
1010
TEST_PROGS += test_loop_04.sh
1111

1212
TEST_PROGS += test_stress_01.sh
13+
TEST_PROGS += test_stress_02.sh
1314

1415
TEST_GEN_PROGS_EXTENDED = kublk
1516

tools/testing/selftests/ublk/test_common.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ _add_ublk_dev() {
155155
echo "${dev_id}"
156156
}
157157

158+
# kill the ublk daemon and return ublk device state
159+
__ublk_kill_daemon()
160+
{
161+
local dev_id=$1
162+
local exp_state=$2
163+
local daemon_pid
164+
local state
165+
166+
daemon_pid=$(_get_ublk_daemon_pid "${dev_id}")
167+
state=$(_get_ublk_dev_state "${dev_id}")
168+
169+
for ((j=0;j<50;j++)); do
170+
[ "$state" == "$exp_state" ] && break
171+
kill -9 "$daemon_pid" > /dev/null 2>&1
172+
sleep 1
173+
state=$(_get_ublk_dev_state "${dev_id}")
174+
done
175+
echo "$state"
176+
}
177+
158178
__remove_ublk_dev_return() {
159179
local dev_id=$1
160180

@@ -168,11 +188,20 @@ __run_io_and_remove()
168188
{
169189
local dev_id=$1
170190
local size=$2
191+
local kill_server=$3
171192

172193
fio --name=job1 --filename=/dev/ublkb"${dev_id}" --ioengine=libaio \
173194
--rw=readwrite --iodepth=64 --size="${size}" --numjobs=4 \
174195
--runtime=20 --time_based > /dev/null 2>&1 &
175196
sleep 2
197+
if [ "${kill_server}" = "yes" ]; then
198+
local state
199+
state=$(__ublk_kill_daemon "${dev_id}" "DEAD")
200+
if [ "$state" != "DEAD" ]; then
201+
echo "device isn't dead($state) after killing daemon"
202+
return 255
203+
fi
204+
fi
176205
if ! __remove_ublk_dev_return "${dev_id}"; then
177206
echo "delete dev ${dev_id} failed"
178207
return 255

tools/testing/selftests/ublk/test_stress_01.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ublk_io_and_remove()
1818
_check_add_dev $TID $? "${backfile}"
1919

2020
echo "run ublk IO vs. remove device(ublk add $*)"
21-
if ! __run_io_and_remove "${DEV_ID}" "${size}"; then
21+
if ! __run_io_and_remove "${DEV_ID}" "${size}" "no"; then
2222
echo "/dev/ublkc${DEV_ID} isn't removed"
2323
_remove_backfile "${backfile}"
2424
exit 255
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
. test_common.sh
5+
TID="stress_02"
6+
ERR_CODE=0
7+
DEV_ID=-1
8+
9+
ublk_io_and_kill_daemon()
10+
{
11+
local size=$1
12+
shift 1
13+
local backfile=""
14+
if echo "$@" | grep -q "loop"; then
15+
backfile=${*: -1}
16+
fi
17+
DEV_ID=$(_add_ublk_dev "$@")
18+
_check_add_dev $TID $? "${backfile}"
19+
20+
echo "run ublk IO vs kill ublk server(ublk add $*)"
21+
if ! __run_io_and_remove "${DEV_ID}" "${size}" "yes"; then
22+
echo "/dev/ublkc${DEV_ID} isn't removed res ${res}"
23+
_remove_backfile "${backfile}"
24+
exit 255
25+
fi
26+
}
27+
28+
_prep_test "stress" "run IO and kill ublk server"
29+
30+
ublk_io_and_kill_daemon 8G -t null
31+
ERR_CODE=$?
32+
if [ ${ERR_CODE} -ne 0 ]; then
33+
_show_result $TID $ERR_CODE
34+
fi
35+
36+
BACK_FILE=$(_create_backfile 256M)
37+
ublk_io_and_kill_daemon 256M -t loop "${BACK_FILE}"
38+
ERR_CODE=$?
39+
if [ ${ERR_CODE} -ne 0 ]; then
40+
_show_result $TID $ERR_CODE
41+
fi
42+
43+
ublk_io_and_kill_daemon 256M -t loop -z "${BACK_FILE}"
44+
ERR_CODE=$?
45+
_cleanup_test "stress"
46+
_remove_backfile "${BACK_FILE}"
47+
_show_result $TID $ERR_CODE

0 commit comments

Comments
 (0)