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 += rtc
K
Kees Cook 已提交
33
TARGETS += seccomp
34
TARGETS += sigaltstack
35
TARGETS += size
36
TARGETS += splice
37
TARGETS += static_keys
38
TARGETS += sync
39
TARGETS += sysctl
S
Shuah Khan 已提交
40
ifneq (1, $(quicktest))
41
TARGETS += timers
S
Shuah Khan 已提交
42
endif
43
TARGETS += user
44
TARGETS += vm
45
TARGETS += x86
46
TARGETS += zram
47
#Please keep the TARGETS list alphabetically sorted
S
Shuah Khan 已提交
48
# Run "make quicktest=1 run_tests" or
49
# "make quicktest=1 kselftest" from top level Makefile
50

51 52 53
TARGETS_HOTPLUG = cpu-hotplug
TARGETS_HOTPLUG += memory-hotplug

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

62 63 64 65
ifneq ($(KBUILD_SRC),)
override LDFLAGS =
endif

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

74 75 76 77 78 79
# 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`

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

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

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

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

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

112 113 114
run_pstore_crash:
	make -C pstore run_crash

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

	@# Ask all targets to emit their test scripts
129
	echo "#!/bin/sh" > $(ALL_SCRIPT)
130 131
	echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
	echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
M
Michael Ellerman 已提交
132
	echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
133 134 135 136 137 138
	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)
139 140
	echo "export KSFT_TAP_LEVEL=1" >> $(ALL_SCRIPT)
	echo "export skip=4" >> $(ALL_SCRIPT)
M
Michael Ellerman 已提交
141 142

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

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

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

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