hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/tools/testing/selftests/Makefile
....@@ -1,35 +1,53 @@
11 # SPDX-License-Identifier: GPL-2.0
22 TARGETS = android
3
+TARGETS += arm64
34 TARGETS += bpf
45 TARGETS += breakpoints
56 TARGETS += capabilities
67 TARGETS += cgroup
8
+TARGETS += clone3
9
+TARGETS += core
710 TARGETS += cpufreq
811 TARGETS += cpu-hotplug
12
+TARGETS += damon
13
+TARGETS += drivers/dma-buf
914 TARGETS += efivarfs
1015 TARGETS += exec
1116 TARGETS += filesystems
17
+TARGETS += filesystems/binderfs
18
+TARGETS += filesystems/epoll
1219 TARGETS += firmware
20
+TARGETS += fpu
1321 TARGETS += ftrace
1422 TARGETS += futex
1523 TARGETS += gpio
1624 TARGETS += intel_pstate
1725 TARGETS += ipc
26
+TARGETS += ir
1827 TARGETS += kcmp
28
+TARGETS += kexec
1929 TARGETS += kvm
2030 TARGETS += lib
31
+TARGETS += livepatch
32
+TARGETS += lkdtm
2133 TARGETS += membarrier
2234 TARGETS += memfd
2335 TARGETS += memory-hotplug
36
+TARGETS += mincore
2437 TARGETS += mount
2538 TARGETS += mqueue
2639 TARGETS += net
40
+TARGETS += net/forwarding
41
+TARGETS += net/mptcp
2742 TARGETS += netfilter
2843 TARGETS += nsfs
44
+TARGETS += pidfd
45
+TARGETS += pid_namespace
2946 TARGETS += powerpc
3047 TARGETS += proc
3148 TARGETS += pstore
3249 TARGETS += ptrace
50
+TARGETS += openat2
3351 TARGETS += rseq
3452 TARGETS += rtc
3553 TARGETS += seccomp
....@@ -40,9 +58,13 @@
4058 TARGETS += static_keys
4159 TARGETS += sync
4260 TARGETS += sysctl
61
+TARGETS += tc-testing
62
+TARGETS += timens
4363 ifneq (1, $(quicktest))
4464 TARGETS += timers
4565 endif
66
+TARGETS += tmpfs
67
+TARGETS += tpm2
4668 TARGETS += user
4769 TARGETS += vm
4870 TARGETS += x86
....@@ -54,114 +76,183 @@
5476 TARGETS_HOTPLUG = cpu-hotplug
5577 TARGETS_HOTPLUG += memory-hotplug
5678
57
-# Clear LDFLAGS and MAKEFLAGS if called from main
58
-# Makefile to avoid test build failures when test
59
-# Makefile doesn't have explicit build rules.
60
-ifeq (1,$(MAKELEVEL))
79
+# User can optionally provide a TARGETS skiplist.
80
+SKIP_TARGETS ?=
81
+ifneq ($(SKIP_TARGETS),)
82
+ TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
83
+ override TARGETS := $(TMP)
84
+endif
85
+
86
+# User can set FORCE_TARGETS to 1 to require all targets to be successfully
87
+# built; make will fail if any of the targets cannot be built. If
88
+# FORCE_TARGETS is not set (the default), make will succeed if at least one
89
+# of the targets gets built.
90
+FORCE_TARGETS ?=
91
+
92
+# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
93
+# implicit rules to sub-test Makefiles which avoids build failures in test
94
+# Makefile that don't have explicit build rules.
95
+ifeq (,$(LINK.c))
6196 override LDFLAGS =
6297 override MAKEFLAGS =
6398 endif
6499
65
-ifneq ($(KBUILD_SRC),)
100
+# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
101
+# KBUILD_OUTPUT with selftest objects and headers installed
102
+# by selftests Makefile or lib.mk.
103
+ifdef building_out_of_srctree
66104 override LDFLAGS =
67105 endif
68106
69
-BUILD := $(O)
70
-ifndef BUILD
71
- BUILD := $(KBUILD_OUTPUT)
72
-endif
73
-ifndef BUILD
74
- BUILD := $(shell pwd)
107
+ifneq ($(O),)
108
+ BUILD := $(O)/kselftest
109
+else
110
+ ifneq ($(KBUILD_OUTPUT),)
111
+ BUILD := $(KBUILD_OUTPUT)/kselftest
112
+ else
113
+ BUILD := $(shell pwd)
114
+ DEFAULT_INSTALL_HDR_PATH := 1
115
+ endif
75116 endif
76117
77
-# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header
78
-# printing from tests. Applicable to run_tests case where run_tests adds
79
-# TAP header prior running tests and when a test program invokes another
80
-# with system() call. Export it here to cover override RUN_TESTS defines.
81
-export KSFT_TAP_LEVEL=`echo 1`
82
-
118
+# Prepare for headers install
119
+top_srcdir ?= ../../..
120
+include $(top_srcdir)/scripts/subarch.include
121
+ARCH ?= $(SUBARCH)
122
+export KSFT_KHDR_INSTALL_DONE := 1
83123 export BUILD
84
-all:
85
- @for TARGET in $(TARGETS); do \
86
- BUILD_TARGET=$$BUILD/$$TARGET; \
87
- mkdir $$BUILD_TARGET -p; \
88
- make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
89
- done;
124
+
125
+# build and run gpio when output directory is the src dir.
126
+# gpio has dependency on tools/gpio and builds tools/gpio
127
+# objects in the src directory in all cases making the src
128
+# repo dirty even when objects are relocated.
129
+ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
130
+ TMP := $(filter-out gpio, $(TARGETS))
131
+ TARGETS := $(TMP)
132
+endif
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;
90170
91171 run_tests: all
92172 @for TARGET in $(TARGETS); do \
93173 BUILD_TARGET=$$BUILD/$$TARGET; \
94
- make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
174
+ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
95175 done;
96176
97177 hotplug:
98178 @for TARGET in $(TARGETS_HOTPLUG); do \
99179 BUILD_TARGET=$$BUILD/$$TARGET; \
100
- make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
180
+ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
101181 done;
102182
103183 run_hotplug: hotplug
104184 @for TARGET in $(TARGETS_HOTPLUG); do \
105185 BUILD_TARGET=$$BUILD/$$TARGET; \
106
- make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
186
+ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
107187 done;
108188
109189 clean_hotplug:
110190 @for TARGET in $(TARGETS_HOTPLUG); do \
111191 BUILD_TARGET=$$BUILD/$$TARGET; \
112
- make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
192
+ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
113193 done;
114194
115195 run_pstore_crash:
116
- make -C pstore run_crash
196
+ $(MAKE) -C pstore run_crash
117197
118
-INSTALL_PATH ?= install
119
-INSTALL_PATH := $(abspath $(INSTALL_PATH))
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)
120209 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
210
+TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
121211
122
-install:
212
+install: all
123213 ifdef INSTALL_PATH
124214 @# Ask all targets to install their files
125
- mkdir -p $(INSTALL_PATH)
126
- @for TARGET in $(TARGETS); do \
127
- BUILD_TARGET=$$BUILD/$$TARGET; \
128
- make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
129
- done;
130
-
131
- @# Ask all targets to emit their test scripts
132
- echo "#!/bin/sh" > $(ALL_SCRIPT)
133
- echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
134
- echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
135
- echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
136
- echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
137
- echo " OUTPUT=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
138
- echo " cat /dev/null > \$$OUTPUT" >> $(ALL_SCRIPT)
139
- echo "else" >> $(ALL_SCRIPT)
140
- echo " OUTPUT=/dev/stdout" >> $(ALL_SCRIPT)
141
- echo "fi" >> $(ALL_SCRIPT)
142
- echo "export KSFT_TAP_LEVEL=1" >> $(ALL_SCRIPT)
143
- echo "export skip=4" >> $(ALL_SCRIPT)
144
-
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; \
145222 for TARGET in $(TARGETS); do \
146223 BUILD_TARGET=$$BUILD/$$TARGET; \
147
- echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT); \
148
- echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
149
- echo "echo ========================================" >> $(ALL_SCRIPT); \
150
- echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
151
- echo "cd $$TARGET" >> $(ALL_SCRIPT); \
152
- make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
153
- echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
154
- done;
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;
155228
156
- chmod u+x $(ALL_SCRIPT)
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;
157241 else
158242 $(error Error: set INSTALL_PATH to use install)
159243 endif
160244
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
+
161252 clean:
162253 @for TARGET in $(TARGETS); do \
163254 BUILD_TARGET=$$BUILD/$$TARGET; \
164
- make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
255
+ $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
165256 done;
166257
167
-.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean
258
+.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar