Blame view

tools/testing/selftests/Makefile 7.43 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  # SPDX-License-Identifier: GPL-2.0
47a18c42d   Pintu Agarwal   android/ion: user...
2
  TARGETS = android
313a4db7f   Cristian Marussi   kselftest: arm64:...
3
  TARGETS += arm64
47a18c42d   Pintu Agarwal   android/ion: user...
4
  TARGETS += bpf
5aa5bd14c   Daniel Borkmann   bpf: add initial ...
5
  TARGETS += breakpoints
f4ecb322a   Bamvor Jian Zhang   selftests/capabil...
6
  TARGETS += capabilities
84092dbcf   Roman Gushchin   selftests: cgroup...
7
  TARGETS += cgroup
de5287235   Christian Brauner   tests: test CLONE...
8
  TARGETS += clone3
2c5db60e4   Christian Brauner   tests: add close_...
9
  TARGETS += core
e66d5b673   Viresh Kumar   selftest: cpufreq...
10
  TARGETS += cpufreq
58c7be84f   Pavel Emelyanov   selftest: add sim...
11
  TARGETS += cpu-hotplug
6edf2e371   Tom Murphy   fix dma-buf/udmab...
12
  TARGETS += drivers/dma-buf
58c7be84f   Pavel Emelyanov   selftest: add sim...
13
  TARGETS += efivarfs
96e869d85   Andrew Morton   tools/testing/sel...
14
  TARGETS += exec
ce290a196   Christian Brauner   selftests: add de...
15
  TARGETS += filesystems
75abec73d   Christian Brauner   selftests: add bi...
16
  TARGETS += filesystems/binderfs
f2728fe80   Heiher   selftests: add ep...
17
  TARGETS += filesystems/epoll
96e869d85   Andrew Morton   tools/testing/sel...
18
  TARGETS += firmware
4185b3b92   Petteri Aimonen   selftests/fpu: Ad...
19
  TARGETS += fpu
96e869d85   Andrew Morton   tools/testing/sel...
20
  TARGETS += ftrace
ecac1a754   Darren Hart   selftests: Add fu...
21
  TARGETS += futex
22f6592b2   Bamvor Jian Zhang   selftest/gpio: ad...
22
  TARGETS += gpio
6320303fb   Stafford Horne   selftests: Add in...
23
  TARGETS += intel_pstate
7e7224738   Bamvor Jian Zhang   selftest/ipc: act...
24
  TARGETS += ipc
e55c884ea   Sean Young   media: rc: self t...
25
  TARGETS += ir
66a01b965   Andrew Morton   tools/testing/sel...
26
  TARGETS += kcmp
c3c0e8114   Mimi Zohar   selftests/kexec: ...
27
  TARGETS += kexec
783e9e512   Paolo Bonzini   kvm: selftests: a...
28
  TARGETS += kvm
317dc34ab   Kees Cook   selftests: run li...
29
  TARGETS += lib
a2818ee4d   Joe Lawrence   selftests/livepat...
30
  TARGETS += livepatch
46d1a0f03   Kees Cook   selftests/lkdtm: ...
31
  TARGETS += lkdtm
b6d973441   Pranith Kumar   selftests: add me...
32
  TARGETS += membarrier
4f5ce5e8d   David Herrmann   selftests: add me...
33
  TARGETS += memfd
58c7be84f   Pavel Emelyanov   selftest: add sim...
34
  TARGETS += memory-hotplug
7a309195d   Ricardo Cañuelo   selftests: add mi...
35
  TARGETS += mincore
db181ce01   Eric W. Biederman   mnt: Add tests fo...
36
  TARGETS += mount
96e869d85   Andrew Morton   tools/testing/sel...
37
  TARGETS += mqueue
a6f68034d   David S. Miller   net: Move selftes...
38
  TARGETS += net
81573b18f   Vadym Kochan   selftests/net/for...
39
  TARGETS += net/forwarding
048d19d44   Florian Westphal   mptcp: add basic ...
40
  TARGETS += net/mptcp
25d8bcedb   Florian Westphal   selftests: add sc...
41
  TARGETS += netfilter
6ad92bf63   Andrey Vagin   tools/testing: ad...
42
  TARGETS += nsfs
575a0ae97   Christian Brauner   selftests: add te...
43
  TARGETS += pidfd
6952a4f64   Christian Brauner   selftests: add pi...
44
  TARGETS += pid_namespace
96e869d85   Andrew Morton   tools/testing/sel...
45
  TARGETS += powerpc
9cd656555   Alexey Dobriyan   proc: test /proc/...
46
  TARGETS += proc
