Skip to content

Commit f2c1330

Browse files
committed
throtl: introduce helper functions to manage test target block devices
The throtl test group uses null_blk devices as test target in its test cases. To prepare for supporting scsi_debug device as the additional test target, introduce three helper functions below to abstract null_blk specific operations: _configure_throtl_blkdev() : Sets up the null_blk device _delete_throtl_blkdev() : Removes the null_blk device for testing _exit_throtl_blkdev() : Cleans up the null_blk device Support two options of _configure_throtl_blkdev(), --sector_size and --memory_backed so that each test case can tailor the setup according to specific requirements. Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent eee3614 commit f2c1330

6 files changed

Lines changed: 50 additions & 14 deletions

File tree

tests/throtl/002

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ QUICK=1
1313
test() {
1414
echo "Running ${TEST_NAME}"
1515

16-
local page_size max_secs
16+
local page_size
1717
local io_size_kb block_size
1818
local iops=256
1919

2020
page_size=$(getconf PAGE_SIZE)
21-
max_secs=$((page_size / 512))
2221

23-
if ! _set_up_throtl max_sectors="${max_secs}"; then
22+
if ! _set_up_throtl --sector_size "${page_size}"; then
2423
return 1;
2524
fi
2625

tests/throtl/003

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ QUICK=1
1313
test() {
1414
echo "Running ${TEST_NAME}"
1515

16-
local page_size max_secs
16+
local page_size
1717
page_size=$(getconf PAGE_SIZE)
18-
max_secs=$((page_size / 512))
1918

20-
if ! _set_up_throtl max_sectors="${max_secs}"; then
19+
if ! _set_up_throtl --sector_size "${page_size}"; then
2120
return 1;
2221
fi
2322

tests/throtl/004

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test() {
2626
} &
2727

2828
sleep 0.6
29-
echo 0 > "/sys/kernel/config/nullb/$THROTL_DEV/power"
29+
_delete_throtl_blkdev
3030
wait $!
3131

3232
_clean_up_throtl

tests/throtl/006

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test_meta_io() {
3434
test() {
3535
echo "Running ${TEST_NAME}"
3636

37-
if ! _set_up_throtl memory_backed=1; then
37+
if ! _set_up_throtl --memory_backed; then
3838
return 1;
3939
fi
4040

tests/throtl/007

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ QUICK=1
1414
test() {
1515
echo "Running ${TEST_NAME}"
1616

17-
local page_size max_secs
17+
local page_size
1818
page_size=$(getconf PAGE_SIZE)
19-
max_secs=$((page_size / 512))
2019

21-
if ! _set_up_throtl max_sectors="${max_secs}"; then
20+
if ! _set_up_throtl --sector_size "${page_size}"; then
2221
return 1;
2322
fi
2423

tests/throtl/rc

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,54 @@ group_requires() {
2121
_have_program bc
2222
}
2323

24+
_configure_throtl_blkdev() {
25+
local sector_size=0 memory_backed=0
26+
local -a args
27+
28+
while [[ $# -gt 0 ]]; do
29+
case $1 in
30+
--sector_size)
31+
sector_size="$2"
32+
shift 2
33+
;;
34+
--memory_backed)
35+
memory_backed=1
36+
shift
37+
;;
38+
*)
39+
echo "WARNING: unknown argument: $1"
40+
shift
41+
;;
42+
esac
43+
done
44+
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
51+
return 1
52+
}
53+
54+
_delete_throtl_blkdev() {
55+
echo 0 > "/sys/kernel/config/nullb/$THROTL_DEV/power"
56+
}
57+
58+
_exit_throtl_blkdev() {
59+
_exit_null_blk
60+
unset THROTL_DEV
61+
}
62+
2463
# Create a new null_blk device, and create a new blk-cgroup for test.
2564
_set_up_throtl() {
2665

27-
if ! _configure_null_blk $THROTL_DEV "$@" power=1; then
66+
if ! _configure_throtl_blkdev "$@"; then
2867
return 1
2968
fi
3069

3170
if ! _init_cgroup2; then
32-
_exit_null_blk
71+
_exit_throtl_blkdev
3372
return 1
3473
fi
3574

@@ -58,7 +97,7 @@ _clean_up_throtl() {
5897
fi
5998

6099
_exit_cgroup2
61-
_exit_null_blk
100+
_exit_throtl_blkdev
62101
}
63102

64103
_throtl_set_limits() {

0 commit comments

Comments
 (0)