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