cc04a46f1   Hiraku Toyooka   selftests/pstore:...
47
  TARGETS += pstore
17afab1de   Andrey Vagin   selftest: add a t...
48
  TARGETS += ptrace
b28a10aed   Aleksa Sarai   selftests: add op...
49
  TARGETS += openat2
ccba8b644   Mathieu Desnoyers   rseq/selftests: P...
50
  TARGETS += rseq
a12ab9e12   Alexandre Belloni   selftests: move R...
51
  TARGETS += rtc
c99ee51a9   Kees Cook   selftests: add se...
52
  TARGETS += seccomp
19fd2868e   Stas Sergeev   selftests/sigalts...
53
  TARGETS += sigaltstack
96e869d85   Andrew Morton   tools/testing/sel...
54
  TARGETS += size
3c5450841   Tom Hromatka   selftests: sparc6...
55
  TARGETS += sparc64
b8826e506   Al Viro   selftest for defa...
56
  TARGETS += splice
1087d0191   Bamvor Jian Zhang   selftests: rename...
57
  TARGETS += static_keys
82208160a   Emilio López   selftest: sync: b...
58
  TARGETS += sync
96e869d85   Andrew Morton   tools/testing/sel...
59
  TARGETS += sysctl
2b9843fbe   Briana Oursler   tc-testing: Add t...
60
  TARGETS += tc-testing
61c576760   Dmitry Safonov   selftests/timens:...
61
  TARGETS += timens
2278e5ed9   Shuah Khan   selftests: add qu...
62
  ifneq (1, $(quicktest))
0bc4b0cf1   Frederic Weisbecker   selftests: add ba...
63
  TARGETS += timers
2278e5ed9   Shuah Khan   selftests: add qu...
64
  endif
a33228682   Alexey Dobriyan   tmpfs: test link ...
65
  TARGETS += tmpfs
6ea3dfe1e   Jarkko Sakkinen   selftests: add TP...
66
  TARGETS += tpm2
3e2a4c183   Kees Cook   test: check copy_...
67
  TARGETS += user
96e869d85   Andrew Morton   tools/testing/sel...
68
  TARGETS += vm
3f705dfdf   Andy Lutomirski   x86, selftests: A...
69
  TARGETS += x86
f21fb798f   Naresh Kamboju   selftests/zram: A...
70
  TARGETS += zram
96e869d85   Andrew Morton   tools/testing/sel...
71
  #Please keep the TARGETS list alphabetically sorted
2278e5ed9   Shuah Khan   selftests: add qu...
72
  # Run "make quicktest=1 run_tests" or
c6a13fafa   SeongJae Park   selftests/Makefil...
73
  # "make quicktest=1 kselftest" from top level Makefile
274343ad3   Frederic Weisbecker   selftests: new ve...
74

ddddda9bc   Shuah Khan   tools: selftests ...
75
76
  TARGETS_HOTPLUG = cpu-hotplug
  TARGETS_HOTPLUG += memory-hotplug
3a24f7f6b   Cristian Marussi   kselftest: add ca...
77
78
79
80
81
82
  # User can optionally provide a TARGETS skiplist.
  SKIP_TARGETS ?=
  ifneq ($(SKIP_TARGETS),)
  	TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
  	override TARGETS := $(TMP)
  endif
9d235a558   Jiri Benc   selftests: allow ...
83
84
85
86
87
  # 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 ?=
f69237e1e   Greg Thelen   selftests: more g...
88
89
90
91
  # 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))
60df4642a   Arnaldo Carvalho de Melo   tools selftests: ...
92
  override LDFLAGS =
67d8712dc   Shuah Khan   selftests: Fix bu...
93
94
  override MAKEFLAGS =
  endif
29e911ef7   Shuah Khan   selftests: Fix ks...
95
  # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
61c2018c0   Shuah Khan   selftests: avoid ...
96
97
  # KBUILD_OUTPUT with selftest objects and headers installed
  # by selftests Makefile or lib.mk.
051f278e9   Masahiro Yamada   kbuild: replace K...
98
  ifdef building_out_of_srctree
52fd1d082   Shuah Khan   selftests: Makefi...
99
100
  override LDFLAGS =
  endif
8ce72dc32   Shuah Khan   selftests: fix he...
101
  ifneq ($(O),)
29e911ef7   Shuah Khan   selftests: Fix ks...
102
  	BUILD := $(O)/kselftest
8ce72dc32   Shuah Khan   selftests: fix he...
103
104
  else
  	ifneq ($(KBUILD_OUTPUT),)
