blob: 5c042b58413d91f17ba2dc043b4f250d007fe861 [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
19TARGETS += ftrace
Darren Hartecac1a72015-05-12 21:07:55 -070020TARGETS += futex
Bamvor Jian Zhang22f65922016-11-21 18:16:11 +080021TARGETS += gpio
Stafford Horne63203032017-01-12 00:16:07 +090022TARGETS += intel_pstate
Bamvor Jian Zhang7e722472015-11-17 22:35:43 +080023TARGETS += ipc
Sean Younge55c8842018-10-16 15:09:31 +010024TARGETS += ir
Pavel Emelyanov58c7be82013-04-30 15:27:06 -070025TARGETS += kcmp
Mimi Zoharc3c0e812019-03-13 10:09:10 -040026TARGETS += kexec
Paolo Bonzini783e9e52018-03-27 11:49:19 +020027TARGETS += kvm
Kees Cook317dc342015-11-06 16:30:32 -080028TARGETS += lib
Joe Lawrencea2818ee2019-01-09 13:43:29 +010029TARGETS += livepatch
Kees Cook46d1a0f2020-01-09 21:02:06 -080030TARGETS += lkdtm
Pranith Kumarb6d97342015-09-11 13:07:42 -070031TARGETS += membarrier
David Herrmann4f5ce5e2014-08-08 14:25:32 -070032TARGETS += memfd
Pavel Emelyanov58c7be82013-04-30 15:27:06 -070033TARGETS += memory-hotplug
Eric W. Biedermandb181ce2014-07-29 15:50:44 -070034TARGETS += mount
Andrew Morton96e869d2014-12-18 16:17:43 -080035TARGETS += mqueue
David S. Millera6f68032013-03-20 15:07:56 -040036TARGETS += net
Vadym Kochan81573b12020-03-23 16:24:04 +020037TARGETS += net/forwarding
Florian Westphal048d19d2020-01-21 16:56:29 -080038TARGETS += net/mptcp
Florian Westphal25d8bce2018-10-31 18:26:21 +010039TARGETS += netfilter
Andrey Vagin6ad92bf2016-09-06 00:47:16 -070040TARGETS += nsfs
Christian Brauner575a0ae2018-12-29 22:27:33 +010041TARGETS += pidfd
Christian Brauner6952a4f2020-03-08 17:26:32 +010042TARGETS += pid_namespace
Michael Ellerman0e56dac2013-08-06 17:42:35 +100043TARGETS += powerpc
Alexey Dobriyan9cd65652018-04-10 16:31:45 -070044TARGETS += proc
Hiraku Toyookacc04a462015-10-02 20:46:39 +090045TARGETS += pstore
Andrew Morton96e869d2014-12-18 16:17:43 -080046TARGETS += ptrace
Aleksa Saraib28a10a2020-01-18 23:08:00 +110047TARGETS += openat2
Mathieu Desnoyersccba8b62018-06-02 08:44:08 -040048TARGETS += rseq
Alexandre Bellonia12ab9e2018-04-19 14:50:29 +020049TARGETS += rtc
Kees Cookc99ee512015-06-16 10:54:14 -070050TARGETS += seccomp
Stas Sergeev19fd2862016-04-14 23:20:05 +030051TARGETS += sigaltstack
Tim Bird3ce51052014-12-03 10:42:21 -080052TARGETS += size
Tom Hromatka3c545082018-04-26 10:54:09 -060053TARGETS += sparc64
Al Virob8826e52017-02-18 22:07:24 -050054TARGETS += splice
Bamvor Jian Zhang1087d012015-09-09 21:06:25 +080055TARGETS += static_keys
Emilio López822081602016-10-19 09:49:48 -030056TARGETS += sync
Andrew Morton96e869d2014-12-18 16:17:43 -080057TARGETS += sysctl
Dmitry Safonov61c57672019-11-12 01:27:17 +000058TARGETS += timens
Shuah Khan2278e5e2015-06-19 13:13:43 -060059ifneq (1, $(quicktest))
Andrew Morton96e869d2014-12-18 16:17:43 -080060TARGETS += timers
Shuah Khan2278e5e2015-06-19 13:13:43 -060061endif
Alexey Dobriyana3322862019-03-05 15:49:24 -080062TARGETS += tmpfs
Jarkko Sakkinen6ea3dfe2019-02-04 15:16:40 +020063TARGETS += tpm2
Andrew Morton96e869d2014-12-18 16:17:43 -080064TARGETS += user
65TARGETS += vm
Andy Lutomirski3f705df2015-04-06 23:11:06 -070066TARGETS += x86
Naresh Kambojuf21fb792015-08-18 12:31:59 +053067TARGETS += zram
Andrew Morton96e869d2014-12-18 16:17:43 -080068#Please keep the TARGETS list alphabetically sorted
Shuah Khan2278e5e2015-06-19 13:13:43 -060069# Run "make quicktest=1 run_tests" or
SeongJae Parkc6a13fa2017-04-14 08:43:16 +090070# "make quicktest=1 kselftest" from top level Makefile
Frederic Weisbecker274343a2012-01-12 17:20:44 -080071
Shuah Khanddddda92014-07-02 09:51:38 -060072TARGETS_HOTPLUG = cpu-hotplug
73TARGETS_HOTPLUG += memory-hotplug
74
Cristian Marussi3a24f7f2019-09-26 18:52:18 +010075# User can optionally provide a TARGETS skiplist.
76SKIP_TARGETS ?=
77ifneq ($(SKIP_TARGETS),)
78 TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
79 override TARGETS := $(TMP)
80endif
81
Jiri Benc9d235a52020-02-06 09:40:00 +010082# User can set FORCE_TARGETS to 1 to require all targets to be successfully
83# built; make will fail if any of the targets cannot be built. If
84# FORCE_TARGETS is not set (the default), make will succeed if at least one
85# of the targets gets built.
86FORCE_TARGETS ?=
87
Shuah Khan67d87122015-03-18 11:57:39 -060088# Clear LDFLAGS and MAKEFLAGS if called from main
89# Makefile to avoid test build failures when test
90# Makefile doesn't have explicit build rules.
91ifeq (1,$(MAKELEVEL))
Arnaldo Carvalho de Melo60df4642015-05-14 16:55:18 -030092override LDFLAGS =
Shuah Khan67d87122015-03-18 11:57:39 -060093override MAKEFLAGS =
94endif
95
Shuah Khan29e911e2020-02-26 15:54:49 -070096# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering
Shuah Khan61c20182019-05-14 14:43:44 -060097# KBUILD_OUTPUT with selftest objects and headers installed
98# by selftests Makefile or lib.mk.
Masahiro Yamada051f2782019-07-06 12:07:12 +090099ifdef building_out_of_srctree
Shuah Khan52fd1d02017-09-07 19:57:43 -0600100override LDFLAGS =
101endif
102
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600103ifneq ($(O),)
Shuah Khan29e911e2020-02-26 15:54:49 -0700104 BUILD := $(O)/kselftest
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600105else
106 ifneq ($(KBUILD_OUTPUT),)
Shuah Khanf60b85e2019-11-28 16:03:21 -0700107 BUILD := $(KBUILD_OUTPUT)/kselftest
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600108 else
109 BUILD := $(shell pwd)
110 DEFAULT_INSTALL_HDR_PATH := 1
111 endif
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800112endif
113
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600114# Prepare for headers install
115top_srcdir ?= ../../..
116include $(top_srcdir)/scripts/subarch.include
117ARCH ?= $(SUBARCH)
118export KSFT_KHDR_INSTALL_DONE := 1
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800119export BUILD
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600120
Shuah Khand917fb82019-04-19 16:31:28 -0600121# build and run gpio when output directory is the src dir.
122# gpio has dependency on tools/gpio and builds tools/gpio
123# objects in the src directory in all cases making the src
124# repo dirty even when objects are relocated.
125ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
126 TMP := $(filter-out gpio, $(TARGETS))
127 TARGETS := $(TMP)
128endif
129
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600130# set default goal to all, so make without a target runs all, even when
131# all isn't the first target in the file.
132.DEFAULT_GOAL := all
133
134# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
135# is used to avoid running headers_install from lib.mk.
136# Invoke headers install with --no-builtin-rules to avoid circular
137# dependency in "make kselftest" case. In this case, second level
138# make inherits builtin-rules which will use the rule generate
139# Makefile.o and runs into
140# "Circular Makefile.o <- prepare dependency dropped."
141# and headers_install fails and test compile fails.
142#
143# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
144# invokes them as sub-makes and --no-builtin-rules is not necessary,
145# but doesn't cause any failures. Keep it simple and use the same
146# flags in both cases.
147# Local build cases: "make kselftest", "make -C" - headers are installed
148# in the default INSTALL_HDR_PATH usr/include.
149khdr:
150ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200151 $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600152else
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200153 $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600154 ARCH=$(ARCH) -C $(top_srcdir) headers_install
155endif
156
157all: khdr
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000158 @ret=1; \
159 for TARGET in $(TARGETS); do \
160 BUILD_TARGET=$$BUILD/$$TARGET; \
161 mkdir $$BUILD_TARGET -p; \
Jiri Benc9d235a52020-02-06 09:40:00 +0100162 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \
163 $(if $(FORCE_TARGETS),|| exit); \
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000164 ret=$$((ret * $$?)); \
165 done; exit $$ret;
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800166
Andrew Mortoncab6b052012-03-28 14:42:54 -0700167run_tests: all
Shuah Khan1ede0532017-09-18 17:30:50 -0600168 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800169 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200170 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
Frederic Weisbeckerf467f712012-03-28 14:42:54 -0700171 done;
172
Shuah Khanddddda92014-07-02 09:51:38 -0600173hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600174 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800175 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200176 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
Shuah Khanddddda92014-07-02 09:51:38 -0600177 done;
178
179run_hotplug: hotplug
Shuah Khan1ede0532017-09-18 17:30:50 -0600180 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800181 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200182 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
Shuah Khanddddda92014-07-02 09:51:38 -0600183 done;
184
185clean_hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600186 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800187 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200188 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Shuah Khanddddda92014-07-02 09:51:38 -0600189 done;
190
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900191run_pstore_crash:
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200192 $(MAKE) -C pstore run_crash
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900193
Shuah Khanc3c59922019-05-07 17:44:21 -0600194# Use $BUILD as the default install root. $BUILD points to the
195# right output location for the following cases:
196# 1. output_dir=kernel_src
197# 2. a separate output directory is specified using O= KBUILD_OUTPUT
198# 3. a separate output directory is specified using KBUILD_OUTPUT
Shuah Khan17eac6c2019-09-26 16:40:14 -0600199# Avoid conflict with INSTALL_PATH set by the main Makefile
Shuah Khanc3c59922019-05-07 17:44:21 -0600200#
Shuah Khan17eac6c2019-09-26 16:40:14 -0600201KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
202KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
203# Avoid changing the rest of the logic here and lib.mk.
204INSTALL_PATH := $(KSFT_INSTALL_PATH)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100205ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
206
Shuah Khanc3c59922019-05-07 17:44:21 -0600207install: all
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100208ifdef INSTALL_PATH
209 @# Ask all targets to install their files
Kees Cookd4e59a52019-04-24 16:12:31 -0700210 mkdir -p $(INSTALL_PATH)/kselftest
Kees Cookc78fd762019-10-30 12:45:36 -0700211 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/
Kees Cookd4e59a52019-04-24 16:12:31 -0700212 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
Kees Cook5c069b62019-04-24 16:12:35 -0700213 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000214 @ret=1; \
215 for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800216 BUILD_TARGET=$$BUILD/$$TARGET; \
Jiri Benc9d235a52020-02-06 09:40:00 +0100217 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \
218 $(if $(FORCE_TARGETS),|| exit); \
Cristian Marussi5f70bde2019-12-10 11:44:59 +0000219 ret=$$((ret * $$?)); \
220 done; exit $$ret;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100221
222 @# Ask all targets to emit their test scripts
Rolf Eike Beera2b1e8a2016-12-14 11:59:34 +0100223 echo "#!/bin/sh" > $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100224 echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
225 echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700226 echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100227 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100228 echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700229 echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
230 echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100231 echo "fi" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100232
Cristian Marussi131b30c2019-09-26 18:52:19 +0100233 @# While building run_kselftest.sh skip also non-existent TARGET dirs:
234 @# they could be the result of a build failure and should NOT be
235 @# included in the generated runlist.
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100236 for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800237 BUILD_TARGET=$$BUILD/$$TARGET; \
Prabhakar Kushwaha02bf1f82019-10-22 13:27:17 +0000238 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
Michael Ellerman88893cf2018-03-23 20:44:27 +1100239 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100240 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
Kees Cookbf660782019-04-24 16:12:32 -0700241 echo -n "run_many" >> $(ALL_SCRIPT); \
Shuah Khan17eac6c2019-09-26 16:40:14 -0600242 echo -n "Emit Tests for $$TARGET\n"; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200243 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
Kees Cookbf660782019-04-24 16:12:32 -0700244 echo "" >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100245 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
246 done;
247
248 chmod u+x $(ALL_SCRIPT)
249else
250 $(error Error: set INSTALL_PATH to use install)
251endif
252
Veronika Kabatovaa5f30462020-05-19 22:00:45 +0200253FORMAT ?= .gz
254TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT})
255gen_tar: install
256 @mkdir -p ${INSTALL_PATH}/kselftest-packages/
257 @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} .
258 @echo "Created ${TAR_PATH}"
259
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800260clean:
Shuah Khan1ede0532017-09-18 17:30:50 -0600261 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800262 BUILD_TARGET=$$BUILD/$$TARGET; \
Ilya Leoshkevich0ac33e42019-08-16 18:06:04 +0200263 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800264 done;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100265
Veronika Kabatovaa5f30462020-05-19 22:00:45 +0200266.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar