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