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
39 TARGETS += net/forwarding
44 TARGETS += pid_namespace
54 TARGETS += sigaltstack
58 TARGETS += static_keys
60 TARGETS += syscall_user_dispatch
64 ifneq (1, $(quicktest))
74 #Please keep the TARGETS list alphabetically sorted
75 # Run "make quicktest=1 run_tests" or
76 # "make quicktest=1 kselftest" from top level Makefile
78 TARGETS_HOTPLUG = cpu-hotplug
79 TARGETS_HOTPLUG += memory-hotplug
81 # User can optionally provide a TARGETS skiplist. By default we skip
82 # BPF since it has cutting edge build time dependencies which require
83 # more effort to install.
85 ifneq ($(SKIP_TARGETS),)
86 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
87 override TARGETS := $(TMP)
90 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
91 # built; make will fail if any of the targets cannot be built. If
92 # FORCE_TARGETS is not set (the default), make will succeed if at least one
93 # of the targets gets built.
96 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
97 # implicit rules to sub-test Makefiles which avoids build failures in test
98 # Makefile that don't have explicit build rules.
104 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
105 # KBUILD_OUTPUT with selftest objects and headers installed
106 # by selftests Makefile or lib.mk.
107 ifdef building_out_of_srctree
112 BUILD := $(O)/kselftest
114 ifneq ($(KBUILD_OUTPUT),)
115 BUILD := $(KBUILD_OUTPUT)/kselftest
117 BUILD := $(shell pwd)
118 DEFAULT_INSTALL_HDR_PATH := 1
122 # Prepare for headers install
123 top_srcdir ?= ../../..
124 include $(top_srcdir)/scripts/subarch.include
126 export KSFT_KHDR_INSTALL_DONE := 1
129 # build and run gpio when output directory is the src dir.
130 # gpio has dependency on tools/gpio and builds tools/gpio
131 # objects in the src directory in all cases making the src
132 # repo dirty even when objects are relocated.
133 ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
134 TMP := $(filter-out gpio, $(TARGETS))
138 # set default goal to all, so make without a target runs all, even when
139 # all isn't the first target in the file.
142 # Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
143 # is used to avoid running headers_install from lib.mk.
144 # Invoke headers install with --no-builtin-rules to avoid circular
145 # dependency in "make kselftest" case. In this case, second level
146 # make inherits builtin-rules which will use the rule generate
147 # Makefile.o and runs into
148 # "Circular Makefile.o <- prepare dependency dropped."
149 # and headers_install fails and test compile fails.
151 # O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
152 # invokes them as sub-makes and --no-builtin-rules is not necessary,
153 # but doesn't cause any failures. Keep it simple and use the same
154 # flags in both cases.
155 # Local build cases: "make kselftest", "make -C" - headers are installed
156 # in the default INSTALL_HDR_PATH usr/include.
158 ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
159 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
161 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
162 ARCH=$(ARCH) -C $(top_srcdir) headers_install
167 for TARGET in $(TARGETS); do \
168 BUILD_TARGET=$$BUILD/$$TARGET; \
169 mkdir $$BUILD_TARGET -p; \
170 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
171 $(if $(FORCE_TARGETS),|| exit); \
172 ret=$$((ret * $$?)); \
176 @for TARGET in $(TARGETS); do \
177 BUILD_TARGET=$$BUILD/$$TARGET; \
178 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
182 @for TARGET in $(TARGETS_HOTPLUG); do \
183 BUILD_TARGET=$$BUILD/$$TARGET; \
184 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
188 @for TARGET in $(TARGETS_HOTPLUG); do \
189 BUILD_TARGET=$$BUILD/$$TARGET; \
190 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
194 @for TARGET in $(TARGETS_HOTPLUG); do \
195 BUILD_TARGET=$$BUILD/$$TARGET; \
196 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
200 $(MAKE) -C pstore run_crash
202 # Use $BUILD as the default install root. $BUILD points to the
203 # right output location for the following cases:
204 # 1. output_dir=kernel_src
205 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
206 # 3. a separate output directory is specified using KBUILD_OUTPUT
207 # Avoid conflict with INSTALL_PATH set by the main Makefile
209 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
210 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
211 # Avoid changing the rest of the logic here and lib.mk.
212 INSTALL_PATH := $(KSFT_INSTALL_PATH)
213 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
214 TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
218 @# Ask all targets to install their files
219 mkdir -p $(INSTALL_PATH)/kselftest
220 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
221 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
222 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
223 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
226 for TARGET in $(TARGETS); do \
227 BUILD_TARGET=$$BUILD/$$TARGET; \
228 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
229 $(if $(FORCE_TARGETS),|| exit); \
230 ret=$$((ret * $$?)); \
234 @# Ask all targets to emit their test scripts
235 @# While building kselftest-list.text skip also non-existent TARGET dirs:
236 @# they could be the result of a build failure and should NOT be
237 @# included in the generated runlist.
238 for TARGET in $(TARGETS); do \
239 BUILD_TARGET=$$BUILD/$$TARGET; \
240 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
241 echo -n "Emit Tests for $$TARGET\n"; \
242 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
243 -C $$TARGET emit_tests >> $(TEST_LIST); \
246 $(error Error: set INSTALL_PATH to use install)
250 TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
252 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
253 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
254 @echo "Created ${TAR_PATH}"
257 @for TARGET in $(TARGETS); do \
258 BUILD_TARGET=$$BUILD/$$TARGET; \
259 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
262 .PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar