Merge tag 'slab-for-6.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/vbabka...
[platform/kernel/linux-starfive.git] / tools / testing / selftests / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2 TARGETS += alsa
3 TARGETS += arm64
4 TARGETS += bpf
5 TARGETS += breakpoints
6 TARGETS += capabilities
7 TARGETS += cgroup
8 TARGETS += clone3
9 TARGETS += core
10 TARGETS += cpufreq
11 TARGETS += cpu-hotplug
12 TARGETS += damon
13 TARGETS += drivers/dma-buf
14 TARGETS += drivers/s390x/uvdevice
15 TARGETS += drivers/net/bonding
16 TARGETS += efivarfs
17 TARGETS += exec
18 TARGETS += filesystems
19 TARGETS += filesystems/binderfs
20 TARGETS += filesystems/epoll
21 TARGETS += filesystems/fat
22 TARGETS += firmware
23 TARGETS += fpu
24 TARGETS += ftrace
25 TARGETS += futex
26 TARGETS += gpio
27 TARGETS += intel_pstate
28 TARGETS += ipc
29 TARGETS += ir
30 TARGETS += kcmp
31 TARGETS += kexec
32 TARGETS += kvm
33 TARGETS += landlock
34 TARGETS += lib
35 TARGETS += livepatch
36 TARGETS += lkdtm
37 TARGETS += membarrier
38 TARGETS += memfd
39 TARGETS += memory-hotplug
40 TARGETS += mincore
41 TARGETS += mount
42 TARGETS += mount_setattr
43 TARGETS += move_mount_set_group
44 TARGETS += mqueue
45 TARGETS += nci
46 TARGETS += net
47 TARGETS += net/af_unix
48 TARGETS += net/forwarding
49 TARGETS += net/mptcp
50 TARGETS += netfilter
51 TARGETS += nsfs
52 TARGETS += pidfd
53 TARGETS += pid_namespace
54 TARGETS += powerpc
55 TARGETS += proc
56 TARGETS += pstore
57 TARGETS += ptrace
58 TARGETS += openat2
59 TARGETS += resctrl
60 TARGETS += rlimits
61 TARGETS += rseq
62 TARGETS += rtc
63 TARGETS += seccomp
64 TARGETS += sgx
65 TARGETS += sigaltstack
66 TARGETS += size
67 TARGETS += sparc64
68 TARGETS += splice
69 TARGETS += static_keys
70 TARGETS += sync
71 TARGETS += syscall_user_dispatch
72 TARGETS += sysctl
73 TARGETS += tc-testing
74 TARGETS += timens
75 ifneq (1, $(quicktest))
76 TARGETS += timers
77 endif
78 TARGETS += tmpfs
79 TARGETS += tpm2
80 TARGETS += user
81 TARGETS += vDSO
82 TARGETS += vm
83 TARGETS += x86
84 TARGETS += zram
85 #Please keep the TARGETS list alphabetically sorted
86 # Run "make quicktest=1 run_tests" or
87 # "make quicktest=1 kselftest" from top level Makefile
88
89 TARGETS_HOTPLUG = cpu-hotplug
90 TARGETS_HOTPLUG += memory-hotplug
91
92 # User can optionally provide a TARGETS skiplist.  By default we skip
93 # BPF since it has cutting edge build time dependencies which require
94 # more effort to install.
95 SKIP_TARGETS ?= bpf
96 ifneq ($(SKIP_TARGETS),)
97         TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
98         override TARGETS := $(TMP)
99 endif
100
101 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
102 # built; make will fail if any of the targets cannot be built. If
103 # FORCE_TARGETS is not set (the default), make will succeed if at least one
104 # of the targets gets built.
105 FORCE_TARGETS ?=
106
107 # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
108 # implicit rules to sub-test Makefiles which avoids build failures in test
109 # Makefile that don't have explicit build rules.
110 ifeq (,$(LINK.c))
111 override LDFLAGS =
112 override MAKEFLAGS =
113 endif
114
115 # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
116 # KBUILD_OUTPUT with selftest objects and headers installed
117 # by selftests Makefile or lib.mk.
118 ifdef building_out_of_srctree
119 override LDFLAGS =
120 endif
121
122 top_srcdir ?= ../../..
123
124 ifeq ("$(origin O)", "command line")
125   KBUILD_OUTPUT := $(O)
126 endif
127
128 ifneq ($(KBUILD_OUTPUT),)
129   # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
130   # expand a shell special character '~'. We use a somewhat tedious way here.
131   abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
132   $(if $(abs_objtree),, \
133     $(error failed to create output directory "$(KBUILD_OUTPUT)"))
134   # $(realpath ...) resolves symlinks
135   abs_objtree := $(realpath $(abs_objtree))
136   BUILD := $(abs_objtree)/kselftest
137   KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
138 else
139   BUILD := $(CURDIR)
140   abs_srctree := $(shell cd $(top_srcdir) && pwd)
141   KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
142   DEFAULT_INSTALL_HDR_PATH := 1
143 endif
144
145 # Prepare for headers install
146 include $(top_srcdir)/scripts/subarch.include
147 ARCH           ?= $(SUBARCH)
148 export BUILD
149 export KHDR_INCLUDES
150
151 # set default goal to all, so make without a target runs all, even when
152 # all isn't the first target in the file.
153 .DEFAULT_GOAL := all
154
155 all:
156         @ret=1;                                                 \
157         for TARGET in $(TARGETS); do                            \
158                 BUILD_TARGET=$$BUILD/$$TARGET;                  \
159                 mkdir $$BUILD_TARGET  -p;                       \
160                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET       \
161                                 O=$(abs_objtree)                \
162                                 $(if $(FORCE_TARGETS),|| exit); \
163                 ret=$$((ret * $$?));                            \
164         done; exit $$ret;
165
166 run_tests: all
167         @for TARGET in $(TARGETS); do \
168                 BUILD_TARGET=$$BUILD/$$TARGET;  \
169                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
170                                 O=$(abs_objtree);                   \
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                                 O=$(abs_objtree)                \
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 -ne "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: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar