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