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