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