Makefile 7.4 KB
Newer Older
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
T
Tom Murphy 已提交
11
TARGETS += drivers/dma-buf
12
TARGETS += efivarfs
13
TARGETS += exec
14
TARGETS += filesystems
15
TARGETS += filesystems/binderfs
H
Heiher 已提交
16
TARGETS += filesystems/epoll
17
TARGETS += firmware
18
TARGETS += fpu
19
TARGETS += ftrace
20
TARGETS += futex
21
TARGETS += gpio
22
TARGETS += intel_pstate
B
Bamvor Jian Zhang 已提交
23
TARGETS += ipc
24
TARGETS += ir
25
TARGETS += kcmp
26
TARGETS += kexec
27
TARGETS += kvm
28
TARGETS += landlock
K
Kees Cook 已提交
29
TARGETS += lib
30
TARGETS += livepatch
31
TARGETS += lkdtm
32
TARGETS += membarrier
33
TARGETS += memfd
34
TARGETS += memory-hotplug
35
TARGETS += mincore
36
TARGETS += mount
37
TARGETS += mount_setattr
38
TARGETS += move_mount_set_group
39
TARGETS += mqueue
B
Bongsu Jeon 已提交
40
TARGETS += nci
41
TARGETS += net
42
TARGETS += net/forwarding
43
TARGETS += net/mptcp
44
TARGETS += netfilter
45
TARGETS += nsfs
46
TARGETS += pidfd
47
TARGETS += pid_namespace
48
TARGETS += powerpc
A
Alexey Dobriyan 已提交
49
TARGETS += proc
50
TARGETS += pstore
51
TARGETS += ptrace
52
TARGETS += openat2
53
TARGETS += rlimits
54
TARGETS += rseq
55
TARGETS += rtc
K
Kees Cook 已提交
56
TARGETS += seccomp
57
TARGETS += sgx
58
TARGETS += sigaltstack
59
TARGETS += size
60
TARGETS += sparc64
61
TARGETS += splice
62
TARGETS += static_keys
63
TARGETS += sync
64
TARGETS += syscall_user_dispatch
65
TARGETS += sysctl
66
TARGETS += tc-testing
67
TARGETS += timens
S
Shuah Khan 已提交
68
ifneq (1, $(quicktest))
69
TARGETS += timers
S
Shuah Khan 已提交
70
endif
71
TARGETS += tmpfs
J
Jarkko Sakkinen 已提交
72
TARGETS += tpm2
73
TARGETS += user
74
TARGETS += vDSO
75
TARGETS += vm
76
TARGETS += x86
77
TARGETS += zram
78
#Please keep the TARGETS list alphabetically sorted
S
Shuah Khan 已提交
79
# Run "make quicktest=1 run_tests" or
80
# "make quicktest=1 kselftest" from top level Makefile
81

82 83 84
TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug

85 86 87 88
# User can optionally provide a TARGETS skiplist.  By default we skip
# BPF since it has cutting edge build time dependencies which require
# more effort to install.
SKIP_TARGETS ?= bpf
89 90 91 92 93
ifneq ($(SKIP_TARGETS),)
	TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
	override TARGETS := $(TMP)
endif

94 95 96 97 98 99
# User can set FORCE_TARGETS to 1 to require all targets to be successfully
# built; make will fail if any of the targets cannot be built. If
# FORCE_TARGETS is not set (the default), make will succeed if at least one
# of the targets gets built.
FORCE_TARGETS ?=

100 101 102 103
# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
# implicit rules to sub-test Makefiles which avoids build failures in test
# Makefile that don't have explicit build rules.
ifeq (,$(LINK.c))
104
override LDFLAGS =
105 106 107
override MAKEFLAGS =
endif

108
# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
109 110
# KBUILD_OUTPUT with selftest objects and headers installed
# by selftests Makefile or lib.mk.
111
ifdef building_out_of_srctree
112 113 114
override LDFLAGS =
endif

115
ifneq ($(O),)
116
	BUILD := $(O)/kselftest
117 118
else
	ifneq ($(KBUILD_OUTPUT),)
119
		BUILD := $(KBUILD_OUTPUT)/kselftest
120 121 122 123
	else
		BUILD := $(shell pwd)
		DEFAULT_INSTALL_HDR_PATH := 1
	endif
124 125
endif

126 127 128 129 130
# Prepare for headers install
top_srcdir ?= ../../..
include $(top_srcdir)/scripts/subarch.include
ARCH           ?= $(SUBARCH)
export KSFT_KHDR_INSTALL_DONE := 1
131
export BUILD
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

