1 # SPDX-License-Identifier: GPL-2.0
9 TARGETS += capabilities
15 TARGETS += cpu-hotplug
17 TARGETS += devices/error_logs
18 TARGETS += devices/probe
19 TARGETS += dmabuf-heaps
20 TARGETS += drivers/dma-buf
21 TARGETS += drivers/ntsync
22 TARGETS += drivers/s390x/uvdevice
23 TARGETS += drivers/net
24 TARGETS += drivers/net/bonding
25 TARGETS += drivers/net/team
26 TARGETS += drivers/net/virtio_net
27 TARGETS += drivers/platform/x86/intel/ifs
32 TARGETS += filesystems
33 TARGETS += filesystems/binderfs
34 TARGETS += filesystems/epoll
35 TARGETS += filesystems/fat
36 TARGETS += filesystems/overlayfs
37 TARGETS += filesystems/statmount
44 TARGETS += intel_pstate
58 TARGETS += memory-hotplug
61 TARGETS += mount_setattr
62 TARGETS += move_mount_set_group
66 TARGETS += net/af_unix
67 TARGETS += net/forwarding
70 TARGETS += net/netfilter
71 TARGETS += net/openvswitch
72 TARGETS += net/packetdrill
76 TARGETS += pci_endpoint
77 TARGETS += pcie_bwctrl
78 TARGETS += perf_events
80 TARGETS += pid_namespace
81 TARGETS += power_supply
101 TARGETS += static_keys
103 TARGETS += syscall_user_dispatch
105 TARGETS += tc-testing
107 TARGETS += thermal/intel/power_floor
108 TARGETS += thermal/intel/workload_hint
110 ifneq (1, $(quicktest))
117 TARGETS += user_events
122 #Please keep the TARGETS list alphabetically sorted
123 # Run "make quicktest=1 run_tests" or
124 # "make quicktest=1 kselftest" from top level Makefile
126 TARGETS_HOTPLUG = cpu-hotplug
127 TARGETS_HOTPLUG += memory-hotplug
129 # Networking tests want the net/lib target, include it automatically
130 ifneq ($(filter net drivers/net drivers/net/hw,$(TARGETS)),)
131 ifeq ($(filter net/lib,$(TARGETS)),)
132 INSTALL_DEP_TARGETS := net/lib
136 # User can optionally provide a TARGETS skiplist. By default we skip
137 # targets using BPF since it has cutting edge build time dependencies
138 # which require more effort to install.
139 SKIP_TARGETS ?= bpf sched_ext
140 ifneq ($(SKIP_TARGETS),)
141 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
142 override TARGETS := $(TMP)
145 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
146 # built; make will fail if any of the targets cannot be built. If
147 # FORCE_TARGETS is not set (the default), make will succeed if at least one
148 # of the targets gets built.
151 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
152 # implicit rules to sub-test Makefiles which avoids build failures in test
153 # Makefile that don't have explicit build rules.
159 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
160 # KBUILD_OUTPUT with selftest objects and headers installed
161 # by selftests Makefile or lib.mk.
162 ifdef building_out_of_srctree
166 top_srcdir ?= ../../..
168 ifeq ("$(origin O)", "command line")
169 KBUILD_OUTPUT := $(O)
172 ifneq ($(KBUILD_OUTPUT),)
173 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
174 # expand a shell special character '~'. We use a somewhat tedious way here.
175 abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
176 $(if $(abs_objtree),, \
177 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
178 # $(realpath ...) resolves symlinks
179 abs_objtree := $(realpath $(abs_objtree))
180 BUILD := $(abs_objtree)/kselftest
181 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
184 abs_srctree := $(shell cd $(top_srcdir) && pwd)
185 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
186 DEFAULT_INSTALL_HDR_PATH := 1
189 # Prepare for headers install
190 include $(top_srcdir)/scripts/subarch.include
195 # set default goal to all, so make without a target runs all, even when
196 # all isn't the first target in the file.
201 for TARGET in $(TARGETS); do \
202 BUILD_TARGET=$$BUILD/$$TARGET; \
203 mkdir $$BUILD_TARGET -p; \
204 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
206 $(if $(FORCE_TARGETS),|| exit); \
207 ret=$$((ret * $$?)); \
211 @for TARGET in $(TARGETS); do \
212 BUILD_TARGET=$$BUILD/$$TARGET; \
213 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
214 SRC_PATH=$(shell readlink -e $$(pwd)) \
220 @for TARGET in $(TARGETS_HOTPLUG); do \
221 BUILD_TARGET=$$BUILD/$$TARGET; \
222 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
226 @for TARGET in $(TARGETS_HOTPLUG); do \
227 BUILD_TARGET=$$BUILD/$$TARGET; \
228 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
232 @for TARGET in $(TARGETS_HOTPLUG); do \
233 BUILD_TARGET=$$BUILD/$$TARGET; \
234 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
238 $(MAKE) -C pstore run_crash
240 # Use $BUILD as the default install root. $BUILD points to the
241 # right output location for the following cases:
242 # 1. output_dir=kernel_src
243 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
244 # 3. a separate output directory is specified using KBUILD_OUTPUT
245 # Avoid conflict with INSTALL_PATH set by the main Makefile
247 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
248 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
249 # Avoid changing the rest of the logic here and lib.mk.
250 INSTALL_PATH := $(KSFT_INSTALL_PATH)
251 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
252 TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
256 @# Ask all targets to install their files
257 mkdir -p $(INSTALL_PATH)/kselftest
258 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
259 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
260 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
261 install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/
262 install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/
263 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
266 for TARGET in $(TARGETS) $(INSTALL_DEP_TARGETS); do \
267 BUILD_TARGET=$$BUILD/$$TARGET; \
268 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install \
269 INSTALL_PATH=$(INSTALL_PATH)/$$TARGET \
270 SRC_PATH=$(shell readlink -e $$(pwd)) \
271 OBJ_PATH=$(INSTALL_PATH) \
273 $(if $(FORCE_TARGETS),|| exit); \
274 ret=$$((ret * $$?)); \
278 @# Ask all targets to emit their test scripts
279 @# While building kselftest-list.text skip also non-existent TARGET dirs:
280 @# they could be the result of a build failure and should NOT be
281 @# included in the generated runlist.
282 for TARGET in $(TARGETS); do \
283 BUILD_TARGET=$$BUILD/$$TARGET; \
284 [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
285 printf "Emit Tests for $$TARGET\n"; \
286 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
287 -C $$TARGET emit_tests >> $(TEST_LIST); \
290 $(error Error: set INSTALL_PATH to use install)
294 TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
296 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
297 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
298 @echo "Created ${TAR_PATH}"
301 @for TARGET in $(TARGETS); do \
302 BUILD_TARGET=$$BUILD/$$TARGET; \
303 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
306 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar