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