blob: c5f9f736cdbd12c03d423f73d91db2f9543eefae [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 Khan52fd1d02017-09-07 19:57:43 -060074ifneq ($(KBUILD_SRC),)
75override LDFLAGS =
76endif
77
Shuah Khan8ce72dc2019-04-15 15:51:42 -060078ifneq ($(O),)
79 BUILD := $(O)
80else
81 ifneq ($(KBUILD_OUTPUT),)
82 BUILD := $(KBUILD_OUTPUT)
83 else
84 BUILD := $(shell pwd)
85 DEFAULT_INSTALL_HDR_PATH := 1
86 endif
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +080087endif
88
Shuah Khan44f01352018-02-21 17:25:55 -070089# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header
90# printing from tests. Applicable to run_tests case where run_tests adds
91# TAP header prior running tests and when a test program invokes another
92# with system() call. Export it here to cover override RUN_TESTS defines.
93export KSFT_TAP_LEVEL=`echo 1`
94
Shuah Khan8ce72dc2019-04-15 15:51:42 -060095# Prepare for headers install
96top_srcdir ?= ../../..
97include $(top_srcdir)/scripts/subarch.include
98ARCH ?= $(SUBARCH)
99export KSFT_KHDR_INSTALL_DONE := 1
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800100export BUILD
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600101
Shuah Khand917fb82019-04-19 16:31:28 -0600102# build and run gpio when output directory is the src dir.
103# gpio has dependency on tools/gpio and builds tools/gpio
104# objects in the src directory in all cases making the src
105# repo dirty even when objects are relocated.
106ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
107 TMP := $(filter-out gpio, $(TARGETS))
108 TARGETS := $(TMP)
109endif
110
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600111# set default goal to all, so make without a target runs all, even when
112# all isn't the first target in the file.
113.DEFAULT_GOAL := all
114
115# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
116# is used to avoid running headers_install from lib.mk.
117# Invoke headers install with --no-builtin-rules to avoid circular
118# dependency in "make kselftest" case. In this case, second level
119# make inherits builtin-rules which will use the rule generate
120# Makefile.o and runs into
121# "Circular Makefile.o <- prepare dependency dropped."
122# and headers_install fails and test compile fails.
123#
124# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
125# invokes them as sub-makes and --no-builtin-rules is not necessary,
126# but doesn't cause any failures. Keep it simple and use the same
127# flags in both cases.
128# Local build cases: "make kselftest", "make -C" - headers are installed
129# in the default INSTALL_HDR_PATH usr/include.
130khdr:
131ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
132 make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
133else
134 make --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
135 ARCH=$(ARCH) -C $(top_srcdir) headers_install
136endif
137
138all: khdr
Shuah Khan1ede0532017-09-18 17:30:50 -0600139 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800140 BUILD_TARGET=$$BUILD/$$TARGET; \
141 mkdir $$BUILD_TARGET -p; \
142 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800143 done;
144
Andrew Mortoncab6b052012-03-28 14:42:54 -0700145run_tests: all
Shuah Khan1ede0532017-09-18 17:30:50 -0600146 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800147 BUILD_TARGET=$$BUILD/$$TARGET; \
148 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
Frederic Weisbeckerf467f712012-03-28 14:42:54 -0700149 done;
150
Shuah Khanddddda92014-07-02 09:51:38 -0600151hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600152 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800153 BUILD_TARGET=$$BUILD/$$TARGET; \
154 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
Shuah Khanddddda92014-07-02 09:51:38 -0600155 done;
156
157run_hotplug: hotplug
Shuah Khan1ede0532017-09-18 17:30:50 -0600158 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800159 BUILD_TARGET=$$BUILD/$$TARGET; \
160 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
Shuah Khanddddda92014-07-02 09:51:38 -0600161 done;
162
163clean_hotplug:
Shuah Khan1ede0532017-09-18 17:30:50 -0600164 @for TARGET in $(TARGETS_HOTPLUG); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800165 BUILD_TARGET=$$BUILD/$$TARGET; \
166 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Shuah Khanddddda92014-07-02 09:51:38 -0600167 done;
168
Hiraku Toyookaf615e2b2015-10-02 20:46:41 +0900169run_pstore_crash:
170 make -C pstore run_crash
171
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100172INSTALL_PATH ?= install
173INSTALL_PATH := $(abspath $(INSTALL_PATH))
174ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
175
176install:
177ifdef INSTALL_PATH
178 @# Ask all targets to install their files
Kees Cookd4e59a52019-04-24 16:12:31 -0700179 mkdir -p $(INSTALL_PATH)/kselftest
180 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
Shuah Khan1ede0532017-09-18 17:30:50 -0600181 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800182 BUILD_TARGET=$$BUILD/$$TARGET; \
183 make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100184 done;
185
186 @# Ask all targets to emit their test scripts
Rolf Eike Beera2b1e8a2016-12-14 11:59:34 +0100187 echo "#!/bin/sh" > $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100188 echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
189 echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700190 echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100191 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100192 echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
Kees Cookd4e59a52019-04-24 16:12:31 -0700193 echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
194 echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
Michael Ellerman14f18892018-01-16 17:10:39 +1100195 echo "fi" >> $(ALL_SCRIPT)
Shuah Khan (Samsung OSG)3df61312018-05-01 12:15:34 -0600196 echo "export KSFT_TAP_LEVEL=1" >> $(ALL_SCRIPT)
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100197
198 for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800199 BUILD_TARGET=$$BUILD/$$TARGET; \
Shuah Khan44f01352018-02-21 17:25:55 -0700200 echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT); \
201 echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100202 echo "echo ========================================" >> $(ALL_SCRIPT); \
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); \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800205 make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100206 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
207 done;
208
209 chmod u+x $(ALL_SCRIPT)
210else
211 $(error Error: set INSTALL_PATH to use install)
212endif
213
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800214clean:
Shuah Khan1ede0532017-09-18 17:30:50 -0600215 @for TARGET in $(TARGETS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800216 BUILD_TARGET=$$BUILD/$$TARGET; \
217 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
Frederic Weisbecker274343a2012-01-12 17:20:44 -0800218 done;
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100219
Shuah Khan8ce72dc2019-04-15 15:51:42 -0600220.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean