1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 25aaf9effSMark BrownTARGETS += alsa 35aaf9effSMark BrownTARGETS += arm64 447a18c42SPintu AgarwalTARGETS += bpf 55aa5bd14SDaniel BorkmannTARGETS += breakpoints 6f4ecb322SBamvor Jian ZhangTARGETS += capabilities 784092dbcSRoman GushchinTARGETS += cgroup 8de528723SChristian BraunerTARGETS += clone3 92c5db60eSChristian BraunerTARGETS += core 10e66d5b67SViresh KumarTARGETS += cpufreq 1166a01b96SAndrew MortonTARGETS += cpu-hotplug 126edf2e37STom MurphyTARGETS += drivers/dma-buf 1366a01b96SAndrew MortonTARGETS += efivarfs 1496e869d8SAndrew MortonTARGETS += exec 15ce290a19SChristian BraunerTARGETS += filesystems 1675abec73SChristian BraunerTARGETS += filesystems/binderfs 17f2728fe8SHeiherTARGETS += filesystems/epoll 1896e869d8SAndrew MortonTARGETS += firmware 194185b3b9SPetteri AimonenTARGETS += fpu 2096e869d8SAndrew MortonTARGETS += ftrace 21ecac1a75SDarren HartTARGETS += futex 2222f6592bSBamvor Jian ZhangTARGETS += gpio 236320303fSStafford HorneTARGETS += intel_pstate 247e722473SBamvor Jian ZhangTARGETS += ipc 25e55c884eSSean YoungTARGETS += ir 2658c7be84SPavel EmelyanovTARGETS += kcmp 27c3c0e811SMimi ZoharTARGETS += kexec 28783e9e51SPaolo BonziniTARGETS += kvm 29e1199815SMickaël SalaünTARGETS += landlock 30317dc34aSKees CookTARGETS += lib 31a2818ee4SJoe LawrenceTARGETS += livepatch 3246d1a0f0SKees CookTARGETS += lkdtm 33b6d97344SPranith KumarTARGETS += membarrier 344f5ce5e8SDavid HerrmannTARGETS += memfd 3558c7be84SPavel EmelyanovTARGETS += memory-hotplug 367a309195SRicardo CañueloTARGETS += mincore 37db181ce0SEric W. BiedermanTARGETS += mount 3801eadc8dSChristian BraunerTARGETS += mount_setattr 398374f431SPavel TikhomirovTARGETS += move_mount_set_group 4096e869d8SAndrew MortonTARGETS += mqueue 41f595cf12SBongsu JeonTARGETS += nci 42a6f68034SDavid S. MillerTARGETS += net 43314001f0SRao ShoaibTARGETS += net/af_unix 4481573b18SVadym KochanTARGETS += net/forwarding 45048d19d4SFlorian WestphalTARGETS += net/mptcp 4625d8bcedSFlorian WestphalTARGETS += netfilter 476ad92bf6SAndrey VaginTARGETS += nsfs 48575a0ae9SChristian BraunerTARGETS += pidfd 496952a4f6SChristian BraunerTARGETS += pid_namespace 500e56dacdSMichael EllermanTARGETS += powerpc 519cd65655SAlexey DobriyanTARGETS += proc 52cc04a46fSHiraku ToyookaTARGETS += pstore 5396e869d8SAndrew MortonTARGETS += ptrace 54b28a10aeSAleksa SaraiTARGETS += openat2 55e4aebf06SAlexey GladkovTARGETS += rlimits 56ccba8b64SMathieu DesnoyersTARGETS += rseq 57a12ab9e1SAlexandre BelloniTARGETS += rtc 58c99ee51aSKees CookTARGETS += seccomp 592adcba79SJarkko SakkinenTARGETS += sgx 6019fd2868SStas SergeevTARGETS += sigaltstack 613ce51050STim BirdTARGETS += size 623c545084STom HromatkaTARGETS += sparc64 63b8826e50SAl ViroTARGETS += splice 641087d019SBamvor Jian ZhangTARGETS += static_keys 6582208160SEmilio LópezTARGETS += sync 66179ef035SGabriel Krisman BertaziTARGETS += syscall_user_dispatch 6796e869d8SAndrew MortonTARGETS += sysctl 682b9843fbSBriana OurslerTARGETS += tc-testing 6961c57676SDmitry SafonovTARGETS += timens 702278e5edSShuah Khanifneq (1, $(quicktest)) 7196e869d8SAndrew MortonTARGETS += timers 722278e5edSShuah Khanendif 73a3322868SAlexey DobriyanTARGETS += tmpfs 746ea3dfe1SJarkko SakkinenTARGETS += tpm2 7596e869d8SAndrew MortonTARGETS += user 7640723419SVincenzo FrascinoTARGETS += vDSO 7796e869d8SAndrew MortonTARGETS += vm 783f705dfdSAndy LutomirskiTARGETS += x86 79f21fb798SNaresh KambojuTARGETS += zram 8096e869d8SAndrew Morton#Please keep the TARGETS list alphabetically sorted 812278e5edSShuah Khan# Run "make quicktest=1 run_tests" or 82c6a13fafSSeongJae Park# "make quicktest=1 kselftest" from top level Makefile 83274343adSFrederic Weisbecker 84ddddda9bSShuah KhanTARGETS_HOTPLUG = cpu-hotplug 85ddddda9bSShuah KhanTARGETS_HOTPLUG += memory-hotplug 86ddddda9bSShuah Khan 877a6eb7c3SMark Brown# User can optionally provide a TARGETS skiplist. By default we skip 887a6eb7c3SMark Brown# BPF since it has cutting edge build time dependencies which require 897a6eb7c3SMark Brown# more effort to install. 907a6eb7c3SMark BrownSKIP_TARGETS ?= bpf 913a24f7f6SCristian Marussiifneq ($(SKIP_TARGETS),) 923a24f7f6SCristian Marussi TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS)) 933a24f7f6SCristian Marussi override TARGETS := $(TMP) 943a24f7f6SCristian Marussiendif 953a24f7f6SCristian Marussi 969d235a55SJiri Benc# User can set FORCE_TARGETS to 1 to require all targets to be successfully 979d235a55SJiri Benc# built; make will fail if any of the targets cannot be built. If 989d235a55SJiri Benc# FORCE_TARGETS is not set (the default), make will succeed if at least one 999d235a55SJiri Benc# of the targets gets built. 1009d235a55SJiri BencFORCE_TARGETS ?= 1019d235a55SJiri Benc 102f69237e1SGreg Thelen# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides 103f69237e1SGreg Thelen# implicit rules to sub-test Makefiles which avoids build failures in test 104f69237e1SGreg Thelen# Makefile that don't have explicit build rules. 105f69237e1SGreg Thelenifeq (,$(LINK.c)) 10660df4642SArnaldo Carvalho de Melooverride LDFLAGS = 10767d8712dSShuah Khanoverride MAKEFLAGS = 10867d8712dSShuah Khanendif 10967d8712dSShuah Khan 11029e911efSShuah Khan# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering 11161c2018cSShuah Khan# KBUILD_OUTPUT with selftest objects and headers installed 11261c2018cSShuah Khan# by selftests Makefile or lib.mk. 113051f278eSMasahiro Yamadaifdef building_out_of_srctree 11452fd1d08SShuah Khanoverride LDFLAGS = 11552fd1d08SShuah Khanendif 11652fd1d08SShuah Khan 1175ad51ab6SMuhammad Usama Anjumtop_srcdir ?= ../../.. 1185ad51ab6SMuhammad Usama Anjum 1195ad51ab6SMuhammad Usama Anjumifeq ("$(origin O)", "command line") 1205ad51ab6SMuhammad Usama Anjum KBUILD_OUTPUT := $(O) 1218ce72dc3SShuah Khanendif 1225ad51ab6SMuhammad Usama Anjum 1235ad51ab6SMuhammad Usama Anjumifneq ($(KBUILD_OUTPUT),) 1245ad51ab6SMuhammad Usama Anjum # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot 1255ad51ab6SMuhammad Usama Anjum # expand a shell special character '~'. We use a somewhat tedious way here. 1265ad51ab6SMuhammad Usama Anjum abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) 1275ad51ab6SMuhammad Usama Anjum $(if $(abs_objtree),, \ 1285ad51ab6SMuhammad Usama Anjum $(error failed to create output directory "$(KBUILD_OUTPUT)")) 1295ad51ab6SMuhammad Usama Anjum # $(realpath ...) resolves symlinks 1305ad51ab6SMuhammad Usama Anjum abs_objtree := $(realpath $(abs_objtree)) 1315ad51ab6SMuhammad Usama Anjum BUILD := $(abs_objtree)/kselftest 132*46e50459SMuhammad Usama Anjum KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include 1335ad51ab6SMuhammad Usama Anjumelse 1345ad51ab6SMuhammad Usama Anjum BUILD := $(CURDIR) 135250f8c11SMuhammad Usama Anjum abs_srctree := $(shell cd $(top_srcdir) && pwd) 136*46e50459SMuhammad Usama Anjum KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include 1375ad51ab6SMuhammad Usama Anjum DEFAULT_INSTALL_HDR_PATH := 1 138a8ba798bSbamvor.zhangjian@huawei.comendif 139a8ba798bSbamvor.zhangjian@huawei.com 1408ce72dc3SShuah Khan# Prepare for headers install 1418ce72dc3SShuah Khaninclude $(top_srcdir)/scripts/subarch.include 1428ce72dc3SShuah KhanARCH ?= $(SUBARCH) 1438ce72dc3SShuah Khanexport KSFT_KHDR_INSTALL_DONE := 1 144a8ba798bSbamvor.zhangjian@huawei.comexport BUILD 145250f8c11SMuhammad Usama Anjumexport KHDR_INCLUDES 1468ce72dc3SShuah Khan 1478ce72dc3SShuah Khan# set default goal to all, so make without a target runs all, even when 1488ce72dc3SShuah Khan# all isn't the first target in the file. 1498ce72dc3SShuah Khan.DEFAULT_GOAL := all 1508ce72dc3SShuah Khan 1518ce72dc3SShuah Khan# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE 1528ce72dc3SShuah Khan# is used to avoid running headers_install from lib.mk. 1538ce72dc3SShuah Khan# Invoke headers install with --no-builtin-rules to avoid circular 1548ce72dc3SShuah Khan# dependency in "make kselftest" case. In this case, second level 1558ce72dc3SShuah Khan# make inherits builtin-rules which will use the rule generate 1568ce72dc3SShuah Khan# Makefile.o and runs into 1578ce72dc3SShuah Khan# "Circular Makefile.o <- prepare dependency dropped." 1588ce72dc3SShuah Khan# and headers_install fails and test compile fails. 1598ce72dc3SShuah Khan# 1608ce72dc3SShuah Khan# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile 1618ce72dc3SShuah Khan# invokes them as sub-makes and --no-builtin-rules is not necessary, 1628ce72dc3SShuah Khan# but doesn't cause any failures. Keep it simple and use the same 1638ce72dc3SShuah Khan# flags in both cases. 1648ce72dc3SShuah Khan# Local build cases: "make kselftest", "make -C" - headers are installed 1658ce72dc3SShuah Khan# in the default INSTALL_HDR_PATH usr/include. 1668ce72dc3SShuah Khankhdr: 1678ce72dc3SShuah Khanifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) 1680ac33e4eSIlya Leoshkevich $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install 1698ce72dc3SShuah Khanelse 170afe5fba8SMuhammad Usama Anjum $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$(abs_objtree)/usr \ 1718ce72dc3SShuah Khan ARCH=$(ARCH) -C $(top_srcdir) headers_install 1728ce72dc3SShuah Khanendif 1738ce72dc3SShuah Khan 1748ce72dc3SShuah Khanall: khdr 1755f70bde2SCristian Marussi @ret=1; \ 1765f70bde2SCristian Marussi for TARGET in $(TARGETS); do \ 177a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 178a8ba798bSbamvor.zhangjian@huawei.com mkdir $$BUILD_TARGET -p; \ 1799d235a55SJiri Benc $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ 1809d235a55SJiri Benc $(if $(FORCE_TARGETS),|| exit); \ 1815f70bde2SCristian Marussi ret=$$((ret * $$?)); \ 1825f70bde2SCristian Marussi done; exit $$ret; 183274343adSFrederic Weisbecker 184cab6b056SAndrew Mortonrun_tests: all 1851ede0536SShuah Khan @for TARGET in $(TARGETS); do \ 186a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1870ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ 188f467f714SFrederic Weisbecker done; 189f467f714SFrederic Weisbecker 190ddddda9bSShuah Khanhotplug: 1911ede0536SShuah Khan @for TARGET in $(TARGETS_HOTPLUG); do \ 192a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1930ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 194ddddda9bSShuah Khan done; 195ddddda9bSShuah Khan 196ddddda9bSShuah Khanrun_hotplug: hotplug 1971ede0536SShuah Khan @for TARGET in $(TARGETS_HOTPLUG); do \ 198a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1990ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ 200ddddda9bSShuah Khan done; 201ddddda9bSShuah Khan 202ddddda9bSShuah Khanclean_hotplug: 2031ede0536SShuah Khan @for TARGET in $(TARGETS_HOTPLUG); do \ 204a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 2050ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 206ddddda9bSShuah Khan done; 207ddddda9bSShuah Khan 208f615e2bbSHiraku Toyookarun_pstore_crash: 2090ac33e4eSIlya Leoshkevich $(MAKE) -C pstore run_crash 210f615e2bbSHiraku Toyooka 211c3c59928SShuah Khan# Use $BUILD as the default install root. $BUILD points to the 212c3c59928SShuah Khan# right output location for the following cases: 213c3c59928SShuah Khan# 1. output_dir=kernel_src 214c3c59928SShuah Khan# 2. a separate output directory is specified using O= KBUILD_OUTPUT 215c3c59928SShuah Khan# 3. a separate output directory is specified using KBUILD_OUTPUT 21617eac6c2SShuah Khan# Avoid conflict with INSTALL_PATH set by the main Makefile 217c3c59928SShuah Khan# 21817eac6c2SShuah KhanKSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install 21917eac6c2SShuah KhanKSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH)) 22017eac6c2SShuah Khan# Avoid changing the rest of the logic here and lib.mk. 22117eac6c2SShuah KhanINSTALL_PATH := $(KSFT_INSTALL_PATH) 22232dcfba6SMichael EllermanALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 223f0f0a5dfSKees CookTEST_LIST := $(INSTALL_PATH)/kselftest-list.txt 22432dcfba6SMichael Ellerman 225c3c59928SShuah Khaninstall: all 22632dcfba6SMichael Ellermanifdef INSTALL_PATH 22732dcfba6SMichael Ellerman @# Ask all targets to install their files 228d4e59a53SKees Cook mkdir -p $(INSTALL_PATH)/kselftest 229c78fd76fSKees Cook install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ 230d4e59a53SKees Cook install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ 2315c069b6dSKees Cook install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ 232f0f0a5dfSKees Cook install -m 744 run_kselftest.sh $(INSTALL_PATH)/ 233f0f0a5dfSKees Cook rm -f $(TEST_LIST) 2345f70bde2SCristian Marussi @ret=1; \ 2355f70bde2SCristian Marussi for TARGET in $(TARGETS); do \ 236a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 2379d235a55SJiri Benc $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ 2389d235a55SJiri Benc $(if $(FORCE_TARGETS),|| exit); \ 2395f70bde2SCristian Marussi ret=$$((ret * $$?)); \ 2405f70bde2SCristian Marussi done; exit $$ret; 24132dcfba6SMichael Ellerman 24232dcfba6SMichael Ellerman 243f0f0a5dfSKees Cook @# Ask all targets to emit their test scripts 244f0f0a5dfSKees Cook @# While building kselftest-list.text skip also non-existent TARGET dirs: 245131b30c9SCristian Marussi @# they could be the result of a build failure and should NOT be 246131b30c9SCristian Marussi @# included in the generated runlist. 24732dcfba6SMichael Ellerman for TARGET in $(TARGETS); do \ 248a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 24902bf1f8bSPrabhakar Kushwaha [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ 25017eac6c2SShuah Khan echo -n "Emit Tests for $$TARGET\n"; \ 251f0f0a5dfSKees Cook $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \ 252f0f0a5dfSKees Cook -C $$TARGET emit_tests >> $(TEST_LIST); \ 25332dcfba6SMichael Ellerman done; 25432dcfba6SMichael Ellermanelse 25532dcfba6SMichael Ellerman $(error Error: set INSTALL_PATH to use install) 25632dcfba6SMichael Ellermanendif 25732dcfba6SMichael Ellerman 258a5f30467SVeronika KabatovaFORMAT ?= .gz 259a5f30467SVeronika KabatovaTAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT}) 260a5f30467SVeronika Kabatovagen_tar: install 261a5f30467SVeronika Kabatova @mkdir -p ${INSTALL_PATH}/kselftest-packages/ 262a5f30467SVeronika Kabatova @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} . 263a5f30467SVeronika Kabatova @echo "Created ${TAR_PATH}" 264a5f30467SVeronika Kabatova 265274343adSFrederic Weisbeckerclean: 2661ede0536SShuah Khan @for TARGET in $(TARGETS); do \ 267a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 2680ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 269274343adSFrederic Weisbecker done; 27032dcfba6SMichael Ellerman 271a5f30467SVeronika Kabatova.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar 272