1 # SPDX-License-Identifier: GPL-2.0
5 TARGETS += capabilities
9 TARGETS += drivers/dma-buf
12 TARGETS += filesystems
13 TARGETS += filesystems/binderfs
18 TARGETS += intel_pstate
28 TARGETS += memory-hotplug
33 TARGETS += networking/timestamping
43 TARGETS += sigaltstack
47 TARGETS += static_keys
50 ifneq (1, $(quicktest))
59 #Please keep the TARGETS list alphabetically sorted
60 # Run "make quicktest=1 run_tests" or
61 # "make quicktest=1 kselftest" from top level Makefile
63 TARGETS_HOTPLUG = cpu-hotplug
64 TARGETS_HOTPLUG += memory-hotplug
66 # Clear LDFLAGS and MAKEFLAGS if called from main
67 # Makefile to avoid test build failures when test
68 # Makefile doesn't have explicit build rules.
74 # Append kselftest to KBUILD_OUTPUT to avoid cluttering
75 # KBUILD_OUTPUT with selftest objects and headers installed
76 # by selftests Makefile or lib.mk.
77 ifneq ($(KBUILD_SRC),)
84 ifneq ($(KBUILD_OUTPUT),)
85 BUILD := $(KBUILD_OUTPUT)/kselftest
88 DEFAULT_INSTALL_HDR_PATH := 1
92 # Prepare for headers install
93 top_srcdir ?= ../../..
94 include $(top_srcdir)/scripts/subarch.include
96 export KSFT_KHDR_INSTALL_DONE := 1
99 # build and run gpio when output directory is the src dir.
100 # gpio has dependency on tools/gpio and builds tools/gpio
101 # objects in the src directory in all cases making the src
102 # repo dirty even when objects are relocated.
103 ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
104 TMP := $(filter-out gpio, $(TARGETS))
108 # set default goal to all, so make without a target runs all, even when
109 # all isn't the first target in the file.
112 # Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
113 # is used to avoid running headers_install from lib.mk.
114 # Invoke headers install with --no-builtin-rules to avoid circular
115 # dependency in "make kselftest" case. In this case, second level
116 # make inherits builtin-rules which will use the rule generate
117 # Makefile.o and runs into
118 # "Circular Makefile.o <- prepare dependency dropped."
119 # and headers_install fails and test compile fails.
121 # O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
122 # invokes them as sub-makes and --no-builtin-rules is not necessary,
123 # but doesn't cause any failures. Keep it simple and use the same
124 # flags in both cases.
125 # Local build cases: "make kselftest", "make -C" - headers are installed
126 # in the default INSTALL_HDR_PATH usr/include.
128 ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
129 make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
131 make --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
132 ARCH=$(ARCH) -C $(top_srcdir) headers_install
136 @for TARGET in $(TARGETS); do \
137 BUILD_TARGET=$$BUILD/$$TARGET; \
138 mkdir $$BUILD_TARGET -p; \
139 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
143 @for TARGET in $(TARGETS); do \
144 BUILD_TARGET=$$BUILD/$$TARGET; \
145 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
149 @for TARGET in $(TARGETS_HOTPLUG); do \
150 BUILD_TARGET=$$BUILD/$$TARGET; \
151 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
155 @for TARGET in $(TARGETS_HOTPLUG); do \
156 BUILD_TARGET=$$BUILD/$$TARGET; \
157 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
161 @for TARGET in $(TARGETS_HOTPLUG); do \
162 BUILD_TARGET=$$BUILD/$$TARGET; \
163 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
167 make -C pstore run_crash
169 # Use $BUILD as the default install root. $BUILD points to the
170 # right output location for the following cases:
171 # 1. output_dir=kernel_src
172 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
173 # 3. a separate output directory is specified using KBUILD_OUTPUT
175 INSTALL_PATH ?= $(BUILD)/install
176 INSTALL_PATH := $(abspath $(INSTALL_PATH))
177 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
181 @# Ask all targets to install their files
182 mkdir -p $(INSTALL_PATH)/kselftest
183 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
184 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
185 @for TARGET in $(TARGETS); do \
186 BUILD_TARGET=$$BUILD/$$TARGET; \
187 make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
190 @# Ask all targets to emit their test scripts
191 echo "#!/bin/sh" > $(ALL_SCRIPT)
192 echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
193 echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
194 echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
195 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
196 echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
197 echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
198 echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
199 echo "fi" >> $(ALL_SCRIPT)
201 for TARGET in $(TARGETS); do \
202 BUILD_TARGET=$$BUILD/$$TARGET; \
203 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
204 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
205 echo -n "run_many" >> $(ALL_SCRIPT); \
206 make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
207 echo "" >> $(ALL_SCRIPT); \
208 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
211 chmod u+x $(ALL_SCRIPT)
213 $(error Error: set INSTALL_PATH to use install)
217 @for TARGET in $(TARGETS); do \
218 BUILD_TARGET=$$BUILD/$$TARGET; \
219 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
222 .PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean