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