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