blob: 1195bd85af386d9384f9fb72813566df2b12eaa2 [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
Kees Cook46d1a0f2020-01-09 21:02:06 -080029TARGETS += lkdtm
Pranith Kumarb6d97342015-09-11 13:07:42 -070030TARGETS += membarrier
David Herrmann4f5ce5e2014-08-08 14:25:32 -070031TARGETS += memfd
Pavel Emelyanov58c7be82013-04-30 15:27:06 -070032TARGETS += memory-hotplug
Eric W. Biedermandb181ce2014-07-29 15:50:44 -070033TARGETS += mount
Andrew Morton96e869d2014-12-18 16:17:43 -080034TARGETS += mqueue
David S. Millera6f68032013-03-20 15:07:56 -040035TARGETS += net
Vadym Kochan81573b12020-03-23 16:24:04 +020036TARGETS += net/forwarding
Florian Westphal048d19d2020-01-21 16:56:29 -080037TARGETS += net/mptcp
Florian Westphal25d8bce2018-10-31 18:26:21 +010038TARGETS += netfilter
Andrey Vagin6ad92bf2016-09-06 00:47:16 -070039TARGETS += nsfs
Christian Brauner575a0ae2018-12-29 22:27:33 +010040TARGETS += pidfd
Christian Brauner6952a4f2020-03-08 17:26:32 +010041TARGETS += pid_namespace
Michael Ellerman0e56dac2013-08-06 17:42:35 +100042TARGETS += powerpc
Alexey Dobriyan9cd65652018-04-10 16:31:45 -070043TARGETS += proc
Hiraku Toyookacc04a462015-10-02 20:46:39 +090044TARGETS += pstore
Andrew Morton96e869d2014-12-18 16:17:43 -080045TARGETS += ptrace
Aleksa Saraib28a10a2020-01-18 23:08:00 +110046TARGETS += openat2
Mathieu Desnoyersccba8b62018-06-02 08:44:08 -040047TARGETS += rseq
Alexandre Bellonia12ab9e2018-04-19 14:50:29 +020048TARGETS += rtc
Kees Cookc99ee512015-06-16 10:54:14 -070049TARGETS += seccomp
Stas Sergeev19fd2862016-04-14 23:20:05 +030050TARGETS += sigaltstack
Tim Bird3ce51052014-12-03 10:42:21 -080051TARGETS += size
Tom Hromatka3c545082018-04-26 10:54:09 -060052TARGETS += sparc64
Al Virob8826e52017-02-18 22:07:24 -050053TARGETS += splice
Bamvor Jian Zhang1087d012015-09-09 21:06:25 +080054TARGETS += static_keys
Emilio López822081602016-10-19 09:49:48 -030055TARGETS += sync
Andrew Morton96e869d2014-12-18 16:17:43 -080056TARGETS += sysctl
Dmitry Safonov61c57672019-11-12 01:27:17 +000057TARGETS += timens
Shuah Khan2278e5e2015-06-19 13:13:43 -060058ifneq (1, $(quicktest))
Andrew Morton96e869d2014-12-18 16:17:43 -080059TARGETS += timers
Shuah Khan2278e5e2015-06-19 13:13:43 -060060endif
Alexey Dobriyana3322862019-03-05 15:49:24 -080061TARGETS += tmpfs
Jarkko Sakkinen6ea3dfe2019-02-04 15:16:40 +020062TARGETS += tpm2
Andrew Morton96e869d2014-12-18 16:17:43 -080063TARGETS += user
64TARGETS += vm
Andy Lutomirski3f705df2015-04-06 23:11:06 -070065TARGETS += x86
Naresh Kambojuf21fb792015-08-18 12:31:59 +053066TARGETS += zram
Andrew Morton96e869d2014-12-18 16:17:43 -080067#Please keep the TARGETS list alphabetically sorted
Shuah Khan2278e5e2015-06-19 13:13:43 -060068# Run "make quicktest=1 run_tests" or
SeongJae Parkc6a13fa2017-04-14 08:43:16 +090069# "make quicktest=1 kselftest" from top level Makefile
Frederic Weisbecker274343a2012-01-12 17:20:44 -080070
Shuah Khanddddda92014-07-02 09:51:38 -060071TARGETS_HOTPLUG = cpu-hotplug
72TARGETS_HOTPLUG += memory-hotplug
73
Cristian Marussi3a24f7f2019-09-26 18:52:18 +010074# User can optionally provide a TARGETS skiplist.
75SKIP_TARGETS ?=
76ifneq ($(SKIP_TARGETS),)
77 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
78 override TARGETS := $(TMP)
79endif
80
Jiri Benc9d235a52020-02-06 09:40:00 +010081# User can set FORCE_TARGETS to 1 to require all targets to be successfully
82# built; make will fail if any of the targets cannot be built. If
83# FORCE_TARGETS is not set (the default), make will succeed if at least one
84# of the targets gets built.
85FORCE_TARGETS ?=
86
Shuah Khan67d87122015-03-18 11:57:39 -060087# Clear LDFLAGS and MAKEFLAGS if called from main
88# Makefile to avoid test build failures when test
89# Makefile doesn't have explicit build rules.
90ifeq (1,$(MAKELEVEL))
Arnaldo Carvalho de Melo60df4642015-05-14 16:55:18 -030091override LDFLAGS =
Shuah Khan67d87122015-03-18 11:57:39 -060092override MAKEFLAGS =
93endif
94
Shuah Khan29e911e2020-02-26 15:54:49 -070095# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
Shuah Khan61c20182019-05-14 14:43:44 -060096# KBUILD_OUTPUT with selftest objects and headers installed
97# by selftests Makefile or lib.mk.
Masahiro Yamada051f2782019-07-06 12:07:12 +090098ifdef building_out_of_srctree
Shuah Khan52fd1d02017-09-07 19:57:43 -060099override LDFLAGS =
100endif
101
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600102ifneq ($(O),)
Shuah Khan29e911e2020-02-26 15:54:49 -0700103 BUILD := $(O)/kselftest
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600104else
105 ifneq ($(KBUILD_OUTPUT),)
Shuah Khanf60b85e2019-11-28 16:03:21 -0700106 BUILD := $(KBUILD_OUTPUT)/kselftest
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600107 else
108 BUILD := $(shell pwd)
109 DEFAULT_INSTALL_HDR_PATH := 1
110 endif
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800111endif
112
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600113# Prepare for headers install
114top_srcdir ?= ../../..
115include $(top_srcdir)/scripts/subarch.include
116ARCH ?= $(SUBARCH)
117export KSFT_KHDR_INSTALL_DONE := 1
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800118export BUILD
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600119
Shuah Khand917fb82019-04-19 16:31:28 -0600120# build and run gpio when output directory is the src dir.
121# gpio has dependency on tools/gpio and builds tools/gpio
122# objects in the src directory in all cases making the src
123# repo dirty even when objects are relocated.
124ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
125 TMP := $(filter-out gpio, $(TARGETS))
126 TARGETS := $(TMP)
127endif
128
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600129# set default goal to all, so make without a target runs all, even when
130# all isn't the first target in the file.
131.DEFAULT_GOAL := all
132
133# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
134# is used to avoid running headers_install from lib.mk.
135# Invoke headers install with --no-builtin-rules to avoid circular
136# dependency in "make kselftest" case. In this case, second level
137# make inherits builtin-rules which will use the rule generate
138# Makefile.o and runs into
139# "Circular Makefile.o <- prepare dependency dropped."
140# and headers_install fails and test compile fails.
141#
142# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
143# invokes them as sub-makes and --no-builtin-rules is not necessary,
144# but doesn't cause any failures. Keep it simple and use the same
145# flags in both cases.
146# Local build cases: "make kselftest", "make -C" - headers are installed
147# in the default INSTALL_HDR_PATH usr/include.
148khdr:
149ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200150 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600151else
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200152 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600153 ARCH=$(ARCH) -C $(top_srcdir) headers_install
154endif
155
156all: khdr
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000157 @ret=1; \
158 for TARGET in $(TARGETS); do \
159 BUILD_TARGET=$$BUILD/$$TARGET; \
160 mkdir $$BUILD_TARGET -p; \
Jiri Benc9d235a52020-02-06 09:40:00 +0100161 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
162 $(if $(FORCE_TARGETS),|| exit); \
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000163 ret=$$((ret * $$?)); \
164 done; exit $$ret;
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800165
Andrew Mortoncab6b052012-03-28 14:42:54 -0700166run_tests: all
Shuah Khan1ede0532017-09-18 17:30:50 -0600167 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800168 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200169 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
Frederic Weisbeckerf467f712012-03-28 14:42:54 -0700170 done;
171
Shuah Khanddddda92014-07-02 09:51:38 -0600172hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600173 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800174 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200175 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
Shuah Khanddddda92014-07-02 09:51:38 -0600176 done;
177
178run_hotplug: hotplug
Shuah Khan1ede0532017-09-18 17:30:50 -0600179 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800180 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200181 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
Shuah Khanddddda92014-07-02 09:51:38 -0600182 done;
183
184clean_hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600185 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800186 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200187 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Shuah Khanddddda92014-07-02 09:51:38 -0600188 done;
189
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900190run_pstore_crash:
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200191 $(MAKE) -C pstore run_crash
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900192
Shuah Khanc3c59922019-05-07 17:44:21 -0600193# Use $BUILD as the default install root. $BUILD points to the
194# right output location for the following cases:
195# 1. output_dir=kernel_src
196# 2. a separate output directory is specified using O= KBUILD_OUTPUT
197# 3. a separate output directory is specified using KBUILD_OUTPUT
Shuah Khan17eac6c2019-09-26 16:40:14 -0600198# Avoid conflict with INSTALL_PATH set by the main Makefile
Shuah Khanc3c59922019-05-07 17:44:21 -0600199#
Shuah Khan17eac6c2019-09-26 16:40:14 -0600200KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
201KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
202# Avoid changing the rest of the logic here and lib.mk.
203INSTALL_PATH := $(KSFT_INSTALL_PATH)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100204ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
205
Shuah Khanc3c59922019-05-07 17:44:21 -0600206install: all
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100207ifdef INSTALL_PATH
208 @# Ask all targets to install their files
Kees Cookd4e59a52019-04-24 16:12:31 -0700209 mkdir -p $(INSTALL_PATH)/kselftest
Kees Cookc78fd762019-10-30 12:45:36 -0700210 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
Kees Cookd4e59a52019-04-24 16:12:31 -0700211 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
Kees Cook5c069b62019-04-24 16:12:35 -0700212 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000213 @ret=1; \
214 for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800215 BUILD_TARGET=$$BUILD/$$TARGET; \
Jiri Benc9d235a52020-02-06 09:40:00 +0100216 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
217 $(if $(FORCE_TARGETS),|| exit); \
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000218 ret=$$((ret * $$?)); \
219 done; exit $$ret;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100220
221 @# Ask all targets to emit their test scripts
Rolf Eike Beera2b1e8a2016-12-14 11:59:34 +0100222 echo "#!/bin/sh" > $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100223 echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
224 echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700225 echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100226 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100227 echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700228 echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
229 echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100230 echo "fi" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100231
Cristian Marussi131b30c2019-09-26 18:52:19 +0100232 @# While building run_kselftest.sh skip also non-existent TARGET dirs:
233 @# they could be the result of a build failure and should NOT be
234 @# included in the generated runlist.
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100235 for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800236 BUILD_TARGET=$$BUILD/$$TARGET; \
Prabhakar Kushwaha02bf1f82019-10-22 13:27:17 +0000237 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
Michael Ellerman88893cf2018-03-23 20:44:27 +1100238 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100239 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
Kees Cookbf660782019-04-24 16:12:32 -0700240 echo -n "run_many" >> $(ALL_SCRIPT); \
Shuah Khan17eac6c2019-09-26 16:40:14 -0600241 echo -n "Emit Tests for $$TARGET\n"; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200242 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
Kees Cookbf660782019-04-24 16:12:32 -0700243 echo "" >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100244 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
245 done;
246
247 chmod u+x $(ALL_SCRIPT)
248else
249 $(error Error: set INSTALL_PATH to use install)
250endif
251
Veronika Kabatovaa5f30462020-05-19 22:00:45 +0200252FORMAT ?= .gz
253TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
254gen_tar: install
255 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
256 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
257 @echo "Created ${TAR_PATH}"
258
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800259clean:
Shuah Khan1ede0532017-09-18 17:30:50 -0600260 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800261 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200262 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800263 done;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100264
Veronika Kabatovaa5f30462020-05-19 22:00:45 +0200265.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar