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