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 148 KHDR_DIR := ${abs_objtree}/usr/include 149else 150 BUILD := $(CURDIR) 151 abs_srctree := $(shell cd $(top_srcdir) && pwd) 152 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include 153 KHDR_DIR := ${abs_srctree}/usr/include 154 DEFAULT_INSTALL_HDR_PATH := 1 155endif 156 157# Prepare for headers install 158include $(top_srcdir)/scripts/subarch.include 159ARCH ?= $(SUBARCH) 160export BUILD 161export KHDR_INCLUDES 162 163# set default goal to all, so make without a target runs all, even when 164# all isn't the first target in the file. 165.DEFAULT_GOAL := all 166 167all: kernel_header_files 168 @ret=1; \ 169 for TARGET in $(TARGETS); do \ 170 BUILD_TARGET=$$BUILD/$$TARGET; \ 171 mkdir $$BUILD_TARGET -p; \ 172 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ 173 O=$(abs_objtree) \ 174 $(if $(FORCE_TARGETS),|| exit); \ 175 ret=$$((ret * $$?)); \ 176 done; exit $$ret; 177 178kernel_header_files: 179 @ls $(KHDR_DIR)/linux/*.h >/dev/null 2>/dev/null; \ 180 if [ $$? -ne 0 ]; then \ 181 RED='\033[1;31m'; \ 182 NOCOLOR='\033[0m'; \ 183 echo; \ 184 echo -e "$${RED}error$${NOCOLOR}: missing kernel header files."; \ 185 echo "Please run this and try again:"; \ 186 echo; \ 187 echo " cd $(top_srcdir)"; \ 188 echo " make headers"; \ 189 echo; \ 190 exit 1; \ 191 fi 192 193.PHONY: kernel_header_files 194 195run_tests: all 196 @for TARGET in $(TARGETS); do \ 197 BUILD_TARGET=$$BUILD/$$TARGET; \ 198 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \ 199 O=$(abs_objtree); \ 200 done; 201 202hotplug: 203 @for TARGET in $(TARGETS_HOTPLUG); do \ 204 BUILD_TARGET=$$BUILD/$$TARGET; \ 205 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 206 done; 207 208run_hotplug: hotplug 209 @for TARGET in $(TARGETS_HOTPLUG); do \ 210 BUILD_TARGET=$$BUILD/$$TARGET; \ 211 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ 212 done; 213 214clean_hotplug: 215 @for TARGET in $(TARGETS_HOTPLUG); do \ 216 BUILD_TARGET=$$BUILD/$$TARGET; \ 217 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 218 done; 219 220run_pstore_crash: 221 $(MAKE) -C pstore run_crash 222 223# Use $BUILD as the default install root. $BUILD points to the 224# right output location for the following cases: 225# 1. output_dir=kernel_src 226# 2. a separate output directory is specified using O= KBUILD_OUTPUT 227# 3. a separate output directory is specified using KBUILD_OUTPUT 228# Avoid conflict with INSTALL_PATH set by the main Makefile 229# 230KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install 231KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH)) 232# Avoid changing the rest of the logic here and lib.mk. 233INSTALL_PATH := $(KSFT_INSTALL_PATH) 234ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 235TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt 236 237install: all 238ifdef INSTALL_PATH 239 @# Ask all targets to install their files 240 mkdir -p $(INSTALL_PATH)/kselftest 241 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ 242 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ 243 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ 244 install -m 744 run_kselftest.sh $(INSTALL_PATH)/ 245 rm -f $(TEST_LIST) 246 @ret=1; \ 247 for TARGET in $(TARGETS); do \ 248 BUILD_TARGET=$$BUILD/$$TARGET; \ 249 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ 250 O=$(abs_objtree) \ 251 $(if $(FORCE_TARGETS),|| exit); \ 252 ret=$$((ret * $$?)); \ 253 done; exit $$ret; 254 255 256 @# Ask all targets to emit their test scripts 257 @# While building kselftest-list.text skip also non-existent TARGET dirs: 258 @# they could be the result of a build failure and should NOT be 259 @# included in the generated runlist. 260 for TARGET in $(TARGETS); do \ 261 BUILD_TARGET=$$BUILD/$$TARGET; \ 262 [ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \ 263 printf "Emit Tests for $$TARGET\n"; \ 264 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \ 265 -C $$TARGET emit_tests >> $(TEST_LIST); \ 266 done; 267else 268 $(error Error: set INSTALL_PATH to use install) 269endif 270 271FORMAT ?= .gz 272TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT}) 273gen_tar: install 274 @mkdir -p ${INSTALL_PATH}/kselftest-packages/ 275 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} . 276 @echo "Created ${TAR_PATH}" 277 278clean: 279 @for TARGET in $(TARGETS); do \ 280 BUILD_TARGET=$$BUILD/$$TARGET; \ 281 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 282 done; 283 284.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar 285