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