xref: /openbmc/linux/tools/testing/selftests/Makefile (revision d9fd5a71)
1# SPDX-License-Identifier: GPL-2.0
2TARGETS = arm64
3TARGETS += bpf
4TARGETS += breakpoints
5TARGETS += capabilities
6TARGETS += cgroup
7TARGETS += clone3
8TARGETS += core
9TARGETS += cpufreq
10TARGETS += cpu-hotplug
11TARGETS += drivers/dma-buf
12TARGETS += efivarfs
13TARGETS += exec
14TARGETS += filesystems
15TARGETS += filesystems/binderfs
16TARGETS += filesystems/epoll
17TARGETS += firmware
18TARGETS += fpu
19TARGETS += ftrace
20TARGETS += futex
21TARGETS += gpio
22TARGETS += intel_pstate
23TARGETS += ipc
24TARGETS += ir
25TARGETS += kcmp
26TARGETS += kexec
27TARGETS += kvm
28TARGETS += lib
29TARGETS += livepatch
30TARGETS += lkdtm
31TARGETS += membarrier
32TARGETS += memfd
33TARGETS += memory-hotplug
34TARGETS += mincore
35TARGETS += mount
36TARGETS += mqueue
37TARGETS += nci
38TARGETS += net
39TARGETS += net/forwarding
40TARGETS += net/mptcp
41TARGETS += netfilter
42TARGETS += nsfs
43TARGETS += pidfd
44TARGETS += pid_namespace
45TARGETS += powerpc
46TARGETS += proc
47TARGETS += pstore
48TARGETS += ptrace
49TARGETS += openat2
50TARGETS += rseq
51TARGETS += rtc
52TARGETS += seccomp
53TARGETS += sgx
54TARGETS += sigaltstack
55TARGETS += size
56TARGETS += sparc64
57TARGETS += splice
58TARGETS += static_keys
59TARGETS += sync
60TARGETS += syscall_user_dispatch
61TARGETS += sysctl
62TARGETS += tc-testing
63TARGETS += timens
64ifneq (1, $(quicktest))
65TARGETS += timers
66endif
67TARGETS += tmpfs
68TARGETS += tpm2
69TARGETS += user
70TARGETS += vDSO
71TARGETS += vm
72TARGETS += x86
73TARGETS += zram
74#Please keep the TARGETS list alphabetically sorted
75# Run "make quicktest=1 run_tests" or
76# "make quicktest=1 kselftest" from top level Makefile
77
78TARGETS_HOTPLUG = cpu-hotplug
79TARGETS_HOTPLUG += memory-hotplug
80
81# User can optionally provide a TARGETS skiplist.  By default we skip
82# BPF since it has cutting edge build time dependencies which require
83# more effort to install.
84SKIP_TARGETS ?= bpf
85ifneq ($(SKIP_TARGETS),)
86	TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
87	override TARGETS := $(TMP)
88endif
89
90# User can set FORCE_TARGETS to 1 to require all targets to be successfully
91# built; make will fail if any of the targets cannot be built. If
92# FORCE_TARGETS is not set (the default), make will succeed if at least one
93# of the targets gets built.
94FORCE_TARGETS ?=
95
96# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
97# implicit rules to sub-test Makefiles which avoids build failures in test
98# Makefile that don't have explicit build rules.
99ifeq (,$(LINK.c))
100override LDFLAGS =
101override MAKEFLAGS =
102endif
103
104# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
105# KBUILD_OUTPUT with selftest objects and headers installed
106# by selftests Makefile or lib.mk.
107ifdef building_out_of_srctree
108override LDFLAGS =
109endif
110
111ifneq ($(O),)
112	BUILD := $(O)/kselftest
113else
114	ifneq ($(KBUILD_OUTPUT),)
115		BUILD := $(KBUILD_OUTPUT)/kselftest
116	else
117		BUILD := $(shell pwd)
118		DEFAULT_INSTALL_HDR_PATH := 1
119	endif
120endif
121
122# Prepare for headers install
123top_srcdir ?= ../../..
124include $(top_srcdir)/scripts/subarch.include
125ARCH           ?= $(SUBARCH)
126export KSFT_KHDR_INSTALL_DONE := 1
127export BUILD
128
129# set default goal to all, so make without a target runs all, even when
130# all isn't the first target in the file.
131.DEFAULT_GOAL := all
132
133# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
134# is used to avoid running headers_install from lib.mk.
135# Invoke headers install with --no-builtin-rules to avoid circular
136# dependency in "make kselftest" case. In this case, second level
137# make inherits builtin-rules which will use the rule generate
138# Makefile.o and runs into
139# "Circular Makefile.o <- prepare dependency dropped."
140# and headers_install fails and test compile fails.
141#
142# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
143# invokes them as sub-makes and --no-builtin-rules is not necessary,
144# but doesn't cause any failures. Keep it simple and use the same
145# flags in both cases.
146# Local build cases: "make kselftest", "make -C" - headers are installed
147# in the default INSTALL_HDR_PATH usr/include.
148khdr:
149ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
150	$(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
151else
152	$(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
153		ARCH=$(ARCH) -C $(top_srcdir) headers_install
154endif
155
156all: khdr
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				$(if $(FORCE_TARGETS),|| exit);	\
163		ret=$$((ret * $$?));				\
164	done; exit $$ret;
165
166run_tests: all
167	@for TARGET in $(TARGETS); do \
168		BUILD_TARGET=$$BUILD/$$TARGET;	\
169		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
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				$(if $(FORCE_TARGETS),|| exit);	\
221		ret=$$((ret * $$?));		\
222	done; exit $$ret;
223
224
225	@# Ask all targets to emit their test scripts
226	@# While building kselftest-list.text skip also non-existent TARGET dirs:
227	@# they could be the result of a build failure and should NOT be
228	@# included in the generated runlist.
229	for TARGET in $(TARGETS); do \
230		BUILD_TARGET=$$BUILD/$$TARGET;	\
231		[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
232		echo -n "Emit Tests for $$TARGET\n"; \
233		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
234			-C $$TARGET emit_tests >> $(TEST_LIST); \
235	done;
236else
237	$(error Error: set INSTALL_PATH to use install)
238endif
239
240FORMAT ?= .gz
241TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
242gen_tar: install
243	@mkdir -p ${INSTALL_PATH}/kselftest-packages/
244	@tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
245	@echo "Created ${TAR_PATH}"
246
247clean:
248	@for TARGET in $(TARGETS); do \
249		BUILD_TARGET=$$BUILD/$$TARGET;	\
250		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
251	done;
252
253.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar
254