Skip to content

Commit d91fa93

Browse files
committed
throtl/rc: support test with scsi_debug
Currently, the throtl test cases set up null_blk devices as test targets. It is desired to run the tests with scsi_debug devices also to expand test coverage and identify failures that do not surface with null_blk as shown in the Link. Introduce the global variable throtl_blkdev_type to choose the test target block device type. When 'nullb' is set to it, run the tests with null_blk. When 'sdebug' is set, run with scsi_debug. The command line below runs the throtl group with scsi_debug. $ sudo bash -c "throtl_blkdev_type=sdebug ./check throtl" Modify the helper functions _configure_throtl_blkdev(), _delete_throtl_blkdev() and _exit_throtl_blkdev() to support both null_blk and scsi_debug. After this change, the global variable THROTL_DEV is no longer constant then shellcheck warns about its references. Add double quotations to suppress the shellcheck warnings. Link: https://lore.kernel.org/linux-block/[email protected]/ Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 95b5003 commit d91fa93

1 file changed

Lines changed: 50 additions & 13 deletions

File tree

  • tests/throtl

tests/throtl/rc

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,26 @@
66

77
. common/rc
88
. common/null_blk
9+
. common/scsi_debug
910
. common/cgroup
1011

1112
THROTL_DIR=$(echo "$TEST_NAME" | tr '/' '_')
12-
THROTL_DEV=dev_nullb
13+
throtl_blkdev_type=${throtl_blkdev_type:-"nullb"}
14+
THROTL_NULL_DEV=dev_nullb
15+
declare THROTL_DEV
1316
declare THROTL_CLEAR_BASE_SUBTREE_CONTROL_IO
1417
declare THROTL_CLEAR_CGROUP2_DIR_CONTROL_IO
1518

1619
group_requires() {
1720
_have_root
1821
_have_null_blk
22+
_have_scsi_debug
1923
_have_kernel_option BLK_DEV_THROTTLING
2024
_have_cgroup2_controller io
2125
_have_program bc
2226
}
2327

28+
# Prepare null_blk or scsi_debug device to test, based on throtl_blkdev_type.
2429
_configure_throtl_blkdev() {
2530
local sector_size=0 memory_backed=0
2631
local -a args
@@ -42,21 +47,53 @@ _configure_throtl_blkdev() {
4247
esac
4348
done
4449

45-
args=("$THROTL_DEV")
46-
((sector_size)) && args+=(max_sectors="$((sector_size / 512))")
47-
((memory_backed)) && args+=(memory_backed=1)
48-
if _configure_null_blk "${args[@]}" power=1; then
49-
return
50-
fi
50+
THROTL_DEV=
51+
case "$throtl_blkdev_type" in
52+
nullb)
53+
args=("$THROTL_NULL_DEV")
54+
((sector_size)) && args+=(max_sectors="$((sector_size / 512))")
55+
((memory_backed)) && args+=(memory_backed=1)
56+
if _configure_null_blk "${args[@]}" power=1; then
57+
THROTL_DEV=$THROTL_NULL_DEV
58+
return
59+
fi
60+
;;
61+
sdebug)
62+
args=(dev_size_mb=1024)
63+
((sector_size)) && args+=(sector_size="${sector_size}")
64+
if _configure_scsi_debug "${args[@]}"; then
65+
THROTL_DEV=${SCSI_DEBUG_DEVICES[0]}
66+
return
67+
fi
68+
;;
69+
*)
70+
echo "Invalid block device type: ${throtl_blkdev_type}" ;;
71+
esac
5172
return 1
5273
}
5374

5475
_delete_throtl_blkdev() {
55-
echo 0 > "/sys/kernel/config/nullb/$THROTL_DEV/power"
76+
case "$throtl_blkdev_type" in
77+
nullb)
78+
echo 0 > "/sys/kernel/config/nullb/$THROTL_DEV/power"
79+
;;
80+
sdebug)
81+
echo 1 > "/sys/block/$THROTL_DEV/device/delete"
82+
;;
83+
*)
84+
echo "Invalid block device type: ${throtl_blkdev_type}" ;;
85+
esac
5686
}
5787

5888
_exit_throtl_blkdev() {
59-
_exit_null_blk
89+
case "$throtl_blkdev_type" in
90+
nullb)
91+
_exit_null_blk ;;
92+
sdebug)
93+
_exit_scsi_debug ;;
94+
*)
95+
echo "Invalid block device type: ${throtl_blkdev_type}" ;;
96+
esac
6097
unset THROTL_DEV
6198
}
6299

@@ -101,12 +138,12 @@ _clean_up_throtl() {
101138
}
102139

103140
_throtl_set_limits() {
104-
echo "$(cat /sys/block/$THROTL_DEV/dev) $*" > \
141+
echo "$(cat /sys/block/"$THROTL_DEV"/dev) $*" > \
105142
"$CGROUP2_DIR/$THROTL_DIR/io.max"
106143
}
107144

108145
_throtl_remove_limits() {
109-
echo "$(cat /sys/block/$THROTL_DEV/dev) rbps=max wbps=max riops=max wiops=max" > \
146+
echo "$(cat /sys/block/"$THROTL_DEV"/dev) rbps=max wbps=max riops=max wiops=max" > \
110147
"$CGROUP2_DIR/$THROTL_DIR/io.max"
111148
}
112149

@@ -145,9 +182,9 @@ _throtl_issue_io() {
145182
start_time=$(date +%s.%N)
146183

147184
if [ "$1" == "read" ]; then
148-
dd if=/dev/$THROTL_DEV of=/dev/null bs="$2" count="$3" iflag=direct status=none
185+
dd if=/dev/"$THROTL_DEV" of=/dev/null bs="$2" count="$3" iflag=direct status=none
149186
elif [ "$1" == "write" ]; then
150-
dd of=/dev/$THROTL_DEV if=/dev/zero bs="$2" count="$3" oflag=direct status=none
187+
dd of=/dev/"$THROTL_DEV" if=/dev/zero bs="$2" count="$3" oflag=direct status=none
151188
fi
152189

153190
end_time=$(date +%s.%N)

0 commit comments

Comments
 (0)