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
24 TARGETS += filesystems
25 TARGETS += filesystems/binderfs
26 TARGETS += filesystems/epoll
27 TARGETS += filesystems/fat
34 TARGETS += intel_pstate
47 TARGETS += memory-hotplug
50 TARGETS += mount_setattr
51 TARGETS += move_mount_set_group
55 TARGETS += net/af_unix
56 TARGETS += net/forwarding
59 TARGETS += net/openvswitch
62 TARGETS += perf_events
64 TARGETS += pid_namespace
78 TARGETS += sigaltstack
82 TARGETS += static_keys
84 TARGETS += syscall_user_dispatch
89 ifneq (1, $(quicktest))
97 TARGETS += user_events
102 #Please keep the TARGETS list alphabetically sorted
103 # Run "make quicktest=1 run_tests" or
104 # "make quicktest=1 kselftest" from top level Makefile
106 TARGETS_HOTPLUG = cpu-hotplug
107 TARGETS_HOTPLUG += memory-hotplug
109 # User can optionally provide a TARGETS skiplist. By default we skip
110 # BPF since it has cutting edge build time dependencies which require
111 # more effort to install.
113 ifneq ($(SKIP_TARGETS),)
114 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
115 override TARGETS := $(TMP)
118 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
119 # built; make will fail if any of the targets cannot be built. If
120 # FORCE_TARGETS is not set (the default), make will succeed if at least one
121 # of the targets gets built.
124 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
125 # implicit rules to sub-test Makefiles which avoids build failures in test
126 # Makefile that don't have explicit build rules.
132 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
133 # KBUILD_OUTPUT with selftest objects and headers installed
134 # by selftests Makefile or lib.mk.
135 ifdef building_out_of_srctree
139 top_srcdir ?= ../../..
141 ifeq ("$(origin O)", "command line")
142 KBUILD_OUTPUT := $(O)
145 ifneq ($(KBUILD_OUTPUT),)
146 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
147 # expand a shell special character '~'. We use a somewhat tedious way here.
148 abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
149 $(if $(abs_objtree),, \
150 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
151 # $(realpath ...) resolves symlinks
152 abs_objtree := $(realpath $(abs_objtree))
153 BUILD := $(abs_objtree)/kselftest
154 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
155 KHDR_DIR := ${abs_objtree}/usr/include
158 abs_srctree := $(shell cd $(top_srcdir) && pwd)
159 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
160 KHDR_DIR := ${abs_srctree}/usr/include
161 DEFAULT_INSTALL_HDR_PATH := 1
164 # Prepare for headers install
165 include $(top_srcdir)/scripts/subarch.include
170 # set default goal to all, so make without a target runs all, even when
171 # all isn't the first target in the file.
174 all: kernel_header_files
176 for TARGET in $(TARGETS); do \
177 BUILD_TARGET=$$BUILD/$$TARGET; \
178 mkdir $$BUILD_TARGET -p; \
179 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
181 $(if $(FORCE_TARGETS),|| exit); \
182 ret=$$((ret * $$?)); \
186 @ls $(KHDR_DIR)/linux/*.h >/dev/null 2>/dev/null; \
187 if [ $$? -ne 0 ]; then \
191 echo -e "$${RED}error$${NOCOLOR}: missing kernel header files."; \
192 echo "Please run this and try again:"; \
194 echo " cd $(top_srcdir)"; \
195 echo " make headers"; \
200 .PHONY: kernel_header_files
203 @for TARGET in $(TARGETS); do \
204 BUILD_TARGET=$$BUILD/$$TARGET; \
205 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
210 @for TARGET in $(TARGETS_HOTPLUG); do \
211 BUILD_TARGET=$$BUILD/$$TARGET; \
212 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
216 @for TARGET in $(TARGETS_HOTPLUG); do \
217 BUILD_TARGET=$$BUILD/$$TARGET; \
218 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
222 @for TARGET in $(TARGETS_HOTPLUG); do \
223 BUILD_TARGET=$$BUILD/$$TARGET; \
224 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
228 $(MAKE) -C pstore run_crash
230 # Use $BUILD as the default install root. $BUILD points to the
231 # right output location for the following cases:
232 # 1. output_dir=kernel_src
233 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
234 # 3. a separate output directory is specified using KBUILD_OUTPUT
235 # Avoid conflict with INSTALL_PATH set by the main Makefile
237 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
238 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
239 # Avoid changing the rest of the logic here and lib.mk.
240 INSTALL_PATH := $(KSFT_INSTALL_PATH)
241 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
242 TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
246 @# Ask all targets to install their files
247 mkdir -p $(INSTALL_PATH)/kselftest
248 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
249 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
250 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
251 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
254 for TARGET in $(TARGETS); do \
255 BUILD_TARGET=$$BUILD/$$TARGET; \
256 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
258 $(if $(FORCE_TARGETS),|| exit); \
259 ret=$$((ret * $$?)); \
263 @# Ask all targets to emit their test scripts
264 @# While building kselftest-list.text skip also non-existent TARGET dirs:
265 @# they could be the result of a build failure and should NOT be
266 @# included in the generated runlist.
267 for TARGET in $(TARGETS); do \
268 BUILD_TARGET=$$BUILD/$$TARGET; \
269 [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
270 printf "Emit Tests for $$TARGET\n"; \
271 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
272 -C $$TARGET emit_tests >> $(TEST_LIST); \
275 $(error Error: set INSTALL_PATH to use install)
279 TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
281 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
282 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
283 @echo "Created ${TAR_PATH}"
286 @for TARGET in $(TARGETS); do \
287 BUILD_TARGET=$$BUILD/$$TARGET; \
288 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
291 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar