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