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