1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 2e722a295SGreg Kroah-HartmanTARGETS = arm64 347a18c42SPintu AgarwalTARGETS += bpf 45aa5bd14SDaniel BorkmannTARGETS += breakpoints 5f4ecb322SBamvor Jian ZhangTARGETS += capabilities 684092dbcSRoman GushchinTARGETS += cgroup 7de528723SChristian BraunerTARGETS += clone3 82c5db60eSChristian BraunerTARGETS += core 9e66d5b67SViresh KumarTARGETS += cpufreq 1066a01b96SAndrew MortonTARGETS += cpu-hotplug 116edf2e37STom MurphyTARGETS += drivers/dma-buf 1266a01b96SAndrew MortonTARGETS += efivarfs 1396e869d8SAndrew MortonTARGETS += exec 14ce290a19SChristian BraunerTARGETS += filesystems 1575abec73SChristian BraunerTARGETS += filesystems/binderfs 16f2728fe8SHeiherTARGETS += filesystems/epoll 1796e869d8SAndrew MortonTARGETS += firmware 184185b3b9SPetteri AimonenTARGETS += fpu 1996e869d8SAndrew MortonTARGETS += ftrace 20ecac1a75SDarren HartTARGETS += futex 2122f6592bSBamvor Jian ZhangTARGETS += gpio 226320303fSStafford HorneTARGETS += intel_pstate 237e722473SBamvor Jian ZhangTARGETS += ipc 24e55c884eSSean YoungTARGETS += ir 2558c7be84SPavel EmelyanovTARGETS += kcmp 26c3c0e811SMimi ZoharTARGETS += kexec 27783e9e51SPaolo BonziniTARGETS += kvm 28317dc34aSKees CookTARGETS += lib 29a2818ee4SJoe LawrenceTARGETS += livepatch 3046d1a0f0SKees CookTARGETS += lkdtm 31b6d97344SPranith KumarTARGETS += membarrier 324f5ce5e8SDavid HerrmannTARGETS += memfd 3358c7be84SPavel EmelyanovTARGETS += memory-hotplug 347a309195SRicardo CañueloTARGETS += mincore 35db181ce0SEric W. BiedermanTARGETS += mount 36*01eadc8dSChristian BraunerTARGETS += mount_setattr 3796e869d8SAndrew MortonTARGETS += mqueue 38a6f68034SDavid S. MillerTARGETS += net 3981573b18SVadym KochanTARGETS += net/forwarding 40048d19d4SFlorian WestphalTARGETS += net/mptcp 4125d8bcedSFlorian WestphalTARGETS += netfilter 426ad92bf6SAndrey VaginTARGETS += nsfs 43575a0ae9SChristian BraunerTARGETS += pidfd 446952a4f6SChristian BraunerTARGETS += pid_namespace 450e56dacdSMichael EllermanTARGETS += powerpc 469cd65655SAlexey DobriyanTARGETS += proc 47cc04a46fSHiraku ToyookaTARGETS += pstore 4896e869d8SAndrew MortonTARGETS += ptrace 49b28a10aeSAleksa SaraiTARGETS += openat2 50ccba8b64SMathieu DesnoyersTARGETS += rseq 51a12ab9e1SAlexandre BelloniTARGETS += rtc 52c99ee51aSKees CookTARGETS += seccomp 532adcba79SJarkko SakkinenTARGETS += sgx 5419fd2868SStas SergeevTARGETS += sigaltstack 553ce51050STim BirdTARGETS += size 563c545084STom HromatkaTARGETS += sparc64 57b8826e50SAl ViroTARGETS += splice 581087d019SBamvor Jian ZhangTARGETS += static_keys 5982208160SEmilio LópezTARGETS += sync 60179ef035SGabriel Krisman BertaziTARGETS += syscall_user_dispatch 6196e869d8SAndrew MortonTARGETS += sysctl 622b9843fbSBriana OurslerTARGETS += tc-testing 6361c57676SDmitry SafonovTARGETS += timens 642278e5edSShuah Khanifneq (1, $(quicktest)) 6596e869d8SAndrew MortonTARGETS += timers 662278e5edSShuah Khanendif 67a3322868SAlexey DobriyanTARGETS += tmpfs 686ea3dfe1SJarkko SakkinenTARGETS += tpm2 6996e869d8SAndrew MortonTARGETS += user 7040723419SVincenzo FrascinoTARGETS += vDSO 7196e869d8SAndrew MortonTARGETS += vm 723f705dfdSAndy LutomirskiTARGETS += x86 73f21fb798SNaresh KambojuTARGETS += zram 7496e869d8SAndrew Morton#Please keep the TARGETS list alphabetically sorted 752278e5edSShuah Khan# Run "make quicktest=1 run_tests" or 76c6a13fafSSeongJae Park# "make quicktest=1 kselftest" from top level Makefile 77274343adSFrederic Weisbecker 78ddddda9bSShuah KhanTARGETS_HOTPLUG = cpu-hotplug 79ddddda9bSShuah KhanTARGETS_HOTPLUG += memory-hotplug 80ddddda9bSShuah Khan 817a6eb7c3SMark Brown# User can optionally provide a TARGETS skiplist. By default we skip 827a6eb7c3SMark Brown# BPF since it has cutting edge build time dependencies which require 837a6eb7c3SMark Brown# more effort to install. 847a6eb7c3SMark BrownSKIP_TARGETS ?= bpf 853a24f7f6SCristian Marussiifneq ($(SKIP_TARGETS),) 863a24f7f6SCristian Marussi TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS)) 873a24f7f6SCristian Marussi override TARGETS := $(TMP) 883a24f7f6SCristian Marussiendif 893a24f7f6SCristian Marussi 909d235a55SJiri Benc# User can set FORCE_TARGETS to 1 to require all targets to be successfully 919d235a55SJiri Benc# built; make will fail if any of the targets cannot be built. If 929d235a55SJiri Benc# FORCE_TARGETS is not set (the default), make will succeed if at least one 939d235a55SJiri Benc# of the targets gets built. 949d235a55SJiri BencFORCE_TARGETS ?= 959d235a55SJiri Benc 96f69237e1SGreg Thelen# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides 97f69237e1SGreg Thelen# implicit rules to sub-test Makefiles which avoids build failures in test 98f69237e1SGreg Thelen# Makefile that don't have explicit build rules. 99f69237e1SGreg Thelenifeq (,$(LINK.c)) 10060df4642SArnaldo Carvalho de Melooverride LDFLAGS = 10167d8712dSShuah Khanoverride MAKEFLAGS = 10267d8712dSShuah Khanendif 10367d8712dSShuah Khan 10429e911efSShuah Khan# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering 10561c2018cSShuah Khan# KBUILD_OUTPUT with selftest objects and headers installed 10661c2018cSShuah Khan# by selftests Makefile or lib.mk. 107051f278eSMasahiro Yamadaifdef building_out_of_srctree 10852fd1d08SShuah Khanoverride LDFLAGS = 10952fd1d08SShuah Khanendif 11052fd1d08SShuah Khan 1118ce72dc3SShuah Khanifneq ($(O),) 11229e911efSShuah Khan BUILD := $(O)/kselftest 1138ce72dc3SShuah Khanelse 1148ce72dc3SShuah Khan ifneq ($(KBUILD_OUTPUT),) 115f60b85e8SShuah Khan BUILD := $(KBUILD_OUTPUT)/kselftest 1168ce72dc3SShuah Khan else 117a8ba798bSbamvor.zhangjian@huawei.com BUILD := $(shell pwd) 1188ce72dc3SShuah Khan DEFAULT_INSTALL_HDR_PATH := 1 1198ce72dc3SShuah Khan endif 120a8ba798bSbamvor.zhangjian@huawei.comendif 121a8ba798bSbamvor.zhangjian@huawei.com 1228ce72dc3SShuah Khan# Prepare for headers install 1238ce72dc3SShuah Khantop_srcdir ?= ../../.. 1248ce72dc3SShuah Khaninclude $(top_srcdir)/scripts/subarch.include 1258ce72dc3SShuah KhanARCH ?= $(SUBARCH) 1268ce72dc3SShuah Khanexport KSFT_KHDR_INSTALL_DONE := 1 127a8ba798bSbamvor.zhangjian@huawei.comexport BUILD 1288ce72dc3SShuah Khan 129d917fb87SShuah Khan# build and run gpio when output directory is the src dir. 130d917fb87SShuah Khan# gpio has dependency on tools/gpio and builds tools/gpio 131d917fb87SShuah Khan# objects in the src directory in all cases making the src 132d917fb87SShuah Khan# repo dirty even when objects are relocated. 133d917fb87SShuah Khanifneq (1,$(DEFAULT_INSTALL_HDR_PATH)) 134d917fb87SShuah Khan TMP := $(filter-out gpio, $(TARGETS)) 135d917fb87SShuah Khan TARGETS := $(TMP) 136d917fb87SShuah Khanendif 137d917fb87SShuah Khan 1388ce72dc3SShuah Khan# set default goal to all, so make without a target runs all, even when 1398ce72dc3SShuah Khan# all isn't the first target in the file. 1408ce72dc3SShuah Khan.DEFAULT_GOAL := all 1418ce72dc3SShuah Khan 1428ce72dc3SShuah Khan# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE 1438ce72dc3SShuah Khan# is used to avoid running headers_install from lib.mk. 1448ce72dc3SShuah Khan# Invoke headers install with --no-builtin-rules to avoid circular 1458ce72dc3SShuah Khan# dependency in "make kselftest" case. In this case, second level 1468ce72dc3SShuah Khan# make inherits builtin-rules which will use the rule generate 1478ce72dc3SShuah Khan# Makefile.o and runs into 1488ce72dc3SShuah Khan# "Circular Makefile.o <- prepare dependency dropped." 1498ce72dc3SShuah Khan# and headers_install fails and test compile fails. 1508ce72dc3SShuah Khan# 1518ce72dc3SShuah Khan# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile 1528ce72dc3SShuah Khan# invokes them as sub-makes and --no-builtin-rules is not necessary, 1538ce72dc3SShuah Khan# but doesn't cause any failures. Keep it simple and use the same 1548ce72dc3SShuah Khan# flags in both cases. 1558ce72dc3SShuah Khan# Local build cases: "make kselftest", "make -C" - headers are installed 1568ce72dc3SShuah Khan# in the default INSTALL_HDR_PATH usr/include. 1578ce72dc3SShuah Khankhdr: 1588ce72dc3SShuah Khanifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) 1590ac33e4eSIlya Leoshkevich $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install 1608ce72dc3SShuah Khanelse 1610ac33e4eSIlya Leoshkevich $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \ 1628ce72dc3SShuah Khan ARCH=$(ARCH) -C $(top_srcdir) headers_install 1638ce72dc3SShuah Khanendif 1648ce72dc3SShuah Khan 1658ce72dc3SShuah Khanall: khdr 1665f70bde2SCristian Marussi @ret=1; \ 1675f70bde2SCristian Marussi for TARGET in $(TARGETS); do \ 168a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 169a8ba798bSbamvor.zhangjian@huawei.com mkdir $$BUILD_TARGET -p; \ 1709d235a55SJiri Benc $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ 1719d235a55SJiri Benc $(if $(FORCE_TARGETS),|| exit); \ 1725f70bde2SCristian Marussi ret=$$((ret * $$?)); \ 1735f70bde2SCristian Marussi done; exit $$ret; 174274343adSFrederic Weisbecker 175cab6b056SAndrew Mortonrun_tests: all 1761ede0536SShuah Khan @for TARGET in $(TARGETS); do \ 177a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1780ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ 179f467f714SFrederic Weisbecker done; 180f467f714SFrederic Weisbecker 181ddddda9bSShuah Khanhotplug: 1821ede0536SShuah Khan @for TARGET in $(TARGETS_HOTPLUG); do \ 183a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1840ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 185ddddda9bSShuah Khan done; 186ddddda9bSShuah Khan 187ddddda9bSShuah Khanrun_hotplug: hotplug 1881ede0536SShuah Khan @for TARGET in $(TARGETS_HOTPLUG); do \ 189a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1900ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ 191ddddda9bSShuah Khan done; 192ddddda9bSShuah Khan 193ddddda9bSShuah Khanclean_hotplug: 1941ede0536SShuah Khan @for TARGET in $(TARGETS_HOTPLUG); do \ 195a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1960ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 197ddddda9bSShuah Khan done; 198ddddda9bSShuah Khan 199f615e2bbSHiraku Toyookarun_pstore_crash: 2000ac33e4eSIlya Leoshkevich $(MAKE) -C pstore run_crash 201f615e2bbSHiraku Toyooka 202c3c59928SShuah Khan# Use $BUILD as the default install root. $BUILD points to the 203c3c59928SShuah Khan# right output location for the following cases: 204c3c59928SShuah Khan# 1. output_dir=kernel_src 205c3c59928SShuah Khan# 2. a separate output directory is specified using O= KBUILD_OUTPUT 206c3c59928SShuah Khan# 3. a separate output directory is specified using KBUILD_OUTPUT 20717eac6c2SShuah Khan# Avoid conflict with INSTALL_PATH set by the main Makefile 208c3c59928SShuah Khan# 20917eac6c2SShuah KhanKSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install 21017eac6c2SShuah KhanKSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH)) 21117eac6c2SShuah Khan# Avoid changing the rest of the logic here and lib.mk. 21217eac6c2SShuah KhanINSTALL_PATH := $(KSFT_INSTALL_PATH) 21332dcfba6SMichael EllermanALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 214f0f0a5dfSKees CookTEST_LIST := $(INSTALL_PATH)/kselftest-list.txt 21532dcfba6SMichael Ellerman 216c3c59928SShuah Khaninstall: all 21732dcfba6SMichael Ellermanifdef INSTALL_PATH 21832dcfba6SMichael Ellerman @# Ask all targets to install their files 219d4e59a53SKees Cook mkdir -p $(INSTALL_PATH)/kselftest 220c78fd76fSKees Cook install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ 221d4e59a53SKees Cook install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ 2225c069b6dSKees Cook install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ 223f0f0a5dfSKees Cook install -m 744 run_kselftest.sh $(INSTALL_PATH)/ 224f0f0a5dfSKees Cook rm -f $(TEST_LIST) 2255f70bde2SCristian Marussi @ret=1; \ 2265f70bde2SCristian Marussi for TARGET in $(TARGETS); do \ 227a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 2289d235a55SJiri Benc $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ 2299d235a55SJiri Benc $(if $(FORCE_TARGETS),|| exit); \ 2305f70bde2SCristian Marussi ret=$$((ret * $$?)); \ 2315f70bde2SCristian Marussi done; exit $$ret; 23232dcfba6SMichael Ellerman 23332dcfba6SMichael Ellerman 234f0f0a5dfSKees Cook @# Ask all targets to emit their test scripts 235f0f0a5dfSKees Cook @# While building kselftest-list.text skip also non-existent TARGET dirs: 236131b30c9SCristian Marussi @# they could be the result of a build failure and should NOT be 237131b30c9SCristian Marussi @# included in the generated runlist. 23832dcfba6SMichael Ellerman for TARGET in $(TARGETS); do \ 239a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 24002bf1f8bSPrabhakar Kushwaha [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ 24117eac6c2SShuah Khan echo -n "Emit Tests for $$TARGET\n"; \ 242f0f0a5dfSKees Cook $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \ 243f0f0a5dfSKees Cook -C $$TARGET emit_tests >> $(TEST_LIST); \ 24432dcfba6SMichael Ellerman done; 24532dcfba6SMichael Ellermanelse 24632dcfba6SMichael Ellerman $(error Error: set INSTALL_PATH to use install) 24732dcfba6SMichael Ellermanendif 24832dcfba6SMichael Ellerman 249a5f30467SVeronika KabatovaFORMAT ?= .gz 250a5f30467SVeronika KabatovaTAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT}) 251a5f30467SVeronika Kabatovagen_tar: install 252a5f30467SVeronika Kabatova @mkdir -p ${INSTALL_PATH}/kselftest-packages/ 253a5f30467SVeronika Kabatova @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} . 254a5f30467SVeronika Kabatova @echo "Created ${TAR_PATH}" 255a5f30467SVeronika Kabatova 256274343adSFrederic Weisbeckerclean: 2571ede0536SShuah Khan @for TARGET in $(TARGETS); do \ 258a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 2590ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 260274343adSFrederic Weisbecker done; 26132dcfba6SMichael Ellerman 262a5f30467SVeronika Kabatova.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar 263