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