[PATCH 3/3] selftests: allow wildcards in TARGETS and SKIP_TARGETS

From: Jori Koolstra (CIQ)

Date: Sun Nov 15 2026 - 11:45:18 EST


Many selftests are split over a top-level target and several targets in
its subdirectories, e.g. filesystems and filesystems/binderfs,
filesystems/epoll, etc. Running all of them requires listing every
subdirectory in TARGETS by hand, and keeping that list up to date as
new targets are added.

Allow entries in TARGETS to contain a '*' wildcard, which is matched
against TARGETS_LIST. The wildcard may also match '/'.

Allow the same in SKIP_TARGETS, e.g. SKIP_TARGETS="drivers/*".

Signed-off-by: Jori Koolstra (CIQ) <jkoolstra@xxxxxxxxx>
---
Documentation/dev-tools/kselftest.rst | 11 +++++++++++
tools/testing/selftests/Makefile | 17 +++++++++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst
index 44da142a67b8..3413f59f5c3a 100644
--- a/Documentation/dev-tools/kselftest.rst
+++ b/Documentation/dev-tools/kselftest.rst
@@ -118,6 +118,17 @@ dedicated skiplist::

$ make TARGETS="breakpoints size timers" SKIP_TARGETS=size kselftest

+Entries in TARGETS and SKIP_TARGETS may contain a '*' wildcard, which is
+matched against TARGETS_LIST and may also match '/'. To run all the
+filesystems tests, including those in subdirectories::
+
+ $ make TARGETS="filesystems*" kselftest
+
+To run only the tests in subdirectories of filesystems, but not the
+top-level filesystems tests::
+
+ $ make TARGETS="filesystems/*" kselftest
+
See TARGETS_LIST in the top-level tools/testing/selftests/Makefile for
the list of all possible targets.

diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 4c223bcd2449..f2b779f7afba 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -156,7 +156,20 @@ TARGETS_LIST += zram
# "make quicktest=1 kselftest" from top level Makefile

# Build and run all targets unless the user asks for specific ones.
-TARGETS ?= $(TARGETS_LIST)
+ifeq ($(strip $(TARGETS)),)
+TARGETS := $(TARGETS_LIST)
+endif
+
+# Expand '*' wildcards in TARGETS, e.g. TARGETS="filesystems/*", against
+# TARGETS_LIST.
+ifneq ($(findstring *,$(TARGETS)),)
+ TMP := $(foreach t,$(TARGETS),\
+ $(if $(findstring *,$(t)),\
+ $(or $(filter $(subst *,%,$(t)),$(TARGETS_LIST)),\
+ $(error No TARGETS match '$(t)')),\
+ $(t)))
+ override TARGETS := $(TMP)
+endif

TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug
@@ -173,7 +186,7 @@ endif
# which require more effort to install.
SKIP_TARGETS ?= bpf sched_ext
ifneq ($(SKIP_TARGETS),)
- TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
+ TMP := $(filter-out $(subst *,%,$(SKIP_TARGETS)), $(TARGETS))
override TARGETS := $(TMP)
endif


--
2.56.0