xref: /openbmc/linux/tools/testing/selftests/Makefile (revision 472d7b9e)
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 BUILD
148export KHDR_INCLUDES
149
150# set default goal to all, so make without a target runs all, even when
151# all isn't the first target in the file.
152.DEFAULT_GOAL := all
153
154all:
155	@ret=1;							\
156	for TARGET in $(TARGETS); do				\
157		BUILD_TARGET=$$BUILD/$$TARGET;			\
158		mkdir $$BUILD_TARGET  -p;			\
159		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET	\
160				O=$(abs_objtree)		\
161				$(if $(FORCE_TARGETS),|| exit);	\
162		ret=$$((ret * $$?));				\
163	done; exit $$ret;
164
165run_tests: all
166	@for TARGET in $(TARGETS); do \
167		BUILD_TARGET=$$BUILD/$$TARGET;	\
168		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
169				O=$(abs_objtree);		    \
170	done;
171
172hotplug:
173	@for TARGET in $(TARGETS_HOTPLUG); do \
174		BUILD_TARGET=$$BUILD/$$TARGET;	\
175		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
176	done;
177
178run_hotplug: hotplug
179	@for TARGET in $(TARGETS_HOTPLUG); do \
180		BUILD_TARGET=$$BUILD/$$TARGET;	\
181		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
182	done;
183
184clean_hotplug:
185	@for TARGET in $(TARGETS_HOTPLUG); do \
186		BUILD_TARGET=$$BUILD/$$TARGET;	\
187		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
188	done;
189
190run_pstore_crash:
191	$(MAKE) -C pstore run_crash
192
193# Use $BUILD as the default install root. $BUILD points to the
194# right output location for the following cases:
195# 1. output_dir=kernel_src
196# 2. a separate output directory is specified using O= KBUILD_OUTPUT
197# 3. a separate output directory is specified using KBUILD_OUTPUT
198# Avoid conflict with INSTALL_PATH set by the main Makefile
199#
200KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
201KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
202# Avoid changing the rest of the logic here and lib.mk.
203INSTALL_PATH := $(KSFT_INSTALL_PATH)
204ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
205TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
206
207install: all
208ifdef INSTALL_PATH
209	@# Ask all targets to install their files
210	mkdir -p $(INSTALL_PATH)/kselftest
211	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
212	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
213	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
214	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
215	rm -f $(TEST_LIST)
216	@ret=1;	\
217	for TARGET in $(TARGETS); do \
218		BUILD_TARGET=$$BUILD/$$TARGET;	\
219		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
220				O=$(abs_objtree)		\
221				$(if $(FORCE_TARGETS),|| exit);	\
222		ret=$$((ret * $$?));		\
223	done; exit $$ret;
224
225
226	@# Ask all targets to emit their test scripts
227	@# While building kselftest-list.text skip also non-existent TARGET dirs:
228	@# they could be the result of a build failure and should NOT be
229	@# included in the generated runlist.
230	for TARGET in $(TARGETS); do \
231		BUILD_TARGET=$$BUILD/$$TARGET;	\
232		[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
233		echo -ne "Emit Tests for $$TARGET\n"; \
234		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
235			-C $$TARGET emit_tests >> $(TEST_LIST); \
236	done;
237else
238	$(error Error: set INSTALL_PATH to use install)
239endif
240
241FORMAT ?= .gz
242TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
243gen_tar: install
244	@mkdir -p ${INSTALL_PATH}/kselftest-packages/
245	@tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
246	@echo "Created ${TAR_PATH}"
247
248clean:
249	@for TARGET in $(TARGETS); do \
250		BUILD_TARGET=$$BUILD/$$TARGET;	\
251		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
252	done;
253
254.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar
255