Merge tag 'zynq-soc-for-v5.7' of https://github.com/Xilinx/linux-xlnx into arm/soc
[linux-block.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 += 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 += ftrace
19 TARGETS += futex
20 TARGETS += gpio
21 TARGETS += intel_pstate
22 TARGETS += ipc
23 TARGETS += ir
24 TARGETS += kcmp
25 TARGETS += kexec
26 TARGETS += kvm
27 TARGETS += lib
28 TARGETS += livepatch
29 TARGETS += lkdtm
30 TARGETS += membarrier
31 TARGETS += memfd
32 TARGETS += memory-hotplug
33 TARGETS += mount
34 TARGETS += mqueue
35 TARGETS += net
36 TARGETS += net/mptcp
37 TARGETS += netfilter
38 TARGETS += networking/timestamping
39 TARGETS += nsfs
40 TARGETS += pidfd
41 TARGETS += powerpc
42 TARGETS += proc
43 TARGETS += pstore
44 TARGETS += ptrace
45 TARGETS += openat2
46 TARGETS += rseq
47 TARGETS += rtc
48 TARGETS += seccomp
49 TARGETS += sigaltstack
50 TARGETS += size
51 TARGETS += sparc64
52 TARGETS += splice
53 TARGETS += static_keys
54 TARGETS += sync
55 TARGETS += sysctl
56 TARGETS += timens
57 ifneq (1, $(quicktest))
58 TARGETS += timers
59 endif
60 TARGETS += tmpfs
61 TARGETS += tpm2
62 TARGETS += user
63 TARGETS += vm
64 TARGETS += x86
65 TARGETS += zram
66 #Please keep the TARGETS list alphabetically sorted
67 # Run "make quicktest=1 run_tests" or
68 # "make quicktest=1 kselftest" from top level Makefile
69
70 TARGETS_HOTPLUG = cpu-hotplug
71 TARGETS_HOTPLUG += memory-hotplug
72
73 # User can optionally provide a TARGETS skiplist.
74 SKIP_TARGETS ?=
75 ifneq ($(SKIP_TARGETS),)
76         TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
77         override TARGETS := $(TMP)
78 endif
79
80 # User can set FORCE_TARGETS to 1 to require all targets to be successfully
81 # built; make will fail if any of the targets cannot be built. If
82 # FORCE_TARGETS is not set (the default), make will succeed if at least one
83 # of the targets gets built.
84 FORCE_TARGETS ?=
85
86 # Clear LDFLAGS and MAKEFLAGS if called from main
87 # Makefile to avoid test build failures when test
88 # Makefile doesn't have explicit build rules.
89 ifeq (1,$(MAKELEVEL))
90 override LDFLAGS =
91 override MAKEFLAGS =
92 endif
93
94 # Append kselftest to KBUILD_OUTPUT to avoid cluttering
95 # KBUILD_OUTPUT with selftest objects and headers installed
96 # by selftests Makefile or lib.mk.
97 ifdef building_out_of_srctree
98 override LDFLAGS =
99 endif
100
101 ifneq ($(O),)
102         BUILD := $(O)
103 else
104         ifneq ($(KBUILD_OUTPUT),)
105                 BUILD := $(KBUILD_OUTPUT)/kselftest
106         else
107                 BUILD := $(shell pwd)
108                 DEFAULT_INSTALL_HDR_PATH := 1
109         endif
110 endif
111
112 # Prepare for headers install
113 top_srcdir ?= ../../..
114 include $(top_srcdir)/scripts/subarch.include
115 ARCH           ?= $(SUBARCH)
116 export KSFT_KHDR_INSTALL_DONE := 1
117 export BUILD
118
119 # build and run gpio when output directory is the src dir.
120 # gpio has dependency on tools/gpio and builds tools/gpio
121 # objects in the src directory in all cases making the src
122 # repo dirty even when objects are relocated.
123 ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
124         TMP := $(filter-out gpio, $(TARGETS))
125         TARGETS := $(TMP)
126 endif
127
128 # set default goal to all, so make without a target runs all, even when
129 # all isn't the first target in the file.
130 .DEFAULT_GOAL := all
131
132 # Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
133 # is used to avoid running headers_install from lib.mk.
134 # Invoke headers install with --no-builtin-rules to avoid circular
135 # dependency in "make kselftest" case. In this case, second level
136 # make inherits builtin-rules which will use the rule generate
137 # Makefile.o and runs into
138 # "Circular Makefile.o <- prepare dependency dropped."
139 # and headers_install fails and test compile fails.
140 #
141 # O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
142 # invokes them as sub-makes and --no-builtin-rules is not necessary,
143 # but doesn't cause any failures. Keep it simple and use the same
144 # flags in both cases.
145 # Local build cases: "make kselftest", "make -C" - headers are installed
146 # in the default INSTALL_HDR_PATH usr/include.
147 khdr:
148 ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
149         $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
150 else
151         $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
152                 ARCH=$(ARCH) -C $(top_srcdir) headers_install
153 endif
154
155 all: khdr
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                                 $(if $(FORCE_TARGETS),|| exit); \
162                 ret=$$((ret * $$?));                            \
163         done; exit $$ret;
164
165 run_tests: all
166         @for TARGET in $(TARGETS); do \
167                 BUILD_TARGET=$$BUILD/$$TARGET;  \
168                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
169         done;
170
171 hotplug:
172         @for TARGET in $(TARGETS_HOTPLUG); do \
173                 BUILD_TARGET=$$BUILD/$$TARGET;  \
174                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
175         done;
176
177 run_hotplug: hotplug
178         @for TARGET in $(TARGETS_HOTPLUG); do \
179                 BUILD_TARGET=$$BUILD/$$TARGET;  \
180                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
181         done;
182
183 clean_hotplug:
184         @for TARGET in $(TARGETS_HOTPLUG); do \
185                 BUILD_TARGET=$$BUILD/$$TARGET;  \
186                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
187         done;
188
189 run_pstore_crash:
190         $(MAKE) -C pstore run_crash
191
192 # Use $BUILD as the default install root. $BUILD points to the
193 # right output location for the following cases:
194 # 1. output_dir=kernel_src
195 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
196 # 3. a separate output directory is specified using KBUILD_OUTPUT
197 # Avoid conflict with INSTALL_PATH set by the main Makefile
198 #
199 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
200 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
201 # Avoid changing the rest of the logic here and lib.mk.
202 INSTALL_PATH := $(KSFT_INSTALL_PATH)
203 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
204
205 install: all
206 ifdef INSTALL_PATH
207         @# Ask all targets to install their files
208         mkdir -p $(INSTALL_PATH)/kselftest
209         install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
210         install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
211         install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
212         @ret=1; \
213         for TARGET in $(TARGETS); do \
214                 BUILD_TARGET=$$BUILD/$$TARGET;  \
215                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
216                                 $(if $(FORCE_TARGETS),|| exit); \
217                 ret=$$((ret * $$?));            \
218         done; exit $$ret;
219
220         @# Ask all targets to emit their test scripts
221         echo "#!/bin/sh" > $(ALL_SCRIPT)
222         echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
223         echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
224         echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
225         echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
226         echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
227         echo "  logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
228         echo "  cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
229         echo "fi" >> $(ALL_SCRIPT)
230
231         @# While building run_kselftest.sh 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 "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
238                 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
239                 echo -n "run_many" >> $(ALL_SCRIPT); \
240                 echo -n "Emit Tests for $$TARGET\n"; \
241                 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
242                 echo "" >> $(ALL_SCRIPT);           \
243                 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
244         done;
245
246         chmod u+x $(ALL_SCRIPT)
247 else
248         $(error Error: set INSTALL_PATH to use install)
249 endif
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