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