f60b85e83   Shuah Khan   Revert "selftests...
105
  		BUILD := $(KBUILD_OUTPUT)/kselftest
8ce72dc32   Shuah Khan   selftests: fix he...
106
107
108
109
  	else
  		BUILD := $(shell pwd)
  		DEFAULT_INSTALL_HDR_PATH := 1
  	endif
a8ba798bc   bamvor.zhangjian@huawei.com   selftests: enable...
110
  endif
8ce72dc32   Shuah Khan   selftests: fix he...
111
112
113
114
115
  # Prepare for headers install
  top_srcdir ?= ../../..
  include $(top_srcdir)/scripts/subarch.include
  ARCH           ?= $(SUBARCH)
  export KSFT_KHDR_INSTALL_DONE := 1
a8ba798bc   bamvor.zhangjian@huawei.com   selftests: enable...
116
  export BUILD
8ce72dc32   Shuah Khan   selftests: fix he...
117

d917fb876   Shuah Khan   selftests: build ...
118
119
120
121
122
123
124
125
  # build and run gpio when output directory is the src dir.
  # gpio has dependency on tools/gpio and builds tools/gpio
  # objects in the src directory in all cases making the src
  # repo dirty even when objects are relocated.
  ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
  	TMP := $(filter-out gpio, $(TARGETS))
  	TARGETS := $(TMP)
  endif
8ce72dc32   Shuah Khan   selftests: fix he...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
  # 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))
