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