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