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