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