Skip to content

Commit b6bbc3b

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add group-based test targets
Add convenient Makefile targets for running specific test groups: - run_generic, run_batch, run_null, run_loop, run_stripe, run_stress, etc. - run_all for running all tests Test groups are auto-detected from TEST_PROGS using pattern matching (test_<group>_<num>.sh -> group), and targets are generated dynamically using define/eval templates. Supports parallel execution via JOBS variable: - JOBS=1 (default): sequential with kselftest TAP output - JOBS>1: parallel execution with xargs -P Usage examples: make run_null # Sequential execution make run_stress JOBS=4 # Parallel with 4 jobs make run_all JOBS=8 # Run all tests with 8 parallel jobs With JOBS=8, running time of `make run_all` is reduced to 2m2s from 6m5s in my test VM. Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2021e61 commit b6bbc3b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tools/testing/selftests/ublk/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,39 @@ $(OUTPUT)/kublk: $(filter-out $(STANDALONE_UTILS),$(wildcard *.c))
7272

7373
check:
7474
shellcheck -x -f gcc *.sh
75+
76+
# Test groups for running subsets of tests
77+
# JOBS=1 (default): sequential with kselftest TAP output
78+
# JOBS>1: parallel execution with xargs -P
79+
# Usage: make run_null JOBS=4
80+
JOBS ?= 1
81+
82+
# Auto-detect test groups from TEST_PROGS (test_<group>_<num>.sh -> group)
83+
TEST_GROUPS := $(shell echo "$(TEST_PROGS)" | tr ' ' '\n' | \
84+
sed 's/test_\([^_]*\)_.*/\1/' | sort -u)
85+
86+
# Template for group test targets
87+
# $(1) = group name (e.g., null, generic, stress)
88+
define RUN_GROUP
89+
run_$(1): all
90+
@if [ $$(JOBS) -gt 1 ]; then \
91+
echo $$(filter test_$(1)_%.sh,$$(TEST_PROGS)) | tr ' ' '\n' | \
92+
xargs -P $$(JOBS) -n1 sh -c './"$$$$0"' || true; \
93+
else \
94+
$$(call RUN_TESTS, $$(filter test_$(1)_%.sh,$$(TEST_PROGS))); \
95+
fi
96+
.PHONY: run_$(1)
97+
endef
98+
99+
# Generate targets for each discovered test group
100+
$(foreach group,$(TEST_GROUPS),$(eval $(call RUN_GROUP,$(group))))
101+
102+
# Run all tests (parallel when JOBS>1)
103+
run_all: all
104+
@if [ $(JOBS) -gt 1 ]; then \
105+
echo $(TEST_PROGS) | tr ' ' '\n' | \
106+
xargs -P $(JOBS) -n1 sh -c './"$$0"' || true; \
107+
else \
108+
$(call RUN_TESTS, $(TEST_PROGS)); \
109+
fi
110+
.PHONY: run_all

0 commit comments

Comments
 (0)