162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ciTARGETS += alsa
362306a36Sopenharmony_ciTARGETS += amd-pstate
462306a36Sopenharmony_ciTARGETS += arm64
562306a36Sopenharmony_ciTARGETS += bpf
662306a36Sopenharmony_ciTARGETS += breakpoints
762306a36Sopenharmony_ciTARGETS += cachestat
862306a36Sopenharmony_ciTARGETS += capabilities
962306a36Sopenharmony_ciTARGETS += cgroup
1062306a36Sopenharmony_ciTARGETS += clone3
1162306a36Sopenharmony_ciTARGETS += connector
1262306a36Sopenharmony_ciTARGETS += core
1362306a36Sopenharmony_ciTARGETS += cpufreq
1462306a36Sopenharmony_ciTARGETS += cpu-hotplug
1562306a36Sopenharmony_ciTARGETS += damon
1662306a36Sopenharmony_ciTARGETS += dmabuf-heaps
1762306a36Sopenharmony_ciTARGETS += drivers/dma-buf
1862306a36Sopenharmony_ciTARGETS += drivers/s390x/uvdevice
1962306a36Sopenharmony_ciTARGETS += drivers/net/bonding
2062306a36Sopenharmony_ciTARGETS += drivers/net/team
2162306a36Sopenharmony_ciTARGETS += efivarfs
2262306a36Sopenharmony_ciTARGETS += exec
2362306a36Sopenharmony_ciTARGETS += fchmodat2
2462306a36Sopenharmony_ciTARGETS += filesystems
2562306a36Sopenharmony_ciTARGETS += filesystems/binderfs
2662306a36Sopenharmony_ciTARGETS += filesystems/epoll
2762306a36Sopenharmony_ciTARGETS += filesystems/fat
2862306a36Sopenharmony_ciTARGETS += firmware
2962306a36Sopenharmony_ciTARGETS += fpu
3062306a36Sopenharmony_ciTARGETS += ftrace
3162306a36Sopenharmony_ciTARGETS += futex
3262306a36Sopenharmony_ciTARGETS += gpio
3362306a36Sopenharmony_ciTARGETS += hid
3462306a36Sopenharmony_ciTARGETS += intel_pstate
3562306a36Sopenharmony_ciTARGETS += iommu
3662306a36Sopenharmony_ciTARGETS += ipc
3762306a36Sopenharmony_ciTARGETS += ir
3862306a36Sopenharmony_ciTARGETS += kcmp
3962306a36Sopenharmony_ciTARGETS += kexec
4062306a36Sopenharmony_ciTARGETS += kvm
4162306a36Sopenharmony_ciTARGETS += landlock
4262306a36Sopenharmony_ciTARGETS += lib
4362306a36Sopenharmony_ciTARGETS += livepatch
4462306a36Sopenharmony_ciTARGETS += lkdtm
4562306a36Sopenharmony_ciTARGETS += membarrier
4662306a36Sopenharmony_ciTARGETS += memfd
4762306a36Sopenharmony_ciTARGETS += memory-hotplug
4862306a36Sopenharmony_ciTARGETS += mincore
4962306a36Sopenharmony_ciTARGETS += mount
5062306a36Sopenharmony_ciTARGETS += mount_setattr
5162306a36Sopenharmony_ciTARGETS += move_mount_set_group
5262306a36Sopenharmony_ciTARGETS += mqueue
5362306a36Sopenharmony_ciTARGETS += nci
5462306a36Sopenharmony_ciTARGETS += net
5562306a36Sopenharmony_ciTARGETS += net/af_unix
5662306a36Sopenharmony_ciTARGETS += net/forwarding
5762306a36Sopenharmony_ciTARGETS += net/hsr
5862306a36Sopenharmony_ciTARGETS += net/mptcp
5962306a36Sopenharmony_ciTARGETS += net/openvswitch
6062306a36Sopenharmony_ciTARGETS += netfilter
6162306a36Sopenharmony_ciTARGETS += nsfs
6262306a36Sopenharmony_ciTARGETS += perf_events
6362306a36Sopenharmony_ciTARGETS += pidfd
6462306a36Sopenharmony_ciTARGETS += pid_namespace
6562306a36Sopenharmony_ciTARGETS += powerpc
6662306a36Sopenharmony_ciTARGETS += prctl
6762306a36Sopenharmony_ciTARGETS += proc
6862306a36Sopenharmony_ciTARGETS += pstore
6962306a36Sopenharmony_ciTARGETS += ptrace
7062306a36Sopenharmony_ciTARGETS += openat2
7162306a36Sopenharmony_ciTARGETS += resctrl
7262306a36Sopenharmony_ciTARGETS += riscv
7362306a36Sopenharmony_ciTARGETS += rlimits
7462306a36Sopenharmony_ciTARGETS += rseq
7562306a36Sopenharmony_ciTARGETS += rtc
7662306a36Sopenharmony_ciTARGETS += seccomp
7762306a36Sopenharmony_ciTARGETS += sgx
7862306a36Sopenharmony_ciTARGETS += sigaltstack
7962306a36Sopenharmony_ciTARGETS += size
8062306a36Sopenharmony_ciTARGETS += sparc64
8162306a36Sopenharmony_ciTARGETS += splice
8262306a36Sopenharmony_ciTARGETS += static_keys
8362306a36Sopenharmony_ciTARGETS += sync
8462306a36Sopenharmony_ciTARGETS += syscall_user_dispatch
8562306a36Sopenharmony_ciTARGETS += sysctl
8662306a36Sopenharmony_ciTARGETS += tc-testing
8762306a36Sopenharmony_ciTARGETS += tdx
8862306a36Sopenharmony_ciTARGETS += timens
8962306a36Sopenharmony_ciifneq (1, $(quicktest))
9062306a36Sopenharmony_ciTARGETS += timers
9162306a36Sopenharmony_ciendif
9262306a36Sopenharmony_ciTARGETS += tmpfs
9362306a36Sopenharmony_ciTARGETS += tpm2
9462306a36Sopenharmony_ciTARGETS += tty
9562306a36Sopenharmony_ciTARGETS += uevent
9662306a36Sopenharmony_ciTARGETS += user
9762306a36Sopenharmony_ciTARGETS += user_events
9862306a36Sopenharmony_ciTARGETS += vDSO
9962306a36Sopenharmony_ciTARGETS += mm
10062306a36Sopenharmony_ciTARGETS += x86
10162306a36Sopenharmony_ciTARGETS += zram
10262306a36Sopenharmony_ci#Please keep the TARGETS list alphabetically sorted
10362306a36Sopenharmony_ci# Run "make quicktest=1 run_tests" or
10462306a36Sopenharmony_ci# "make quicktest=1 kselftest" from top level Makefile
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ciTARGETS_HOTPLUG = cpu-hotplug
10762306a36Sopenharmony_ciTARGETS_HOTPLUG += memory-hotplug
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci# User can optionally provide a TARGETS skiplist.  By default we skip
11062306a36Sopenharmony_ci# BPF since it has cutting edge build time dependencies which require
11162306a36Sopenharmony_ci# more effort to install.
11262306a36Sopenharmony_ciSKIP_TARGETS ?= bpf
11362306a36Sopenharmony_ciifneq ($(SKIP_TARGETS),)
11462306a36Sopenharmony_ci	TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
11562306a36Sopenharmony_ci	override TARGETS := $(TMP)
11662306a36Sopenharmony_ciendif
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci# User can set FORCE_TARGETS to 1 to require all targets to be successfully
11962306a36Sopenharmony_ci# built; make will fail if any of the targets cannot be built. If
12062306a36Sopenharmony_ci# FORCE_TARGETS is not set (the default), make will succeed if at least one
12162306a36Sopenharmony_ci# of the targets gets built.
12262306a36Sopenharmony_ciFORCE_TARGETS ?=
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing.  This provides
12562306a36Sopenharmony_ci# implicit rules to sub-test Makefiles which avoids build failures in test
12662306a36Sopenharmony_ci# Makefile that don't have explicit build rules.
12762306a36Sopenharmony_ciifeq (,$(LINK.c))
12862306a36Sopenharmony_cioverride LDFLAGS =
12962306a36Sopenharmony_cioverride MAKEFLAGS =
13062306a36Sopenharmony_ciendif
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
13362306a36Sopenharmony_ci# KBUILD_OUTPUT with selftest objects and headers installed
13462306a36Sopenharmony_ci# by selftests Makefile or lib.mk.
13562306a36Sopenharmony_ciifdef building_out_of_srctree
13662306a36Sopenharmony_cioverride LDFLAGS =
13762306a36Sopenharmony_ciendif
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_citop_srcdir ?= ../../..
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ciifeq ("$(origin O)", "command line")
14262306a36Sopenharmony_ci  KBUILD_OUTPUT := $(O)
14362306a36Sopenharmony_ciendif
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciifneq ($(KBUILD_OUTPUT),)
14662306a36Sopenharmony_ci  # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
14762306a36Sopenharmony_ci  # expand a shell special character '~'. We use a somewhat tedious way here.
14862306a36Sopenharmony_ci  abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
14962306a36Sopenharmony_ci  $(if $(abs_objtree),, \
15062306a36Sopenharmony_ci    $(error failed to create output directory "$(KBUILD_OUTPUT)"))
15162306a36Sopenharmony_ci  # $(realpath ...) resolves symlinks
15262306a36Sopenharmony_ci  abs_objtree := $(realpath $(abs_objtree))
15362306a36Sopenharmony_ci  BUILD := $(abs_objtree)/kselftest
15462306a36Sopenharmony_ci  KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include
15562306a36Sopenharmony_cielse
15662306a36Sopenharmony_ci  BUILD := $(CURDIR)
15762306a36Sopenharmony_ci  abs_srctree := $(shell cd $(top_srcdir) && pwd)
15862306a36Sopenharmony_ci  KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include
15962306a36Sopenharmony_ci  DEFAULT_INSTALL_HDR_PATH := 1
16062306a36Sopenharmony_ciendif
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci# Prepare for headers install
16362306a36Sopenharmony_ciinclude $(top_srcdir)/scripts/subarch.include
16462306a36Sopenharmony_ciARCH           ?= $(SUBARCH)
16562306a36Sopenharmony_ciexport BUILD
16662306a36Sopenharmony_ciexport KHDR_INCLUDES
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci# set default goal to all, so make without a target runs all, even when
16962306a36Sopenharmony_ci# all isn't the first target in the file.
17062306a36Sopenharmony_ci.DEFAULT_GOAL := all
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ciall:
17362306a36Sopenharmony_ci	@ret=1;							\
17462306a36Sopenharmony_ci	for TARGET in $(TARGETS); do				\
17562306a36Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;			\
17662306a36Sopenharmony_ci		mkdir $$BUILD_TARGET  -p;			\
17762306a36Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET	\
17862306a36Sopenharmony_ci				O=$(abs_objtree)		\
17962306a36Sopenharmony_ci				$(if $(FORCE_TARGETS),|| exit);	\
18062306a36Sopenharmony_ci		ret=$$((ret * $$?));				\
18162306a36Sopenharmony_ci	done; exit $$ret;
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_cirun_tests: all
18462306a36Sopenharmony_ci	@for TARGET in $(TARGETS); do \
18562306a36Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
18662306a36Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests \
18762306a36Sopenharmony_ci				O=$(abs_objtree);		    \
18862306a36Sopenharmony_ci	done;
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_cihotplug:
19162306a36Sopenharmony_ci	@for TARGET in $(TARGETS_HOTPLUG); do \
19262306a36Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
19362306a36Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
19462306a36Sopenharmony_ci	done;
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_cirun_hotplug: hotplug
19762306a36Sopenharmony_ci	@for TARGET in $(TARGETS_HOTPLUG); do \
19862306a36Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
19962306a36Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
20062306a36Sopenharmony_ci	done;
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ciclean_hotplug:
20362306a36Sopenharmony_ci	@for TARGET in $(TARGETS_HOTPLUG); do \
20462306a36Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
20562306a36Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
20662306a36Sopenharmony_ci	done;
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_cirun_pstore_crash:
20962306a36Sopenharmony_ci	$(MAKE) -C pstore run_crash
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci# Use $BUILD as the default install root. $BUILD points to the
21262306a36Sopenharmony_ci# right output location for the following cases:
21362306a36Sopenharmony_ci# 1. output_dir=kernel_src
21462306a36Sopenharmony_ci# 2. a separate output directory is specified using O= KBUILD_OUTPUT
21562306a36Sopenharmony_ci# 3. a separate output directory is specified using KBUILD_OUTPUT
21662306a36Sopenharmony_ci# Avoid conflict with INSTALL_PATH set by the main Makefile
21762306a36Sopenharmony_ci#
21862306a36Sopenharmony_ciKSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
21962306a36Sopenharmony_ciKSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
22062306a36Sopenharmony_ci# Avoid changing the rest of the logic here and lib.mk.
22162306a36Sopenharmony_ciINSTALL_PATH := $(KSFT_INSTALL_PATH)
22262306a36Sopenharmony_ciALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
22362306a36Sopenharmony_ciTEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ciinstall: all
22662306a36Sopenharmony_ciifdef INSTALL_PATH
22762306a36Sopenharmony_ci	@# Ask all targets to install their files
22862306a36Sopenharmony_ci	mkdir -p $(INSTALL_PATH)/kselftest
22962306a36Sopenharmony_ci	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
23062306a36Sopenharmony_ci	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
23162306a36Sopenharmony_ci	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
23262306a36Sopenharmony_ci	install -m 744 run_kselftest.sh $(INSTALL_PATH)/
23362306a36Sopenharmony_ci	rm -f $(TEST_LIST)
23462306a36Sopenharmony_ci	@ret=1;	\
23562306a36Sopenharmony_ci	for TARGET in $(TARGETS); do \
23662306a36Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
23762306a36Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
23862306a36Sopenharmony_ci				O=$(abs_objtree)		\
23962306a36Sopenharmony_ci				$(if $(FORCE_TARGETS),|| exit);	\
24062306a36Sopenharmony_ci		ret=$$((ret * $$?));		\
24162306a36Sopenharmony_ci	done; exit $$ret;
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci	@# Ask all targets to emit their test scripts
24562306a36Sopenharmony_ci	@# While building kselftest-list.text skip also non-existent TARGET dirs:
24662306a36Sopenharmony_ci	@# they could be the result of a build failure and should NOT be
24762306a36Sopenharmony_ci	@# included in the generated runlist.
24862306a36Sopenharmony_ci	for TARGET in $(TARGETS); do \
24962306a36Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
25062306a36Sopenharmony_ci		[ ! -d $(INSTALL_PATH)/$$TARGET ] && printf "Skipping non-existent dir: $$TARGET\n" && continue; \
25162306a36Sopenharmony_ci		printf "Emit Tests for $$TARGET\n"; \
25262306a36Sopenharmony_ci		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
25362306a36Sopenharmony_ci			-C $$TARGET emit_tests >> $(TEST_LIST); \
25462306a36Sopenharmony_ci	done;
25562306a36Sopenharmony_cielse
25662306a36Sopenharmony_ci	$(error Error: set INSTALL_PATH to use install)
25762306a36Sopenharmony_ciendif
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ciFORMAT ?= .gz
26062306a36Sopenharmony_ciTAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
26162306a36Sopenharmony_cigen_tar: install
26262306a36Sopenharmony_ci	@mkdir -p ${INSTALL_PATH}/kselftest-packages/
26362306a36Sopenharmony_ci	@tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
26462306a36Sopenharmony_ci	@echo "Created ${TAR_PATH}"
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_ciclean:
26762306a36Sopenharmony_ci	@for TARGET in $(TARGETS); do \
26862306a36Sopenharmony_ci		BUILD_TARGET=$$BUILD/$$TARGET;	\
26962306a36Sopenharmony_ci		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
27062306a36Sopenharmony_ci	done;
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ci.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar
273