0ac33e4e9   Ilya Leoshkevich   selftests: use "$...
147
  	$(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
8ce72dc32   Shuah Khan   selftests: fix he...
148
  else
0ac33e4e9   Ilya Leoshkevich   selftests: use "$...
149
  	$(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
8ce72dc32   Shuah Khan   selftests: fix he...
150
151
152
153
  		ARCH=$(ARCH) -C $(top_srcdir) headers_install
  endif
  
  all: khdr
5f70bde26   Cristian Marussi   selftests: fix bu...
154
155
156
157
  	@ret=1;							\
  	for TARGET in $(TARGETS); do				\
  		BUILD_TARGET=$$BUILD/$$TARGET;			\
  		mkdir $$BUILD_TARGET  -p;			\
9d235a558   Jiri Benc   selftests: allow ...
158
159
  		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET	\
  				$(if $(FORCE_TARGETS),|| exit);	\
5f70bde26   Cristian Marussi   selftests: fix bu...
160
161
  		ret=$$((ret * $$?));				\
  	done; exit $$ret;
274343ad3   Frederic Weisbecker   selftests: new ve...
162

cab6b0560   Andrew Morton   selftests/Makefil...
163
  run_tests: all
1ede05363   Shuah Khan   selftests: Makefi...
164
  	@for TARGET in $(TARGETS); do \
a8ba798bc   bamvor.zhangjian@huawei.com   selftests: enable...
165
  		BUILD_TARGET=$$BUILD/$$TARGET;	\
0ac33e4e9   Ilya Leoshkevich   selftests: use "$...
166
  		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
f467f7140   Frederic Weisbecker   selftests: launch...
167
  	done;
ddddda9bc   Shuah Khan   tools: selftests ...
168
  hotplug:
1ede05363   Shuah Khan   selftests: Makefi...
169
  	@for TARGET in $(TARGETS_HOTPLUG); do \
a8ba798bc   bamvor.zhangjian@huawei.com   selftests: enable...
170
  		BUILD_TARGET=$$BUILD/$$TARGET;	\
0ac33e4e9   Ilya Leoshkevich   selftests: use "$...
171
  		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
ddddda9bc   Shuah Khan   tools: selftests ...
172
173
174
  	done;
  
  run_hotplug: hotplug
1ede05363   Shuah Khan   selftests: Makefi...
175
  	@for TARGET in $(TARGETS_HOTPLUG); do \
a8ba798bc   bamvor.zhangjian@huawei.com   selftests: enable...
176
  		BUILD_TARGET=$$BUILD/$$TARGET;	\
0ac33e4e9   Ilya Leoshkevich   selftests: use "$...
177
  		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
ddddda9bc   Shuah Khan   tools: selftests ...
178
179
180
  	done;
  
  clean_hotplug:
1ede05363   Shuah Khan   selftests: Makefi...
181
  	@for TARGET in $(TARGETS_HOTPLUG); do \
a8ba798bc   bamvor.zhangjian@huawei.com   selftests: enable...
182
  		BUILD_TARGET=$$BUILD/$$TARGET;	\
0ac33e4e9   Ilya Leoshkevich   selftests: use "$...
183
  		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
ddddda9bc   Shuah Khan   tools: selftests ...
184
  	done;
f615e2bb1   Hiraku Toyooka   selftests/pstore:...
185
  run_pstore_crash:
0ac33e4e9   Ilya Leoshkevich   selftests: use "$...
186
  	$(MAKE) -C pstore run_crash
f615e2bb1   Hiraku Toyooka   selftests/pstore:...
187

c3c599281   Shuah Khan   selftests: fix in...
188
189
190
191
192
  # 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
17eac6c2d   Shuah Khan   selftests: Add ks...
193
  # Avoid conflict with INSTALL_PATH set by the main Makefile
c3c599281   Shuah Khan   selftests: fix in...
194
  #
17eac6c2d   Shuah Khan   selftests: Add ks...
195
196
197
198
  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)
32dcfba6f   Michael Ellerman   selftests: Add in...
199
  ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
f0f0a5df4   Kees Cook   selftests: Extrac...
200
  TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
32dcfba6f   Michael Ellerman   selftests: Add in...
201

c3c599281   Shuah Khan   selftests: fix in...
202
  install: all
32dcfba6f   Michael Ellerman   selftests: Add in...
203
204
  ifdef INSTALL_PATH
  	@# Ask all targets to install their files
d4e59a536   Kees Cook   selftests: Use ru...
205
  	mkdir -p $(INSTALL_PATH)/kselftest
c78fd76f2   Kees Cook   selftests: Move k...
206
  	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
d4e59a536   Kees Cook   selftests: Use ru...
207
  	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
5c069b6de   Kees Cook   selftests: Move t...
208
  	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
f0f0a5df4   Kees Cook   selftests: Extrac...
209
210
  	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
  	rm -f $(TEST_LIST)
5f70bde26   Cristian Marussi   selftests: fix bu...
211
212
  	@ret=1;	\
  	for TARGET in $(TARGETS); do \
a8ba798bc   bamvor.zhangjian@huawei.com   selftests: enable...
213
  		BUILD_TARGET=$$BUILD/$$TARGET;	\
9d235a558   Jiri Benc   selftests: allow ...
214
215
  		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
  				$(if $(FORCE_TARGETS),|| exit);	\
5f70bde26   Cristian Marussi   selftests: fix bu...
216
217
  		ret=$$((ret * $$?));		\
  	done; exit $$ret;
32dcfba6f   Michael Ellerman   selftests: Add in...
218

32dcfba6f   Michael Ellerman   selftests: Add in...
219

f0f0a5df4   Kees Cook   selftests: Extrac...
220
221
  	@# Ask all targets to emit their test scripts
  	@# While building kselftest-list.text skip also non-existent TARGET dirs:
131b30c94   Cristian Marussi   kselftest: exclud...
222
223
  	@# they could be the result of a build failure and should NOT be
  	@# included in the generated runlist.
32dcfba6f   Michael Ellerman   selftests: Add in...
224
  	for TARGET in $(TARGETS); do \
a8ba798bc   bamvor.zhangjian@huawei.com   selftests: enable...
225
  		BUILD_TARGET=$$BUILD/$$TARGET;	\
02bf1f8b3   Prabhakar Kushwaha   kselftest: Fix NU...
226
  		[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
17eac6c2d   Shuah Khan   selftests: Add ks...
227
228
  		echo -n "Emit Tests for $$TARGET
  "; \
f0f0a5df4   Kees Cook   selftests: Extrac...
229
230
  		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
  			-C $$TARGET emit_tests >> $(TEST_LIST); \
32dcfba6f   Michael Ellerman   selftests: Add in...
231
  	done;
32dcfba6f   Michael Ellerman   selftests: Add in...
232
233
234
  else
  	$(error Error: set INSTALL_PATH to use install)
  endif
a5f304670   Veronika Kabatova   selftests: introd...
235
236
237
238
239
240
  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}"
274343ad3   Frederic Weisbecker   selftests: new ve...
241
  clean:
1ede05363   Shuah Khan   selftests: Makefi...
242
  	@for TARGET in $(TARGETS); do \
a8ba798bc   bamvor.zhangjian@huawei.com   selftests: enable...
243
  		BUILD_TARGET=$$BUILD/$$TARGET;	\
0ac33e4e9   Ilya Leoshkevich   selftests: use "$...
244
  		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
274343ad3   Frederic Weisbecker   selftests: new ve...
245
  	done;
32dcfba6f   Michael Ellerman   selftests: Add in...
246

a5f304670   Veronika Kabatova   selftests: introd...
247
  .PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar