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