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
158 KHDR_DIR := ${abs_objtree}/usr/include
161 abs_srctree := $(shell cd $(top_srcdir) && pwd)
162 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
163 KHDR_DIR := ${abs_srctree}/usr/include
164 DEFAULT_INSTALL_HDR_PATH := 1
167 # Prepare for headers install
168 include $(top_srcdir)/scripts/subarch.include
173 # set default goal to all, so make without a target runs all, even when
174 # all isn't the first target in the file.
177 all: kernel_header_files
179 for TARGET in $(TARGETS); do \
180 BUILD_TARGET=$$BUILD/$$TARGET; \
181 mkdir $$BUILD_TARGET -p; \
182 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
184 $(if $(FORCE_TARGETS),|| exit); \
185 ret=$$((ret * $$?)); \
189 @ls $(KHDR_DIR)/linux/*.h >/dev/null 2>/dev/null; \
190 if [ $$? -ne 0 ]; then \
194 echo -e "$${RED}error$${NOCOLOR}: missing kernel header files."; \
195 echo "Please run this and try again:"; \
197 echo " cd $(top_srcdir)"; \
198 echo " make headers"; \
203 .PHONY: kernel_header_files
206 @for TARGET in $(TARGETS); do \
207 BUILD_TARGET=$$BUILD/$$TARGET; \
208 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
213 @for TARGET in $(TARGETS_HOTPLUG); do \
214 BUILD_TARGET=$$BUILD/$$TARGET; \
215 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
219 @for TARGET in $(TARGETS_HOTPLUG); do \
220 BUILD_TARGET=$$BUILD/$$TARGET; \
221 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
225 @for TARGET in $(TARGETS_HOTPLUG); do \
226 BUILD_TARGET=$$BUILD/$$TARGET; \
227 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
231 $(MAKE) -C pstore run_crash
233 # Use $BUILD as the default install root. $BUILD points to the
234 # right output location for the following cases:
235 # 1. output_dir=kernel_src
236 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
237 # 3. a separate output directory is specified using KBUILD_OUTPUT
238 # Avoid conflict with INSTALL_PATH set by the main Makefile
240 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
241 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
242 # Avoid changing the rest of the logic here and lib.mk.
243 INSTALL_PATH := $(KSFT_INSTALL_PATH)
244 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
245 TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
249 @# Ask all targets to install their files
250 mkdir -p $(INSTALL_PATH)/kselftest
251 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
252 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
253 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
254 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
257 for TARGET in $(TARGETS); do \
258 BUILD_TARGET=$$BUILD/$$TARGET; \
259 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
261 $(if $(FORCE_TARGETS),|| exit); \
262 ret=$$((ret * $$?)); \
266 @# Ask all targets to emit their test scripts
267 @# While building kselftest-list.text skip also non-existent TARGET dirs:
268 @# they could be the result of a build failure and should NOT be
269 @# included in the generated runlist.
270 for TARGET in $(TARGETS); do \
271 BUILD_TARGET=$$BUILD/$$TARGET; \
272 [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
273 printf "Emit Tests for $$TARGET\n"; \
274 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
275 -C $$TARGET emit_tests >> $(TEST_LIST); \
278 $(error Error: set INSTALL_PATH to use install)
282 TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
284 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
285 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
286 @echo "Created ${TAR_PATH}"
289 @for TARGET in $(TARGETS); do \
290 BUILD_TARGET=$$BUILD/$$TARGET; \
291 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
294 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar