kdbus: test suite changed to common format
[platform/kernel/linux-rpi.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 += intel_pstate
19 TARGETS += ipc
20 TARGETS += ir
21 TARGETS += kcmp
22 TARGETS += kdbus
23 TARGETS += kexec
24 TARGETS += kvm
25 TARGETS += lib
26 TARGETS += livepatch
27 TARGETS += membarrier
28 TARGETS += memfd
29 TARGETS += memory-hotplug
30 TARGETS += mount
31 TARGETS += mqueue
32 TARGETS += net
33 TARGETS += netfilter
34 TARGETS += networking/timestamping
35 TARGETS += nsfs
36 TARGETS += pidfd
37 TARGETS += powerpc
38 TARGETS += proc
39 TARGETS += pstore
40 TARGETS += ptrace
41 TARGETS += rseq
42 TARGETS += rtc
43 TARGETS += seccomp
44 TARGETS += sigaltstack
45 TARGETS += size
46 TARGETS += sparc64
47 TARGETS += splice
48 TARGETS += static_keys
49 TARGETS += sync
50 TARGETS += sysctl
51 ifneq (1, $(quicktest))
52 TARGETS += timers
53 endif
54 TARGETS += tmpfs
55 TARGETS += tpm2
56 TARGETS += user
57 TARGETS += vm
58 TARGETS += x86
59 TARGETS += zram
60 #Please keep the TARGETS list alphabetically sorted
61 # Run "make quicktest=1 run_tests" or
62 # "make quicktest=1 kselftest" from top level Makefile
63
64 TARGETS_HOTPLUG = cpu-hotplug
65 TARGETS_HOTPLUG += memory-hotplug
66
67 # User can optionally provide a TARGETS skiplist.
68 SKIP_TARGETS ?=
69 ifneq ($(SKIP_TARGETS),)
70         TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS))
71         override TARGETS := $(TMP)
72 endif
73
74 # Clear LDFLAGS and MAKEFLAGS if called from main
75 # Makefile to avoid test build failures when test
76 # Makefile doesn't have explicit build rules.
77 ifeq (1,$(MAKELEVEL))
78 override LDFLAGS =
79 override MAKEFLAGS =
80 endif
81
82 # Append kselftest to KBUILD_OUTPUT to avoid cluttering
83 # KBUILD_OUTPUT with selftest objects and headers installed
84 # by selftests Makefile or lib.mk.
85 ifdef building_out_of_srctree
86 override LDFLAGS =
87 endif
88
89 ifneq ($(O),)
90         BUILD := $(O)
91 else
92         ifneq ($(KBUILD_OUTPUT),)
93                 BUILD := $(KBUILD_OUTPUT)/kselftest
94         else
95                 BUILD := $(shell pwd)
96                 DEFAULT_INSTALL_HDR_PATH := 1
97         endif
98 endif
99
100 # Prepare for headers install
101 top_srcdir ?= ../../..
102 include $(top_srcdir)/scripts/subarch.include
103 ARCH           ?= $(SUBARCH)
104 export KSFT_KHDR_INSTALL_DONE := 1
105 export BUILD
106
107 # build and run gpio when output directory is the src dir.
108 # gpio has dependency on tools/gpio and builds tools/gpio
109 # objects in the src directory in all cases making the src
110 # repo dirty even when objects are relocated.
111 ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
112         TMP := $(filter-out gpio, $(TARGETS))
113         TARGETS := $(TMP)
114 endif
115
116 # set default goal to all, so make without a target runs all, even when
117 # all isn't the first target in the file.
118 .DEFAULT_GOAL := all
119
120 # Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
121 # is used to avoid running headers_install from lib.mk.
122 # Invoke headers install with --no-builtin-rules to avoid circular
123 # dependency in "make kselftest" case. In this case, second level
124 # make inherits builtin-rules which will use the rule generate
125 # Makefile.o and runs into
126 # "Circular Makefile.o <- prepare dependency dropped."
127 # and headers_install fails and test compile fails.
128 #
129 # O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
130 # invokes them as sub-makes and --no-builtin-rules is not necessary,
131 # but doesn't cause any failures. Keep it simple and use the same
132 # flags in both cases.
133 # Local build cases: "make kselftest", "make -C" - headers are installed
134 # in the default INSTALL_HDR_PATH usr/include.
135 khdr:
136 ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
137         $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
138 else
139         $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
140                 ARCH=$(ARCH) -C $(top_srcdir) headers_install
141 endif
142
143 all: khdr
144         @for TARGET in $(TARGETS); do           \
145                 BUILD_TARGET=$$BUILD/$$TARGET;  \
146                 mkdir $$BUILD_TARGET  -p;       \
147                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
148         done;
149
150 run_tests: all
151         @for TARGET in $(TARGETS); do \
152                 BUILD_TARGET=$$BUILD/$$TARGET;  \
153                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
154         done;
155
156 hotplug:
157         @for TARGET in $(TARGETS_HOTPLUG); do \
158                 BUILD_TARGET=$$BUILD/$$TARGET;  \
159                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\
160         done;
161
162 run_hotplug: hotplug
163         @for TARGET in $(TARGETS_HOTPLUG); do \
164                 BUILD_TARGET=$$BUILD/$$TARGET;  \
165                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
166         done;
167
168 clean_hotplug:
169         @for TARGET in $(TARGETS_HOTPLUG); do \
170                 BUILD_TARGET=$$BUILD/$$TARGET;  \
171                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
172         done;
173
174 run_pstore_crash:
175         $(MAKE) -C pstore run_crash
176
177 # Use $BUILD as the default install root. $BUILD points to the
178 # right output location for the following cases:
179 # 1. output_dir=kernel_src
180 # 2. a separate output directory is specified using O= KBUILD_OUTPUT
181 # 3. a separate output directory is specified using KBUILD_OUTPUT
182 # Avoid conflict with INSTALL_PATH set by the main Makefile
183 #
184 KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install
185 KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH))
186 # Avoid changing the rest of the logic here and lib.mk.
187 INSTALL_PATH := $(KSFT_INSTALL_PATH)
188 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
189
190 install: all
191 ifdef INSTALL_PATH
192         @# Ask all targets to install their files
193         mkdir -p $(INSTALL_PATH)/kselftest
194         install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
195         install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
196         @for TARGET in $(TARGETS); do \
197                 BUILD_TARGET=$$BUILD/$$TARGET;  \
198                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
199         done;
200
201         @# Ask all targets to emit their test scripts
202         echo "#!/bin/sh" > $(ALL_SCRIPT)
203         echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
204         echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
205         echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT)
206         echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
207         echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
208         echo "  logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
209         echo "  cat /dev/null > \$$logfile" >> $(ALL_SCRIPT)
210         echo "fi" >> $(ALL_SCRIPT)
211
212         @# While building run_kselftest.sh skip also non-existent TARGET dirs:
213         @# they could be the result of a build failure and should NOT be
214         @# included in the generated runlist.
215         for TARGET in $(TARGETS); do \
216                 BUILD_TARGET=$$BUILD/$$TARGET;  \
217                 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \
218                 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
219                 echo "cd $$TARGET" >> $(ALL_SCRIPT); \
220                 echo -n "run_many" >> $(ALL_SCRIPT); \
221                 echo -n "Emit Tests for $$TARGET\n"; \
222                 $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
223                 echo "" >> $(ALL_SCRIPT);           \
224                 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
225         done;
226
227         chmod u+x $(ALL_SCRIPT)
228 else
229         $(error Error: set INSTALL_PATH to use install)
230 endif
231
232 clean:
233         @for TARGET in $(TARGETS); do \
234                 BUILD_TARGET=$$BUILD/$$TARGET;  \
235                 $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
236         done;
237
238 .PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean