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