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
20 TARGETS += filesystems/fat
26 TARGETS += intel_pstate
38 TARGETS += memory-hotplug
41 TARGETS += mount_setattr
42 TARGETS += move_mount_set_group
46 TARGETS += net/af_unix
47 TARGETS += net/forwarding
52 TARGETS += pid_namespace
64 TARGETS += sigaltstack
68 TARGETS += static_keys
70 TARGETS += syscall_user_dispatch
74 ifneq (1, $(quicktest))
84 #Please keep the TARGETS list alphabetically sorted
85 # Run "make quicktest=1 run_tests" or
86 # "make quicktest=1 kselftest" from top level Makefile
88 TARGETS_HOTPLUG = cpu-hotplug
89 TARGETS_HOTPLUG += memory-hotplug
91 # User can optionally provide a TARGETS skiplist. By default we skip
92 # BPF since it has cutting edge build time dependencies which require
93 # more effort to install.
95 ifneq ($(SKIP_TARGETS),)
96 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
97 override TARGETS := $(TMP)
100 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
101 # built; make will fail if any of the targets cannot be built. If
102 # FORCE_TARGETS is not set (the default), make will succeed if at least one
103 # of the targets gets built.
106 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
107 # implicit rules to sub-test Makefiles which avoids build failures in test
108 # Makefile that don't have explicit build rules.
114 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
115 # KBUILD_OUTPUT with selftest objects and headers installed
116 # by selftests Makefile or lib.mk.
117 ifdef building_out_of_srctree
121 top_srcdir ?= ../../..
123 ifeq ("$(origin O)", "command line")
124 KBUILD_OUTPUT := $(O)
127 ifneq ($(KBUILD_OUTPUT),)
128 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
129 # expand a shell special character '~'. We use a somewhat tedious way here.
130 abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
131 $(if $(abs_objtree),, \
132 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
133 # $(realpath ...) resolves symlinks
134 abs_objtree := $(realpath $(abs_objtree))
135 BUILD := $(abs_objtree)/kselftest
136 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
139 abs_srctree := $(shell cd $(top_srcdir) && pwd)
140 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
141 DEFAULT_INSTALL_HDR_PATH := 1
144 # Prepare for headers install
145 include $(top_srcdir)/scripts/subarch.include
150 # set default goal to all, so make without a target runs all, even when
151 # all isn't the first target in the file.
156 for TARGET in $(TARGETS); do \
157 BUILD_TARGET=$$BUILD/$$TARGET; \
158 mkdir $$BUILD_TARGET -p; \
159 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
161 $(if $(FORCE_TARGETS),|| exit); \
162 ret=$$((ret * $$?)); \
166 @for TARGET in $(TARGETS); do \
167 BUILD_TARGET=$$BUILD/$$TARGET; \
168 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
173 @for TARGET in $(TARGETS_HOTPLUG); do \
174 BUILD_TARGET=$$BUILD/$$TARGET; \
175 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
179 @for TARGET in $(TARGETS_HOTPLUG); do \
180 BUILD_TARGET=$$BUILD/$$TARGET; \
181 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
185 @for TARGET in $(TARGETS_HOTPLUG); do \
186 BUILD_TARGET=$$BUILD/$$TARGET; \
187 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
191 $(MAKE) -C pstore run_crash
193 # Use $BUILD as the default install root. $BUILD points to the
194 # right output location for the following cases:
195 # 1. output_dir=kernel_src
196 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
197 # 3. a separate output directory is specified using KBUILD_OUTPUT
198 # Avoid conflict with INSTALL_PATH set by the main Makefile
200 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
201 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
202 # Avoid changing the rest of the logic here and lib.mk.
203 INSTALL_PATH := $(KSFT_INSTALL_PATH)
204 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
205 TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
209 @# Ask all targets to install their files
210 mkdir -p $(INSTALL_PATH)/kselftest
211 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
212 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
213 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
214 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
217 for TARGET in $(TARGETS); do \
218 BUILD_TARGET=$$BUILD/$$TARGET; \
219 $(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 -ne "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: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar