1 # SPDX-License-Identifier: GPL-2.0
5 TARGETS += capabilities
10 TARGETS += cpu-hotplug
11 TARGETS += drivers/dma-buf
14 TARGETS += filesystems
15 TARGETS += filesystems/binderfs
16 TARGETS += filesystems/epoll
22 TARGETS += intel_pstate
33 TARGETS += memory-hotplug
36 TARGETS += mount_setattr
40 TARGETS += net/forwarding
45 TARGETS += pid_namespace
55 TARGETS += sigaltstack
59 TARGETS += static_keys
61 TARGETS += syscall_user_dispatch
65 ifneq (1, $(quicktest))
75 #Please keep the TARGETS list alphabetically sorted
76 # Run "make quicktest=1 run_tests" or
77 # "make quicktest=1 kselftest" from top level Makefile
79 TARGETS_HOTPLUG = cpu-hotplug
80 TARGETS_HOTPLUG += memory-hotplug
82 # User can optionally provide a TARGETS skiplist. By default we skip
83 # BPF since it has cutting edge build time dependencies which require
84 # more effort to install.
86 ifneq ($(SKIP_TARGETS),)
87 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
88 override TARGETS := $(TMP)
91 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
92 # built; make will fail if any of the targets cannot be built. If
93 # FORCE_TARGETS is not set (the default), make will succeed if at least one
94 # of the targets gets built.
97 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
98 # implicit rules to sub-test Makefiles which avoids build failures in test
99 # Makefile that don't have explicit build rules.
105 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
106 # KBUILD_OUTPUT with selftest objects and headers installed
107 # by selftests Makefile or lib.mk.
108 ifdef building_out_of_srctree
113 BUILD := $(O)/kselftest
115 ifneq ($(KBUILD_OUTPUT),)
116 BUILD := $(KBUILD_OUTPUT)/kselftest
118 BUILD := $(shell pwd)
119 DEFAULT_INSTALL_HDR_PATH := 1
123 # Prepare for headers install
124 top_srcdir ?= ../../..
125 include $(top_srcdir)/scripts/subarch.include
127 export KSFT_KHDR_INSTALL_DONE := 1
130 # set default goal to all, so make without a target runs all, even when
131 # all isn't the first target in the file.
134 # Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
135 # is used to avoid running headers_install from lib.mk.
136 # Invoke headers install with --no-builtin-rules to avoid circular
137 # dependency in "make kselftest" case. In this case, second level
138 # make inherits builtin-rules which will use the rule generate
139 # Makefile.o and runs into
140 # "Circular Makefile.o <- prepare dependency dropped."
141 # and headers_install fails and test compile fails.
143 # O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
144 # invokes them as sub-makes and --no-builtin-rules is not necessary,
145 # but doesn't cause any failures. Keep it simple and use the same
146 # flags in both cases.
147 # Local build cases: "make kselftest", "make -C" - headers are installed
148 # in the default INSTALL_HDR_PATH usr/include.
150 ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
151 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
153 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
154 ARCH=$(ARCH) -C $(top_srcdir) headers_install
159 for TARGET in $(TARGETS); do \
160 BUILD_TARGET=$$BUILD/$$TARGET; \
161 mkdir $$BUILD_TARGET -p; \
162 $(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;\
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 \
221 $(if $(FORCE_TARGETS),|| exit); \
222 ret=$$((ret * $$?)); \
226 @# Ask all targets to emit their test scripts
227 @# While building kselftest-list.text skip also non-existent TARGET dirs:
228 @# they could be the result of a build failure and should NOT be
229 @# included in the generated runlist.
230 for TARGET in $(TARGETS); do \
231 BUILD_TARGET=$$BUILD/$$TARGET; \
232 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
233 echo -n "Emit Tests for $$TARGET\n"; \
234 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
235 -C $$TARGET emit_tests >> $(TEST_LIST); \
238 $(error Error: set INSTALL_PATH to use install)
242 TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
244 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
245 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
246 @echo "Created ${TAR_PATH}"
249 @for TARGET in $(TARGETS); do \
250 BUILD_TARGET=$$BUILD/$$TARGET; \
251 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
254 .PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar