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