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