# set default goal to all, so make without a target runs all, even when
# all isn't the first target in the file.
.DEFAULT_GOAL := all

# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
# is used to avoid running headers_install from lib.mk.
# Invoke headers install with --no-builtin-rules to avoid circular
# dependency in "make kselftest" case. In this case, second level
# make inherits builtin-rules which will use the rule generate
# Makefile.o and runs into
# "Circular Makefile.o <- prepare dependency dropped."
# and headers_install fails and test compile fails.
#
# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
# invokes them as sub-makes and --no-builtin-rules is not necessary,
# but doesn't cause any failures. Keep it simple and use the same
# flags in both cases.
# Local build cases: "make kselftest", "make -C" - headers are installed
# in the default INSTALL_HDR_PATH usr/include.
khdr:
ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
154
	$(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
155
else
156
	$(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
157 158 159 160
		ARCH=$(ARCH) -C $(top_srcdir) headers_install
endif

all: khdr
161 162 163 164
	@ret=1;							\
	for TARGET in $(TARGETS); do				\
		BUILD_TARGET=$$BUILD/$$TARGET;			\
		mkdir $$BUILD_TARGET  -p;			\
165 166
		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET	\
				$(if $(FORCE_TARGETS),|| exit);	\
167 168
		ret=$$((ret * $$?));				\
	done; exit $$ret;
169

170
run_tests: all
171
	@for TARGET in $(TARGETS); do \
172
		BUILD_TARGET=$$BUILD/$$TARGET;	\
173
		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
174 175
	done;

176
hotplug:
177
	@for TARGET in $(TARGETS_HOTPLUG); do \
178
		BUILD_TARGET=$$BUILD/$$TARGET;	\
179
		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
180 181 182
	done;

run_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 187 188
	done;

clean_hotplug:
189
	@for TARGET in $(TARGETS_HOTPLUG); do \
190
		BUILD_TARGET=$$BUILD/$$TARGET;	\
191
		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
192 193
	done;

194
run_pstore_crash:
195
	$(MAKE) -C pstore run_crash
196

197 198 199 200 201
# Use $BUILD as the default install root. $BUILD points to the
# right output location for the following cases:
# 1. output_dir=kernel_src
# 2. a separate output directory is specified using O= KBUILD_OUTPUT
# 3. a separate output directory is specified using KBUILD_OUTPUT
202
# Avoid conflict with INSTALL_PATH set by the main Makefile
203
#
204 205 206 207
KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
# Avoid changing the rest of the logic here and lib.mk.
INSTALL_PATH := $(KSFT_INSTALL_PATH)
M
Michael Ellerman 已提交
208
ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
209
TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
M
Michael Ellerman 已提交
210

211
install: all
M
Michael Ellerman 已提交
212 213
ifdef INSTALL_PATH
	@# Ask all targets to install their files
214
	mkdir -p $(INSTALL_PATH)/kselftest
215
	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
216
	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
217
	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
218 219
	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
	rm -f $(TEST_LIST)
220 221
	@ret=1;	\
	for TARGET in $(TARGETS); do \
222
		BUILD_TARGET=$$BUILD/$$TARGET;	\
223 224
		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
				$(if $(FORCE_TARGETS),|| exit);	\
225 226
		ret=$$((ret * $$?));		\
	done; exit $$ret;
M
Michael Ellerman 已提交
227 228


229 230
	@# Ask all targets to emit their test scripts
	@# While building kselftest-list.text skip also non-existent TARGET dirs:
231 232
	@# they could be the result of a build failure and should NOT be
	@# included in the generated runlist.
M
Michael Ellerman 已提交
233
	for TARGET in $(TARGETS); do \
234
		BUILD_TARGET=$$BUILD/$$TARGET;	\
235
		[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
236
		echo -n "Emit Tests for $$TARGET\n"; \
237 238
		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
			-C $$TARGET emit_tests >> $(TEST_LIST); \
M
Michael Ellerman 已提交
239 240 241 242 243
	done;
else
	$(error Error: set INSTALL_PATH to use install)
endif

244 245 246 247 248 249 250
FORMAT ?= .gz
TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
gen_tar: install
	@mkdir -p ${INSTALL_PATH}/kselftest-packages/
	@tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
	@echo "Created ${TAR_PATH}"

251
clean:
252
	@for TARGET in $(TARGETS); do \
253
		BUILD_TARGET=$$BUILD/$$TARGET;	\
254
		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
255
	done;
M
Michael Ellerman 已提交
256

257
.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar