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