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