1 # SPDX-License-Identifier: GPL-2.0
6 TARGETS += capabilities
11 TARGETS += cpu-hotplug
13 TARGETS += drivers/dma-buf
14 TARGETS += drivers/s390x/uvdevice
15 TARGETS += drivers/net/bonding
16 TARGETS += drivers/net/team
19 TARGETS += filesystems
20 TARGETS += filesystems/binderfs
21 TARGETS += filesystems/epoll
22 TARGETS += filesystems/fat
28 TARGETS += intel_pstate
40 TARGETS += memory-hotplug
43 TARGETS += mount_setattr
44 TARGETS += move_mount_set_group
48 TARGETS += net/af_unix
49 TARGETS += net/forwarding
54 TARGETS += pid_namespace
66 TARGETS += sigaltstack
70 TARGETS += static_keys
72 TARGETS += syscall_user_dispatch
76 ifneq (1, $(quicktest))
86 #Please keep the TARGETS list alphabetically sorted
87 # Run "make quicktest=1 run_tests" or
88 # "make quicktest=1 kselftest" from top level Makefile
90 TARGETS_HOTPLUG = cpu-hotplug
91 TARGETS_HOTPLUG += memory-hotplug
93 # User can optionally provide a TARGETS skiplist. By default we skip
94 # BPF since it has cutting edge build time dependencies which require
95 # more effort to install.
97 ifneq ($(SKIP_TARGETS),)
98 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
99 override TARGETS := $(TMP)
102 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
103 # built; make will fail if any of the targets cannot be built. If
104 # FORCE_TARGETS is not set (the default), make will succeed if at least one
105 # of the targets gets built.
108 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
109 # implicit rules to sub-test Makefiles which avoids build failures in test
110 # Makefile that don't have explicit build rules.
116 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
117 # KBUILD_OUTPUT with selftest objects and headers installed
118 # by selftests Makefile or lib.mk.
119 ifdef building_out_of_srctree
123 top_srcdir ?= ../../..
125 ifeq ("$(origin O)", "command line")
126 KBUILD_OUTPUT := $(O)
129 ifneq ($(KBUILD_OUTPUT),)
130 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
131 # expand a shell special character '~'. We use a somewhat tedious way here.
132 abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
133 $(if $(abs_objtree),, \
134 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
135 # $(realpath ...) resolves symlinks
136 abs_objtree := $(realpath $(abs_objtree))
137 BUILD := $(abs_objtree)/kselftest
138 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
141 abs_srctree := $(shell cd $(top_srcdir) && pwd)
142 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
143 DEFAULT_INSTALL_HDR_PATH := 1
146 # Prepare for headers install
147 include $(top_srcdir)/scripts/subarch.include
152 # set default goal to all, so make without a target runs all, even when
153 # all isn't the first target in the file.
158 for TARGET in $(TARGETS); do \
159 BUILD_TARGET=$$BUILD/$$TARGET; \
160 mkdir $$BUILD_TARGET -p; \
161 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
163 $(if $(FORCE_TARGETS),|| exit); \
164 ret=$$((ret * $$?)); \
168 @for TARGET in $(TARGETS); do \
169 BUILD_TARGET=$$BUILD/$$TARGET; \
170 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
175 @for TARGET in $(TARGETS_HOTPLUG); do \
176 BUILD_TARGET=$$BUILD/$$TARGET; \
177 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
181 @for TARGET in $(TARGETS_HOTPLUG); do \
182 BUILD_TARGET=$$BUILD/$$TARGET; \
183 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
187 @for TARGET in $(TARGETS_HOTPLUG); do \
188 BUILD_TARGET=$$BUILD/$$TARGET; \
189 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
193 $(MAKE) -C pstore run_crash
195 # Use $BUILD as the default install root. $BUILD points to the
196 # right output location for the following cases:
197 # 1. output_dir=kernel_src
198 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
199 # 3. a separate output directory is specified using KBUILD_OUTPUT
200 # Avoid conflict with INSTALL_PATH set by the main Makefile
202 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
203 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
204 # Avoid changing the rest of the logic here and lib.mk.
205 INSTALL_PATH := $(KSFT_INSTALL_PATH)
206 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
207 TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
211 @# Ask all targets to install their files
212 mkdir -p $(INSTALL_PATH)/kselftest
213 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
214 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
215 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
216 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
219 for TARGET in $(TARGETS); do \
220 BUILD_TARGET=$$BUILD/$$TARGET; \
221 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
223 $(if $(FORCE_TARGETS),|| exit); \
224 ret=$$((ret * $$?)); \
228 @# Ask all targets to emit their test scripts
229 @# While building kselftest-list.text skip also non-existent TARGET dirs:
230 @# they could be the result of a build failure and should NOT be
231 @# included in the generated runlist.
232 for TARGET in $(TARGETS); do \
233 BUILD_TARGET=$$BUILD/$$TARGET; \
234 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
235 echo -ne "Emit Tests for $$TARGET\n"; \
236 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
237 -C $$TARGET emit_tests >> $(TEST_LIST); \
240 $(error Error: set INSTALL_PATH to use install)
244 TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
246 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
247 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
248 @echo "Created ${TAR_PATH}"
251 @for TARGET in $(TARGETS); do \
252 BUILD_TARGET=$$BUILD/$$TARGET; \
253 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
256 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar