18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ciTARGETS = android
38c2ecf20Sopenharmony_ciTARGETS += arm64
48c2ecf20Sopenharmony_ciTARGETS += bpf
58c2ecf20Sopenharmony_ciTARGETS += breakpoints
68c2ecf20Sopenharmony_ciTARGETS += capabilities
78c2ecf20Sopenharmony_ciTARGETS += cgroup
88c2ecf20Sopenharmony_ciTARGETS += clone3
98c2ecf20Sopenharmony_ciTARGETS += core
108c2ecf20Sopenharmony_ciTARGETS += cpufreq
118c2ecf20Sopenharmony_ciTARGETS += cpu-hotplug
128c2ecf20Sopenharmony_ciTARGETS += drivers/dma-buf
138c2ecf20Sopenharmony_ciTARGETS += efivarfs
148c2ecf20Sopenharmony_ciTARGETS += exec
158c2ecf20Sopenharmony_ciTARGETS += filesystems
168c2ecf20Sopenharmony_ciTARGETS += filesystems/binderfs
178c2ecf20Sopenharmony_ciTARGETS += filesystems/epoll
188c2ecf20Sopenharmony_ciTARGETS += firmware
198c2ecf20Sopenharmony_ciTARGETS += fpu
208c2ecf20Sopenharmony_ciTARGETS += ftrace
218c2ecf20Sopenharmony_ciTARGETS += futex
228c2ecf20Sopenharmony_ciTARGETS += gpio
238c2ecf20Sopenharmony_ciTARGETS += intel_pstate
248c2ecf20Sopenharmony_ciTARGETS += ipc
258c2ecf20Sopenharmony_ciTARGETS += ir
268c2ecf20Sopenharmony_ciTARGETS += kcmp
278c2ecf20Sopenharmony_ciTARGETS += kexec
288c2ecf20Sopenharmony_ciTARGETS += kvm
298c2ecf20Sopenharmony_ciTARGETS += lib
308c2ecf20Sopenharmony_ciTARGETS += livepatch
318c2ecf20Sopenharmony_ciTARGETS += lkdtm
328c2ecf20Sopenharmony_ciTARGETS += membarrier
338c2ecf20Sopenharmony_ciTARGETS += memfd
348c2ecf20Sopenharmony_ciTARGETS += memory-hotplug
358c2ecf20Sopenharmony_ciTARGETS += mincore
368c2ecf20Sopenharmony_ciTARGETS += mount
378c2ecf20Sopenharmony_ciTARGETS += mqueue
388c2ecf20Sopenharmony_ciTARGETS += net
398c2ecf20Sopenharmony_ciTARGETS += net/forwarding
408c2ecf20Sopenharmony_ciTARGETS += net/mptcp
418c2ecf20Sopenharmony_ciTARGETS += netfilter
428c2ecf20Sopenharmony_ciTARGETS += nsfs
438c2ecf20Sopenharmony_ciTARGETS += pidfd
448c2ecf20Sopenharmony_ciTARGETS += pid_namespace
458c2ecf20Sopenharmony_ciTARGETS += powerpc
468c2ecf20Sopenharmony_ciTARGETS += proc
478c2ecf20Sopenharmony_ciTARGETS += pstore
488c2ecf20Sopenharmony_ciTARGETS += ptrace
498c2ecf20Sopenharmony_ciTARGETS += openat2
508c2ecf20Sopenharmony_ciTARGETS += rseq
518c2ecf20Sopenharmony_ciTARGETS += rtc
528c2ecf20Sopenharmony_ciTARGETS += seccomp
538c2ecf20Sopenharmony_ciTARGETS += sigaltstack
548c2ecf20Sopenharmony_ciTARGETS += size
558c2ecf20Sopenharmony_ciTARGETS += sparc64
568c2ecf20Sopenharmony_ciTARGETS += splice
578c2ecf20Sopenharmony_ciTARGETS += static_keys
588c2ecf20Sopenharmony_ciTARGETS += sync
598c2ecf20Sopenharmony_ciTARGETS += sysctl
608c2ecf20Sopenharmony_ciTARGETS += tc-testing
618c2ecf20Sopenharmony_ciTARGETS += timens
628c2ecf20Sopenharmony_ciifneq (1, $(quicktest))
638c2ecf20Sopenharmony_ciTARGETS += timers
648c2ecf20Sopenharmony_ciendif
658c2ecf20Sopenharmony_ciTARGETS += tmpfs
668c2ecf20Sopenharmony_ciTARGETS += tpm2
678c2ecf20Sopenharmony_ciTARGETS += user
688c2ecf20Sopenharmony_ciTARGETS += vm
698c2ecf20Sopenharmony_ciTARGETS += x86
708c2ecf20Sopenharmony_ciTARGETS += zram
718c2ecf20Sopenharmony_ci#Please keep the TARGETS list alphabetically sorted
728c2ecf20Sopenharmony_ci# Run "make quicktest=1 run_tests" or
738c2ecf20Sopenharmony_ci# "make quicktest=1 kselftest" from top level Makefile
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciTARGETS_HOTPLUG = cpu-hotplug
768c2ecf20Sopenharmony_ciTARGETS_HOTPLUG += memory-hotplug
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci# User can optionally provide a TARGETS skiplist.
798c2ecf20Sopenharmony_ciSKIP_TARGETS ?=
808c2ecf20Sopenharmony_ciifneq ($(SKIP_TARGETS),)
818c2ecf20Sopenharmony_ci	TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
828c2ecf20Sopenharmony_ci	override TARGETS := $(TMP)
838c2ecf20Sopenharmony_ciendif
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci# User can set FORCE_TARGETS to 1 to require all targets to be successfully
868c2ecf20Sopenharmony_ci# built; make will fail if any of the targets cannot be built. If
878c2ecf20Sopenharmony_ci# FORCE_TARGETS is not set (the default), make will succeed if at least one
888c2ecf20Sopenharmony_ci# of the targets gets built.
898c2ecf20Sopenharmony_ciFORCE_TARGETS ?=
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
928c2ecf20Sopenharmony_ci# implicit rules to sub-test Makefiles which avoids build failures in test
938c2ecf20Sopenharmony_ci# Makefile that don't have explicit build rules.
948c2ecf20Sopenharmony_ciifeq (,$(LINK.c))
958c2ecf20Sopenharmony_cioverride LDFLAGS =
968c2ecf20Sopenharmony_cioverride MAKEFLAGS =
978c2ecf20Sopenharmony_ciendif
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
1008c2ecf20Sopenharmony_ci# KBUILD_OUTPUT with selftest objects and headers installed
1018c2ecf20Sopenharmony_ci# by selftests Makefile or lib.mk.
1028c2ecf20Sopenharmony_ciifdef building_out_of_srctree
1038c2ecf20Sopenharmony_cioverride LDFLAGS =
1048c2ecf20Sopenharmony_ciendif
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_citop_srcdir ?= ../../..
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciifeq ("$(origin O)", "command line")
1098c2ecf20Sopenharmony_ci  KBUILD_OUTPUT := $(O)
1108c2ecf20Sopenharmony_ciendif
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ciifneq ($(KBUILD_OUTPUT),)
1138c2ecf20Sopenharmony_ci  # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
1148c2ecf20Sopenharmony_ci  # expand a shell special character '~'. We use a somewhat tedious way here.
1158c2ecf20Sopenharmony_ci  abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
1168c2ecf20Sopenharmony_ci  $(if $(abs_objtree),, \
1178c2ecf20Sopenharmony_ci    $(error failed to create output directory "$(KBUILD_OUTPUT)"))
1188c2ecf20Sopenharmony_ci  # $(realpath ...) resolves symlinks
1198c2ecf20Sopenharmony_ci  abs_objtree := $(realpath $(abs_objtree))
1208c2ecf20Sopenharmony_ci  BUILD := $(abs_objtree)/kselftest
1218c2ecf20Sopenharmony_cielse
1228c2ecf20Sopenharmony_ci  BUILD := $(CURDIR)
1238c2ecf20Sopenharmony_ci  DEFAULT_INSTALL_HDR_PATH := 1
1248c2ecf20Sopenharmony_ciendif
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci# Prepare for headers install
1278c2ecf20Sopenharmony_ciinclude $(top_srcdir)/scripts/subarch.include
1288c2ecf20Sopenharmony_ciARCH           ?= $(SUBARCH)
1298c2ecf20Sopenharmony_ciexport KSFT_KHDR_INSTALL_DONE := 1
1308c2ecf20Sopenharmony_ciexport BUILD
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci# build and run gpio when output directory is the src dir.
1338c2ecf20Sopenharmony_ci# gpio has dependency on tools/gpio and builds tools/gpio
1348c2ecf20Sopenharmony_ci# objects in the src directory in all cases making the src
1358c2ecf20Sopenharmony_ci# repo dirty even when objects are relocated.
1368c2ecf20Sopenharmony_ciifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
1378c2ecf20Sopenharmony_ci	TMP := $(filter-out gpio, $(TARGETS))
1388c2ecf20Sopenharmony_ci	TARGETS := $(TMP)
1398c2ecf20Sopenharmony_ciendif
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci# set default goal to all, so make without a target runs all, even when
1428c2ecf20Sopenharmony_ci# all isn't the first target in the file.
1438c2ecf20Sopenharmony_ci.DEFAULT_GOAL := all
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
1468c2ecf20Sopenharmony_ci# is used to avoid running headers_install from lib.mk.
1478c2ecf20Sopenharmony_ci# Invoke headers install with --no-builtin-rules to avoid circular
1488c2ecf20Sopenharmony_ci# dependency in "make kselftest" case. In this case, second level
1498c2ecf20Sopenharmony_ci# make inherits builtin-rules which will use the rule generate
1508c2ecf20Sopenharmony_ci# Makefile.o and runs into
1518c2ecf20Sopenharmony_ci# "Circular Makefile.o <- prepare dependency dropped."
1528c2ecf20Sopenharmony_ci# and headers_install fails and test compile fails.
1538c2ecf20Sopenharmony_ci#
1548c2ecf20Sopenharmony_ci# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
1558c2ecf20Sopenharmony_ci# invokes them as sub-makes and --no-builtin-rules is not necessary,
1568c2ecf20Sopenharmony_ci# but doesn't cause any failures. Keep it simple and use the same
1578c2ecf20Sopenharmony_ci# flags in both cases.
1588c2ecf20Sopenharmony_ci# Local build cases: "make kselftest", "make -C" - headers are installed
1598c2ecf20Sopenharmony_ci# in the default INSTALL_HDR_PATH usr/include.
1608c2ecf20Sopenharmony_cikhdr:
1618c2ecf20Sopenharmony_ciifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
1628c2ecf20Sopenharmony_ci	$(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
1638c2ecf20Sopenharmony_cielse
1648c2ecf20Sopenharmony_ci	$(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
1658c2ecf20Sopenharmony_ci		ARCH=$(ARCH) -C $(top_srcdir) headers_install
1668c2ecf20Sopenharmony_ciendif
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ciall: khdr
1698c2ecf20Sopenharmony_ci	@ret=1;							\
1708c2ecf20Sopenharmony_ci	for TARGET in $(TARGETS); do				\
1718c2ecf20Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;			\
1728c2ecf20Sopenharmony_ci		mkdir $$BUILD_TARGET  -p;			\
1738c2ecf20Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET	\
1748c2ecf20Sopenharmony_ci				$(if $(FORCE_TARGETS),|| exit);	\
1758c2ecf20Sopenharmony_ci		ret=$$((ret * $$?));				\
1768c2ecf20Sopenharmony_ci	done; exit $$ret;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cirun_tests: all
1798c2ecf20Sopenharmony_ci	@for TARGET in $(TARGETS); do \
1808c2ecf20Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
1818c2ecf20Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
1828c2ecf20Sopenharmony_ci	done;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cihotplug:
1858c2ecf20Sopenharmony_ci	@for TARGET in $(TARGETS_HOTPLUG); do \
1868c2ecf20Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
1878c2ecf20Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
1888c2ecf20Sopenharmony_ci	done;
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_cirun_hotplug: hotplug
1918c2ecf20Sopenharmony_ci	@for TARGET in $(TARGETS_HOTPLUG); do \
1928c2ecf20Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
1938c2ecf20Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
1948c2ecf20Sopenharmony_ci	done;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ciclean_hotplug:
1978c2ecf20Sopenharmony_ci	@for TARGET in $(TARGETS_HOTPLUG); do \
1988c2ecf20Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
1998c2ecf20Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
2008c2ecf20Sopenharmony_ci	done;
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cirun_pstore_crash:
2038c2ecf20Sopenharmony_ci	$(MAKE) -C pstore run_crash
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci# Use $BUILD as the default install root. $BUILD points to the
2068c2ecf20Sopenharmony_ci# right output location for the following cases:
2078c2ecf20Sopenharmony_ci# 1. output_dir=kernel_src
2088c2ecf20Sopenharmony_ci# 2. a separate output directory is specified using O= KBUILD_OUTPUT
2098c2ecf20Sopenharmony_ci# 3. a separate output directory is specified using KBUILD_OUTPUT
2108c2ecf20Sopenharmony_ci# Avoid conflict with INSTALL_PATH set by the main Makefile
2118c2ecf20Sopenharmony_ci#
2128c2ecf20Sopenharmony_ciKSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
2138c2ecf20Sopenharmony_ciKSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
2148c2ecf20Sopenharmony_ci# Avoid changing the rest of the logic here and lib.mk.
2158c2ecf20Sopenharmony_ciINSTALL_PATH := $(KSFT_INSTALL_PATH)
2168c2ecf20Sopenharmony_ciALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
2178c2ecf20Sopenharmony_ciTEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ciinstall: all
2208c2ecf20Sopenharmony_ciifdef INSTALL_PATH
2218c2ecf20Sopenharmony_ci	@# Ask all targets to install their files
2228c2ecf20Sopenharmony_ci	mkdir -p $(INSTALL_PATH)/kselftest
2238c2ecf20Sopenharmony_ci	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
2248c2ecf20Sopenharmony_ci	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
2258c2ecf20Sopenharmony_ci	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
2268c2ecf20Sopenharmony_ci	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
2278c2ecf20Sopenharmony_ci	rm -f $(TEST_LIST)
2288c2ecf20Sopenharmony_ci	@ret=1;	\
2298c2ecf20Sopenharmony_ci	for TARGET in $(TARGETS); do \
2308c2ecf20Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
2318c2ecf20Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
2328c2ecf20Sopenharmony_ci				$(if $(FORCE_TARGETS),|| exit);	\
2338c2ecf20Sopenharmony_ci		ret=$$((ret * $$?));		\
2348c2ecf20Sopenharmony_ci	done; exit $$ret;
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	@# Ask all targets to emit their test scripts
2388c2ecf20Sopenharmony_ci	@# While building kselftest-list.text skip also non-existent TARGET dirs:
2398c2ecf20Sopenharmony_ci	@# they could be the result of a build failure and should NOT be
2408c2ecf20Sopenharmony_ci	@# included in the generated runlist.
2418c2ecf20Sopenharmony_ci	for TARGET in $(TARGETS); do \
2428c2ecf20Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
2438c2ecf20Sopenharmony_ci		[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
2448c2ecf20Sopenharmony_ci		echo -n "Emit Tests for $$TARGET\n"; \
2458c2ecf20Sopenharmony_ci		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
2468c2ecf20Sopenharmony_ci			-C $$TARGET emit_tests >> $(TEST_LIST); \
2478c2ecf20Sopenharmony_ci	done;
2488c2ecf20Sopenharmony_cielse
2498c2ecf20Sopenharmony_ci	$(error Error: set INSTALL_PATH to use install)
2508c2ecf20Sopenharmony_ciendif
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ciFORMAT ?= .gz
2538c2ecf20Sopenharmony_ciTAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
2548c2ecf20Sopenharmony_cigen_tar: install
2558c2ecf20Sopenharmony_ci	@mkdir -p ${INSTALL_PATH}/kselftest-packages/
2568c2ecf20Sopenharmony_ci	@tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
2578c2ecf20Sopenharmony_ci	@echo "Created ${TAR_PATH}"
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ciclean:
2608c2ecf20Sopenharmony_ci	@for TARGET in $(TARGETS); do \
2618c2ecf20Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
2628c2ecf20Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
2638c2ecf20Sopenharmony_ci	done;
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar
266