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