xref: /linux/tools/testing/selftests/Makefile (revision b28a10aedcd4d175470171a32f4f20b0a60a612b)
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
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
1896e869d8SAndrew MortonTARGETS += ftrace
19ecac1a75SDarren HartTARGETS += futex
2022f6592bSBamvor Jian ZhangTARGETS += gpio
216320303fSStafford HorneTARGETS += intel_pstate
227e722473SBamvor Jian ZhangTARGETS += ipc
23e55c884eSSean YoungTARGETS += ir
2458c7be84SPavel EmelyanovTARGETS += kcmp
25c3c0e811SMimi ZoharTARGETS += kexec
26783e9e51SPaolo BonziniTARGETS += kvm
27317dc34aSKees CookTARGETS += lib
28a2818ee4SJoe LawrenceTARGETS += livepatch
29b6d97344SPranith KumarTARGETS += membarrier
304f5ce5e8SDavid HerrmannTARGETS += memfd
3158c7be84SPavel EmelyanovTARGETS += memory-hotplug
32db181ce0SEric W. BiedermanTARGETS += mount
3396e869d8SAndrew MortonTARGETS += mqueue
34a6f68034SDavid S. MillerTARGETS += net
3525d8bcedSFlorian WestphalTARGETS += netfilter
36cda261f4SWillem de BruijnTARGETS += networking/timestamping
376ad92bf6SAndrey VaginTARGETS += nsfs
38575a0ae9SChristian BraunerTARGETS += pidfd
390e56dacdSMichael EllermanTARGETS += powerpc
409cd65655SAlexey DobriyanTARGETS += proc
41cc04a46fSHiraku ToyookaTARGETS += pstore
4296e869d8SAndrew MortonTARGETS += ptrace
43*b28a10aeSAleksa SaraiTARGETS += openat2
44ccba8b64SMathieu DesnoyersTARGETS += rseq
45a12ab9e1SAlexandre BelloniTARGETS += rtc
46c99ee51aSKees CookTARGETS += seccomp
4719fd2868SStas SergeevTARGETS += sigaltstack
483ce51050STim BirdTARGETS += size
493c545084STom HromatkaTARGETS += sparc64
50b8826e50SAl ViroTARGETS += splice
511087d019SBamvor Jian ZhangTARGETS += static_keys
5282208160SEmilio LópezTARGETS += sync
5396e869d8SAndrew MortonTARGETS += sysctl
542278e5edSShuah Khanifneq (1, $(quicktest))
5596e869d8SAndrew MortonTARGETS += timers
562278e5edSShuah Khanendif
57a3322868SAlexey DobriyanTARGETS += tmpfs
586ea3dfe1SJarkko SakkinenTARGETS += tpm2
5996e869d8SAndrew MortonTARGETS += user
6096e869d8SAndrew MortonTARGETS += vm
613f705dfdSAndy LutomirskiTARGETS += x86
62f21fb798SNaresh KambojuTARGETS += zram
6396e869d8SAndrew Morton#Please keep the TARGETS list alphabetically sorted
642278e5edSShuah Khan# Run "make quicktest=1 run_tests" or
65c6a13fafSSeongJae Park# "make quicktest=1 kselftest" from top level Makefile
66274343adSFrederic Weisbecker
67ddddda9bSShuah KhanTARGETS_HOTPLUG = cpu-hotplug
68ddddda9bSShuah KhanTARGETS_HOTPLUG += memory-hotplug
69ddddda9bSShuah Khan
703a24f7f6SCristian Marussi# User can optionally provide a TARGETS skiplist.
713a24f7f6SCristian MarussiSKIP_TARGETS ?=
723a24f7f6SCristian Marussiifneq ($(SKIP_TARGETS),)
733a24f7f6SCristian Marussi	TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
743a24f7f6SCristian Marussi	override TARGETS := $(TMP)
753a24f7f6SCristian Marussiendif
763a24f7f6SCristian Marussi
7767d8712dSShuah Khan# Clear LDFLAGS and MAKEFLAGS if called from main
7867d8712dSShuah Khan# Makefile to avoid test build failures when test
7967d8712dSShuah Khan# Makefile doesn't have explicit build rules.
8067d8712dSShuah Khanifeq (1,$(MAKELEVEL))
8160df4642SArnaldo Carvalho de Melooverride LDFLAGS =
8267d8712dSShuah Khanoverride MAKEFLAGS =
8367d8712dSShuah Khanendif
8467d8712dSShuah Khan
8561c2018cSShuah Khan# Append kselftest to KBUILD_OUTPUT to avoid cluttering
8661c2018cSShuah Khan# KBUILD_OUTPUT with selftest objects and headers installed
8761c2018cSShuah Khan# by selftests Makefile or lib.mk.
88051f278eSMasahiro Yamadaifdef building_out_of_srctree
8952fd1d08SShuah Khanoverride LDFLAGS =
9052fd1d08SShuah Khanendif
9152fd1d08SShuah Khan
928ce72dc3SShuah Khanifneq ($(O),)
93f60b85e8SShuah Khan	BUILD := $(O)
948ce72dc3SShuah Khanelse
958ce72dc3SShuah Khan	ifneq ($(KBUILD_OUTPUT),)
96f60b85e8SShuah Khan		BUILD := $(KBUILD_OUTPUT)/kselftest
978ce72dc3SShuah Khan	else
98a8ba798bSbamvor.zhangjian@huawei.com		BUILD := $(shell pwd)
998ce72dc3SShuah Khan		DEFAULT_INSTALL_HDR_PATH := 1
1008ce72dc3SShuah Khan	endif
101a8ba798bSbamvor.zhangjian@huawei.comendif
102a8ba798bSbamvor.zhangjian@huawei.com
1038ce72dc3SShuah Khan# Prepare for headers install
1048ce72dc3SShuah Khantop_srcdir ?= ../../..
1058ce72dc3SShuah Khaninclude $(top_srcdir)/scripts/subarch.include
1068ce72dc3SShuah KhanARCH           ?= $(SUBARCH)
1078ce72dc3SShuah Khanexport KSFT_KHDR_INSTALL_DONE := 1
108a8ba798bSbamvor.zhangjian@huawei.comexport BUILD
1098ce72dc3SShuah Khan
110d917fb87SShuah Khan# build and run gpio when output directory is the src dir.
111d917fb87SShuah Khan# gpio has dependency on tools/gpio and builds tools/gpio
112d917fb87SShuah Khan# objects in the src directory in all cases making the src
113d917fb87SShuah Khan# repo dirty even when objects are relocated.
114d917fb87SShuah Khanifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
115d917fb87SShuah Khan	TMP := $(filter-out gpio, $(TARGETS))
116d917fb87SShuah Khan	TARGETS := $(TMP)
117d917fb87SShuah Khanendif
118d917fb87SShuah Khan
1198ce72dc3SShuah Khan# set default goal to all, so make without a target runs all, even when
1208ce72dc3SShuah Khan# all isn't the first target in the file.
1218ce72dc3SShuah Khan.DEFAULT_GOAL := all
1228ce72dc3SShuah Khan
1238ce72dc3SShuah Khan# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
1248ce72dc3SShuah Khan# is used to avoid running headers_install from lib.mk.
1258ce72dc3SShuah Khan# Invoke headers install with --no-builtin-rules to avoid circular
1268ce72dc3SShuah Khan# dependency in "make kselftest" case. In this case, second level
1278ce72dc3SShuah Khan# make inherits builtin-rules which will use the rule generate
1288ce72dc3SShuah Khan# Makefile.o and runs into
1298ce72dc3SShuah Khan# "Circular Makefile.o <- prepare dependency dropped."
1308ce72dc3SShuah Khan# and headers_install fails and test compile fails.
1318ce72dc3SShuah Khan#
1328ce72dc3SShuah Khan# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
1338ce72dc3SShuah Khan# invokes them as sub-makes and --no-builtin-rules is not necessary,
1348ce72dc3SShuah Khan# but doesn't cause any failures. Keep it simple and use the same
1358ce72dc3SShuah Khan# flags in both cases.
1368ce72dc3SShuah Khan# Local build cases: "make kselftest", "make -C" - headers are installed
1378ce72dc3SShuah Khan# in the default INSTALL_HDR_PATH usr/include.
1388ce72dc3SShuah Khankhdr:
1398ce72dc3SShuah Khanifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
1400ac33e4eSIlya Leoshkevich	$(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
1418ce72dc3SShuah Khanelse
1420ac33e4eSIlya Leoshkevich	$(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
1438ce72dc3SShuah Khan		ARCH=$(ARCH) -C $(top_srcdir) headers_install
1448ce72dc3SShuah Khanendif
1458ce72dc3SShuah Khan
1468ce72dc3SShuah Khanall: khdr
1471ede0536SShuah Khan	@for TARGET in $(TARGETS); do		\
148a8ba798bSbamvor.zhangjian@huawei.com		BUILD_TARGET=$$BUILD/$$TARGET;	\
149a8ba798bSbamvor.zhangjian@huawei.com		mkdir $$BUILD_TARGET  -p;	\
1500ac33e4eSIlya Leoshkevich		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
151274343adSFrederic Weisbecker	done;
152274343adSFrederic Weisbecker
153cab6b056SAndrew Mortonrun_tests: all
1541ede0536SShuah Khan	@for TARGET in $(TARGETS); do \
155a8ba798bSbamvor.zhangjian@huawei.com		BUILD_TARGET=$$BUILD/$$TARGET;	\
1560ac33e4eSIlya Leoshkevich		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
157f467f714SFrederic Weisbecker	done;
158f467f714SFrederic Weisbecker
159ddddda9bSShuah Khanhotplug:
1601ede0536SShuah Khan	@for TARGET in $(TARGETS_HOTPLUG); do \
161a8ba798bSbamvor.zhangjian@huawei.com		BUILD_TARGET=$$BUILD/$$TARGET;	\
1620ac33e4eSIlya Leoshkevich		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
163ddddda9bSShuah Khan	done;
164ddddda9bSShuah Khan
165ddddda9bSShuah Khanrun_hotplug: hotplug
1661ede0536SShuah Khan	@for TARGET in $(TARGETS_HOTPLUG); do \
167a8ba798bSbamvor.zhangjian@huawei.com		BUILD_TARGET=$$BUILD/$$TARGET;	\
1680ac33e4eSIlya Leoshkevich		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
169ddddda9bSShuah Khan	done;
170ddddda9bSShuah Khan
171ddddda9bSShuah Khanclean_hotplug:
1721ede0536SShuah Khan	@for TARGET in $(TARGETS_HOTPLUG); do \
173a8ba798bSbamvor.zhangjian@huawei.com		BUILD_TARGET=$$BUILD/$$TARGET;	\
1740ac33e4eSIlya Leoshkevich		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
175ddddda9bSShuah Khan	done;
176ddddda9bSShuah Khan
177f615e2bbSHiraku Toyookarun_pstore_crash:
1780ac33e4eSIlya Leoshkevich	$(MAKE) -C pstore run_crash
179f615e2bbSHiraku Toyooka
180c3c59928SShuah Khan# Use $BUILD as the default install root. $BUILD points to the
181c3c59928SShuah Khan# right output location for the following cases:
182c3c59928SShuah Khan# 1. output_dir=kernel_src
183c3c59928SShuah Khan# 2. a separate output directory is specified using O= KBUILD_OUTPUT
184c3c59928SShuah Khan# 3. a separate output directory is specified using KBUILD_OUTPUT
18517eac6c2SShuah Khan# Avoid conflict with INSTALL_PATH set by the main Makefile
186c3c59928SShuah Khan#
18717eac6c2SShuah KhanKSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
18817eac6c2SShuah KhanKSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
18917eac6c2SShuah Khan# Avoid changing the rest of the logic here and lib.mk.
19017eac6c2SShuah KhanINSTALL_PATH := $(KSFT_INSTALL_PATH)
19132dcfba6SMichael EllermanALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
19232dcfba6SMichael Ellerman
193c3c59928SShuah Khaninstall: all
19432dcfba6SMichael Ellermanifdef INSTALL_PATH
19532dcfba6SMichael Ellerman	@# Ask all targets to install their files
196d4e59a53SKees Cook	mkdir -p $(INSTALL_PATH)/kselftest
197c78fd76fSKees Cook	install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
198d4e59a53SKees Cook	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
1995c069b6dSKees Cook	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
2001ede0536SShuah Khan	@for TARGET in $(TARGETS); do \
201a8ba798bSbamvor.zhangjian@huawei.com		BUILD_TARGET=$$BUILD/$$TARGET;	\
2020ac33e4eSIlya Leoshkevich		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
20332dcfba6SMichael Ellerman	done;
20432dcfba6SMichael Ellerman
20532dcfba6SMichael Ellerman	@# Ask all targets to emit their test scripts
206a2b1e8a2SRolf Eike Beer	echo "#!/bin/sh" > $(ALL_SCRIPT)
20714f1889fSMichael Ellerman	echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
20814f1889fSMichael Ellerman	echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
209d4e59a53SKees Cook	echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
21032dcfba6SMichael Ellerman	echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
21114f1889fSMichael Ellerman	echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
212d4e59a53SKees Cook	echo "  logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
213d4e59a53SKees Cook	echo "  cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
21414f1889fSMichael Ellerman	echo "fi" >> $(ALL_SCRIPT)
21532dcfba6SMichael Ellerman
216131b30c9SCristian Marussi	@# While building run_kselftest.sh skip also non-existent TARGET dirs:
217131b30c9SCristian Marussi	@# they could be the result of a build failure and should NOT be
218131b30c9SCristian Marussi	@# included in the generated runlist.
21932dcfba6SMichael Ellerman	for TARGET in $(TARGETS); do \
220a8ba798bSbamvor.zhangjian@huawei.com		BUILD_TARGET=$$BUILD/$$TARGET;	\
22102bf1f8bSPrabhakar Kushwaha		[ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
22288893cf7SMichael Ellerman		echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
22332dcfba6SMichael Ellerman		echo "cd $$TARGET" >> $(ALL_SCRIPT); \
224bf660782SKees Cook		echo -n "run_many" >> $(ALL_SCRIPT); \
22517eac6c2SShuah Khan		echo -n "Emit Tests for $$TARGET\n"; \
2260ac33e4eSIlya Leoshkevich		$(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
227bf660782SKees Cook		echo "" >> $(ALL_SCRIPT);	    \
22832dcfba6SMichael Ellerman		echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
22932dcfba6SMichael Ellerman	done;
23032dcfba6SMichael Ellerman
23132dcfba6SMichael Ellerman	chmod u+x $(ALL_SCRIPT)
23232dcfba6SMichael Ellermanelse
23332dcfba6SMichael Ellerman	$(error Error: set INSTALL_PATH to use install)
23432dcfba6SMichael Ellermanendif
23532dcfba6SMichael Ellerman
236274343adSFrederic Weisbeckerclean:
2371ede0536SShuah Khan	@for TARGET in $(TARGETS); do \
238a8ba798bSbamvor.zhangjian@huawei.com		BUILD_TARGET=$$BUILD/$$TARGET;	\
2390ac33e4eSIlya Leoshkevich		$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
240274343adSFrederic Weisbecker	done;
24132dcfba6SMichael Ellerman
2428ce72dc3SShuah Khan.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean
243