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