Makefile 4.3 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 9
TARGETS += cpu-hotplug
TARGETS += efivarfs
10
TARGETS += exec
11
TARGETS += filesystems
12 13
TARGETS += firmware
TARGETS += ftrace
14
TARGETS += futex
15
TARGETS += gpio
16
TARGETS += intel_pstate
B
Bamvor Jian Zhang 已提交
17
TARGETS += ipc
18
TARGETS += kcmp
19
TARGETS += kvm
K
Kees Cook 已提交
20
TARGETS += lib
21
TARGETS += membarrier
22
TARGETS += memfd
23
TARGETS += memory-hotplug
24
TARGETS += mount
25
TARGETS += mqueue
26
TARGETS += net
27
TARGETS += nsfs
28
TARGETS += powerpc
A
Alexey Dobriyan 已提交
29
TARGETS += proc
30
TARGETS += pstore
31
TARGETS += ptrace
32
TARGETS += rseq
33
TARGETS += rtc
K
Kees Cook 已提交
34
TARGETS += seccomp
35
TARGETS += sigaltstack
36
TARGETS += size
37
TARGETS += sparc64
38
TARGETS += splice
39
TARGETS += static_keys
40
TARGETS += sync
41
TARGETS += sysctl
S
Shuah Khan 已提交
42
ifneq (1, $(quicktest))
43
TARGETS += timers
S
Shuah Khan 已提交
44
endif
45
TARGETS += user
46
TARGETS += vm
47
TARGETS += x86
48
TARGETS += zram
49
#Please keep the TARGETS list alphabetically sorted
S
Shuah Khan 已提交
50
# Run "make quicktest=1 run_tests" or
51
# "make quicktest=1 kselftest" from top level Makefile
52

53 54 55
TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug

56 57 58 59
# 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))
60
override LDFLAGS =
61 62 63
override MAKEFLAGS =
endif

64 65 66 67
ifneq ($(KBUILD_SRC),)
override LDFLAGS =
endif

68 69 70 71 72 73 74 75
BUILD := $(O)
ifndef BUILD
  BUILD := $(KBUILD_OUTPUT)
endif
ifndef BUILD
  BUILD := $(shell pwd)
endif

76 77 78 79 80 81
# 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`

82
export BUILD
83
all:
84
	@for TARGET in $(TARGETS); do		\
85 86 87
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		mkdir $$BUILD_TARGET  -p;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
88 89
	done;

90
run_tests: all
91
	@for TARGET in $(TARGETS); do \
92 93
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
94 95
	done;

96
hotplug:
97
	@for TARGET in $(TARGETS_HOTPLUG); do \
98 99
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
100 101 102
	done;

run_hotplug: hotplug
103
	@for TARGET in $(TARGETS_HOTPLUG); do \
104 105
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
106 107 108
	done;

clean_hotplug:
109
	@for TARGET in $(TARGETS_HOTPLUG); do \
110 111
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
112 113
	done;

114 115 116
run_pstore_crash:
	make -C pstore run_crash

M
Michael Ellerman 已提交
117 118 119 120 121 122 123 124
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
	mkdir -p $(INSTALL_PATH)
125
	@for TARGET in $(TARGETS); do \
126 127
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
M
Michael Ellerman 已提交
128 129 130
	done;

	@# Ask all targets to emit their test scripts
131
	echo "#!/bin/sh" > $(ALL_SCRIPT)
132 133
	echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
	echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
M
Michael Ellerman 已提交
134
	echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
135 136 137 138 139 140
	echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
	echo "  OUTPUT=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
	echo "  cat /dev/null > \$$OUTPUT" >> $(ALL_SCRIPT)
	echo "else" >> $(ALL_SCRIPT)
	echo "  OUTPUT=/dev/stdout" >> $(ALL_SCRIPT)
	echo "fi" >> $(ALL_SCRIPT)
141 142
	echo "export KSFT_TAP_LEVEL=1" >> $(ALL_SCRIPT)
	echo "export skip=4" >> $(ALL_SCRIPT)
M
Michael Ellerman 已提交
143 144

	for TARGET in $(TARGETS); do \
145
		BUILD_TARGET=$$BUILD/$$TARGET;	\
146 147
		echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT);	\
		echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
M
Michael Ellerman 已提交
148
		echo "echo ========================================" >> $(ALL_SCRIPT); \
149
		echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
M
Michael Ellerman 已提交
150
		echo "cd $$TARGET" >> $(ALL_SCRIPT); \
151
		make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
M
Michael Ellerman 已提交
152 153 154 155 156 157 158 159
		echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
	done;

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

160
clean:
161
	@for TARGET in $(TARGETS); do \
162 163
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
164
	done;
M
Michael Ellerman 已提交
165

166
.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean