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
34 TARGETS += memory-hotplug
37 TARGETS += mount_setattr
41 TARGETS += net/forwarding
46 TARGETS += pid_namespace
56 TARGETS += sigaltstack
60 TARGETS += static_keys
62 TARGETS += syscall_user_dispatch
66 ifneq (1, $(quicktest))
76 #Please keep the TARGETS list alphabetically sorted
77 # Run "make quicktest=1 run_tests" or
78 # "make quicktest=1 kselftest" from top level Makefile
80 TARGETS_HOTPLUG = cpu-hotplug
81 TARGETS_HOTPLUG += memory-hotplug
83 # User can optionally provide a TARGETS skiplist. By default we skip
84 # BPF since it has cutting edge build time dependencies which require
85 # more effort to install.
87 ifneq ($(SKIP_TARGETS),)
88 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
89 override TARGETS := $(TMP)
92 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
93 # built; make will fail if any of the targets cannot be built. If
94 # FORCE_TARGETS is not set (the default), make will succeed if at least one
95 # of the targets gets built.
98 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
99 # implicit rules to sub-test Makefiles which avoids build failures in test
100 # Makefile that don't have explicit build rules.
106 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
107 # KBUILD_OUTPUT with selftest objects and headers installed
108 # by selftests Makefile or lib.mk.
109 ifdef building_out_of_srctree
114 BUILD := $(O)/kselftest
116 ifneq ($(KBUILD_OUTPUT),)
117 BUILD := $(KBUILD_OUTPUT)/kselftest
119 BUILD := $(shell pwd)
120 DEFAULT_INSTALL_HDR_PATH := 1
124 # Prepare for headers install
125 top_srcdir ?= ../../..
126 include $(top_srcdir)/scripts/subarch.include
128 export KSFT_KHDR_INSTALL_DONE := 1
131 # set default goal to all, so make without a target runs all, even when
132 # all isn't the first target in the file.
135 # Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
136 # is used to avoid running headers_install from lib.mk.
137 # Invoke headers install with --no-builtin-rules to avoid circular
138 # dependency in "make kselftest" case. In this case, second level
139 # make inherits builtin-rules which will use the rule generate
140 # Makefile.o and runs into
141 # "Circular Makefile.o <- prepare dependency dropped."
142 # and headers_install fails and test compile fails.
144 # O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
145 # invokes them as sub-makes and --no-builtin-rules is not necessary,
146 # but doesn't cause any failures. Keep it simple and use the same
147 # flags in both cases.
148 # Local build cases: "make kselftest", "make -C" - headers are installed
149 # in the default INSTALL_HDR_PATH usr/include.
151 ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
152 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
154 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
155 ARCH=$(ARCH) -C $(top_srcdir) headers_install
160 for TARGET in $(TARGETS); do \
161 BUILD_TARGET=$$BUILD/$$TARGET; \
162 mkdir $$BUILD_TARGET -p; \
163 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
164 $(if $(FORCE_TARGETS),|| exit); \
165 ret=$$((ret * $$?)); \
169 @for TARGET in $(TARGETS); do \
170 BUILD_TARGET=$$BUILD/$$TARGET; \
171 $(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 \
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 -n "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: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar