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