1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 247a18c42SPintu AgarwalTARGETS = android 3313a4db7SCristian MarussiTARGETS += 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 29317dc34aSKees CookTARGETS += lib 30a2818ee4SJoe LawrenceTARGETS += livepatch 3146d1a0f0SKees CookTARGETS += lkdtm 32b6d97344SPranith KumarTARGETS += membarrier 334f5ce5e8SDavid HerrmannTARGETS += memfd 3458c7be84SPavel EmelyanovTARGETS += memory-hotplug 35*7a309195SRicardo CañueloTARGETS += mincore 36db181ce0SEric W. BiedermanTARGETS += mount 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 5319fd2868SStas SergeevTARGETS += sigaltstack 543ce51050STim BirdTARGETS += size 553c545084STom HromatkaTARGETS += sparc64 56b8826e50SAl ViroTARGETS += splice 571087d019SBamvor Jian ZhangTARGETS += static_keys 5882208160SEmilio LópezTARGETS += sync 5996e869d8SAndrew MortonTARGETS += sysctl 602b9843fbSBriana OurslerTARGETS += tc-testing 6161c57676SDmitry SafonovTARGETS += timens 622278e5edSShuah Khanifneq (1, $(quicktest)) 6396e869d8SAndrew MortonTARGETS += timers 642278e5edSShuah Khanendif 65a3322868SAlexey DobriyanTARGETS += tmpfs 666ea3dfe1SJarkko SakkinenTARGETS += tpm2 6796e869d8SAndrew MortonTARGETS += user 6896e869d8SAndrew MortonTARGETS += vm 693f705dfdSAndy LutomirskiTARGETS += x86 70f21fb798SNaresh KambojuTARGETS += zram 7196e869d8SAndrew Morton#Please keep the TARGETS list alphabetically sorted 722278e5edSShuah Khan# Run "make quicktest=1 run_tests" or 73c6a13fafSSeongJae Park# "make quicktest=1 kselftest" from top level Makefile 74274343adSFrederic Weisbecker 75ddddda9bSShuah KhanTARGETS_HOTPLUG = cpu-hotplug 76ddddda9bSShuah KhanTARGETS_HOTPLUG += memory-hotplug 77ddddda9bSShuah Khan 783a24f7f6SCristian Marussi# User can optionally provide a TARGETS skiplist. 793a24f7f6SCristian MarussiSKIP_TARGETS ?= 803a24f7f6SCristian Marussiifneq ($(SKIP_TARGETS),) 813a24f7f6SCristian Marussi TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS)) 823a24f7f6SCristian Marussi override TARGETS := $(TMP) 833a24f7f6SCristian Marussiendif 843a24f7f6SCristian Marussi 859d235a55SJiri Benc# User can set FORCE_TARGETS to 1 to require all targets to be successfully 869d235a55SJiri Benc# built; make will fail if any of the targets cannot be built. If 879d235a55SJiri Benc# FORCE_TARGETS is not set (the default), make will succeed if at least one 889d235a55SJiri Benc# of the targets gets built. 899d235a55SJiri BencFORCE_TARGETS ?= 909d235a55SJiri Benc 9167d8712dSShuah Khan# Clear LDFLAGS and MAKEFLAGS if called from main 9267d8712dSShuah Khan# Makefile to avoid test build failures when test 9367d8712dSShuah Khan# Makefile doesn't have explicit build rules. 9467d8712dSShuah Khanifeq (1,$(MAKELEVEL)) 9560df4642SArnaldo Carvalho de Melooverride LDFLAGS = 9667d8712dSShuah Khanoverride MAKEFLAGS = 9767d8712dSShuah Khanendif 9867d8712dSShuah Khan 9929e911efSShuah Khan# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering 10061c2018cSShuah Khan# KBUILD_OUTPUT with selftest objects and headers installed 10161c2018cSShuah Khan# by selftests Makefile or lib.mk. 102051f278eSMasahiro Yamadaifdef building_out_of_srctree 10352fd1d08SShuah Khanoverride LDFLAGS = 10452fd1d08SShuah Khanendif 10552fd1d08SShuah Khan 1068ce72dc3SShuah Khanifneq ($(O),) 10729e911efSShuah Khan BUILD := $(O)/kselftest 1088ce72dc3SShuah Khanelse 1098ce72dc3SShuah Khan ifneq ($(KBUILD_OUTPUT),) 110f60b85e8SShuah Khan BUILD := $(KBUILD_OUTPUT)/kselftest 1118ce72dc3SShuah Khan else 112a8ba798bSbamvor.zhangjian@huawei.com BUILD := $(shell pwd) 1138ce72dc3SShuah Khan DEFAULT_INSTALL_HDR_PATH := 1 1148ce72dc3SShuah Khan endif 115a8ba798bSbamvor.zhangjian@huawei.comendif 116a8ba798bSbamvor.zhangjian@huawei.com 1178ce72dc3SShuah Khan# Prepare for headers install 1188ce72dc3SShuah Khantop_srcdir ?= ../../.. 1198ce72dc3SShuah Khaninclude $(top_srcdir)/scripts/subarch.include 1208ce72dc3SShuah KhanARCH ?= $(SUBARCH) 1218ce72dc3SShuah Khanexport KSFT_KHDR_INSTALL_DONE := 1 122a8ba798bSbamvor.zhangjian@huawei.comexport BUILD 1238ce72dc3SShuah Khan 124d917fb87SShuah Khan# build and run gpio when output directory is the src dir. 125d917fb87SShuah Khan# gpio has dependency on tools/gpio and builds tools/gpio 126d917fb87SShuah Khan# objects in the src directory in all cases making the src 127d917fb87SShuah Khan# repo dirty even when objects are relocated. 128d917fb87SShuah Khanifneq (1,$(DEFAULT_INSTALL_HDR_PATH)) 129d917fb87SShuah Khan TMP := $(filter-out gpio, $(TARGETS)) 130d917fb87SShuah Khan TARGETS := $(TMP) 131d917fb87SShuah Khanendif 132d917fb87SShuah Khan 1338ce72dc3SShuah Khan# set default goal to all, so make without a target runs all, even when 1348ce72dc3SShuah Khan# all isn't the first target in the file. 1358ce72dc3SShuah Khan.DEFAULT_GOAL := all 1368ce72dc3SShuah Khan 1378ce72dc3SShuah Khan# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE 1388ce72dc3SShuah Khan# is used to avoid running headers_install from lib.mk. 1398ce72dc3SShuah Khan# Invoke headers install with --no-builtin-rules to avoid circular 1408ce72dc3SShuah Khan# dependency in "make kselftest" case. In this case, second level 1418ce72dc3SShuah Khan# make inherits builtin-rules which will use the rule generate 1428ce72dc3SShuah Khan# Makefile.o and runs into 1438ce72dc3SShuah Khan# "Circular Makefile.o <- prepare dependency dropped." 1448ce72dc3SShuah Khan# and headers_install fails and test compile fails. 1458ce72dc3SShuah Khan# 1468ce72dc3SShuah Khan# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile 1478ce72dc3SShuah Khan# invokes them as sub-makes and --no-builtin-rules is not necessary, 1488ce72dc3SShuah Khan# but doesn't cause any failures. Keep it simple and use the same 1498ce72dc3SShuah Khan# flags in both cases. 1508ce72dc3SShuah Khan# Local build cases: "make kselftest", "make -C" - headers are installed 1518ce72dc3SShuah Khan# in the default INSTALL_HDR_PATH usr/include. 1528ce72dc3SShuah Khankhdr: 1538ce72dc3SShuah Khanifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) 1540ac33e4eSIlya Leoshkevich $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install 1558ce72dc3SShuah Khanelse 1560ac33e4eSIlya Leoshkevich $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \ 1578ce72dc3SShuah Khan ARCH=$(ARCH) -C $(top_srcdir) headers_install 1588ce72dc3SShuah Khanendif 1598ce72dc3SShuah Khan 1608ce72dc3SShuah Khanall: khdr 1615f70bde2SCristian Marussi @ret=1; \ 1625f70bde2SCristian Marussi for TARGET in $(TARGETS); do \ 163a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 164a8ba798bSbamvor.zhangjian@huawei.com mkdir $$BUILD_TARGET -p; \ 1659d235a55SJiri Benc $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ 1669d235a55SJiri Benc $(if $(FORCE_TARGETS),|| exit); \ 1675f70bde2SCristian Marussi ret=$$((ret * $$?)); \ 1685f70bde2SCristian Marussi done; exit $$ret; 169274343adSFrederic Weisbecker 170cab6b056SAndrew Mortonrun_tests: all 1711ede0536SShuah Khan @for TARGET in $(TARGETS); do \ 172a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1730ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ 174f467f714SFrederic Weisbecker done; 175f467f714SFrederic Weisbecker 176ddddda9bSShuah Khanhotplug: 1771ede0536SShuah Khan @for TARGET in $(TARGETS_HOTPLUG); do \ 178a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1790ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 180ddddda9bSShuah Khan done; 181ddddda9bSShuah Khan 182ddddda9bSShuah Khanrun_hotplug: hotplug 1831ede0536SShuah Khan @for TARGET in $(TARGETS_HOTPLUG); do \ 184a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1850ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ 186ddddda9bSShuah Khan done; 187ddddda9bSShuah Khan 188ddddda9bSShuah Khanclean_hotplug: 1891ede0536SShuah Khan @for TARGET in $(TARGETS_HOTPLUG); do \ 190a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 1910ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 192ddddda9bSShuah Khan done; 193ddddda9bSShuah Khan 194f615e2bbSHiraku Toyookarun_pstore_crash: 1950ac33e4eSIlya Leoshkevich $(MAKE) -C pstore run_crash 196f615e2bbSHiraku Toyooka 197c3c59928SShuah Khan# Use $BUILD as the default install root. $BUILD points to the 198c3c59928SShuah Khan# right output location for the following cases: 199c3c59928SShuah Khan# 1. output_dir=kernel_src 200c3c59928SShuah Khan# 2. a separate output directory is specified using O= KBUILD_OUTPUT 201c3c59928SShuah Khan# 3. a separate output directory is specified using KBUILD_OUTPUT 20217eac6c2SShuah Khan# Avoid conflict with INSTALL_PATH set by the main Makefile 203c3c59928SShuah Khan# 20417eac6c2SShuah KhanKSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install 20517eac6c2SShuah KhanKSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH)) 20617eac6c2SShuah Khan# Avoid changing the rest of the logic here and lib.mk. 20717eac6c2SShuah KhanINSTALL_PATH := $(KSFT_INSTALL_PATH) 20832dcfba6SMichael EllermanALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 20932dcfba6SMichael Ellerman 210c3c59928SShuah Khaninstall: all 21132dcfba6SMichael Ellermanifdef INSTALL_PATH 21232dcfba6SMichael Ellerman @# Ask all targets to install their files 213d4e59a53SKees Cook mkdir -p $(INSTALL_PATH)/kselftest 214c78fd76fSKees Cook install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ 215d4e59a53SKees Cook install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ 2165c069b6dSKees Cook install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ 2175f70bde2SCristian Marussi @ret=1; \ 2185f70bde2SCristian Marussi for TARGET in $(TARGETS); do \ 219a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 2209d235a55SJiri Benc $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ 2219d235a55SJiri Benc $(if $(FORCE_TARGETS),|| exit); \ 2225f70bde2SCristian Marussi ret=$$((ret * $$?)); \ 2235f70bde2SCristian Marussi done; exit $$ret; 22432dcfba6SMichael Ellerman 22532dcfba6SMichael Ellerman @# Ask all targets to emit their test scripts 226a2b1e8a2SRolf Eike Beer echo "#!/bin/sh" > $(ALL_SCRIPT) 22714f1889fSMichael Ellerman echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT) 22814f1889fSMichael Ellerman echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT) 229d4e59a53SKees Cook echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT) 23032dcfba6SMichael Ellerman echo "ROOT=\$$PWD" >> $(ALL_SCRIPT) 23114f1889fSMichael Ellerman echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT) 232d4e59a53SKees Cook echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT) 233d4e59a53SKees Cook echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT) 23414f1889fSMichael Ellerman echo "fi" >> $(ALL_SCRIPT) 23532dcfba6SMichael Ellerman 236131b30c9SCristian Marussi @# While building run_kselftest.sh skip also non-existent TARGET dirs: 237131b30c9SCristian Marussi @# they could be the result of a build failure and should NOT be 238131b30c9SCristian Marussi @# included in the generated runlist. 23932dcfba6SMichael Ellerman for TARGET in $(TARGETS); do \ 240a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 24102bf1f8bSPrabhakar Kushwaha [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ 24288893cf7SMichael Ellerman echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \ 24332dcfba6SMichael Ellerman echo "cd $$TARGET" >> $(ALL_SCRIPT); \ 244bf660782SKees Cook echo -n "run_many" >> $(ALL_SCRIPT); \ 24517eac6c2SShuah Khan echo -n "Emit Tests for $$TARGET\n"; \ 2460ac33e4eSIlya Leoshkevich $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ 247bf660782SKees Cook echo "" >> $(ALL_SCRIPT); \ 24832dcfba6SMichael Ellerman echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ 24932dcfba6SMichael Ellerman done; 25032dcfba6SMichael Ellerman 25132dcfba6SMichael Ellerman chmod u+x $(ALL_SCRIPT) 25232dcfba6SMichael Ellermanelse 25332dcfba6SMichael Ellerman $(error Error: set INSTALL_PATH to use install) 25432dcfba6SMichael Ellermanendif 25532dcfba6SMichael Ellerman 256a5f30467SVeronika KabatovaFORMAT ?= .gz 257a5f30467SVeronika KabatovaTAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT}) 258a5f30467SVeronika Kabatovagen_tar: install 259a5f30467SVeronika Kabatova @mkdir -p ${INSTALL_PATH}/kselftest-packages/ 260a5f30467SVeronika Kabatova @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} . 261a5f30467SVeronika Kabatova @echo "Created ${TAR_PATH}" 262a5f30467SVeronika Kabatova 263274343adSFrederic Weisbeckerclean: 2641ede0536SShuah Khan @for TARGET in $(TARGETS); do \ 265a8ba798bSbamvor.zhangjian@huawei.com BUILD_TARGET=$$BUILD/$$TARGET; \ 2660ac33e4eSIlya Leoshkevich $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 267274343adSFrederic Weisbecker done; 26832dcfba6SMichael Ellerman 269a5f30467SVeronika Kabatova.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar 270