Merge branch 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[muen/linux.git] / tools / testing / selftests / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2 TARGETS = android
3 TARGETS += bpf
4 TARGETS += breakpoints
5 TARGETS += capabilities
6 TARGETS += cpufreq
7 TARGETS += cpu-hotplug
8 TARGETS += efivarfs
9 TARGETS += exec
10 TARGETS += filesystems
11 TARGETS += firmware
12 TARGETS += ftrace
13 TARGETS += futex
14 TARGETS += gpio
15 TARGETS += intel_pstate
16 TARGETS += ipc
17 TARGETS += kcmp
18 TARGETS += lib
19 TARGETS += membarrier
20 TARGETS += memfd
21 TARGETS += memory-hotplug
22 TARGETS += mount
23 TARGETS += mqueue
24 TARGETS += net
25 TARGETS += nsfs
26 TARGETS += powerpc
27 TARGETS += pstore
28 TARGETS += ptrace
29 TARGETS += seccomp
30 TARGETS += sigaltstack
31 TARGETS += size
32 TARGETS += splice
33 TARGETS += static_keys
34 TARGETS += sync
35 TARGETS += sysctl
36 ifneq (1, $(quicktest))
37 TARGETS += timers
38 endif
39 TARGETS += user
40 TARGETS += vm
41 TARGETS += x86
42 TARGETS += zram
43 #Please keep the TARGETS list alphabetically sorted
44 # Run "make quicktest=1 run_tests" or
45 # "make quicktest=1 kselftest" from top level Makefile
46
47 TARGETS_HOTPLUG = cpu-hotplug
48 TARGETS_HOTPLUG += memory-hotplug
49
50 # Clear LDFLAGS and MAKEFLAGS if called from main
51 # Makefile to avoid test build failures when test
52 # Makefile doesn't have explicit build rules.
53 ifeq (1,$(MAKELEVEL))
54 override LDFLAGS =
55 override MAKEFLAGS =
56 endif
57
58 ifneq ($(KBUILD_SRC),)
59 override LDFLAGS =
60 endif
61
62 BUILD := $(O)
63 ifndef BUILD
64   BUILD := $(KBUILD_OUTPUT)
65 endif
66 ifndef BUILD
67   BUILD := $(shell pwd)
68 endif
69
70 export BUILD
71 all:
72         @for TARGET in $(TARGETS); do           \
73                 BUILD_TARGET=$$BUILD/$$TARGET;  \
74                 mkdir $$BUILD_TARGET  -p;       \
75                 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
76         done;
77
78 run_tests: all
79         @for TARGET in $(TARGETS); do \
80                 BUILD_TARGET=$$BUILD/$$TARGET;  \
81                 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
82         done;
83
84 hotplug:
85         @for TARGET in $(TARGETS_HOTPLUG); do \
86                 BUILD_TARGET=$$BUILD/$$TARGET;  \
87                 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
88         done;
89
90 run_hotplug: hotplug
91         @for TARGET in $(TARGETS_HOTPLUG); do \
92                 BUILD_TARGET=$$BUILD/$$TARGET;  \
93                 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
94         done;
95
96 clean_hotplug:
97         @for TARGET in $(TARGETS_HOTPLUG); do \
98                 BUILD_TARGET=$$BUILD/$$TARGET;  \
99                 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
100         done;
101
102 run_pstore_crash:
103         make -C pstore run_crash
104
105 INSTALL_PATH ?= install
106 INSTALL_PATH := $(abspath $(INSTALL_PATH))
107 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
108
109 install:
110 ifdef INSTALL_PATH
111         @# Ask all targets to install their files
112         mkdir -p $(INSTALL_PATH)
113         @for TARGET in $(TARGETS); do \
114                 BUILD_TARGET=$$BUILD/$$TARGET;  \
115                 make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
116         done;
117
118         @# Ask all targets to emit their test scripts
119         echo "#!/bin/sh" > $(ALL_SCRIPT)
120         echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
121         echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
122         echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
123         echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
124         echo "  OUTPUT=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
125         echo "  cat /dev/null > \$$OUTPUT" >> $(ALL_SCRIPT)
126         echo "else" >> $(ALL_SCRIPT)
127         echo "  OUTPUT=/dev/stdout" >> $(ALL_SCRIPT)
128         echo "fi" >> $(ALL_SCRIPT)
129
130         for TARGET in $(TARGETS); do \
131                 BUILD_TARGET=$$BUILD/$$TARGET;  \
132                 echo "echo ; echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
133                 echo "echo ========================================" >> $(ALL_SCRIPT); \
134                 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
135                 make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
136                 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
137         done;
138
139         chmod u+x $(ALL_SCRIPT)
140 else
141         $(error Error: set INSTALL_PATH to use install)
142 endif
143
144 clean:
145         @for TARGET in $(TARGETS); do \
146                 BUILD_TARGET=$$BUILD/$$TARGET;  \
147                 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
148         done;
149
150 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean