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