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