Skip to content

Commit 64406dd

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add _ublk_sleep helper for parallel execution
Add _ublk_sleep() helper function that uses different sleep times depending on whether tests run in parallel or sequential mode. Usage: _ublk_sleep <normal_secs> <parallel_secs> Export JOBS variable from Makefile so test scripts can detect parallel execution, and use _ublk_sleep in test_part_02.sh to handle the partition scan delay (1s normal, 5s parallel). Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b6bbc3b commit 64406dd

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

tools/testing/selftests/ublk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ check:
7878
# JOBS>1: parallel execution with xargs -P
7979
# Usage: make run_null JOBS=4
8080
JOBS ?= 1
81+
export JOBS
8182

8283
# Auto-detect test groups from TEST_PROGS (test_<group>_<num>.sh -> group)
8384
TEST_GROUPS := $(shell echo "$(TEST_PROGS)" | tr ' ' '\n' | \

tools/testing/selftests/ublk/test_common.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ _have_program() {
1515
return 1
1616
}
1717

18+
# Sleep with awareness of parallel execution.
19+
# Usage: _ublk_sleep <normal_secs> <parallel_secs>
20+
_ublk_sleep() {
21+
if [ "${JOBS:-1}" -gt 1 ]; then
22+
sleep "$2"
23+
else
24+
sleep "$1"
25+
fi
26+
}
27+
1828
_get_disk_dev_t() {
1929
local dev_id=$1
2030
local dev

tools/testing/selftests/ublk/test_part_02.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ _test_partition_scan_no_hang()
3333
# The add command should return quickly because partition scan is async.
3434
# Now sleep briefly to let the async partition scan work start and hit
3535
# the delay in the fault_inject handler.
36-
sleep 1
36+
_ublk_sleep 1 5
3737

3838
# Kill the ublk daemon while partition scan is potentially blocked
3939
# And check state transitions properly

0 commit comments

Comments
 (0)