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