Merge tag 'linux-kselftest-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel...
[sfrench/cifs-2.6.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 += cgroup
7 TARGETS += cpufreq
8 TARGETS += cpu-hotplug
9 TARGETS += drivers/dma-buf
10 TARGETS += efivarfs
11 TARGETS += exec
12 TARGETS += filesystems
13 TARGETS += firmware
14 TARGETS += ftrace
15 TARGETS += futex
16 TARGETS += gpio
17 TARGETS += intel_pstate
18 TARGETS += ipc
19 TARGETS += ir
20 TARGETS += kcmp
21 TARGETS += kvm
22 TARGETS += lib
23 TARGETS += membarrier
24 TARGETS += memfd
25 TARGETS += memory-hotplug
26 TARGETS += mount
27 TARGETS += mqueue
28 TARGETS += net
29 TARGETS += netfilter
30 TARGETS += networking/timestamping
31 TARGETS += nsfs
32 TARGETS += powerpc
33 TARGETS += proc
34 TARGETS += pstore
35 TARGETS += ptrace
36 TARGETS += rseq
37 TARGETS += rtc
38 TARGETS += seccomp
39 TARGETS += sigaltstack
40 TARGETS += size
41 TARGETS += sparc64
42 TARGETS += splice
43 TARGETS += static_keys
44 TARGETS += sync
45 TARGETS += sysctl
46 ifneq (1, $(quicktest))
47 TARGETS += timers
48 endif
49 TARGETS += user
50 TARGETS += vm
51 TARGETS += x86
52 TARGETS += zram
53 #Please keep the TARGETS list alphabetically sorted
54 # Run "make quicktest=1 run_tests" or
55 # "make quicktest=1 kselftest" from top level Makefile
56
57 TARGETS_HOTPLUG = cpu-hotplug
58 TARGETS_HOTPLUG += memory-hotplug
59
60 # Clear LDFLAGS and MAKEFLAGS if called from main
61 # Makefile to avoid test build failures when test
62 # Makefile doesn't have explicit build rules.
63 ifeq (1,$(MAKELEVEL))
64 override LDFLAGS =
65 override MAKEFLAGS =
66 endif
67
68 ifneq ($(KBUILD_SRC),)
69 override LDFLAGS =
70 endif
71
72 BUILD := $(O)
73 ifndef BUILD
74   BUILD := $(KBUILD_OUTPUT)
75 endif
76 ifndef BUILD
77   BUILD := $(shell pwd)
78 endif
79
80 # KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header
81 # printing from tests. Applicable to run_tests case where run_tests adds
82 # TAP header prior running tests and when a test program invokes another
83 # with system() call. Export it here to cover override RUN_TESTS defines.
84 export KSFT_TAP_LEVEL=`echo 1`
85
86 export BUILD
87 all:
88         @for TARGET in $(TARGETS); do           \
89                 BUILD_TARGET=$$BUILD/$$TARGET;  \
90                 mkdir $$BUILD_TARGET  -p;       \
91                 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
92         done;
93
94 run_tests: all
95         @for TARGET in $(TARGETS); do \
96                 BUILD_TARGET=$$BUILD/$$TARGET;  \
97                 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
98         done;
99
100 hotplug:
101         @for TARGET in $(TARGETS_HOTPLUG); do \
102                 BUILD_TARGET=$$BUILD/$$TARGET;  \
103                 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
104         done;
105
106 run_hotplug: hotplug
107         @for TARGET in $(TARGETS_HOTPLUG); do \
108                 BUILD_TARGET=$$BUILD/$$TARGET;  \
109                 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
110         done;
111
112 clean_hotplug:
113         @for TARGET in $(TARGETS_HOTPLUG); do \
114                 BUILD_TARGET=$$BUILD/$$TARGET;  \
115                 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
116         done;
117
118 run_pstore_crash:
119         make -C pstore run_crash
120
121 INSTALL_PATH ?= install
122 INSTALL_PATH := $(abspath $(INSTALL_PATH))
123 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
124
125 install:
126 ifdef INSTALL_PATH
127         @# Ask all targets to install their files
128         mkdir -p $(INSTALL_PATH)
129         @for TARGET in $(TARGETS); do \
130                 BUILD_TARGET=$$BUILD/$$TARGET;  \
131                 make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
132         done;
133
134         @# Ask all targets to emit their test scripts
135         echo "#!/bin/sh" > $(ALL_SCRIPT)
136         echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
137         echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
138         echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
139         echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
140         echo "  OUTPUT=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
141         echo "  cat /dev/null > \$$OUTPUT" >> $(ALL_SCRIPT)
142         echo "else" >> $(ALL_SCRIPT)
143         echo "  OUTPUT=/dev/stdout" >> $(ALL_SCRIPT)
144         echo "fi" >> $(ALL_SCRIPT)
145         echo "export KSFT_TAP_LEVEL=1" >> $(ALL_SCRIPT)
146         echo "export skip=4" >> $(ALL_SCRIPT)
147
148         for TARGET in $(TARGETS); do \
149                 BUILD_TARGET=$$BUILD/$$TARGET;  \
150                 echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT);     \
151                 echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
152                 echo "echo ========================================" >> $(ALL_SCRIPT); \
153                 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
154                 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
155                 make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
156                 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
157         done;
158
159         chmod u+x $(ALL_SCRIPT)
160 else
161         $(error Error: set INSTALL_PATH to use install)
162 endif
163
164 clean:
165         @for TARGET in $(TARGETS); do \
166                 BUILD_TARGET=$$BUILD/$$TARGET;  \
167                 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
168         done;
169
170 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean