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