Commit | Line | Data |
---|---|---|
b2441318 | 1 | # SPDX-License-Identifier: GPL-2.0 |
47a18c42 | 2 | TARGETS = android |
313a4db7 | 3 | TARGETS += arm64 |
47a18c42 | 4 | TARGETS += bpf |
5aa5bd14 | 5 | TARGETS += breakpoints |
f4ecb322 | 6 | TARGETS += capabilities |
84092dbc | 7 | TARGETS += cgroup |
de528723 | 8 | TARGETS += clone3 |
e66d5b67 | 9 | TARGETS += cpufreq |
58c7be84 | 10 | TARGETS += cpu-hotplug |
6edf2e37 | 11 | TARGETS += drivers/dma-buf |
58c7be84 | 12 | TARGETS += efivarfs |
96e869d8 | 13 | TARGETS += exec |
ce290a19 | 14 | TARGETS += filesystems |
75abec73 | 15 | TARGETS += filesystems/binderfs |
f2728fe8 | 16 | TARGETS += filesystems/epoll |
96e869d8 AM |
17 | TARGETS += firmware |
18 | TARGETS += ftrace | |
ecac1a75 | 19 | TARGETS += futex |
22f6592b | 20 | TARGETS += gpio |
6320303f | 21 | TARGETS += intel_pstate |
7e722473 | 22 | TARGETS += ipc |
e55c884e | 23 | TARGETS += ir |
66a01b96 | 24 | TARGETS += kcmp |
c3c0e811 | 25 | TARGETS += kexec |
783e9e51 | 26 | TARGETS += kvm |
317dc34a | 27 | TARGETS += lib |
a2818ee4 | 28 | TARGETS += livepatch |
46d1a0f0 | 29 | TARGETS += lkdtm |
b6d97344 | 30 | TARGETS += membarrier |
4f5ce5e8 | 31 | TARGETS += memfd |
58c7be84 | 32 | TARGETS += memory-hotplug |
db181ce0 | 33 | TARGETS += mount |
96e869d8 | 34 | TARGETS += mqueue |
a6f68034 | 35 | TARGETS += net |
048d19d4 | 36 | TARGETS += net/mptcp |
25d8bced | 37 | TARGETS += netfilter |
cda261f4 | 38 | TARGETS += networking/timestamping |
6ad92bf6 | 39 | TARGETS += nsfs |
575a0ae9 | 40 | TARGETS += pidfd |
96e869d8 | 41 | TARGETS += powerpc |
9cd65655 | 42 | TARGETS += proc |
cc04a46f | 43 | TARGETS += pstore |
17afab1d | 44 | TARGETS += ptrace |
b28a10ae | 45 | TARGETS += openat2 |
ccba8b64 | 46 | TARGETS += rseq |
a12ab9e1 | 47 | TARGETS += rtc |
c99ee51a | 48 | TARGETS += seccomp |
19fd2868 | 49 | TARGETS += sigaltstack |
96e869d8 | 50 | TARGETS += size |
3c545084 | 51 | TARGETS += sparc64 |
b8826e50 | 52 | TARGETS += splice |
1087d019 | 53 | TARGETS += static_keys |
82208160 | 54 | TARGETS += sync |
96e869d8 | 55 | TARGETS += sysctl |
61c57676 | 56 | TARGETS += timens |
2278e5ed | 57 | ifneq (1, $(quicktest)) |
0bc4b0cf | 58 | TARGETS += timers |
2278e5ed | 59 | endif |
a3322868 | 60 | TARGETS += tmpfs |
6ea3dfe1 | 61 | TARGETS += tpm2 |
3e2a4c18 | 62 | TARGETS += user |
96e869d8 | 63 | TARGETS += vm |
3f705dfd | 64 | TARGETS += x86 |
f21fb798 | 65 | TARGETS += zram |
96e869d8 | 66 | #Please keep the TARGETS list alphabetically sorted |
2278e5ed | 67 | # Run "make quicktest=1 run_tests" or |
c6a13faf | 68 | # "make quicktest=1 kselftest" from top level Makefile |
274343ad | 69 | |
ddddda9b SK |
70 | TARGETS_HOTPLUG = cpu-hotplug |
71 | TARGETS_HOTPLUG += memory-hotplug | |
72 | ||
3a24f7f6 CM |
73 | # User can optionally provide a TARGETS skiplist. |
74 | SKIP_TARGETS ?= | |
75 | ifneq ($(SKIP_TARGETS),) | |
76 | TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS)) | |
77 | override TARGETS := $(TMP) | |
78 | endif | |
79 | ||
67d8712d SK |
80 | # Clear LDFLAGS and MAKEFLAGS if called from main |
81 | # Makefile to avoid test build failures when test | |
82 | # Makefile doesn't have explicit build rules. | |
83 | ifeq (1,$(MAKELEVEL)) | |
60df4642 | 84 | override LDFLAGS = |
67d8712d SK |
85 | override MAKEFLAGS = |
86 | endif | |
87 | ||
61c2018c SK |
88 | # Append kselftest to KBUILD_OUTPUT to avoid cluttering |
89 | # KBUILD_OUTPUT with selftest objects and headers installed | |
90 | # by selftests Makefile or lib.mk. | |
051f278e | 91 | ifdef building_out_of_srctree |
52fd1d08 SK |
92 | override LDFLAGS = |
93 | endif | |
94 | ||
8ce72dc3 | 95 | ifneq ($(O),) |
f60b85e8 | 96 | BUILD := $(O) |
8ce72dc3 SK |
97 | else |
98 | ifneq ($(KBUILD_OUTPUT),) | |
f60b85e8 | 99 | BUILD := $(KBUILD_OUTPUT)/kselftest |
8ce72dc3 SK |
100 | else |
101 | BUILD := $(shell pwd) | |
102 | DEFAULT_INSTALL_HDR_PATH := 1 | |
103 | endif | |
a8ba798b | 104 | endif |
105 | ||
8ce72dc3 SK |
106 | # Prepare for headers install |
107 | top_srcdir ?= ../../.. | |
108 | include $(top_srcdir)/scripts/subarch.include | |
109 | ARCH ?= $(SUBARCH) | |
110 | export KSFT_KHDR_INSTALL_DONE := 1 | |
a8ba798b | 111 | export BUILD |
8ce72dc3 | 112 | |
d917fb87 SK |
113 | # build and run gpio when output directory is the src dir. |
114 | # gpio has dependency on tools/gpio and builds tools/gpio | |
115 | # objects in the src directory in all cases making the src | |
116 | # repo dirty even when objects are relocated. | |
117 | ifneq (1,$(DEFAULT_INSTALL_HDR_PATH)) | |
118 | TMP := $(filter-out gpio, $(TARGETS)) | |
119 | TARGETS := $(TMP) | |
120 | endif | |
121 | ||
8ce72dc3 SK |
122 | # set default goal to all, so make without a target runs all, even when |
123 | # all isn't the first target in the file. | |
124 | .DEFAULT_GOAL := all | |
125 | ||
126 | # Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE | |
127 | # is used to avoid running headers_install from lib.mk. | |
128 | # Invoke headers install with --no-builtin-rules to avoid circular | |
129 | # dependency in "make kselftest" case. In this case, second level | |
130 | # make inherits builtin-rules which will use the rule generate | |
131 | # Makefile.o and runs into | |
132 | # "Circular Makefile.o <- prepare dependency dropped." | |
133 | # and headers_install fails and test compile fails. | |
134 | # | |
135 | # O= KBUILD_OUTPUT cases don't run into this error, since main Makefile | |
136 | # invokes them as sub-makes and --no-builtin-rules is not necessary, | |
137 | # but doesn't cause any failures. Keep it simple and use the same | |
138 | # flags in both cases. | |
139 | # Local build cases: "make kselftest", "make -C" - headers are installed | |
140 | # in the default INSTALL_HDR_PATH usr/include. | |
141 | khdr: | |
142 | ifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) | |
0ac33e4e | 143 | $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install |
8ce72dc3 | 144 | else |
0ac33e4e | 145 | $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \ |
8ce72dc3 SK |
146 | ARCH=$(ARCH) -C $(top_srcdir) headers_install |
147 | endif | |
148 | ||
149 | all: khdr | |
5f70bde2 CM |
150 | @ret=1; \ |
151 | for TARGET in $(TARGETS); do \ | |
152 | BUILD_TARGET=$$BUILD/$$TARGET; \ | |
153 | mkdir $$BUILD_TARGET -p; \ | |
154 | $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET; \ | |
155 | ret=$$((ret * $$?)); \ | |
156 | done; exit $$ret; | |
274343ad | 157 | |
cab6b056 | 158 | run_tests: all |
1ede0536 | 159 | @for TARGET in $(TARGETS); do \ |
a8ba798b | 160 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
0ac33e4e | 161 | $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ |
f467f714 FW |
162 | done; |
163 | ||
ddddda9b | 164 | hotplug: |
1ede0536 | 165 | @for TARGET in $(TARGETS_HOTPLUG); do \ |
a8ba798b | 166 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
0ac33e4e | 167 | $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\ |
ddddda9b SK |
168 | done; |
169 | ||
170 | run_hotplug: hotplug | |
1ede0536 | 171 | @for TARGET in $(TARGETS_HOTPLUG); do \ |
a8ba798b | 172 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
0ac33e4e | 173 | $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ |
ddddda9b SK |
174 | done; |
175 | ||
176 | clean_hotplug: | |
1ede0536 | 177 | @for TARGET in $(TARGETS_HOTPLUG); do \ |
a8ba798b | 178 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
0ac33e4e | 179 | $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ |
ddddda9b SK |
180 | done; |
181 | ||
f615e2bb | 182 | run_pstore_crash: |
0ac33e4e | 183 | $(MAKE) -C pstore run_crash |
f615e2bb | 184 | |
c3c59928 SK |
185 | # Use $BUILD as the default install root. $BUILD points to the |
186 | # right output location for the following cases: | |
187 | # 1. output_dir=kernel_src | |
188 | # 2. a separate output directory is specified using O= KBUILD_OUTPUT | |
189 | # 3. a separate output directory is specified using KBUILD_OUTPUT | |
17eac6c2 | 190 | # Avoid conflict with INSTALL_PATH set by the main Makefile |
c3c59928 | 191 | # |
17eac6c2 SK |
192 | KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install |
193 | KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH)) | |
194 | # Avoid changing the rest of the logic here and lib.mk. | |
195 | INSTALL_PATH := $(KSFT_INSTALL_PATH) | |
32dcfba6 ME |
196 | ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh |
197 | ||
c3c59928 | 198 | install: all |
32dcfba6 ME |
199 | ifdef INSTALL_PATH |
200 | @# Ask all targets to install their files | |
d4e59a53 | 201 | mkdir -p $(INSTALL_PATH)/kselftest |
c78fd76f | 202 | install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ |
d4e59a53 | 203 | install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ |
5c069b6d | 204 | install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ |
5f70bde2 CM |
205 | @ret=1; \ |
206 | for TARGET in $(TARGETS); do \ | |
a8ba798b | 207 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
0ac33e4e | 208 | $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \ |
5f70bde2 CM |
209 | ret=$$((ret * $$?)); \ |
210 | done; exit $$ret; | |
32dcfba6 ME |
211 | |
212 | @# Ask all targets to emit their test scripts | |
a2b1e8a2 | 213 | echo "#!/bin/sh" > $(ALL_SCRIPT) |
14f1889f ME |
214 | echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT) |
215 | echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT) | |
d4e59a53 | 216 | echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT) |
32dcfba6 | 217 | echo "ROOT=\$$PWD" >> $(ALL_SCRIPT) |
14f1889f | 218 | echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT) |
d4e59a53 KC |
219 | echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT) |
220 | echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT) | |
14f1889f | 221 | echo "fi" >> $(ALL_SCRIPT) |
32dcfba6 | 222 | |
131b30c9 CM |
223 | @# While building run_kselftest.sh skip also non-existent TARGET dirs: |
224 | @# they could be the result of a build failure and should NOT be | |
225 | @# included in the generated runlist. | |
32dcfba6 | 226 | for TARGET in $(TARGETS); do \ |
a8ba798b | 227 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
02bf1f8b | 228 | [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ |
88893cf7 | 229 | echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \ |
32dcfba6 | 230 | echo "cd $$TARGET" >> $(ALL_SCRIPT); \ |
bf660782 | 231 | echo -n "run_many" >> $(ALL_SCRIPT); \ |
17eac6c2 | 232 | echo -n "Emit Tests for $$TARGET\n"; \ |
0ac33e4e | 233 | $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ |
bf660782 | 234 | echo "" >> $(ALL_SCRIPT); \ |
32dcfba6 ME |
235 | echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ |
236 | done; | |
237 | ||
238 | chmod u+x $(ALL_SCRIPT) | |
239 | else | |
240 | $(error Error: set INSTALL_PATH to use install) | |
241 | endif | |
242 | ||
274343ad | 243 | clean: |
1ede0536 | 244 | @for TARGET in $(TARGETS); do \ |
a8ba798b | 245 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
0ac33e4e | 246 | $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ |
274343ad | 247 | done; |
32dcfba6 | 248 | |
8ce72dc3 | 249 | .PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean |