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