mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-11 11:30:57 -04:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
47
tools/testing/selftests/ublk/test_stress_02.sh
Executable file
47
tools/testing/selftests/ublk/test_stress_02.sh
Executable file
@@ -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
|
||||
Reference in New Issue
Block a user