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