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