xref: /linux/tools/testing/selftests/Makefile (revision 2c7e4a2663a1ab5a740c59c31991579b6b865a26)
1# SPDX-License-Identifier: GPL-2.0
2TARGETS += acct
3TARGETS += alsa
4TARGETS += amd-pstate
5TARGETS += arm64
6TARGETS += bpf
7TARGETS += breakpoints
8TARGETS += cachestat
9TARGETS += capabilities
10TARGETS += cgroup
11TARGETS += clone3
12TARGETS += connector
13TARGETS += core
14TARGETS += cpufreq
15TARGETS += cpu-hotplug
16TARGETS += damon
17TARGETS += devices/error_logs
18TARGETS += devices/probe
19TARGETS += dmabuf-heaps
20TARGETS += drivers/dma-buf
21TARGETS += drivers/ntsync
22TARGETS += drivers/s390x/uvdevice
23TARGETS += drivers/net
24TARGETS += drivers/net/bonding
25TARGETS += drivers/net/team
26TARGETS += drivers/net/virtio_net
27TARGETS += drivers/platform/x86/intel/ifs
28TARGETS += dt
29TARGETS += efivarfs
30TARGETS += exec
31TARGETS += fchmodat2
32TARGETS += filesystems
33TARGETS += filesystems/binderfs
34TARGETS += filesystems/epoll
35TARGETS += filesystems/fat
36TARGETS += filesystems/overlayfs
37TARGETS += filesystems/statmount
38TARGETS += filesystems/mount-notify
39TARGETS += firmware
40TARGETS += fpu
41TARGETS += ftrace
42TARGETS += futex
43TARGETS += gpio
44TARGETS += hid
45TARGETS += intel_pstate
46TARGETS += iommu
47TARGETS += ipc
48TARGETS += ir
49TARGETS += kcmp
50TARGETS += kexec
51TARGETS += kselftest_harness
52TARGETS += kvm
53TARGETS += landlock
54TARGETS += lib
55TARGETS += livepatch
56TARGETS += lkdtm
57TARGETS += lsm
58TARGETS += membarrier
59TARGETS += memfd
60TARGETS += memory-hotplug
61TARGETS += mincore
62TARGETS += mount
63TARGETS += mount_setattr
64TARGETS += move_mount_set_group
65TARGETS += mqueue
66TARGETS += mseal_system_mappings
67TARGETS += nci
68TARGETS += net
69TARGETS += net/af_unix
70TARGETS += net/can
71TARGETS += net/forwarding
72TARGETS += net/hsr
73TARGETS += net/mptcp
74TARGETS += net/netfilter
75TARGETS += net/openvswitch
76TARGETS += net/ovpn
77TARGETS += net/packetdrill
78TARGETS += net/rds
79TARGETS += net/tcp_ao
80TARGETS += nsfs
81TARGETS += pci_endpoint
82TARGETS += pcie_bwctrl
83TARGETS += perf_events
84TARGETS += pidfd
85TARGETS += pid_namespace
86TARGETS += power_supply
87TARGETS += powerpc
88TARGETS += prctl
89TARGETS += proc
90TARGETS += pstore
91TARGETS += ptrace
92TARGETS += openat2
93TARGETS += resctrl
94TARGETS += riscv
95TARGETS += rlimits
96TARGETS += rseq
97TARGETS += rtc
98TARGETS += rust
99TARGETS += sched_ext
100TARGETS += seccomp
101TARGETS += sgx
102TARGETS += signal
103TARGETS += size
104TARGETS += sparc64
105TARGETS += splice
106TARGETS += static_keys
107TARGETS += sync
108TARGETS += syscall_user_dispatch
109TARGETS += sysctl
110TARGETS += tc-testing
111TARGETS += tdx
112TARGETS += thermal/intel/power_floor
113TARGETS += thermal/intel/workload_hint
114TARGETS += timens
115ifneq (1, $(quicktest))
116TARGETS += timers
117endif
118TARGETS += tmpfs
119TARGETS += tpm2
120TARGETS += tty
121TARGETS += ublk
122TARGETS += uevent
123TARGETS += user_events
124TARGETS += vDSO
125TARGETS += mm
126TARGETS += x86
127TARGETS += x86/bugs
128TARGETS += zram
129#Please keep the TARGETS list alphabetically sorted
130# Run "make quicktest=1 run_tests" or
131# "make quicktest=1 kselftest" from top level Makefile
132
133TARGETS_HOTPLUG = cpu-hotplug
134TARGETS_HOTPLUG += memory-hotplug
135
136# Networking tests want the net/lib target, include it automatically
137ifneq ($(filter net drivers/net drivers/net/hw,$(TARGETS)),)
138ifeq ($(filter net/lib,$(TARGETS)),)
139	INSTALL_DEP_TARGETS := net/lib
140endif
141endif
142
143# User can optionally provide a TARGETS skiplist. By default we skip
144# targets using BPF since it has cutting edge build time dependencies
145# which require more effort to install.
146SKIP_TARGETS ?= bpf sched_ext
147ifneq ($(SKIP_TARGETS),)
148	TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
149	override TARGETS := $(TMP)
150endif
151
152# User can set FORCE_TARGETS to 1 to require all targets to be successfully
153# built; make will fail if any of the targets cannot be built. If
154# FORCE_TARGETS is not set (the default), make will succeed if at least one
155# of the targets gets built.
156FORCE_TARGETS ?=
157
158# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
159# implicit rules to sub-test Makefiles which avoids build failures in test
160# Makefile that don't have explicit build rules.
161ifeq (,$(LINK.c))
162override LDFLAGS =
163override MAKEFLAGS =
164endif
165
166# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
167# KBUILD_OUTPUT with selftest objects and headers installed
168# by selftests Makefile or lib.mk.
169ifdef building_out_of_srctree
170override LDFLAGS =
171endif
172
173top_srcdir ?= ../../..
174
175ifeq ("$(origin O)", "command line")
176  KBUILD_OUTPUT := $(O)
177endif
178
179ifneq ($(KBUILD_OUTPUT),)
180  # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
181  # expand a shell special character '~'. We use a somewhat tedious way here.
182  abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
183  $(if $(abs_objtree),, \
184    $(error failed to create output directory "$(KBUILD_OUTPUT)"))
185  # $(realpath ...) resolves symlinks
186  abs_objtree := $(realpath $(abs_objtree))
187  BUILD := $(abs_objtree)/kselftest
188  KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
189else
190  BUILD := $(CURDIR)
191  abs_srctree := $(shell cd $(top_srcdir) && pwd)
192  KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
193  DEFAULT_INSTALL_HDR_PATH := 1
194endif
195
196# Prepare for headers install
197include $(top_srcdir)/scripts/subarch.include
198ARCH           ?= $(SUBARCH)
199export BUILD
200export KHDR_INCLUDES
201
202# set default goal to all, so make without a target runs all, even when
203# all isn't the first target in the file.
204.DEFAULT_GOAL := all
205
206all:
207	@ret=1;							\
208	for TARGET in $(TARGETS) $(INSTALL_DEP_TARGETS); do	\
209		BUILD_TARGET=$$BUILD/$$TARGET;			\
210		mkdir $$BUILD_TARGET  -p;			\
211		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET	\
212				O=$(abs_objtree)		\
213				$(if $(FORCE_TARGETS),|| exit);	\
214		ret=$$((ret * $$?));				\
215	done; exit $$ret;
216
217run_tests: all
218	@for TARGET in $(TARGETS); do \
219		BUILD_TARGET=$$BUILD/$$TARGET;	\
220		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
221				SRC_PATH=$(shell readlink -e $$(pwd)) \
222				OBJ_PATH=$(BUILD)                   \
223				O=$(abs_objtree);		    \
224	done;
225
226hotplug:
227	@for TARGET in $(TARGETS_HOTPLUG); do \
228		BUILD_TARGET=$$BUILD/$$TARGET;	\
229		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
230	done;
231
232run_hotplug: hotplug
233	@for TARGET in $(TARGETS_HOTPLUG); do \
234		BUILD_TARGET=$$BUILD/$$TARGET;	\
235		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
236	done;
237
238clean_hotplug:
239	@for TARGET in $(TARGETS_HOTPLUG); do \
240		BUILD_TARGET=$$BUILD/$$TARGET;	\
241		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
242	done;
243
244run_pstore_crash:
245	$(MAKE) -C pstore run_crash
246
247# Use $BUILD as the default install root. $BUILD points to the
248# right output location for the following cases:
249# 1. output_dir=kernel_src
250# 2. a separate output directory is specified using O= KBUILD_OUTPUT
251# 3. a separate output directory is specified using KBUILD_OUTPUT
252# Avoid conflict with INSTALL_PATH set by the main Makefile
253#
254KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
255KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
256# Avoid changing the rest of the logic here and lib.mk.
257INSTALL_PATH := $(KSFT_INSTALL_PATH)
258ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
259TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
260
261install: all
262ifdef INSTALL_PATH
263	@# Ask all targets to install their files
264	mkdir -p $(INSTALL_PATH)/kselftest
265	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
266	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
267	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
268	install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/
269	install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/
270	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
271	rm -f $(TEST_LIST)
272	@ret=1;	\
273	for TARGET in $(TARGETS) $(INSTALL_DEP_TARGETS); do \
274		BUILD_TARGET=$$BUILD/$$TARGET;	\
275		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install \
276				INSTALL_PATH=$(INSTALL_PATH)/$$TARGET \
277				SRC_PATH=$(shell readlink -e $$(pwd)) \
278				OBJ_PATH=$(INSTALL_PATH) \
279				O=$(abs_objtree)		\
280				$(if $(FORCE_TARGETS),|| exit);	\
281		ret=$$((ret * $$?));		\
282	done; exit $$ret;
283
284
285	@# Ask all targets to emit their test scripts
286	@# While building kselftest-list.text skip also non-existent TARGET dirs:
287	@# they could be the result of a build failure and should NOT be
288	@# included in the generated runlist.
289	for TARGET in $(TARGETS); do \
290		BUILD_TARGET=$$BUILD/$$TARGET;	\
291		[ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
292		printf "Emit Tests for $$TARGET\n"; \
293		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
294			-C $$TARGET emit_tests >> $(TEST_LIST); \
295	done;
296else
297	$(error Error: set INSTALL_PATH to use install)
298endif
299
300FORMAT ?= .gz
301TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
302gen_tar: install
303	@mkdir -p ${INSTALL_PATH}/kselftest-packages/
304	@tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
305	@echo "Created ${TAR_PATH}"
306
307clean:
308	@for TARGET in $(TARGETS); do \
309		BUILD_TARGET=$$BUILD/$$TARGET;	\
310		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
311	done;
312
313.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar
314