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