xref: /linux/tools/testing/selftests/Makefile (revision b1c21075d30c40762750be0cded9822791df422b)
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 += nolibc
81TARGETS += nsfs
82TARGETS += pci_endpoint
83TARGETS += pcie_bwctrl
84TARGETS += perf_events
85TARGETS += pidfd
86TARGETS += pid_namespace
87TARGETS += power_supply
88TARGETS += powerpc
89TARGETS += prctl
90TARGETS += proc
91TARGETS += pstore
92TARGETS += ptrace
93TARGETS += openat2
94TARGETS += resctrl
95TARGETS += riscv
96TARGETS += rlimits
97TARGETS += rseq
98TARGETS += rtc
99TARGETS += rust
100TARGETS += sched_ext
101TARGETS += seccomp
102TARGETS += sgx
103TARGETS += signal
104TARGETS += size
105TARGETS += sparc64
106TARGETS += splice
107TARGETS += static_keys
108TARGETS += sync
109TARGETS += syscall_user_dispatch
110TARGETS += sysctl
111TARGETS += tc-testing
112TARGETS += tdx
113TARGETS += thermal/intel/power_floor
114TARGETS += thermal/intel/workload_hint
115TARGETS += timens
116ifneq (1, $(quicktest))
117TARGETS += timers
118endif
119TARGETS += tmpfs
120TARGETS += tpm2
121TARGETS += tty
122TARGETS += ublk
123TARGETS += uevent
124TARGETS += user_events
125TARGETS += vDSO
126TARGETS += mm
127TARGETS += x86
128TARGETS += x86/bugs
129TARGETS += zram
130#Please keep the TARGETS list alphabetically sorted
131# Run "make quicktest=1 run_tests" or
132# "make quicktest=1 kselftest" from top level Makefile
133
134TARGETS_HOTPLUG = cpu-hotplug
135TARGETS_HOTPLUG += memory-hotplug
136
137# Networking tests want the net/lib target, include it automatically
138ifneq ($(filter net drivers/net drivers/net/hw,$(TARGETS)),)
139ifeq ($(filter net/lib,$(TARGETS)),)
140	INSTALL_DEP_TARGETS := net/lib
141endif
142endif
143
144# User can optionally provide a TARGETS skiplist. By default we skip
145# targets using BPF since it has cutting edge build time dependencies
146# which require more effort to install.
147SKIP_TARGETS ?= bpf sched_ext
148ifneq ($(SKIP_TARGETS),)
149	TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
150	override TARGETS := $(TMP)
151endif
152
153# User can set FORCE_TARGETS to 1 to require all targets to be successfully
154# built; make will fail if any of the targets cannot be built. If
155# FORCE_TARGETS is not set (the default), make will succeed if at least one
156# of the targets gets built.
157FORCE_TARGETS ?=
158
159# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
160# implicit rules to sub-test Makefiles which avoids build failures in test
161# Makefile that don't have explicit build rules.
162ifeq (,$(LINK.c))
163override LDFLAGS =
164override MAKEFLAGS =
165endif
166
167# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
168# KBUILD_OUTPUT with selftest objects and headers installed
169# by selftests Makefile or lib.mk.
170ifdef building_out_of_srctree
171override LDFLAGS =
172endif
173
174top_srcdir ?= ../../..
175
176ifeq ("$(origin O)", "command line")
177  KBUILD_OUTPUT := $(O)
178endif
179
180ifneq ($(KBUILD_OUTPUT),)
181  # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
182  # expand a shell special character '~'. We use a somewhat tedious way here.
183  abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
184  $(if $(abs_objtree),, \
185    $(error failed to create output directory "$(KBUILD_OUTPUT)"))
186  # $(realpath ...) resolves symlinks
187  abs_objtree := $(realpath $(abs_objtree))
188  BUILD := $(abs_objtree)/kselftest
189  KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
190else
191  BUILD := $(CURDIR)
192  abs_srctree := $(shell cd $(top_srcdir) && pwd)
193  KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
194  DEFAULT_INSTALL_HDR_PATH := 1
195endif
196
197# Prepare for headers install
198include $(top_srcdir)/scripts/subarch.include
199ARCH           ?= $(SUBARCH)
200export BUILD
201export KHDR_INCLUDES
202
203# set default goal to all, so make without a target runs all, even when
204# all isn't the first target in the file.
205.DEFAULT_GOAL := all
206
207all:
208	@ret=1;							\
209	for TARGET in $(TARGETS) $(INSTALL_DEP_TARGETS); do	\
210		BUILD_TARGET=$$BUILD/$$TARGET;			\
211		mkdir $$BUILD_TARGET  -p;			\
212		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET	\
213				O=$(abs_objtree)		\
214				$(if $(FORCE_TARGETS),|| exit);	\
215		ret=$$((ret * $$?));				\
216	done; exit $$ret;
217
218run_tests: all
219	@for TARGET in $(TARGETS); do \
220		BUILD_TARGET=$$BUILD/$$TARGET;	\
221		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
222				SRC_PATH=$(shell readlink -e $$(pwd)) \
223				OBJ_PATH=$(BUILD)                   \
224				O=$(abs_objtree);		    \
225	done;
226
227hotplug:
228	@for TARGET in $(TARGETS_HOTPLUG); do \
229		BUILD_TARGET=$$BUILD/$$TARGET;	\
230		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
231	done;
232
233run_hotplug: hotplug
234	@for TARGET in $(TARGETS_HOTPLUG); do \
235		BUILD_TARGET=$$BUILD/$$TARGET;	\
236		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
237	done;
238
239clean_hotplug:
240	@for TARGET in $(TARGETS_HOTPLUG); do \
241		BUILD_TARGET=$$BUILD/$$TARGET;	\
242		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
243	done;
244
245run_pstore_crash:
246	$(MAKE) -C pstore run_crash
247
248# Use $BUILD as the default install root. $BUILD points to the
249# right output location for the following cases:
250# 1. output_dir=kernel_src
251# 2. a separate output directory is specified using O= KBUILD_OUTPUT
252# 3. a separate output directory is specified using KBUILD_OUTPUT
253# Avoid conflict with INSTALL_PATH set by the main Makefile
254#
255KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
256KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
257# Avoid changing the rest of the logic here and lib.mk.
258INSTALL_PATH := $(KSFT_INSTALL_PATH)
259ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
260TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
261
262install: all
263ifdef INSTALL_PATH
264	@# Ask all targets to install their files
265	mkdir -p $(INSTALL_PATH)/kselftest
266	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
267	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
268	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
269	install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/
270	install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/
271	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
272	rm -f $(TEST_LIST)
273	@ret=1;	\
274	for TARGET in $(TARGETS) $(INSTALL_DEP_TARGETS); do \
275		BUILD_TARGET=$$BUILD/$$TARGET;	\
276		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install \
277				INSTALL_PATH=$(INSTALL_PATH)/$$TARGET \
278				SRC_PATH=$(shell readlink -e $$(pwd)) \
279				OBJ_PATH=$(INSTALL_PATH) \
280				O=$(abs_objtree)		\
281				$(if $(FORCE_TARGETS),|| exit);	\
282		ret=$$((ret * $$?));		\
283	done; exit $$ret;
284
285
286	@# Ask all targets to emit their test scripts
287	@# While building kselftest-list.text skip also non-existent TARGET dirs:
288	@# they could be the result of a build failure and should NOT be
289	@# included in the generated runlist.
290	for TARGET in $(TARGETS); do \
291		BUILD_TARGET=$$BUILD/$$TARGET;	\
292		[ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
293		printf "Emit Tests for $$TARGET\n"; \
294		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
295			-C $$TARGET emit_tests >> $(TEST_LIST); \
296	done;
297	@VERSION=$$(git describe HEAD 2>/dev/null); \
298	if [ -n "$$VERSION" ]; then \
299		echo "$$VERSION" > $(INSTALL_PATH)/VERSION; \
300		printf "Version saved to $(INSTALL_PATH)/VERSION\n"; \
301	else \
302		printf "Unable to get version from git describe\n"; \
303	fi
304	@echo "**Kselftest Installation is complete: $(INSTALL_PATH)**"
305else
306	$(error Error: set INSTALL_PATH to use install)
307endif
308
309FORMAT ?= .gz
310TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
311gen_tar: install
312	@mkdir -p ${INSTALL_PATH}/kselftest-packages/
313	@tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
314	@echo "Created ${TAR_PATH}"
315
316clean:
317	@for TARGET in $(TARGETS); do \
318		BUILD_TARGET=$$BUILD/$$TARGET;	\
319		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
320	done;
321
322.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar
323