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