• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0
2TARGETS = android
3TARGETS += arm64
4TARGETS += bpf
5TARGETS += breakpoints
6TARGETS += capabilities
7TARGETS += cgroup
8TARGETS += clone3
9TARGETS += core
10TARGETS += cpufreq
11TARGETS += cpu-hotplug
12TARGETS += damon
13TARGETS += drivers/dma-buf
14TARGETS += efivarfs
15TARGETS += exec
16TARGETS += filesystems
17TARGETS += filesystems/binderfs
18TARGETS += filesystems/epoll
19TARGETS += firmware
20TARGETS += fpu
21TARGETS += ftrace
22TARGETS += futex
23TARGETS += gpio
24TARGETS += intel_pstate
25TARGETS += ipc
26TARGETS += ir
27TARGETS += kcmp
28TARGETS += kexec
29TARGETS += kvm
30TARGETS += lib
31TARGETS += livepatch
32TARGETS += lkdtm
33TARGETS += membarrier
34TARGETS += memfd
35TARGETS += memory-hotplug
36TARGETS += mincore
37TARGETS += mount
38TARGETS += mqueue
39TARGETS += net
40TARGETS += net/forwarding
41TARGETS += net/mptcp
42TARGETS += netfilter
43TARGETS += nsfs
44TARGETS += pidfd
45TARGETS += pid_namespace
46TARGETS += powerpc
47TARGETS += proc
48TARGETS += pstore
49TARGETS += ptrace
50TARGETS += openat2
51TARGETS += rseq
52TARGETS += rtc
53TARGETS += seccomp
54TARGETS += sigaltstack
55TARGETS += size
56TARGETS += sparc64
57TARGETS += splice
58TARGETS += static_keys
59TARGETS += sync
60TARGETS += sysctl
61TARGETS += tc-testing
62TARGETS += timens
63ifneq (1, $(quicktest))
64TARGETS += timers
65endif
66TARGETS += tmpfs
67TARGETS += tpm2
68TARGETS += user
69TARGETS += vm
70TARGETS += x86
71TARGETS += zram
72#Please keep the TARGETS list alphabetically sorted
73# Run "make quicktest=1 run_tests" or
74# "make quicktest=1 kselftest" from top level Makefile
75
76TARGETS_HOTPLUG = cpu-hotplug
77TARGETS_HOTPLUG += memory-hotplug
78
79# User can optionally provide a TARGETS skiplist.
80SKIP_TARGETS ?=
81ifneq ($(SKIP_TARGETS),)
82	TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
83	override TARGETS := $(TMP)
84endif
85
86# User can set FORCE_TARGETS to 1 to require all targets to be successfully
87# built; make will fail if any of the targets cannot be built. If
88# FORCE_TARGETS is not set (the default), make will succeed if at least one
89# of the targets gets built.
90FORCE_TARGETS ?=
91
92# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
93# implicit rules to sub-test Makefiles which avoids build failures in test
94# Makefile that don't have explicit build rules.
95ifeq (,$(LINK.c))
96override LDFLAGS =
97override MAKEFLAGS =
98endif
99
100# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
101# KBUILD_OUTPUT with selftest objects and headers installed
102# by selftests Makefile or lib.mk.
103ifdef building_out_of_srctree
104override LDFLAGS =
105endif
106
107top_srcdir ?= ../../..
108
109ifeq ("$(origin O)", "command line")
110  KBUILD_OUTPUT := $(O)
111endif
112
113ifneq ($(KBUILD_OUTPUT),)
114  # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
115  # expand a shell special character '~'. We use a somewhat tedious way here.
116  abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
117  $(if $(abs_objtree),, \
118    $(error failed to create output directory "$(KBUILD_OUTPUT)"))
119  # $(realpath ...) resolves symlinks
120  abs_objtree := $(realpath $(abs_objtree))
121  BUILD := $(abs_objtree)/kselftest
122else
123  BUILD := $(CURDIR)
124  DEFAULT_INSTALL_HDR_PATH := 1
125endif
126
127# Prepare for headers install
128include $(top_srcdir)/scripts/subarch.include
129ARCH           ?= $(SUBARCH)
130export KSFT_KHDR_INSTALL_DONE := 1
131export BUILD
132
133# build and run gpio when output directory is the src dir.
134# gpio has dependency on tools/gpio and builds tools/gpio
135# objects in the src directory in all cases making the src
136# repo dirty even when objects are relocated.
137ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
138	TMP := $(filter-out gpio, $(TARGETS))
139	TARGETS := $(TMP)
140endif
141
142# set default goal to all, so make without a target runs all, even when
143# all isn't the first target in the file.
144.DEFAULT_GOAL := all
145
146# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
147# is used to avoid running headers_install from lib.mk.
148# Invoke headers install with --no-builtin-rules to avoid circular
149# dependency in "make kselftest" case. In this case, second level
150# make inherits builtin-rules which will use the rule generate
151# Makefile.o and runs into
152# "Circular Makefile.o <- prepare dependency dropped."
153# and headers_install fails and test compile fails.
154#
155# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
156# invokes them as sub-makes and --no-builtin-rules is not necessary,
157# but doesn't cause any failures. Keep it simple and use the same
158# flags in both cases.
159# Local build cases: "make kselftest", "make -C" - headers are installed
160# in the default INSTALL_HDR_PATH usr/include.
161khdr:
162ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
163	$(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
164else
165	$(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
166		ARCH=$(ARCH) -C $(top_srcdir) headers_install
167endif
168
169all: khdr
170	@ret=1;							\
171	for TARGET in $(TARGETS); do				\
172		BUILD_TARGET=$$BUILD/$$TARGET;			\
173		mkdir $$BUILD_TARGET  -p;			\
174		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET	\
175				$(if $(FORCE_TARGETS),|| exit);	\
176		ret=$$((ret * $$?));				\
177	done; exit $$ret;
178
179run_tests: all
180	@for TARGET in $(TARGETS); do \
181		BUILD_TARGET=$$BUILD/$$TARGET;	\
182		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
183	done;
184
185hotplug:
186	@for TARGET in $(TARGETS_HOTPLUG); do \
187		BUILD_TARGET=$$BUILD/$$TARGET;	\
188		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
189	done;
190
191run_hotplug: hotplug
192	@for TARGET in $(TARGETS_HOTPLUG); do \
193		BUILD_TARGET=$$BUILD/$$TARGET;	\
194		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
195	done;
196
197clean_hotplug:
198	@for TARGET in $(TARGETS_HOTPLUG); do \
199		BUILD_TARGET=$$BUILD/$$TARGET;	\
200		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
201	done;
202
203run_pstore_crash:
204	$(MAKE) -C pstore run_crash
205
206# Use $BUILD as the default install root. $BUILD points to the
207# right output location for the following cases:
208# 1. output_dir=kernel_src
209# 2. a separate output directory is specified using O= KBUILD_OUTPUT
210# 3. a separate output directory is specified using KBUILD_OUTPUT
211# Avoid conflict with INSTALL_PATH set by the main Makefile
212#
213KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
214KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
215# Avoid changing the rest of the logic here and lib.mk.
216INSTALL_PATH := $(KSFT_INSTALL_PATH)
217ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
218TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
219
220install: all
221ifdef INSTALL_PATH
222	@# Ask all targets to install their files
223	mkdir -p $(INSTALL_PATH)/kselftest
224	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
225	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
226	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
227	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
228	rm -f $(TEST_LIST)
229	@ret=1;	\
230	for TARGET in $(TARGETS); do \
231		BUILD_TARGET=$$BUILD/$$TARGET;	\
232		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
233				$(if $(FORCE_TARGETS),|| exit);	\
234		ret=$$((ret * $$?));		\
235	done; exit $$ret;
236
237
238	@# Ask all targets to emit their test scripts
239	@# While building kselftest-list.text skip also non-existent TARGET dirs:
240	@# they could be the result of a build failure and should NOT be
241	@# included in the generated runlist.
242	for TARGET in $(TARGETS); do \
243		BUILD_TARGET=$$BUILD/$$TARGET;	\
244		[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
245		echo -n "Emit Tests for $$TARGET\n"; \
246		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
247			-C $$TARGET emit_tests >> $(TEST_LIST); \
248	done;
249else
250	$(error Error: set INSTALL_PATH to use install)
251endif
252
253FORMAT ?= .gz
254TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
255gen_tar: install
256	@mkdir -p ${INSTALL_PATH}/kselftest-packages/
257	@tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
258	@echo "Created ${TAR_PATH}"
259
260clean:
261	@for TARGET in $(TARGETS); do \
262		BUILD_TARGET=$$BUILD/$$TARGET;	\
263		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
264	done;
265
266.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar
267