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