Loading...
1TARGETS = bpf
2TARGETS += breakpoints
3TARGETS += capabilities
4TARGETS += cpu-hotplug
5TARGETS += efivarfs
6TARGETS += exec
7TARGETS += firmware
8TARGETS += ftrace
9TARGETS += futex
10TARGETS += gpio
11TARGETS += ipc
12TARGETS += kcmp
13TARGETS += lib
14TARGETS += membarrier
15TARGETS += memfd
16TARGETS += memory-hotplug
17TARGETS += mount
18TARGETS += mqueue
19TARGETS += net
20TARGETS += nsfs
21TARGETS += powerpc
22TARGETS += pstore
23TARGETS += ptrace
24TARGETS += seccomp
25TARGETS += sigaltstack
26TARGETS += size
27TARGETS += static_keys
28TARGETS += sync
29TARGETS += sysctl
30ifneq (1, $(quicktest))
31TARGETS += timers
32endif
33TARGETS += user
34TARGETS += vm
35TARGETS += x86
36TARGETS += zram
37#Please keep the TARGETS list alphabetically sorted
38# Run "make quicktest=1 run_tests" or
39# "make quicktest=1 kselftest from top level Makefile
40
41TARGETS_HOTPLUG = cpu-hotplug
42TARGETS_HOTPLUG += memory-hotplug
43
44# Clear LDFLAGS and MAKEFLAGS if called from main
45# Makefile to avoid test build failures when test
46# Makefile doesn't have explicit build rules.
47ifeq (1,$(MAKELEVEL))
48override LDFLAGS =
49override MAKEFLAGS =
50endif
51
52all:
53 for TARGET in $(TARGETS); do \
54 make -C $$TARGET; \
55 done;
56
57run_tests: all
58 for TARGET in $(TARGETS); do \
59 make -C $$TARGET run_tests; \
60 done;
61
62hotplug:
63 for TARGET in $(TARGETS_HOTPLUG); do \
64 make -C $$TARGET; \
65 done;
66
67run_hotplug: hotplug
68 for TARGET in $(TARGETS_HOTPLUG); do \
69 make -C $$TARGET run_full_test; \
70 done;
71
72clean_hotplug:
73 for TARGET in $(TARGETS_HOTPLUG); do \
74 make -C $$TARGET clean; \
75 done;
76
77run_pstore_crash:
78 make -C pstore run_crash
79
80INSTALL_PATH ?= install
81INSTALL_PATH := $(abspath $(INSTALL_PATH))
82ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
83
84install:
85ifdef INSTALL_PATH
86 @# Ask all targets to install their files
87 mkdir -p $(INSTALL_PATH)
88 for TARGET in $(TARGETS); do \
89 make -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
90 done;
91
92 @# Ask all targets to emit their test scripts
93 echo "#!/bin/sh" > $(ALL_SCRIPT)
94 echo "cd \$$(dirname \$$0)" >> $(ALL_SCRIPT)
95 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
96
97 for TARGET in $(TARGETS); do \
98 echo "echo ; echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
99 echo "echo ========================================" >> $(ALL_SCRIPT); \
100 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
101 make -s --no-print-directory -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
102 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
103 done;
104
105 chmod u+x $(ALL_SCRIPT)
106else
107 $(error Error: set INSTALL_PATH to use install)
108endif
109
110clean:
111 for TARGET in $(TARGETS); do \
112 make -C $$TARGET clean; \
113 done;
114
115.PHONY: install
1# SPDX-License-Identifier: GPL-2.0
2TARGETS = android
3TARGETS += arm64
4TARGETS += bpf
5TARGETS += breakpoints
6TARGETS += capabilities
7TARGETS += cgroup
8TARGETS += clone3
9TARGETS += core
10TARGETS += cpufreq
11TARGETS += cpu-hotplug
12TARGETS += drivers/dma-buf
13TARGETS += efivarfs
14TARGETS += exec
15TARGETS += filesystems
16TARGETS += filesystems/binderfs
17TARGETS += filesystems/epoll
18TARGETS += firmware
19TARGETS += fpu
20TARGETS += ftrace
21TARGETS += futex
22TARGETS += gpio
23TARGETS += intel_pstate
24TARGETS += ipc
25TARGETS += ir
26TARGETS += kcmp
27TARGETS += kexec
28TARGETS += kvm
29TARGETS += lib
30TARGETS += livepatch
31TARGETS += lkdtm
32TARGETS += membarrier
33TARGETS += memfd
34TARGETS += memory-hotplug
35TARGETS += mincore
36TARGETS += mount
37TARGETS += mqueue
38TARGETS += net
39TARGETS += net/forwarding
40TARGETS += net/mptcp
41TARGETS += netfilter
42TARGETS += nsfs
43TARGETS += pidfd
44TARGETS += pid_namespace
45TARGETS += powerpc
46TARGETS += proc
47TARGETS += pstore
48TARGETS += ptrace
49TARGETS += openat2
50TARGETS += rseq
51TARGETS += rtc
52TARGETS += seccomp
53TARGETS += sigaltstack
54TARGETS += size
55TARGETS += sparc64
56TARGETS += splice
57TARGETS += static_keys
58TARGETS += sync
59TARGETS += sysctl
60TARGETS += tc-testing
61TARGETS += timens
62ifneq (1, $(quicktest))
63TARGETS += timers
64endif
65TARGETS += tmpfs
66TARGETS += tpm2
67TARGETS += user
68TARGETS += vm
69TARGETS += x86
70TARGETS += 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
75TARGETS_HOTPLUG = cpu-hotplug
76TARGETS_HOTPLUG += memory-hotplug
77
78# User can optionally provide a TARGETS skiplist.
79SKIP_TARGETS ?=
80ifneq ($(SKIP_TARGETS),)
81 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
82 override TARGETS := $(TMP)
83endif
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.
89FORCE_TARGETS ?=
90
91# Clear LDFLAGS and MAKEFLAGS if called from main
92# Makefile to avoid test build failures when test
93# Makefile doesn't have explicit build rules.
94ifeq (1,$(MAKELEVEL))
95override LDFLAGS =
96override MAKEFLAGS =
97endif
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.
102ifdef building_out_of_srctree
103override LDFLAGS =
104endif
105
106ifneq ($(O),)
107 BUILD := $(O)/kselftest
108else
109 ifneq ($(KBUILD_OUTPUT),)
110 BUILD := $(KBUILD_OUTPUT)/kselftest
111 else
112 BUILD := $(shell pwd)
113 DEFAULT_INSTALL_HDR_PATH := 1
114 endif
115endif
116
117# Prepare for headers install
118top_srcdir ?= ../../..
119include $(top_srcdir)/scripts/subarch.include
120ARCH ?= $(SUBARCH)
121export KSFT_KHDR_INSTALL_DONE := 1
122export 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.
128ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
129 TMP := $(filter-out gpio, $(TARGETS))
130 TARGETS := $(TMP)
131endif
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.
152khdr:
153ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
154 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
155else
156 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
157 ARCH=$(ARCH) -C $(top_srcdir) headers_install
158endif
159
160all: 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
170run_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
176hotplug:
177 @for TARGET in $(TARGETS_HOTPLUG); do \
178 BUILD_TARGET=$$BUILD/$$TARGET; \
179 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
180 done;
181
182run_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
188clean_hotplug:
189 @for TARGET in $(TARGETS_HOTPLUG); do \
190 BUILD_TARGET=$$BUILD/$$TARGET; \
191 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
192 done;
193
194run_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#
204KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
205KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
206# Avoid changing the rest of the logic here and lib.mk.
207INSTALL_PATH := $(KSFT_INSTALL_PATH)
208ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
209
210install: all
211ifdef INSTALL_PATH
212 @# Ask all targets to install their files
213 mkdir -p $(INSTALL_PATH)/kselftest
214 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
215 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
216 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
217 @ret=1; \
218 for TARGET in $(TARGETS); do \
219 BUILD_TARGET=$$BUILD/$$TARGET; \
220 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
221 $(if $(FORCE_TARGETS),|| exit); \
222 ret=$$((ret * $$?)); \
223 done; exit $$ret;
224
225 @# Ask all targets to emit their test scripts
226 echo "#!/bin/sh" > $(ALL_SCRIPT)
227 echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
228 echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
229 echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
230 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
231 echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
232 echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
233 echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
234 echo "fi" >> $(ALL_SCRIPT)
235
236 @# While building run_kselftest.sh skip also non-existent TARGET dirs:
237 @# they could be the result of a build failure and should NOT be
238 @# included in the generated runlist.
239 for TARGET in $(TARGETS); do \
240 BUILD_TARGET=$$BUILD/$$TARGET; \
241 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
242 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
243 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
244 echo -n "run_many" >> $(ALL_SCRIPT); \
245 echo -n "Emit Tests for $$TARGET\n"; \
246 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
247 echo "" >> $(ALL_SCRIPT); \
248 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
249 done;
250
251 chmod u+x $(ALL_SCRIPT)
252else
253 $(error Error: set INSTALL_PATH to use install)
254endif
255
256FORMAT ?= .gz
257TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
258gen_tar: install
259 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
260 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
261 @echo "Created ${TAR_PATH}"
262
263clean:
264 @for TARGET in $(TARGETS); do \
265 BUILD_TARGET=$$BUILD/$$TARGET; \
266 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
267 done;
268
269.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar