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