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