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