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