1# SPDX-License-Identifier: GPL-2.0 2TARGETS = arm64 3TARGETS += bpf 4TARGETS += breakpoints 5TARGETS += capabilities 6TARGETS += cgroup 7TARGETS += clone3 8TARGETS += core 9TARGETS += cpufreq 10TARGETS += cpu-hotplug 11TARGETS += drivers/dma-buf 12TARGETS += efivarfs 13TARGETS += exec 14TARGETS += filesystems 15TARGETS += filesystems/binderfs 16TARGETS += filesystems/epoll 17TARGETS += firmware 18TARGETS += fpu 19TARGETS += ftrace 20TARGETS += futex 21TARGETS += gpio 22TARGETS += intel_pstate 23TARGETS += ipc 24TARGETS += ir 25TARGETS += kcmp 26TARGETS += kexec 27TARGETS += kvm 28TARGETS += lib 29TARGETS += livepatch 30TARGETS += lkdtm 31TARGETS += membarrier 32TARGETS += memfd 33TARGETS += memory-hotplug 34TARGETS += mincore 35TARGETS += mount 36TARGETS += mqueue 37TARGETS += net 38TARGETS += net/forwarding 39TARGETS += net/mptcp 40TARGETS += netfilter 41TARGETS += nsfs 42TARGETS += pidfd 43TARGETS += pid_namespace 44TARGETS += powerpc 45TARGETS += proc 46TARGETS += pstore 47TARGETS += ptrace 48TARGETS += openat2 49TARGETS += rseq 50TARGETS += rtc 51TARGETS += seccomp 52TARGETS += sgx 53TARGETS += sigaltstack 54TARGETS += size 55TARGETS += sparc64 56TARGETS += splice 57TARGETS += static_keys 58TARGETS += sync 59TARGETS += syscall_user_dispatch 60TARGETS += sysctl 61TARGETS += tc-testing 62TARGETS += timens 63ifneq (1, $(quicktest)) 64TARGETS += timers 65endif 66TARGETS += tmpfs 67TARGETS += tpm2 68TARGETS += user 69TARGETS += vDSO 70TARGETS += vm 71TARGETS += x86 72TARGETS += zram 73#Please keep the TARGETS list alphabetically sorted 74# Run "make quicktest=1 run_tests" or 75# "make quicktest=1 kselftest" from top level Makefile 76 77TARGETS_HOTPLUG = cpu-hotplug 78TARGETS_HOTPLUG += memory-hotplug 79 80# User can optionally provide a TARGETS skiplist. By default we skip 81# BPF since it has cutting edge build time dependencies which require 82# more effort to install. 83SKIP_TARGETS ?= bpf 84ifneq ($(SKIP_TARGETS),) 85 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS)) 86 override TARGETS := $(TMP) 87endif 88 89# User can set FORCE_TARGETS to 1 to require all targets to be successfully 90# built; make will fail if any of the targets cannot be built. If 91# FORCE_TARGETS is not set (the default), make will succeed if at least one 92# of the targets gets built. 93FORCE_TARGETS ?= 94 95# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides 96# implicit rules to sub-test Makefiles which avoids build failures in test 97# Makefile that don't have explicit build rules. 98ifeq (,$(LINK.c)) 99override LDFLAGS = 100override MAKEFLAGS = 101endif 102 103# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering 104# KBUILD_OUTPUT with selftest objects and headers installed 105# by selftests Makefile or lib.mk. 106ifdef building_out_of_srctree 107override LDFLAGS = 108endif 109 110ifneq ($(O),) 111 BUILD := $(O)/kselftest 112else 113 ifneq ($(KBUILD_OUTPUT),) 114 BUILD := $(KBUILD_OUTPUT)/kselftest 115 else 116 BUILD := $(shell pwd) 117 DEFAULT_INSTALL_HDR_PATH := 1 118 endif 119endif 120 121# Prepare for headers install 122top_srcdir ?= ../../.. 123include $(top_srcdir)/scripts/subarch.include 124ARCH ?= $(SUBARCH) 125export KSFT_KHDR_INSTALL_DONE := 1 126export BUILD 127 128# build and run gpio when output directory is the src dir. 129# gpio has dependency on tools/gpio and builds tools/gpio 130# objects in the src directory in all cases making the src 131# repo dirty even when objects are relocated. 132ifneq (1,$(DEFAULT_INSTALL_HDR_PATH)) 133 TMP := $(filter-out gpio, $(TARGETS)) 134 TARGETS := $(TMP) 135endif 136 137# set default goal to all, so make without a target runs all, even when 138# all isn't the first target in the file. 139.DEFAULT_GOAL := all 140 141# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE 142# is used to avoid running headers_install from lib.mk. 143# Invoke headers install with --no-builtin-rules to avoid circular 144# dependency in "make kselftest" case. In this case, second level 145# make inherits builtin-rules which will use the rule generate 146# Makefile.o and runs into 147# "Circular Makefile.o <- prepare dependency dropped." 148# and headers_install fails and test compile fails. 149# 150# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile 151# invokes them as sub-makes and --no-builtin-rules is not necessary, 152# but doesn't cause any failures. Keep it simple and use the same 153# flags in both cases. 154# Local build cases: "make kselftest", "make -C" - headers are installed 155# in the default INSTALL_HDR_PATH usr/include. 156khdr: 157ifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) 158 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install 159else 160 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \ 161 ARCH=$(ARCH) -C $(top_srcdir) headers_install 162endif 163 164all: khdr 165 @ret=1; \ 166 for TARGET in $(TARGETS); do \ 167 BUILD_TARGET=$$BUILD/$$TARGET; \ 168 mkdir $$BUILD_TARGET -p; \ 169 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ 170 $(if $(FORCE_TARGETS),|| exit); \ 171 ret=$$((ret * $$?)); \ 172 done; exit $$ret; 173 174run_tests: all 175 @for TARGET in $(TARGETS); do \ 176 BUILD_TARGET=$$BUILD/$$TARGET; \ 177 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ 178 done; 179 180hotplug: 181 @for TARGET in $(TARGETS_HOTPLUG); do \ 182 BUILD_TARGET=$$BUILD/$$TARGET; \ 183 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 184 done; 185 186run_hotplug: hotplug 187 @for TARGET in $(TARGETS_HOTPLUG); do \ 188 BUILD_TARGET=$$BUILD/$$TARGET; \ 189 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ 190 done; 191 192clean_hotplug: 193 @for TARGET in $(TARGETS_HOTPLUG); do \ 194 BUILD_TARGET=$$BUILD/$$TARGET; \ 195 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 196 done; 197 198run_pstore_crash: 199 $(MAKE) -C pstore run_crash 200 201# Use $BUILD as the default install root. $BUILD points to the 202# right output location for the following cases: 203# 1. output_dir=kernel_src 204# 2. a separate output directory is specified using O= KBUILD_OUTPUT 205# 3. a separate output directory is specified using KBUILD_OUTPUT 206# Avoid conflict with INSTALL_PATH set by the main Makefile 207# 208KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install 209KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH)) 210# Avoid changing the rest of the logic here and lib.mk. 211INSTALL_PATH := $(KSFT_INSTALL_PATH) 212ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 213TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt 214 215install: all 216ifdef INSTALL_PATH 217 @# Ask all targets to install their files 218 mkdir -p $(INSTALL_PATH)/kselftest 219 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ 220 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ 221 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ 222 install -m 744 run_kselftest.sh $(INSTALL_PATH)/ 223 rm -f $(TEST_LIST) 224 @ret=1; \ 225 for TARGET in $(TARGETS); do \ 226 BUILD_TARGET=$$BUILD/$$TARGET; \ 227 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ 228 $(if $(FORCE_TARGETS),|| exit); \ 229 ret=$$((ret * $$?)); \ 230 done; exit $$ret; 231 232 233 @# Ask all targets to emit their test scripts 234 @# While building kselftest-list.text skip also non-existent TARGET dirs: 235 @# they could be the result of a build failure and should NOT be 236 @# included in the generated runlist. 237 for TARGET in $(TARGETS); do \ 238 BUILD_TARGET=$$BUILD/$$TARGET; \ 239 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ 240 echo -n "Emit Tests for $$TARGET\n"; \ 241 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \ 242 -C $$TARGET emit_tests >> $(TEST_LIST); \ 243 done; 244else 245 $(error Error: set INSTALL_PATH to use install) 246endif 247 248FORMAT ?= .gz 249TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT}) 250gen_tar: install 251 @mkdir -p ${INSTALL_PATH}/kselftest-packages/ 252 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} . 253 @echo "Created ${TAR_PATH}" 254 255clean: 256 @for TARGET in $(TARGETS); do \ 257 BUILD_TARGET=$$BUILD/$$TARGET; \ 258 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 259 done; 260 261.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar 262