blob: d9c2835031590ed5ca46480ae017bbd84cfc920e [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
Christian Brauner2c5db602019-05-20 16:13:28 +02009TARGETS += core
Viresh Kumare66d5b62017-01-13 12:06:45 +053010TARGETS += cpufreq
Andrew Morton66a01b92013-02-27 17:05:56 -080011TARGETS += cpu-hotplug
Tom Murphy6edf2e32018-11-27 10:33:08 +000012TARGETS += drivers/dma-buf
Andrew Morton66a01b92013-02-27 17:05:56 -080013TARGETS += efivarfs
Andrew Morton96e869d2014-12-18 16:17:43 -080014TARGETS += exec
Christian Braunerce290a12018-03-13 17:55:27 +010015TARGETS += filesystems
Christian Brauner75abec72019-01-17 12:48:54 +010016TARGETS += filesystems/binderfs
Heiherf2728fe2019-12-04 16:52:19 -080017TARGETS += filesystems/epoll
Andrew Morton96e869d2014-12-18 16:17:43 -080018TARGETS += firmware
Petteri Aimonen4185b3b2020-06-18 16:37:37 +020019TARGETS += fpu
Andrew Morton96e869d2014-12-18 16:17:43 -080020TARGETS += ftrace
Darren Hartecac1a72015-05-12 21:07:55 -070021TARGETS += futex
Bamvor Jian Zhang22f65922016-11-21 18:16:11 +080022TARGETS += gpio
Stafford Horne63203032017-01-12 00:16:07 +090023TARGETS += intel_pstate
Bamvor Jian Zhang7e722472015-11-17 22:35:43 +080024TARGETS += ipc
Sean Younge55c8842018-10-16 15:09:31 +010025TARGETS += ir
Pavel Emelyanov58c7be82013-04-30 15:27:06 -070026TARGETS += kcmp
Mimi Zoharc3c0e812019-03-13 10:09:10 -040027TARGETS += kexec
Paolo Bonzini783e9e52018-03-27 11:49:19 +020028TARGETS += kvm
Kees Cook317dc342015-11-06 16:30:32 -080029TARGETS += lib
Joe Lawrencea2818ee2019-01-09 13:43:29 +010030TARGETS += livepatch
Kees Cook46d1a0f2020-01-09 21:02:06 -080031TARGETS += lkdtm
Pranith Kumarb6d97342015-09-11 13:07:42 -070032TARGETS += membarrier
David Herrmann4f5ce5e2014-08-08 14:25:32 -070033TARGETS += memfd
Pavel Emelyanov58c7be82013-04-30 15:27:06 -070034TARGETS += memory-hotplug
Ricardo Cañuelo7a309192020-08-06 23:23:51 -070035TARGETS += mincore
Eric W. Biedermandb181ce2014-07-29 15:50:44 -070036TARGETS += mount
Andrew Morton96e869d2014-12-18 16:17:43 -080037TARGETS += mqueue
David S. Millera6f68032013-03-20 15:07:56 -040038TARGETS += net
Vadym Kochan81573b12020-03-23 16:24:04 +020039TARGETS += net/forwarding
Florian Westphal048d19d2020-01-21 16:56:29 -080040TARGETS += net/mptcp
Florian Westphal25d8bce2018-10-31 18:26:21 +010041TARGETS += netfilter
Andrey Vagin6ad92bf2016-09-06 00:47:16 -070042TARGETS += nsfs
Christian Brauner575a0ae2018-12-29 22:27:33 +010043TARGETS += pidfd
Christian Brauner6952a4f2020-03-08 17:26:32 +010044TARGETS += pid_namespace
Michael Ellerman0e56dac2013-08-06 17:42:35 +100045TARGETS += powerpc
Alexey Dobriyan9cd65652018-04-10 16:31:45 -070046TARGETS += proc
Hiraku Toyookacc04a462015-10-02 20:46:39 +090047TARGETS += pstore
Andrew Morton96e869d2014-12-18 16:17:43 -080048TARGETS += ptrace
Aleksa Saraib28a10a2020-01-18 23:08:00 +110049TARGETS += openat2
Mathieu Desnoyersccba8b62018-06-02 08:44:08 -040050TARGETS += rseq
Alexandre Bellonia12ab9e2018-04-19 14:50:29 +020051TARGETS += rtc
Kees Cookc99ee512015-06-16 10:54:14 -070052TARGETS += seccomp
Stas Sergeev19fd2862016-04-14 23:20:05 +030053TARGETS += sigaltstack
Tim Bird3ce51052014-12-03 10:42:21 -080054TARGETS += size
Tom Hromatka3c545082018-04-26 10:54:09 -060055TARGETS += sparc64
Al Virob8826e52017-02-18 22:07:24 -050056TARGETS += splice
Bamvor Jian Zhang1087d012015-09-09 21:06:25 +080057TARGETS += static_keys
Emilio López822081602016-10-19 09:49:48 -030058TARGETS += sync
Andrew Morton96e869d2014-12-18 16:17:43 -080059TARGETS += sysctl
Briana Oursler2b9843f2020-07-17 14:54:39 -070060TARGETS += tc-testing
Dmitry Safonov61c57672019-11-12 01:27:17 +000061TARGETS += timens
Shuah Khan2278e5e2015-06-19 13:13:43 -060062ifneq (1, $(quicktest))
Andrew Morton96e869d2014-12-18 16:17:43 -080063TARGETS += timers
Shuah Khan2278e5e2015-06-19 13:13:43 -060064endif
Alexey Dobriyana3322862019-03-05 15:49:24 -080065TARGETS += tmpfs
Jarkko Sakkinen6ea3dfe2019-02-04 15:16:40 +020066TARGETS += tpm2
Andrew Morton96e869d2014-12-18 16:17:43 -080067TARGETS += user
68TARGETS += vm
Andy Lutomirski3f705df2015-04-06 23:11:06 -070069TARGETS += x86
Naresh Kambojuf21fb792015-08-18 12:31:59 +053070TARGETS += zram
Andrew Morton96e869d2014-12-18 16:17:43 -080071#Please keep the TARGETS list alphabetically sorted
Shuah Khan2278e5e2015-06-19 13:13:43 -060072# Run "make quicktest=1 run_tests" or
SeongJae Parkc6a13fa2017-04-14 08:43:16 +090073# "make quicktest=1 kselftest" from top level Makefile
Frederic Weisbecker274343a2012-01-12 17:20:44 -080074
Shuah Khanddddda92014-07-02 09:51:38 -060075TARGETS_HOTPLUG = cpu-hotplug
76TARGETS_HOTPLUG += memory-hotplug
77
Cristian Marussi3a24f7f2019-09-26 18:52:18 +010078# User can optionally provide a TARGETS skiplist.
79SKIP_TARGETS ?=
80ifneq ($(SKIP_TARGETS),)
81 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
82 override TARGETS := $(TMP)
83endif
84
Jiri Benc9d235a52020-02-06 09:40:00 +010085# User can set FORCE_TARGETS to 1 to require all targets to be successfully
86# built; make will fail if any of the targets cannot be built. If
87# FORCE_TARGETS is not set (the default), make will succeed if at least one
88# of the targets gets built.
89FORCE_TARGETS ?=
90
Greg Thelenf69237e2020-07-28 00:32:41 -070091# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides
92# implicit rules to sub-test Makefiles which avoids build failures in test
93# Makefile that don't have explicit build rules.
94ifeq (,$(LINK.c))
Arnaldo Carvalho de Melo60df4642015-05-14 16:55:18 -030095override LDFLAGS =
Shuah Khan67d87122015-03-18 11:57:39 -060096override MAKEFLAGS =
97endif
98
Shuah Khan29e911e2020-02-26 15:54:49 -070099# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
Shuah Khan61c20182019-05-14 14:43:44 -0600100# KBUILD_OUTPUT with selftest objects and headers installed
101# by selftests Makefile or lib.mk.
Masahiro Yamada051f2782019-07-06 12:07:12 +0900102ifdef building_out_of_srctree
Shuah Khan52fd1d02017-09-07 19:57:43 -0600103override LDFLAGS =
104endif
105
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600106ifneq ($(O),)
Shuah Khan29e911e2020-02-26 15:54:49 -0700107 BUILD := $(O)/kselftest
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600108else
109 ifneq ($(KBUILD_OUTPUT),)
Shuah Khanf60b85e2019-11-28 16:03:21 -0700110 BUILD := $(KBUILD_OUTPUT)/kselftest
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600111 else
112 BUILD := $(shell pwd)
113 DEFAULT_INSTALL_HDR_PATH := 1
114 endif
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800115endif
116
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600117# Prepare for headers install
118top_srcdir ?= ../../..
119include $(top_srcdir)/scripts/subarch.include
120ARCH ?= $(SUBARCH)
121export KSFT_KHDR_INSTALL_DONE := 1
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800122export BUILD
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600123
Shuah Khand917fb82019-04-19 16:31:28 -0600124# build and run gpio when output directory is the src dir.
125# gpio has dependency on tools/gpio and builds tools/gpio
126# objects in the src directory in all cases making the src
127# repo dirty even when objects are relocated.
128ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
129 TMP := $(filter-out gpio, $(TARGETS))
130 TARGETS := $(TMP)
131endif
132
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600133# set default goal to all, so make without a target runs all, even when
134# all isn't the first target in the file.
135.DEFAULT_GOAL := all
136
137# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
138# is used to avoid running headers_install from lib.mk.
139# Invoke headers install with --no-builtin-rules to avoid circular
140# dependency in "make kselftest" case. In this case, second level
141# make inherits builtin-rules which will use the rule generate
142# Makefile.o and runs into
143# "Circular Makefile.o <- prepare dependency dropped."
144# and headers_install fails and test compile fails.
145#
146# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
147# invokes them as sub-makes and --no-builtin-rules is not necessary,
148# but doesn't cause any failures. Keep it simple and use the same
149# flags in both cases.
150# Local build cases: "make kselftest", "make -C" - headers are installed
151# in the default INSTALL_HDR_PATH usr/include.
152khdr:
153ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200154 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600155else
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200156 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600157 ARCH=$(ARCH) -C $(top_srcdir) headers_install
158endif
159
160all: khdr
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000161 @ret=1; \
162 for TARGET in $(TARGETS); do \
163 BUILD_TARGET=$$BUILD/$$TARGET; \
164 mkdir $$BUILD_TARGET -p; \
Jiri Benc9d235a52020-02-06 09:40:00 +0100165 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
166 $(if $(FORCE_TARGETS),|| exit); \
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000167 ret=$$((ret * $$?)); \
168 done; exit $$ret;
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800169
Andrew Mortoncab6b052012-03-28 14:42:54 -0700170run_tests: all
Shuah Khan1ede0532017-09-18 17:30:50 -0600171 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800172 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200173 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
Frederic Weisbeckerf467f712012-03-28 14:42:54 -0700174 done;
175
Shuah Khanddddda92014-07-02 09:51:38 -0600176hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600177 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800178 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200179 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
Shuah Khanddddda92014-07-02 09:51:38 -0600180 done;
181
182run_hotplug: hotplug
Shuah Khan1ede0532017-09-18 17:30:50 -0600183 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800184 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200185 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
Shuah Khanddddda92014-07-02 09:51:38 -0600186 done;
187
188clean_hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600189 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800190 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200191 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Shuah Khanddddda92014-07-02 09:51:38 -0600192 done;
193
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900194run_pstore_crash:
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200195 $(MAKE) -C pstore run_crash
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900196
Shuah Khanc3c59922019-05-07 17:44:21 -0600197# Use $BUILD as the default install root. $BUILD points to the
198# right output location for the following cases:
199# 1. output_dir=kernel_src
200# 2. a separate output directory is specified using O= KBUILD_OUTPUT
201# 3. a separate output directory is specified using KBUILD_OUTPUT
Shuah Khan17eac6c2019-09-26 16:40:14 -0600202# Avoid conflict with INSTALL_PATH set by the main Makefile
Shuah Khanc3c59922019-05-07 17:44:21 -0600203#
Shuah Khan17eac6c2019-09-26 16:40:14 -0600204KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
205KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
206# Avoid changing the rest of the logic here and lib.mk.
207INSTALL_PATH := $(KSFT_INSTALL_PATH)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100208ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
Kees Cookf0f0a5d2020-09-28 13:26:48 -0700209TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100210
Shuah Khanc3c59922019-05-07 17:44:21 -0600211install: all
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100212ifdef INSTALL_PATH
213 @# Ask all targets to install their files
Kees Cookd4e59a52019-04-24 16:12:31 -0700214 mkdir -p $(INSTALL_PATH)/kselftest
Kees Cookc78fd762019-10-30 12:45:36 -0700215 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
Kees Cookd4e59a52019-04-24 16:12:31 -0700216 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
Kees Cook5c069b62019-04-24 16:12:35 -0700217 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
Kees Cookf0f0a5d2020-09-28 13:26:48 -0700218 install -m 744 run_kselftest.sh $(INSTALL_PATH)/
219 rm -f $(TEST_LIST)
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000220 @ret=1; \
221 for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800222 BUILD_TARGET=$$BUILD/$$TARGET; \
Jiri Benc9d235a52020-02-06 09:40:00 +0100223 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
224 $(if $(FORCE_TARGETS),|| exit); \
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000225 ret=$$((ret * $$?)); \
226 done; exit $$ret;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100227
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100228
Kees Cookf0f0a5d2020-09-28 13:26:48 -0700229 @# Ask all targets to emit their test scripts
230 @# While building kselftest-list.text skip also non-existent TARGET dirs:
Cristian Marussi131b30c2019-09-26 18:52:19 +0100231 @# they could be the result of a build failure and should NOT be
232 @# included in the generated runlist.
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100233 for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800234 BUILD_TARGET=$$BUILD/$$TARGET; \
Prabhakar Kushwaha02bf1f82019-10-22 13:27:17 +0000235 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
Shuah Khan17eac6c2019-09-26 16:40:14 -0600236 echo -n "Emit Tests for $$TARGET\n"; \
Kees Cookf0f0a5d2020-09-28 13:26:48 -0700237 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \
238 -C $$TARGET emit_tests >> $(TEST_LIST); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100239 done;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100240else
241 $(error Error: set INSTALL_PATH to use install)
242endif
243
Veronika Kabatovaa5f30462020-05-19 22:00:45 +0200244FORMAT ?= .gz
245TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
246gen_tar: install
247 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
248 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
249 @echo "Created ${TAR_PATH}"
250
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800251clean:
Shuah Khan1ede0532017-09-18 17:30:50 -0600252 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800253 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200254 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800255 done;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100256
Veronika Kabatovaa5f30462020-05-19 22:00:45 +0200257.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar