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
18 TARGETS += filesystems
19 TARGETS += filesystems/binderfs
20 TARGETS += filesystems/epoll
21 TARGETS += filesystems/fat
27 TARGETS += intel_pstate
39 TARGETS += memory-hotplug
42 TARGETS += mount_setattr
43 TARGETS += move_mount_set_group
47 TARGETS += net/af_unix
48 TARGETS += net/forwarding
53 TARGETS += pid_namespace
65 TARGETS += sigaltstack
69 TARGETS += static_keys
71 TARGETS += syscall_user_dispatch
75 ifneq (1, $(quicktest))
85 #Please keep the TARGETS list alphabetically sorted
86 # Run "make quicktest=1 run_tests" or
87 # "make quicktest=1 kselftest" from top level Makefile
89 TARGETS_HOTPLUG = cpu-hotplug
90 TARGETS_HOTPLUG += memory-hotplug
92 # User can optionally provide a TARGETS skiplist. By default we skip
93 # BPF since it has cutting edge build time dependencies which require
94 # more effort to install.
96 ifneq ($(SKIP_TARGETS),)
97 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
98 override TARGETS := $(TMP)
101 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
102 # built; make will fail if any of the targets cannot be built. If
103 # FORCE_TARGETS is not set (the default), make will succeed if at least one
104 # of the targets gets built.
107 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
108 # implicit rules to sub-test Makefiles which avoids build failures in test
109 # Makefile that don't have explicit build rules.
115 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
116 # KBUILD_OUTPUT with selftest objects and headers installed
117 # by selftests Makefile or lib.mk.
118 ifdef building_out_of_srctree
122 top_srcdir ?= ../../..
124 ifeq ("$(origin O)", "command line")
125 KBUILD_OUTPUT := $(O)
128 ifneq ($(KBUILD_OUTPUT),)
129 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
130 # expand a shell special character '~'. We use a somewhat tedious way here.
131 abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
132 $(if $(abs_objtree),, \
133 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
134 # $(realpath ...) resolves symlinks
135 abs_objtree := $(realpath $(abs_objtree))
136 BUILD := $(abs_objtree)/kselftest
137 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
140 abs_srctree := $(shell cd $(top_srcdir) && pwd)
141 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
142 DEFAULT_INSTALL_HDR_PATH := 1
145 # Prepare for headers install
146 include $(top_srcdir)/scripts/subarch.include
151 # set default goal to all, so make without a target runs all, even when
152 # all isn't the first target in the file.
157 for TARGET in $(TARGETS); do \
158 BUILD_TARGET=$$BUILD/$$TARGET; \
159 mkdir $$BUILD_TARGET -p; \
160 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
162 $(if $(FORCE_TARGETS),|| exit); \
163 ret=$$((ret * $$?)); \
167 @for TARGET in $(TARGETS); do \
168 BUILD_TARGET=$$BUILD/$$TARGET; \
169 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
174 @for TARGET in $(TARGETS_HOTPLUG); do \
175 BUILD_TARGET=$$BUILD/$$TARGET; \
176 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
180 @for TARGET in $(TARGETS_HOTPLUG); do \
181 BUILD_TARGET=$$BUILD/$$TARGET; \
182 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
186 @for TARGET in $(TARGETS_HOTPLUG); do \
187 BUILD_TARGET=$$BUILD/$$TARGET; \
188 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
192 $(MAKE) -C pstore run_crash
194 # Use $BUILD as the default install root. $BUILD points to the
195 # right output location for the following cases:
196 # 1. output_dir=kernel_src
197 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
198 # 3. a separate output directory is specified using KBUILD_OUTPUT
199 # Avoid conflict with INSTALL_PATH set by the main Makefile
201 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
202 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
203 # Avoid changing the rest of the logic here and lib.mk.
204 INSTALL_PATH := $(KSFT_INSTALL_PATH)
205 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
206 TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
210 @# Ask all targets to install their files
211 mkdir -p $(INSTALL_PATH)/kselftest
212 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
213 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
214 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
215 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
218 for TARGET in $(TARGETS); do \
219 BUILD_TARGET=$$BUILD/$$TARGET; \
220 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
222 $(if $(FORCE_TARGETS),|| exit); \
223 ret=$$((ret * $$?)); \
227 @# Ask all targets to emit their test scripts
228 @# While building kselftest-list.text skip also non-existent TARGET dirs:
229 @# they could be the result of a build failure and should NOT be
230 @# included in the generated runlist.
231 for TARGET in $(TARGETS); do \
232 BUILD_TARGET=$$BUILD/$$TARGET; \
233 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
234 echo -ne "Emit Tests for $$TARGET\n"; \
235 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
236 -C $$TARGET emit_tests >> $(TEST_LIST); \
239 $(error Error: set INSTALL_PATH to use install)
243 TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
245 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
246 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
247 @echo "Created ${TAR_PATH}"
250 @for TARGET in $(TARGETS); do \
251 BUILD_TARGET=$$BUILD/$$TARGET; \
252 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
255 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar