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