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