blob: 4f502448dc7e48578b163fd30e7cf82306b8c492 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Pintu Agarwal47a18c42017-11-01 13:00:39 -04002TARGETS = android
Cristian Marussi313a4db2019-10-25 18:57:06 +01003TARGETS += arm64
Pintu Agarwal47a18c42017-11-01 13:00:39 -04004TARGETS += bpf
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +02005TARGETS += breakpoints
Bamvor Jian Zhangf4ecb322015-11-17 22:35:42 +08006TARGETS += capabilities
Roman Gushchin84092dbc2018-05-11 19:03:49 +01007TARGETS += cgroup
Christian Braunerde528722019-10-14 12:45:38 +02008TARGETS += clone3
Viresh Kumare66d5b62017-01-13 12:06:45 +05309TARGETS += cpufreq
Andrew Morton66a01b92013-02-27 17:05:56 -080010TARGETS += cpu-hotplug
Tom Murphy6edf2e32018-11-27 10:33:08 +000011TARGETS += drivers/dma-buf
Andrew Morton66a01b92013-02-27 17:05:56 -080012TARGETS += efivarfs
Andrew Morton96e869d2014-12-18 16:17:43 -080013TARGETS += exec
Christian Braunerce290a12018-03-13 17:55:27 +010014TARGETS += filesystems
Christian Brauner75abec72019-01-17 12:48:54 +010015TARGETS += filesystems/binderfs
Heiherf2728fe2019-12-04 16:52:19 -080016TARGETS += filesystems/epoll
Andrew Morton96e869d2014-12-18 16:17:43 -080017TARGETS += firmware
18TARGETS += ftrace
Darren Hartecac1a72015-05-12 21:07:55 -070019TARGETS += futex
Bamvor Jian Zhang22f65922016-11-21 18:16:11 +080020TARGETS += gpio
Stafford Horne63203032017-01-12 00:16:07 +090021TARGETS += intel_pstate
Bamvor Jian Zhang7e722472015-11-17 22:35:43 +080022TARGETS += ipc
Sean Younge55c8842018-10-16 15:09:31 +010023TARGETS += ir
Pavel Emelyanov58c7be82013-04-30 15:27:06 -070024TARGETS += kcmp
Mimi Zoharc3c0e812019-03-13 10:09:10 -040025TARGETS += kexec
Paolo Bonzini783e9e52018-03-27 11:49:19 +020026TARGETS += kvm
Kees Cook317dc342015-11-06 16:30:32 -080027TARGETS += lib
Joe Lawrencea2818ee2019-01-09 13:43:29 +010028TARGETS += livepatch
Pranith Kumarb6d97342015-09-11 13:07:42 -070029TARGETS += membarrier
David Herrmann4f5ce5e2014-08-08 14:25:32 -070030TARGETS += memfd
Pavel Emelyanov58c7be82013-04-30 15:27:06 -070031TARGETS += memory-hotplug
Eric W. Biedermandb181ce2014-07-29 15:50:44 -070032TARGETS += mount
Andrew Morton96e869d2014-12-18 16:17:43 -080033TARGETS += mqueue
David S. Millera6f68032013-03-20 15:07:56 -040034TARGETS += net
Florian Westphal25d8bce2018-10-31 18:26:21 +010035TARGETS += netfilter
Willem de Bruijncda261f2018-12-20 16:22:54 -050036TARGETS += networking/timestamping
Andrey Vagin6ad92bf2016-09-06 00:47:16 -070037TARGETS += nsfs
Christian Brauner575a0ae2018-12-29 22:27:33 +010038TARGETS += pidfd
Michael Ellerman0e56dac2013-08-06 17:42:35 +100039TARGETS += powerpc
Alexey Dobriyan9cd65652018-04-10 16:31:45 -070040TARGETS += proc
Hiraku Toyookacc04a462015-10-02 20:46:39 +090041TARGETS += pstore
Andrew Morton96e869d2014-12-18 16:17:43 -080042TARGETS += ptrace
Aleksa Saraib28a10a2020-01-18 23:08:00 +110043TARGETS += openat2
Mathieu Desnoyersccba8b62018-06-02 08:44:08 -040044TARGETS += rseq
Alexandre Bellonia12ab9e2018-04-19 14:50:29 +020045TARGETS += rtc
Kees Cookc99ee512015-06-16 10:54:14 -070046TARGETS += seccomp
Stas Sergeev19fd2862016-04-14 23:20:05 +030047TARGETS += sigaltstack
Tim Bird3ce51052014-12-03 10:42:21 -080048TARGETS += size
Tom Hromatka3c545082018-04-26 10:54:09 -060049TARGETS += sparc64
Al Virob8826e52017-02-18 22:07:24 -050050TARGETS += splice
Bamvor Jian Zhang1087d012015-09-09 21:06:25 +080051TARGETS += static_keys
Emilio López822081602016-10-19 09:49:48 -030052TARGETS += sync
Andrew Morton96e869d2014-12-18 16:17:43 -080053TARGETS += sysctl
Shuah Khan2278e5e2015-06-19 13:13:43 -060054ifneq (1, $(quicktest))
Andrew Morton96e869d2014-12-18 16:17:43 -080055TARGETS += timers
Shuah Khan2278e5e2015-06-19 13:13:43 -060056endif
Alexey Dobriyana3322862019-03-05 15:49:24 -080057TARGETS += tmpfs
Jarkko Sakkinen6ea3dfe2019-02-04 15:16:40 +020058TARGETS += tpm2
Andrew Morton96e869d2014-12-18 16:17:43 -080059TARGETS += user
60TARGETS += vm
Andy Lutomirski3f705df2015-04-06 23:11:06 -070061TARGETS += x86
Naresh Kambojuf21fb792015-08-18 12:31:59 +053062TARGETS += zram
Andrew Morton96e869d2014-12-18 16:17:43 -080063#Please keep the TARGETS list alphabetically sorted
Shuah Khan2278e5e2015-06-19 13:13:43 -060064# Run "make quicktest=1 run_tests" or
SeongJae Parkc6a13fa2017-04-14 08:43:16 +090065# "make quicktest=1 kselftest" from top level Makefile
Frederic Weisbecker274343a2012-01-12 17:20:44 -080066
Shuah Khanddddda92014-07-02 09:51:38 -060067TARGETS_HOTPLUG = cpu-hotplug
68TARGETS_HOTPLUG += memory-hotplug
69
Cristian Marussi3a24f7f2019-09-26 18:52:18 +010070# User can optionally provide a TARGETS skiplist.
71SKIP_TARGETS ?=
72ifneq ($(SKIP_TARGETS),)
73 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
74 override TARGETS := $(TMP)
75endif
76
Shuah Khan67d87122015-03-18 11:57:39 -060077# Clear LDFLAGS and MAKEFLAGS if called from main
78# Makefile to avoid test build failures when test
79# Makefile doesn't have explicit build rules.
80ifeq (1,$(MAKELEVEL))
Arnaldo Carvalho de Melo60df4642015-05-14 16:55:18 -030081override LDFLAGS =
Shuah Khan67d87122015-03-18 11:57:39 -060082override MAKEFLAGS =
83endif
84
Shuah Khan61c20182019-05-14 14:43:44 -060085# Append kselftest to KBUILD_OUTPUT to avoid cluttering
86# KBUILD_OUTPUT with selftest objects and headers installed
87# by selftests Makefile or lib.mk.
Masahiro Yamada051f2782019-07-06 12:07:12 +090088ifdef building_out_of_srctree
Shuah Khan52fd1d02017-09-07 19:57:43 -060089override LDFLAGS =
90endif
91
Shuah Khan8ce72dc2019-04-15 15:51:42 -060092ifneq ($(O),)
Shuah Khanf60b85e2019-11-28 16:03:21 -070093 BUILD := $(O)
Shuah Khan8ce72dc2019-04-15 15:51:42 -060094else
95 ifneq ($(KBUILD_OUTPUT),)
Shuah Khanf60b85e2019-11-28 16:03:21 -070096 BUILD := $(KBUILD_OUTPUT)/kselftest
Shuah Khan8ce72dc2019-04-15 15:51:42 -060097 else
98 BUILD := $(shell pwd)
99 DEFAULT_INSTALL_HDR_PATH := 1
100 endif
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800101endif
102
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600103# Prepare for headers install
104top_srcdir ?= ../../..
105include $(top_srcdir)/scripts/subarch.include
106ARCH ?= $(SUBARCH)
107export KSFT_KHDR_INSTALL_DONE := 1
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800108export BUILD
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600109
Shuah Khand917fb82019-04-19 16:31:28 -0600110# build and run gpio when output directory is the src dir.
111# gpio has dependency on tools/gpio and builds tools/gpio
112# objects in the src directory in all cases making the src
113# repo dirty even when objects are relocated.
114ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
115 TMP := $(filter-out gpio, $(TARGETS))
116 TARGETS := $(TMP)
117endif
118
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600119# set default goal to all, so make without a target runs all, even when
120# all isn't the first target in the file.
121.DEFAULT_GOAL := all
122
123# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
124# is used to avoid running headers_install from lib.mk.
125# Invoke headers install with --no-builtin-rules to avoid circular
126# dependency in "make kselftest" case. In this case, second level
127# make inherits builtin-rules which will use the rule generate
128# Makefile.o and runs into
129# "Circular Makefile.o <- prepare dependency dropped."
130# and headers_install fails and test compile fails.
131#
132# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
133# invokes them as sub-makes and --no-builtin-rules is not necessary,
134# but doesn't cause any failures. Keep it simple and use the same
135# flags in both cases.
136# Local build cases: "make kselftest", "make -C" - headers are installed
137# in the default INSTALL_HDR_PATH usr/include.
138khdr:
139ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200140 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600141else
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200142 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600143 ARCH=$(ARCH) -C $(top_srcdir) headers_install
144endif
145
146all: khdr
Shuah Khan1ede0532017-09-18 17:30:50 -0600147 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800148 BUILD_TARGET=$$BUILD/$$TARGET; \
149 mkdir $$BUILD_TARGET -p; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200150 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800151 done;
152
Andrew Mortoncab6b052012-03-28 14:42:54 -0700153run_tests: all
Shuah Khan1ede0532017-09-18 17:30:50 -0600154 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800155 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200156 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
Frederic Weisbeckerf467f712012-03-28 14:42:54 -0700157 done;
158
Shuah Khanddddda92014-07-02 09:51:38 -0600159hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600160 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800161 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200162 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
Shuah Khanddddda92014-07-02 09:51:38 -0600163 done;
164
165run_hotplug: hotplug
Shuah Khan1ede0532017-09-18 17:30:50 -0600166 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800167 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200168 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
Shuah Khanddddda92014-07-02 09:51:38 -0600169 done;
170
171clean_hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600172 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800173 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200174 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Shuah Khanddddda92014-07-02 09:51:38 -0600175 done;
176
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900177run_pstore_crash:
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200178 $(MAKE) -C pstore run_crash
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900179
Shuah Khanc3c59922019-05-07 17:44:21 -0600180# Use $BUILD as the default install root. $BUILD points to the
181# right output location for the following cases:
182# 1. output_dir=kernel_src
183# 2. a separate output directory is specified using O= KBUILD_OUTPUT
184# 3. a separate output directory is specified using KBUILD_OUTPUT
Shuah Khan17eac6c2019-09-26 16:40:14 -0600185# Avoid conflict with INSTALL_PATH set by the main Makefile
Shuah Khanc3c59922019-05-07 17:44:21 -0600186#
Shuah Khan17eac6c2019-09-26 16:40:14 -0600187KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
188KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
189# Avoid changing the rest of the logic here and lib.mk.
190INSTALL_PATH := $(KSFT_INSTALL_PATH)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100191ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
192
Shuah Khanc3c59922019-05-07 17:44:21 -0600193install: all
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100194ifdef INSTALL_PATH
195 @# Ask all targets to install their files
Kees Cookd4e59a52019-04-24 16:12:31 -0700196 mkdir -p $(INSTALL_PATH)/kselftest
Kees Cookc78fd762019-10-30 12:45:36 -0700197 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
Kees Cookd4e59a52019-04-24 16:12:31 -0700198 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
Kees Cook5c069b62019-04-24 16:12:35 -0700199 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
Shuah Khan1ede0532017-09-18 17:30:50 -0600200 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800201 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200202 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100203 done;
204
205 @# Ask all targets to emit their test scripts
Rolf Eike Beera2b1e8a2016-12-14 11:59:34 +0100206 echo "#!/bin/sh" > $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100207 echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
208 echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700209 echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100210 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100211 echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700212 echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
213 echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100214 echo "fi" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100215
Cristian Marussi131b30c2019-09-26 18:52:19 +0100216 @# While building run_kselftest.sh skip also non-existent TARGET dirs:
217 @# they could be the result of a build failure and should NOT be
218 @# included in the generated runlist.
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100219 for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800220 BUILD_TARGET=$$BUILD/$$TARGET; \
Prabhakar Kushwaha02bf1f82019-10-22 13:27:17 +0000221 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
Michael Ellerman88893cf2018-03-23 20:44:27 +1100222 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100223 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
Kees Cookbf660782019-04-24 16:12:32 -0700224 echo -n "run_many" >> $(ALL_SCRIPT); \
Shuah Khan17eac6c2019-09-26 16:40:14 -0600225 echo -n "Emit Tests for $$TARGET\n"; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200226 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
Kees Cookbf660782019-04-24 16:12:32 -0700227 echo "" >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100228 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
229 done;
230
231 chmod u+x $(ALL_SCRIPT)
232else
233 $(error Error: set INSTALL_PATH to use install)
234endif
235
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800236clean:
Shuah Khan1ede0532017-09-18 17:30:50 -0600237 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800238 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200239 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800240 done;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100241
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600242.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean