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