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