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