Makefile 6.1 KB
Newer Older
1
# SPDX-License-Identifier: GPL-2.0
2 3
TARGETS = android
TARGETS += bpf
4
TARGETS += breakpoints
5
TARGETS += capabilities
6
TARGETS += cgroup
7
TARGETS += cpufreq
8
TARGETS += cpu-hotplug
T
Tom Murphy 已提交
9
TARGETS += drivers/dma-buf
10
TARGETS += efivarfs
11
TARGETS += exec
12
TARGETS += filesystems
13
TARGETS += filesystems/binderfs
14 15
TARGETS += firmware
TARGETS += ftrace
16
TARGETS += futex
17
TARGETS += gpio
18
TARGETS += intel_pstate
B
Bamvor Jian Zhang 已提交
19
TARGETS += ipc
20
TARGETS += ir
21
TARGETS += kcmp
22
TARGETS += kexec
23
TARGETS += kvm
K
Kees Cook 已提交
24
TARGETS += lib
25
TARGETS += livepatch
26
TARGETS += membarrier
27
TARGETS += memfd
28
TARGETS += memory-hotplug
29
TARGETS += mount
30
TARGETS += mqueue
31
TARGETS += net
32
TARGETS += netfilter
33
TARGETS += networking/timestamping
34
TARGETS += nsfs
35
TARGETS += pidfd
36
TARGETS += powerpc
A
Alexey Dobriyan 已提交
37
TARGETS += proc
38
TARGETS += pstore
39
TARGETS += ptrace
40
TARGETS += rseq
41
TARGETS += rtc
K
Kees Cook 已提交
42
TARGETS += seccomp
43
TARGETS += sigaltstack
44
TARGETS += size
45
TARGETS += sparc64
46
TARGETS += splice
47
TARGETS += static_keys
48
TARGETS += sync
49
TARGETS += sysctl
S
Shuah Khan 已提交
50
ifneq (1, $(quicktest))
51
TARGETS += timers
S
Shuah Khan 已提交
52
endif
53
TARGETS += tmpfs
J
Jarkko Sakkinen 已提交
54
TARGETS += tpm2
55
TARGETS += user
56
TARGETS += vm
57
TARGETS += x86
58
TARGETS += zram
59
#Please keep the TARGETS list alphabetically sorted
S
Shuah Khan 已提交
60
# Run "make quicktest=1 run_tests" or
61
# "make quicktest=1 kselftest" from top level Makefile
62

63 64 65
TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug

66 67 68 69
# Clear LDFLAGS and MAKEFLAGS if called from main
# Makefile to avoid test build failures when test
# Makefile doesn't have explicit build rules.
ifeq (1,$(MAKELEVEL))
70
override LDFLAGS =
71 72 73
override MAKEFLAGS =
endif

74 75 76 77
ifneq ($(KBUILD_SRC),)
override LDFLAGS =
endif

78 79 80 81 82 83 84 85 86
ifneq ($(O),)
	BUILD := $(O)
else
	ifneq ($(KBUILD_OUTPUT),)
		BUILD := $(KBUILD_OUTPUT)
	else
		BUILD := $(shell pwd)
		DEFAULT_INSTALL_HDR_PATH := 1
	endif
87 88
endif

89 90 91 92 93 94
# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header
# printing from tests. Applicable to run_tests case where run_tests adds
# TAP header prior running tests and when a test program invokes another
# with system() call. Export it here to cover override RUN_TESTS defines.
export KSFT_TAP_LEVEL=`echo 1`

95 96 97 98 99
# Prepare for headers install
top_srcdir ?= ../../..
include $(top_srcdir)/scripts/subarch.include
ARCH           ?= $(SUBARCH)
export KSFT_KHDR_INSTALL_DONE := 1
100
export BUILD
101

102 103 104 105 106 107 108 109 110
# build and run gpio when output directory is the src dir.
# gpio has dependency on tools/gpio and builds tools/gpio
# objects in the src directory in all cases making the src
# repo dirty even when objects are relocated.
ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
	TMP := $(filter-out gpio, $(TARGETS))
	TARGETS := $(TMP)
endif

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
# set default goal to all, so make without a target runs all, even when
# all isn't the first target in the file.
.DEFAULT_GOAL := all

# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
# is used to avoid running headers_install from lib.mk.
# Invoke headers install with --no-builtin-rules to avoid circular
# dependency in "make kselftest" case. In this case, second level
# make inherits builtin-rules which will use the rule generate
# Makefile.o and runs into
# "Circular Makefile.o <- prepare dependency dropped."
# and headers_install fails and test compile fails.
#
# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
# invokes them as sub-makes and --no-builtin-rules is not necessary,
# but doesn't cause any failures. Keep it simple and use the same
# flags in both cases.
# Local build cases: "make kselftest", "make -C" - headers are installed
# in the default INSTALL_HDR_PATH usr/include.
khdr:
ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
	make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
else
	make --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
		ARCH=$(ARCH) -C $(top_srcdir) headers_install
endif

all: khdr
139
	@for TARGET in $(TARGETS); do		\
140 141 142
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		mkdir $$BUILD_TARGET  -p;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
143 144
	done;

145
run_tests: all
146
	@for TARGET in $(TARGETS); do \
147 148
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
149 150
	done;

151
hotplug:
152
	@for TARGET in $(TARGETS_HOTPLUG); do \
153 154
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
155 156 157
	done;

run_hotplug: hotplug
158
	@for TARGET in $(TARGETS_HOTPLUG); do \
159 160
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
161 162 163
	done;

clean_hotplug:
164
	@for TARGET in $(TARGETS_HOTPLUG); do \
165 166
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
167 168
	done;

169 170 171
run_pstore_crash:
	make -C pstore run_crash

M
Michael Ellerman 已提交
172 173 174 175 176 177 178
INSTALL_PATH ?= install
INSTALL_PATH := $(abspath $(INSTALL_PATH))
ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh

install:
ifdef INSTALL_PATH
	@# Ask all targets to install their files
179 180
	mkdir -p $(INSTALL_PATH)/kselftest
	install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
181
	install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
182
	@for TARGET in $(TARGETS); do \
183 184
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
M
Michael Ellerman 已提交
185 186 187
	done;

	@# Ask all targets to emit their test scripts
188
	echo "#!/bin/sh" > $(ALL_SCRIPT)
189 190
	echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
	echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
191
	echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
M
Michael Ellerman 已提交
192
	echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
193
	echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
194 195
	echo "  logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
	echo "  cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
196
	echo "fi" >> $(ALL_SCRIPT)
M
Michael Ellerman 已提交
197 198

	for TARGET in $(TARGETS); do \
199
		BUILD_TARGET=$$BUILD/$$TARGET;	\
200
		echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
M
Michael Ellerman 已提交
201
		echo "cd $$TARGET" >> $(ALL_SCRIPT); \
202
		echo -n "run_many" >> $(ALL_SCRIPT); \
203
		make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
204
		echo "" >> $(ALL_SCRIPT);	    \
M
Michael Ellerman 已提交
205 206 207 208 209 210 211 212
		echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
	done;

	chmod u+x $(ALL_SCRIPT)
else
	$(error Error: set INSTALL_PATH to use install)
endif

213
clean:
214
	@for TARGET in $(TARGETS); do \
215 216
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
217
	done;
M
Michael Ellerman 已提交
218

219
.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean