Loading...
1# SPDX-License-Identifier: GPL-2.0
2TARGETS += alsa
3TARGETS += amd-pstate
4TARGETS += arm64
5TARGETS += bpf
6TARGETS += breakpoints
7TARGETS += capabilities
8TARGETS += cgroup
9TARGETS += clone3
10TARGETS += core
11TARGETS += cpufreq
12TARGETS += cpu-hotplug
13TARGETS += damon
14TARGETS += drivers/dma-buf
15TARGETS += drivers/s390x/uvdevice
16TARGETS += drivers/net/bonding
17TARGETS += drivers/net/team
18TARGETS += efivarfs
19TARGETS += exec
20TARGETS += filesystems
21TARGETS += filesystems/binderfs
22TARGETS += filesystems/epoll
23TARGETS += filesystems/fat
24TARGETS += firmware
25TARGETS += fpu
26TARGETS += ftrace
27TARGETS += futex
28TARGETS += gpio
29TARGETS += intel_pstate
30TARGETS += iommu
31TARGETS += ipc
32TARGETS += ir
33TARGETS += kcmp
34TARGETS += kexec
35TARGETS += kvm
36TARGETS += landlock
37TARGETS += lib
38TARGETS += livepatch
39TARGETS += lkdtm
40TARGETS += membarrier
41TARGETS += memfd
42TARGETS += memory-hotplug
43TARGETS += mincore
44TARGETS += mount
45TARGETS += mount_setattr
46TARGETS += move_mount_set_group
47TARGETS += mqueue
48TARGETS += nci
49TARGETS += net
50TARGETS += net/af_unix
51TARGETS += net/forwarding
52TARGETS += net/hsr
53TARGETS += net/mptcp
54TARGETS += net/openvswitch
55TARGETS += netfilter
56TARGETS += nsfs
57TARGETS += pidfd
58TARGETS += pid_namespace
59TARGETS += powerpc
60TARGETS += proc
61TARGETS += pstore
62TARGETS += ptrace
63TARGETS += openat2
64TARGETS += resctrl
65TARGETS += rlimits
66TARGETS += rseq
67TARGETS += rtc
68TARGETS += seccomp
69TARGETS += sgx
70TARGETS += sigaltstack
71TARGETS += size
72TARGETS += sparc64
73TARGETS += splice
74TARGETS += static_keys
75TARGETS += sync
76TARGETS += syscall_user_dispatch
77TARGETS += sysctl
78TARGETS += tc-testing
79TARGETS += tdx
80TARGETS += timens
81ifneq (1, $(quicktest))
82TARGETS += timers
83endif
84TARGETS += tmpfs
85TARGETS += tpm2
86TARGETS += user
87TARGETS += vDSO
88TARGETS += vm
89TARGETS += x86
90TARGETS += zram
91#Please keep the TARGETS list alphabetically sorted
92# Run "make quicktest=1 run_tests" or
93# "make quicktest=1 kselftest" from top level Makefile
94
95TARGETS_HOTPLUG = cpu-hotplug
96TARGETS_HOTPLUG += memory-hotplug
97
98# User can optionally provide a TARGETS skiplist. By default we skip
99# BPF since it has cutting edge build time dependencies which require
100# more effort to install.
101SKIP_TARGETS ?= bpf
102ifneq ($(SKIP_TARGETS),)
103 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
104 override TARGETS := $(TMP)
105endif
106
107# User can set FORCE_TARGETS to 1 to require all targets to be successfully
108# built; make will fail if any of the targets cannot be built. If
109# FORCE_TARGETS is not set (the default), make will succeed if at least one
110# of the targets gets built.
111FORCE_TARGETS ?=
112
113# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
114# implicit rules to sub-test Makefiles which avoids build failures in test
115# Makefile that don't have explicit build rules.
116ifeq (,$(LINK.c))
117override LDFLAGS =
118override MAKEFLAGS =
119endif
120
121# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
122# KBUILD_OUTPUT with selftest objects and headers installed
123# by selftests Makefile or lib.mk.
124ifdef building_out_of_srctree
125override LDFLAGS =
126endif
127
128top_srcdir ?= ../../..
129
130ifeq ("$(origin O)", "command line")
131 KBUILD_OUTPUT := $(O)
132endif
133
134ifneq ($(KBUILD_OUTPUT),)
135 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
136 # expand a shell special character '~'. We use a somewhat tedious way here.
137 abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
138 $(if $(abs_objtree),, \
139 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
140 # $(realpath ...) resolves symlinks
141 abs_objtree := $(realpath $(abs_objtree))
142 BUILD := $(abs_objtree)/kselftest
143 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
144else
145 BUILD := $(CURDIR)
146 abs_srctree := $(shell cd $(top_srcdir) && pwd)
147 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
148 DEFAULT_INSTALL_HDR_PATH := 1
149endif
150
151# Prepare for headers install
152include $(top_srcdir)/scripts/subarch.include
153ARCH ?= $(SUBARCH)
154export BUILD
155export KHDR_INCLUDES
156
157# set default goal to all, so make without a target runs all, even when
158# all isn't the first target in the file.
159.DEFAULT_GOAL := all
160
161all:
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 O=$(abs_objtree) \
168 $(if $(FORCE_TARGETS),|| exit); \
169 ret=$$((ret * $$?)); \
170 done; exit $$ret;
171
172run_tests: all
173 @for TARGET in $(TARGETS); do \
174 BUILD_TARGET=$$BUILD/$$TARGET; \
175 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
176 O=$(abs_objtree); \
177 done;
178
179hotplug:
180 @for TARGET in $(TARGETS_HOTPLUG); do \
181 BUILD_TARGET=$$BUILD/$$TARGET; \
182 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
183 done;
184
185run_hotplug: hotplug
186 @for TARGET in $(TARGETS_HOTPLUG); do \
187 BUILD_TARGET=$$BUILD/$$TARGET; \
188 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
189 done;
190
191clean_hotplug:
192 @for TARGET in $(TARGETS_HOTPLUG); do \
193 BUILD_TARGET=$$BUILD/$$TARGET; \
194 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
195 done;
196
197run_pstore_crash:
198 $(MAKE) -C pstore run_crash
199
200# Use $BUILD as the default install root. $BUILD points to the
201# right output location for the following cases:
202# 1. output_dir=kernel_src
203# 2. a separate output directory is specified using O= KBUILD_OUTPUT
204# 3. a separate output directory is specified using KBUILD_OUTPUT
205# Avoid conflict with INSTALL_PATH set by the main Makefile
206#
207KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
208KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
209# Avoid changing the rest of the logic here and lib.mk.
210INSTALL_PATH := $(KSFT_INSTALL_PATH)
211ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
212TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
213
214install: all
215ifdef INSTALL_PATH
216 @# Ask all targets to install their files
217 mkdir -p $(INSTALL_PATH)/kselftest
218 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
219 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
220 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
221 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
222 rm -f $(TEST_LIST)
223 @ret=1; \
224 for TARGET in $(TARGETS); do \
225 BUILD_TARGET=$$BUILD/$$TARGET; \
226 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
227 O=$(abs_objtree) \
228 $(if $(FORCE_TARGETS),|| exit); \
229 ret=$$((ret * $$?)); \
230 done; exit $$ret;
231
232
233 @# Ask all targets to emit their test scripts
234 @# While building kselftest-list.text skip also non-existent TARGET dirs:
235 @# they could be the result of a build failure and should NOT be
236 @# included in the generated runlist.
237 for TARGET in $(TARGETS); do \
238 BUILD_TARGET=$$BUILD/$$TARGET; \
239 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
240 echo -ne "Emit Tests for $$TARGET\n"; \
241 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
242 -C $$TARGET emit_tests >> $(TEST_LIST); \
243 done;
244else
245 $(error Error: set INSTALL_PATH to use install)
246endif
247
248FORMAT ?= .gz
249TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
250gen_tar: install
251 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
252 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
253 @echo "Created ${TAR_PATH}"
254
255clean:
256 @for TARGET in $(TARGETS); do \
257 BUILD_TARGET=$$BUILD/$$TARGET; \
258 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
259 done;
260
261.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar
1# SPDX-License-Identifier: GPL-2.0
2TARGETS += acct
3TARGETS += alsa
4TARGETS += amd-pstate
5TARGETS += arm64
6TARGETS += bpf
7TARGETS += breakpoints
8TARGETS += cachestat
9TARGETS += capabilities
10TARGETS += cgroup
11TARGETS += clone3
12TARGETS += connector
13TARGETS += core
14TARGETS += cpufreq
15TARGETS += cpu-hotplug
16TARGETS += damon
17TARGETS += devices/error_logs
18TARGETS += devices/probe
19TARGETS += dmabuf-heaps
20TARGETS += drivers/dma-buf
21TARGETS += drivers/s390x/uvdevice
22TARGETS += drivers/net
23TARGETS += drivers/net/bonding
24TARGETS += drivers/net/team
25TARGETS += drivers/net/virtio_net
26TARGETS += drivers/platform/x86/intel/ifs
27TARGETS += dt
28TARGETS += efivarfs
29TARGETS += exec
30TARGETS += fchmodat2
31TARGETS += filesystems
32TARGETS += filesystems/binderfs
33TARGETS += filesystems/epoll
34TARGETS += filesystems/fat
35TARGETS += filesystems/overlayfs
36TARGETS += filesystems/statmount
37TARGETS += firmware
38TARGETS += fpu
39TARGETS += ftrace
40TARGETS += futex
41TARGETS += gpio
42TARGETS += hid
43TARGETS += intel_pstate
44TARGETS += iommu
45TARGETS += ipc
46TARGETS += ir
47TARGETS += kcmp
48TARGETS += kexec
49TARGETS += kvm
50TARGETS += landlock
51TARGETS += lib
52TARGETS += livepatch
53TARGETS += lkdtm
54TARGETS += lsm
55TARGETS += membarrier
56TARGETS += memfd
57TARGETS += memory-hotplug
58TARGETS += mincore
59TARGETS += mount
60TARGETS += mount_setattr
61TARGETS += move_mount_set_group
62TARGETS += mqueue
63TARGETS += nci
64TARGETS += net
65TARGETS += net/af_unix
66TARGETS += net/forwarding
67TARGETS += net/hsr
68TARGETS += net/mptcp
69TARGETS += net/netfilter
70TARGETS += net/openvswitch
71TARGETS += net/packetdrill
72TARGETS += net/rds
73TARGETS += net/tcp_ao
74TARGETS += nsfs
75TARGETS += pcie_bwctrl
76TARGETS += perf_events
77TARGETS += pidfd
78TARGETS += pid_namespace
79TARGETS += power_supply
80TARGETS += powerpc
81TARGETS += prctl
82TARGETS += proc
83TARGETS += pstore
84TARGETS += ptrace
85TARGETS += openat2
86TARGETS += resctrl
87TARGETS += riscv
88TARGETS += rlimits
89TARGETS += rseq
90TARGETS += rtc
91TARGETS += rust
92TARGETS += sched_ext
93TARGETS += seccomp
94TARGETS += sgx
95TARGETS += signal
96TARGETS += size
97TARGETS += sparc64
98TARGETS += splice
99TARGETS += static_keys
100TARGETS += sync
101TARGETS += syscall_user_dispatch
102TARGETS += sysctl
103TARGETS += tc-testing
104TARGETS += tdx
105TARGETS += thermal/intel/power_floor
106TARGETS += thermal/intel/workload_hint
107TARGETS += timens
108ifneq (1, $(quicktest))
109TARGETS += timers
110endif
111TARGETS += tmpfs
112TARGETS += tpm2
113TARGETS += tty
114TARGETS += uevent
115TARGETS += user_events
116TARGETS += vDSO
117TARGETS += mm
118TARGETS += x86
119TARGETS += zram
120#Please keep the TARGETS list alphabetically sorted
121# Run "make quicktest=1 run_tests" or
122# "make quicktest=1 kselftest" from top level Makefile
123
124TARGETS_HOTPLUG = cpu-hotplug
125TARGETS_HOTPLUG += memory-hotplug
126
127# Networking tests want the net/lib target, include it automatically
128ifneq ($(filter net drivers/net drivers/net/hw,$(TARGETS)),)
129ifeq ($(filter net/lib,$(TARGETS)),)
130 INSTALL_DEP_TARGETS := net/lib
131endif
132endif
133
134# User can optionally provide a TARGETS skiplist. By default we skip
135# targets using BPF since it has cutting edge build time dependencies
136# which require more effort to install.
137SKIP_TARGETS ?= bpf sched_ext
138ifneq ($(SKIP_TARGETS),)
139 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
140 override TARGETS := $(TMP)
141endif
142
143# User can set FORCE_TARGETS to 1 to require all targets to be successfully
144# built; make will fail if any of the targets cannot be built. If
145# FORCE_TARGETS is not set (the default), make will succeed if at least one
146# of the targets gets built.
147FORCE_TARGETS ?=
148
149# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
150# implicit rules to sub-test Makefiles which avoids build failures in test
151# Makefile that don't have explicit build rules.
152ifeq (,$(LINK.c))
153override LDFLAGS =
154override MAKEFLAGS =
155endif
156
157# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
158# KBUILD_OUTPUT with selftest objects and headers installed
159# by selftests Makefile or lib.mk.
160ifdef building_out_of_srctree
161override LDFLAGS =
162endif
163
164top_srcdir ?= ../../..
165
166ifeq ("$(origin O)", "command line")
167 KBUILD_OUTPUT := $(O)
168endif
169
170ifneq ($(KBUILD_OUTPUT),)
171 # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
172 # expand a shell special character '~'. We use a somewhat tedious way here.
173 abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
174 $(if $(abs_objtree),, \
175 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
176 # $(realpath ...) resolves symlinks
177 abs_objtree := $(realpath $(abs_objtree))
178 BUILD := $(abs_objtree)/kselftest
179 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
180else
181 BUILD := $(CURDIR)
182 abs_srctree := $(shell cd $(top_srcdir) && pwd)
183 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
184 DEFAULT_INSTALL_HDR_PATH := 1
185endif
186
187# Prepare for headers install
188include $(top_srcdir)/scripts/subarch.include
189ARCH ?= $(SUBARCH)
190export BUILD
191export KHDR_INCLUDES
192
193# set default goal to all, so make without a target runs all, even when
194# all isn't the first target in the file.
195.DEFAULT_GOAL := all
196
197all:
198 @ret=1; \
199 for TARGET in $(TARGETS); do \
200 BUILD_TARGET=$$BUILD/$$TARGET; \
201 mkdir $$BUILD_TARGET -p; \
202 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
203 O=$(abs_objtree) \
204 $(if $(FORCE_TARGETS),|| exit); \
205 ret=$$((ret * $$?)); \
206 done; exit $$ret;
207
208run_tests: all
209 @for TARGET in $(TARGETS); do \
210 BUILD_TARGET=$$BUILD/$$TARGET; \
211 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
212 SRC_PATH=$(shell readlink -e $$(pwd)) \
213 OBJ_PATH=$(BUILD) \
214 O=$(abs_objtree); \
215 done;
216
217hotplug:
218 @for TARGET in $(TARGETS_HOTPLUG); do \
219 BUILD_TARGET=$$BUILD/$$TARGET; \
220 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
221 done;
222
223run_hotplug: hotplug
224 @for TARGET in $(TARGETS_HOTPLUG); do \
225 BUILD_TARGET=$$BUILD/$$TARGET; \
226 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
227 done;
228
229clean_hotplug:
230 @for TARGET in $(TARGETS_HOTPLUG); do \
231 BUILD_TARGET=$$BUILD/$$TARGET; \
232 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
233 done;
234
235run_pstore_crash:
236 $(MAKE) -C pstore run_crash
237
238# Use $BUILD as the default install root. $BUILD points to the
239# right output location for the following cases:
240# 1. output_dir=kernel_src
241# 2. a separate output directory is specified using O= KBUILD_OUTPUT
242# 3. a separate output directory is specified using KBUILD_OUTPUT
243# Avoid conflict with INSTALL_PATH set by the main Makefile
244#
245KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
246KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
247# Avoid changing the rest of the logic here and lib.mk.
248INSTALL_PATH := $(KSFT_INSTALL_PATH)
249ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
250TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
251
252install: all
253ifdef INSTALL_PATH
254 @# Ask all targets to install their files
255 mkdir -p $(INSTALL_PATH)/kselftest
256 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
257 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
258 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
259 install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/
260 install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/
261 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
262 rm -f $(TEST_LIST)
263 @ret=1; \
264 for TARGET in $(TARGETS) $(INSTALL_DEP_TARGETS); do \
265 BUILD_TARGET=$$BUILD/$$TARGET; \
266 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install \
267 INSTALL_PATH=$(INSTALL_PATH)/$$TARGET \
268 SRC_PATH=$(shell readlink -e $$(pwd)) \
269 OBJ_PATH=$(INSTALL_PATH) \
270 O=$(abs_objtree) \
271 $(if $(FORCE_TARGETS),|| exit); \
272 ret=$$((ret * $$?)); \
273 done; exit $$ret;
274
275
276 @# Ask all targets to emit their test scripts
277 @# While building kselftest-list.text skip also non-existent TARGET dirs:
278 @# they could be the result of a build failure and should NOT be
279 @# included in the generated runlist.
280 for TARGET in $(TARGETS); do \
281 BUILD_TARGET=$$BUILD/$$TARGET; \
282 [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
283 printf "Emit Tests for $$TARGET\n"; \
284 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
285 -C $$TARGET emit_tests >> $(TEST_LIST); \
286 done;
287else
288 $(error Error: set INSTALL_PATH to use install)
289endif
290
291FORMAT ?= .gz
292TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
293gen_tar: install
294 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
295 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
296 @echo "Created ${TAR_PATH}"
297
298clean:
299 @for TARGET in $(TARGETS); do \
300 BUILD_TARGET=$$BUILD/$$TARGET; \
301 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
302 done;
303
304.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar