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