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