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