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