blob: 9781ca79794af774ca86b3ef0708283cfa73db0a [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
3TARGETS += bpf
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +02004TARGETS += breakpoints
Bamvor Jian Zhangf4ecb322015-11-17 22:35:42 +08005TARGETS += capabilities
Roman Gushchin84092dbc2018-05-11 19:03:49 +01006TARGETS += cgroup
Viresh Kumare66d5b62017-01-13 12:06:45 +05307TARGETS += cpufreq
Andrew Morton66a01b92013-02-27 17:05:56 -08008TARGETS += cpu-hotplug
Tom Murphy6edf2e32018-11-27 10:33:08 +00009TARGETS += drivers/dma-buf
Andrew Morton66a01b92013-02-27 17:05:56 -080010TARGETS += efivarfs
Andrew Morton96e869d2014-12-18 16:17:43 -080011TARGETS += exec
Christian Braunerce290a12018-03-13 17:55:27 +010012TARGETS += filesystems
Christian Brauner75abec72019-01-17 12:48:54 +010013TARGETS += filesystems/binderfs
Andrew Morton96e869d2014-12-18 16:17:43 -080014TARGETS += firmware
15TARGETS += ftrace
Darren Hartecac1a72015-05-12 21:07:55 -070016TARGETS += futex
Bamvor Jian Zhang22f65922016-11-21 18:16:11 +080017TARGETS += gpio
Stafford Horne63203032017-01-12 00:16:07 +090018TARGETS += intel_pstate
Bamvor Jian Zhang7e722472015-11-17 22:35:43 +080019TARGETS += ipc
Sean Younge55c8842018-10-16 15:09:31 +010020TARGETS += ir
Pavel Emelyanov58c7be82013-04-30 15:27:06 -070021TARGETS += kcmp
Mimi Zoharc3c0e812019-03-13 10:09:10 -040022TARGETS += kexec
Paolo Bonzini783e9e52018-03-27 11:49:19 +020023TARGETS += kvm
Kees Cook317dc342015-11-06 16:30:32 -080024TARGETS += lib
Joe Lawrencea2818ee2019-01-09 13:43:29 +010025TARGETS += livepatch
Pranith Kumarb6d97342015-09-11 13:07:42 -070026TARGETS += membarrier
David Herrmann4f5ce5e2014-08-08 14:25:32 -070027TARGETS += memfd
Pavel Emelyanov58c7be82013-04-30 15:27:06 -070028TARGETS += memory-hotplug
Eric W. Biedermandb181ce2014-07-29 15:50:44 -070029TARGETS += mount
Andrew Morton96e869d2014-12-18 16:17:43 -080030TARGETS += mqueue
David S. Millera6f68032013-03-20 15:07:56 -040031TARGETS += net
Florian Westphal25d8bce2018-10-31 18:26:21 +010032TARGETS += netfilter
Willem de Bruijncda261f2018-12-20 16:22:54 -050033TARGETS += networking/timestamping
Andrey Vagin6ad92bf2016-09-06 00:47:16 -070034TARGETS += nsfs
Christian Brauner575a0ae2018-12-29 22:27:33 +010035TARGETS += pidfd
Michael Ellerman0e56dac2013-08-06 17:42:35 +100036TARGETS += powerpc
Alexey Dobriyan9cd65652018-04-10 16:31:45 -070037TARGETS += proc
Hiraku Toyookacc04a462015-10-02 20:46:39 +090038TARGETS += pstore
Andrew Morton96e869d2014-12-18 16:17:43 -080039TARGETS += ptrace
Mathieu Desnoyersccba8b62018-06-02 08:44:08 -040040TARGETS += rseq
Alexandre Bellonia12ab9e2018-04-19 14:50:29 +020041TARGETS += rtc
Kees Cookc99ee512015-06-16 10:54:14 -070042TARGETS += seccomp
Stas Sergeev19fd2862016-04-14 23:20:05 +030043TARGETS += sigaltstack
Tim Bird3ce51052014-12-03 10:42:21 -080044TARGETS += size
Tom Hromatka3c545082018-04-26 10:54:09 -060045TARGETS += sparc64
Al Virob8826e52017-02-18 22:07:24 -050046TARGETS += splice
Bamvor Jian Zhang1087d012015-09-09 21:06:25 +080047TARGETS += static_keys
Emilio López822081602016-10-19 09:49:48 -030048TARGETS += sync
Andrew Morton96e869d2014-12-18 16:17:43 -080049TARGETS += sysctl
Shuah Khan2278e5e2015-06-19 13:13:43 -060050ifneq (1, $(quicktest))
Andrew Morton96e869d2014-12-18 16:17:43 -080051TARGETS += timers
Shuah Khan2278e5e2015-06-19 13:13:43 -060052endif
Alexey Dobriyana3322862019-03-05 15:49:24 -080053TARGETS += tmpfs
Jarkko Sakkinen6ea3dfe2019-02-04 15:16:40 +020054TARGETS += tpm2
Andrew Morton96e869d2014-12-18 16:17:43 -080055TARGETS += user
56TARGETS += vm
Andy Lutomirski3f705df2015-04-06 23:11:06 -070057TARGETS += x86
Naresh Kambojuf21fb792015-08-18 12:31:59 +053058TARGETS += zram
Andrew Morton96e869d2014-12-18 16:17:43 -080059#Please keep the TARGETS list alphabetically sorted
Shuah Khan2278e5e2015-06-19 13:13:43 -060060# Run "make quicktest=1 run_tests" or
SeongJae Parkc6a13fa2017-04-14 08:43:16 +090061# "make quicktest=1 kselftest" from top level Makefile
Frederic Weisbecker274343a2012-01-12 17:20:44 -080062
Shuah Khanddddda92014-07-02 09:51:38 -060063TARGETS_HOTPLUG = cpu-hotplug
64TARGETS_HOTPLUG += memory-hotplug
65
Shuah Khan67d87122015-03-18 11:57:39 -060066# Clear LDFLAGS and MAKEFLAGS if called from main
67# Makefile to avoid test build failures when test
68# Makefile doesn't have explicit build rules.
69ifeq (1,$(MAKELEVEL))
Arnaldo Carvalho de Melo60df4642015-05-14 16:55:18 -030070override LDFLAGS =
Shuah Khan67d87122015-03-18 11:57:39 -060071override MAKEFLAGS =
72endif
73
Shuah Khan61c20182019-05-14 14:43:44 -060074# Append kselftest to KBUILD_OUTPUT to avoid cluttering
75# KBUILD_OUTPUT with selftest objects and headers installed
76# by selftests Makefile or lib.mk.
Shuah Khan52fd1d02017-09-07 19:57:43 -060077ifneq ($(KBUILD_SRC),)
78override LDFLAGS =
79endif
80
Shuah Khan8ce72dc2019-04-15 15:51:42 -060081ifneq ($(O),)
82 BUILD := $(O)
83else
84 ifneq ($(KBUILD_OUTPUT),)
Shuah Khan61c20182019-05-14 14:43:44 -060085 BUILD := $(KBUILD_OUTPUT)/kselftest
Shuah Khan8ce72dc2019-04-15 15:51:42 -060086 else
87 BUILD := $(shell pwd)
88 DEFAULT_INSTALL_HDR_PATH := 1
89 endif
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +080090endif
91
Shuah Khan8ce72dc2019-04-15 15:51:42 -060092# Prepare for headers install
93top_srcdir ?= ../../..
94include $(top_srcdir)/scripts/subarch.include
95ARCH ?= $(SUBARCH)
96export KSFT_KHDR_INSTALL_DONE := 1
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +080097export BUILD
Shuah Khan8ce72dc2019-04-15 15:51:42 -060098
Shuah Khand917fb82019-04-19 16:31:28 -060099# build and run gpio when output directory is the src dir.
100# gpio has dependency on tools/gpio and builds tools/gpio
101# objects in the src directory in all cases making the src
102# repo dirty even when objects are relocated.
103ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
104 TMP := $(filter-out gpio, $(TARGETS))
105 TARGETS := $(TMP)
106endif
107
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600108# set default goal to all, so make without a target runs all, even when
109# all isn't the first target in the file.
110.DEFAULT_GOAL := all
111
112# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
113# is used to avoid running headers_install from lib.mk.
114# Invoke headers install with --no-builtin-rules to avoid circular
115# dependency in "make kselftest" case. In this case, second level
116# make inherits builtin-rules which will use the rule generate
117# Makefile.o and runs into
118# "Circular Makefile.o <- prepare dependency dropped."
119# and headers_install fails and test compile fails.
120#
121# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
122# invokes them as sub-makes and --no-builtin-rules is not necessary,
123# but doesn't cause any failures. Keep it simple and use the same
124# flags in both cases.
125# Local build cases: "make kselftest", "make -C" - headers are installed
126# in the default INSTALL_HDR_PATH usr/include.
127khdr:
128ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
129 make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
130else
131 make --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
132 ARCH=$(ARCH) -C $(top_srcdir) headers_install
133endif
134
135all: khdr
Shuah Khan1ede0532017-09-18 17:30:50 -0600136 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800137 BUILD_TARGET=$$BUILD/$$TARGET; \
138 mkdir $$BUILD_TARGET -p; \
139 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800140 done;
141
Andrew Mortoncab6b052012-03-28 14:42:54 -0700142run_tests: all
Shuah Khan1ede0532017-09-18 17:30:50 -0600143 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800144 BUILD_TARGET=$$BUILD/$$TARGET; \
145 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
Frederic Weisbeckerf467f712012-03-28 14:42:54 -0700146 done;
147
Shuah Khanddddda92014-07-02 09:51:38 -0600148hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600149 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800150 BUILD_TARGET=$$BUILD/$$TARGET; \
151 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
Shuah Khanddddda92014-07-02 09:51:38 -0600152 done;
153
154run_hotplug: hotplug
Shuah Khan1ede0532017-09-18 17:30:50 -0600155 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800156 BUILD_TARGET=$$BUILD/$$TARGET; \
157 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
Shuah Khanddddda92014-07-02 09:51:38 -0600158 done;
159
160clean_hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600161 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800162 BUILD_TARGET=$$BUILD/$$TARGET; \
163 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Shuah Khanddddda92014-07-02 09:51:38 -0600164 done;
165
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900166run_pstore_crash:
167 make -C pstore run_crash
168
Shuah Khanc3c59922019-05-07 17:44:21 -0600169# Use $BUILD as the default install root. $BUILD points to the
170# right output location for the following cases:
171# 1. output_dir=kernel_src
172# 2. a separate output directory is specified using O= KBUILD_OUTPUT
173# 3. a separate output directory is specified using KBUILD_OUTPUT
174#
175INSTALL_PATH ?= $(BUILD)/install
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100176INSTALL_PATH := $(abspath $(INSTALL_PATH))
177ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
178
Shuah Khanc3c59922019-05-07 17:44:21 -0600179install: all
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100180ifdef INSTALL_PATH
181 @# Ask all targets to install their files
Kees Cookd4e59a52019-04-24 16:12:31 -0700182 mkdir -p $(INSTALL_PATH)/kselftest
183 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
Kees Cook5c069b62019-04-24 16:12:35 -0700184 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
Shuah Khan1ede0532017-09-18 17:30:50 -0600185 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800186 BUILD_TARGET=$$BUILD/$$TARGET; \
187 make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100188 done;
189
190 @# Ask all targets to emit their test scripts
Rolf Eike Beera2b1e8a2016-12-14 11:59:34 +0100191 echo "#!/bin/sh" > $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100192 echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
193 echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700194 echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100195 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100196 echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700197 echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
198 echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100199 echo "fi" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100200
201 for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800202 BUILD_TARGET=$$BUILD/$$TARGET; \
Michael Ellerman88893cf2018-03-23 20:44:27 +1100203 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100204 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
Kees Cookbf660782019-04-24 16:12:32 -0700205 echo -n "run_many" >> $(ALL_SCRIPT); \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800206 make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
Kees Cookbf660782019-04-24 16:12:32 -0700207 echo "" >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100208 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
209 done;
210
211 chmod u+x $(ALL_SCRIPT)
212else
213 $(error Error: set INSTALL_PATH to use install)
214endif
215
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800216clean:
Shuah Khan1ede0532017-09-18 17:30:50 -0600217 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800218 BUILD_TARGET=$$BUILD/$$TARGET; \
219 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800220 done;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100221
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600222.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean