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