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. Signed-off-by: Shin'ichiro Kawasaki --- tests/throtl/002 | 5 ++--- tests/throtl/003 | 5 ++--- tests/throtl/004 | 2 +- tests/throtl/006 | 2 +- tests/throtl/007 | 5 ++--- tests/throtl/rc | 45 ++++++++++++++++++++++++++++++++++++++++++--- 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/tests/throtl/002 b/tests/throtl/002 index 02b0969..bed876d 100755 --- a/tests/throtl/002 +++ b/tests/throtl/002 @@ -13,14 +13,13 @@ QUICK=1 test() { echo "Running ${TEST_NAME}" - local page_size max_secs + local page_size local io_size_kb block_size local iops=256 page_size=$(getconf PAGE_SIZE) - max_secs=$((page_size / 512)) - if ! _set_up_throtl max_sectors="${max_secs}"; then + if ! _set_up_throtl --sector_size "${page_size}"; then return 1; fi diff --git a/tests/throtl/003 b/tests/throtl/003 index 8276d87..d76a0d5 100755 --- a/tests/throtl/003 +++ b/tests/throtl/003 @@ -13,11 +13,10 @@ QUICK=1 test() { echo "Running ${TEST_NAME}" - local page_size max_secs + local page_size page_size=$(getconf PAGE_SIZE) - max_secs=$((page_size / 512)) - if ! _set_up_throtl max_sectors="${max_secs}"; then + if ! _set_up_throtl --sector_size "${page_size}"; then return 1; fi diff --git a/tests/throtl/004 b/tests/throtl/004 index d1461b9..d623097 100755 --- a/tests/throtl/004 +++ b/tests/throtl/004 @@ -26,7 +26,7 @@ test() { } & sleep 0.6 - echo 0 > "/sys/kernel/config/nullb/$THROTL_DEV/power" + _delete_throtl_blkdev wait $! _clean_up_throtl diff --git a/tests/throtl/006 b/tests/throtl/006 index b6f47d1..263415f 100755 --- a/tests/throtl/006 +++ b/tests/throtl/006 @@ -34,7 +34,7 @@ test_meta_io() { test() { echo "Running ${TEST_NAME}" - if ! _set_up_throtl memory_backed=1; then + if ! _set_up_throtl --memory_backed; then return 1; fi diff --git a/tests/throtl/007 b/tests/throtl/007 index ae59c6f..83d8dc7 100755 --- a/tests/throtl/007 +++ b/tests/throtl/007 @@ -14,11 +14,10 @@ QUICK=1 test() { echo "Running ${TEST_NAME}" - local page_size max_secs + local page_size page_size=$(getconf PAGE_SIZE) - max_secs=$((page_size / 512)) - if ! _set_up_throtl max_sectors="${max_secs}"; then + if ! _set_up_throtl --sector_size "${page_size}"; then return 1; fi diff --git a/tests/throtl/rc b/tests/throtl/rc index 327084b..d20dc94 100644 --- a/tests/throtl/rc +++ b/tests/throtl/rc @@ -21,15 +21,54 @@ group_requires() { _have_program bc } +_configure_throtl_blkdev() { + local sector_size=0 memory_backed=0 + local -a args + + while [[ $# -gt 0 ]]; do + case $1 in + --sector_size) + sector_size="$2" + shift 2 + ;; + --memory_backed) + memory_backed=1 + shift + ;; + *) + echo "WARNING: unknown argument: $1" + shift + ;; + esac + done + + args=("$THROTL_DEV") + ((sector_size)) && args+=(max_sectors="$((sector_size / 512))") + ((memory_backed)) && args+=(memory_backed=1) + if _configure_null_blk "${args[@]}" power=1; then + return + fi + return 1 +} + +_delete_throtl_blkdev() { + echo 0 > "/sys/kernel/config/nullb/$THROTL_DEV/power" +} + +_exit_throtl_blkdev() { + _exit_null_blk + unset THROTL_DEV +} + # Create a new null_blk device, and create a new blk-cgroup for test. _set_up_throtl() { - if ! _configure_null_blk $THROTL_DEV "$@" power=1; then + if ! _configure_throtl_blkdev "$@"; then return 1 fi if ! _init_cgroup2; then - _exit_null_blk + _exit_throtl_blkdev return 1 fi @@ -58,7 +97,7 @@ _clean_up_throtl() { fi _exit_cgroup2 - _exit_null_blk + _exit_throtl_blkdev } _throtl_set_limits() { -- 2.51.0