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