1 # SPDX-License-Identifier: GPL-2.0
8 TARGETS += capabilities
14 TARGETS += cpu-hotplug
16 TARGETS += dmabuf-heaps
17 TARGETS += drivers/dma-buf
18 TARGETS += drivers/s390x/uvdevice
19 TARGETS += drivers/net/bonding
20 TARGETS += drivers/net/team
25 TARGETS += filesystems
26 TARGETS += filesystems/binderfs
27 TARGETS += filesystems/epoll
28 TARGETS += filesystems/fat
35 TARGETS += intel_pstate
48 TARGETS += memory-hotplug
51 TARGETS += mount_setattr
52 TARGETS += move_mount_set_group
56 TARGETS += net/af_unix
57 TARGETS += net/forwarding
60 TARGETS += net/openvswitch
63 TARGETS += perf_events
65 TARGETS += pid_namespace
79 TARGETS += sigaltstack
83 TARGETS += static_keys
85 TARGETS += syscall_user_dispatch
89 TARGETS += thermal/intel/power_floor
90 TARGETS += thermal/intel/workload_hint
92 ifneq (1, $(quicktest))
100 TARGETS += user_events
105 #Please keep the TARGETS list alphabetically sorted
106 # Run "make quicktest=1 run_tests" or
107 # "make quicktest=1 kselftest" from top level Makefile
109 TARGETS_HOTPLUG = cpu-hotplug
110 TARGETS_HOTPLUG += memory-hotplug
112 # User can optionally provide a TARGETS skiplist. By default we skip
113 # BPF since it has cutting edge build time dependencies which require
114 # more effort to install.
116 ifneq ($(SKIP_TARGETS),)
117 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
118 override TARGETS := $(TMP)
121 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
122 # built; make will fail if any of the targets cannot be built. If
123 # FORCE_TARGETS is not set (the default), make will succeed if at least one
124 # of the targets gets built.
127 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
128 # implicit rules to sub-test Makefiles which avoids build failures in test
129 # Makefile that don't have explicit build rules.
135 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
136 # KBUILD_OUTPUT with selftest objects and headers installed
137 # by selftests Makefile or lib.mk.
138 ifdef building_out_of_srctree
142 top_srcdir ?= ../../..
144 ifeq ("$(origin O)", "command line")
145 KBUILD_OUTPUT := $(O)
148 ifneq ($(KBUILD_OUTPUT),)
149 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
150 # expand a shell special character '~'. We use a somewhat tedious way here.
151 abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
152 $(if $(abs_objtree),, \
153 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
154 # $(realpath ...) resolves symlinks
155 abs_objtree := $(realpath $(abs_objtree))
156 BUILD := $(abs_objtree)/kselftest
157 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
160 abs_srctree := $(shell cd $(top_srcdir) && pwd)
161 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
162 DEFAULT_INSTALL_HDR_PATH := 1
165 # Prepare for headers install
166 include $(top_srcdir)/scripts/subarch.include
171 # set default goal to all, so make without a target runs all, even when
172 # all isn't the first target in the file.
177 for TARGET in $(TARGETS); do \
178 BUILD_TARGET=$$BUILD/$$TARGET; \
179 mkdir $$BUILD_TARGET -p; \
180 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
182 $(if $(FORCE_TARGETS),|| exit); \
183 ret=$$((ret * $$?)); \
187 @for TARGET in $(TARGETS); do \
188 BUILD_TARGET=$$BUILD/$$TARGET; \
189 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
194 @for TARGET in $(TARGETS_HOTPLUG); do \
195 BUILD_TARGET=$$BUILD/$$TARGET; \
196 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
200 @for TARGET in $(TARGETS_HOTPLUG); do \
201 BUILD_TARGET=$$BUILD/$$TARGET; \
202 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
206 @for TARGET in $(TARGETS_HOTPLUG); do \
207 BUILD_TARGET=$$BUILD/$$TARGET; \
208 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
212 $(MAKE) -C pstore run_crash
214 # Use $BUILD as the default install root. $BUILD points to the
215 # right output location for the following cases:
216 # 1. output_dir=kernel_src
217 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
218 # 3. a separate output directory is specified using KBUILD_OUTPUT
219 # Avoid conflict with INSTALL_PATH set by the main Makefile
221 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
222 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
223 # Avoid changing the rest of the logic here and lib.mk.
224 INSTALL_PATH := $(KSFT_INSTALL_PATH)
225 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
226 TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
230 @# Ask all targets to install their files
231 mkdir -p $(INSTALL_PATH)/kselftest
232 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
233 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
234 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
235 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
238 for TARGET in $(TARGETS); do \
239 BUILD_TARGET=$$BUILD/$$TARGET; \
240 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
242 $(if $(FORCE_TARGETS),|| exit); \
243 ret=$$((ret * $$?)); \
247 @# Ask all targets to emit their test scripts
248 @# While building kselftest-list.text skip also non-existent TARGET dirs:
249 @# they could be the result of a build failure and should NOT be
250 @# included in the generated runlist.
251 for TARGET in $(TARGETS); do \
252 BUILD_TARGET=$$BUILD/$$TARGET; \
253 [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
254 printf "Emit Tests for $$TARGET\n"; \
255 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
256 -C $$TARGET emit_tests >> $(TEST_LIST); \
259 $(error Error: set INSTALL_PATH to use install)
263 TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
265 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
266 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
267 @echo "Created ${TAR_PATH}"
270 @for TARGET in $(TARGETS); do \
271 BUILD_TARGET=$$BUILD/$$TARGET; \
272 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
275 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar