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 += filesystems/fuse 40TARGETS += firmware 41TARGETS += fpu 42TARGETS += ftrace 43TARGETS += futex 44TARGETS += gpio 45TARGETS += hid 46TARGETS += intel_pstate 47TARGETS += iommu 48TARGETS += ipc 49TARGETS += ir 50TARGETS += kcmp 51TARGETS += kexec 52TARGETS += kselftest_harness 53TARGETS += kvm 54TARGETS += landlock 55TARGETS += lib 56TARGETS += livepatch 57TARGETS += lkdtm 58TARGETS += lsm 59TARGETS += membarrier 60TARGETS += memfd 61TARGETS += memory-hotplug 62TARGETS += mincore 63TARGETS += mount 64TARGETS += mount_setattr 65TARGETS += move_mount_set_group 66TARGETS += mqueue 67TARGETS += mseal_system_mappings 68TARGETS += nci 69TARGETS += net 70TARGETS += net/af_unix 71TARGETS += net/can 72TARGETS += net/forwarding 73TARGETS += net/hsr 74TARGETS += net/mptcp 75TARGETS += net/netfilter 76TARGETS += net/openvswitch 77TARGETS += net/ovpn 78TARGETS += net/packetdrill 79TARGETS += net/rds 80TARGETS += net/tcp_ao 81TARGETS += nolibc 82TARGETS += nsfs 83TARGETS += pci_endpoint 84TARGETS += pcie_bwctrl 85TARGETS += perf_events 86TARGETS += pidfd 87TARGETS += pid_namespace 88TARGETS += power_supply 89TARGETS += powerpc 90TARGETS += prctl 91TARGETS += proc 92TARGETS += pstore 93TARGETS += ptrace 94TARGETS += openat2 95TARGETS += resctrl 96TARGETS += riscv 97TARGETS += rlimits 98TARGETS += rseq 99TARGETS += rtc 100TARGETS += rust 101TARGETS += sched_ext 102TARGETS += seccomp 103TARGETS += sgx 104TARGETS += signal 105TARGETS += size 106TARGETS += sparc64 107TARGETS += splice 108TARGETS += static_keys 109TARGETS += sync 110TARGETS += syscall_user_dispatch 111TARGETS += sysctl 112TARGETS += tc-testing 113TARGETS += tdx 114TARGETS += thermal/intel/power_floor 115TARGETS += thermal/intel/workload_hint 116TARGETS += timens 117ifneq (1, $(quicktest)) 118TARGETS += timers 119endif 120TARGETS += tmpfs 121TARGETS += tpm2 122TARGETS += tty 123TARGETS += ublk 124TARGETS += uevent 125TARGETS += user_events 126TARGETS += vDSO 127TARGETS += mm 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) $(INSTALL_DEP_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