1 # SPDX-License-Identifier: GPL-2.0
6 TARGETS += capabilities
11 TARGETS += cpu-hotplug
13 TARGETS += drivers/dma-buf
14 TARGETS += drivers/s390x/uvdevice
17 TARGETS += filesystems
18 TARGETS += filesystems/binderfs
19 TARGETS += filesystems/epoll
25 TARGETS += intel_pstate
37 TARGETS += memory-hotplug
40 TARGETS += mount_setattr
41 TARGETS += move_mount_set_group
45 TARGETS += net/af_unix
46 TARGETS += net/forwarding
51 TARGETS += pid_namespace
63 TARGETS += sigaltstack
67 TARGETS += static_keys
69 TARGETS += syscall_user_dispatch
73 ifneq (1, $(quicktest))
83 #Please keep the TARGETS list alphabetically sorted
84 # Run "make quicktest=1 run_tests" or
85 # "make quicktest=1 kselftest" from top level Makefile
87 TARGETS_HOTPLUG = cpu-hotplug
88 TARGETS_HOTPLUG += memory-hotplug
90 # User can optionally provide a TARGETS skiplist. By default we skip
91 # BPF since it has cutting edge build time dependencies which require
92 # more effort to install.
94 ifneq ($(SKIP_TARGETS),)
95 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
96 override TARGETS := $(TMP)
99 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
100 # built; make will fail if any of the targets cannot be built. If
101 # FORCE_TARGETS is not set (the default), make will succeed if at least one
102 # of the targets gets built.
105 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
106 # implicit rules to sub-test Makefiles which avoids build failures in test
107 # Makefile that don't have explicit build rules.
113 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
114 # KBUILD_OUTPUT with selftest objects and headers installed
115 # by selftests Makefile or lib.mk.
116 ifdef building_out_of_srctree
120 top_srcdir ?= ../../..
122 ifeq ("$(origin O)", "command line")
123 KBUILD_OUTPUT := $(O)
126 ifneq ($(KBUILD_OUTPUT),)
127 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
128 # expand a shell special character '~'. We use a somewhat tedious way here.
129 abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
130 $(if $(abs_objtree),, \
131 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
132 # $(realpath ...) resolves symlinks
133 abs_objtree := $(realpath $(abs_objtree))
134 BUILD := $(abs_objtree)/kselftest
135 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
138 abs_srctree := $(shell cd $(top_srcdir) && pwd)
139 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
140 DEFAULT_INSTALL_HDR_PATH := 1
143 # Prepare for headers install
144 include $(top_srcdir)/scripts/subarch.include
149 # set default goal to all, so make without a target runs all, even when
150 # all isn't the first target in the file.
155 for TARGET in $(TARGETS); do \
156 BUILD_TARGET=$$BUILD/$$TARGET; \
157 mkdir $$BUILD_TARGET -p; \
158 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
160 $(if $(FORCE_TARGETS),|| exit); \
161 ret=$$((ret * $$?)); \
165 @for TARGET in $(TARGETS); do \
166 BUILD_TARGET=$$BUILD/$$TARGET; \
167 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
172 @for TARGET in $(TARGETS_HOTPLUG); do \
173 BUILD_TARGET=$$BUILD/$$TARGET; \
174 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
178 @for TARGET in $(TARGETS_HOTPLUG); do \
179 BUILD_TARGET=$$BUILD/$$TARGET; \
180 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
184 @for TARGET in $(TARGETS_HOTPLUG); do \
185 BUILD_TARGET=$$BUILD/$$TARGET; \
186 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
190 $(MAKE) -C pstore run_crash
192 # Use $BUILD as the default install root. $BUILD points to the
193 # right output location for the following cases:
194 # 1. output_dir=kernel_src
195 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
196 # 3. a separate output directory is specified using KBUILD_OUTPUT
197 # Avoid conflict with INSTALL_PATH set by the main Makefile
199 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
200 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
201 # Avoid changing the rest of the logic here and lib.mk.
202 INSTALL_PATH := $(KSFT_INSTALL_PATH)
203 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
204 TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
208 @# Ask all targets to install their files
209 mkdir -p $(INSTALL_PATH)/kselftest
210 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
211 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
212 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
213 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
216 for TARGET in $(TARGETS); do \
217 BUILD_TARGET=$$BUILD/$$TARGET; \
218 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
220 $(if $(FORCE_TARGETS),|| exit); \
221 ret=$$((ret * $$?)); \
225 @# Ask all targets to emit their test scripts
226 @# While building kselftest-list.text skip also non-existent TARGET dirs:
227 @# they could be the result of a build failure and should NOT be
228 @# included in the generated runlist.
229 for TARGET in $(TARGETS); do \
230 BUILD_TARGET=$$BUILD/$$TARGET; \
231 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
232 echo -ne "Emit Tests for $$TARGET\n"; \
233 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
234 -C $$TARGET emit_tests >> $(TEST_LIST); \
237 $(error Error: set INSTALL_PATH to use install)
241 TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
243 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
244 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
245 @echo "Created ${TAR_PATH}"
248 @for TARGET in $(TARGETS); do \
249 BUILD_TARGET=$$BUILD/$$TARGET; \
250 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
253 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar