xref: /openbmc/linux/tools/testing/selftests/Makefile (revision 752beb5e)
1# SPDX-License-Identifier: GPL-2.0
2TARGETS = android
3TARGETS += bpf
4TARGETS += breakpoints
5TARGETS += capabilities
6TARGETS += cgroup
7TARGETS += cpufreq
8TARGETS += cpu-hotplug
9TARGETS += drivers/dma-buf
10TARGETS += efivarfs
11TARGETS += exec
12TARGETS += filesystems
13TARGETS += filesystems/binderfs
14TARGETS += firmware
15TARGETS += ftrace
16TARGETS += futex
17TARGETS += gpio
18TARGETS += intel_pstate
19TARGETS += ipc
20TARGETS += ir
21TARGETS += kcmp
22TARGETS += kexec
23TARGETS += kvm
24TARGETS += lib
25TARGETS += livepatch
26TARGETS += membarrier
27TARGETS += memfd
28TARGETS += memory-hotplug
29TARGETS += mount
30TARGETS += mqueue
31TARGETS += net
32TARGETS += netfilter
33TARGETS += networking/timestamping
34TARGETS += nsfs
35TARGETS += pidfd
36TARGETS += powerpc
37TARGETS += proc
38TARGETS += pstore
39TARGETS += ptrace
40TARGETS += rseq
41TARGETS += rtc
42TARGETS += seccomp
43TARGETS += sigaltstack
44TARGETS += size
45TARGETS += sparc64
46TARGETS += splice
47TARGETS += static_keys
48TARGETS += sync
49TARGETS += sysctl
50ifneq (1, $(quicktest))
51TARGETS += timers
52endif
53TARGETS += tmpfs
54TARGETS += tpm2
55TARGETS += user
56TARGETS += vm
57TARGETS += x86
58TARGETS += zram
59#Please keep the TARGETS list alphabetically sorted
60# Run "make quicktest=1 run_tests" or
61# "make quicktest=1 kselftest" from top level Makefile
62
63TARGETS_HOTPLUG = cpu-hotplug
64TARGETS_HOTPLUG += memory-hotplug
65
66# Clear LDFLAGS and MAKEFLAGS if called from main
67# Makefile to avoid test build failures when test
68# Makefile doesn't have explicit build rules.
69ifeq (1,$(MAKELEVEL))
70override LDFLAGS =
71override MAKEFLAGS =
72endif
73
74ifneq ($(KBUILD_SRC),)
75override LDFLAGS =
76endif
77
78ifneq ($(O),)
79	BUILD := $(O)
80else
81	ifneq ($(KBUILD_OUTPUT),)
82		BUILD := $(KBUILD_OUTPUT)
83	else
84		BUILD := $(shell pwd)
85		DEFAULT_INSTALL_HDR_PATH := 1
86	endif
87endif
88
89# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header
90# printing from tests. Applicable to run_tests case where run_tests adds
91# TAP header prior running tests and when a test program invokes another
92# with system() call. Export it here to cover override RUN_TESTS defines.
93export KSFT_TAP_LEVEL=`echo 1`
94
95# Prepare for headers install
96top_srcdir ?= ../../..
97include $(top_srcdir)/scripts/subarch.include
98ARCH           ?= $(SUBARCH)
99export KSFT_KHDR_INSTALL_DONE := 1
100export BUILD
101
102# build and run gpio when output directory is the src dir.
103# gpio has dependency on tools/gpio and builds tools/gpio
104# objects in the src directory in all cases making the src
105# repo dirty even when objects are relocated.
106ifneq (1,$(DEFAULT_INSTALL_HDR_PATH))
107	TMP := $(filter-out gpio, $(TARGETS))
108	TARGETS := $(TMP)
109endif
110
111# set default goal to all, so make without a target runs all, even when
112# all isn't the first target in the file.
113.DEFAULT_GOAL := all
114
115# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE
116# is used to avoid running headers_install from lib.mk.
117# Invoke headers install with --no-builtin-rules to avoid circular
118# dependency in "make kselftest" case. In this case, second level
119# make inherits builtin-rules which will use the rule generate
120# Makefile.o and runs into
121# "Circular Makefile.o <- prepare dependency dropped."
122# and headers_install fails and test compile fails.
123#
124# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
125# invokes them as sub-makes and --no-builtin-rules is not necessary,
126# but doesn't cause any failures. Keep it simple and use the same
127# flags in both cases.
128# Local build cases: "make kselftest", "make -C" - headers are installed
129# in the default INSTALL_HDR_PATH usr/include.
130khdr:
131ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
132	make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
133else
134	make --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \
135		ARCH=$(ARCH) -C $(top_srcdir) headers_install
136endif
137
138all: khdr
139	@for TARGET in $(TARGETS); do		\
140		BUILD_TARGET=$$BUILD/$$TARGET;	\
141		mkdir $$BUILD_TARGET  -p;	\
142		make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
143	done;
144
145run_tests: all
146	@for TARGET in $(TARGETS); do \
147		BUILD_TARGET=$$BUILD/$$TARGET;	\
148		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
149	done;
150
151hotplug:
152	@for TARGET in $(TARGETS_HOTPLUG); do \
153		BUILD_TARGET=$$BUILD/$$TARGET;	\
154		make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
155	done;
156
157run_hotplug: hotplug
158	@for TARGET in $(TARGETS_HOTPLUG); do \
159		BUILD_TARGET=$$BUILD/$$TARGET;	\
160		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
161	done;
162
163clean_hotplug:
164	@for TARGET in $(TARGETS_HOTPLUG); do \
165		BUILD_TARGET=$$BUILD/$$TARGET;	\
166		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
167	done;
168
169run_pstore_crash:
170	make -C pstore run_crash
171
172INSTALL_PATH ?= install
173INSTALL_PATH := $(abspath $(INSTALL_PATH))
174ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
175
176install:
177ifdef INSTALL_PATH
178	@# Ask all targets to install their files
179	mkdir -p $(INSTALL_PATH)
180	@for TARGET in $(TARGETS); do \
181		BUILD_TARGET=$$BUILD/$$TARGET;	\
182		make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
183	done;
184
185	@# Ask all targets to emit their test scripts
186	echo "#!/bin/sh" > $(ALL_SCRIPT)
187	echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
188	echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
189	echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
190	echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
191	echo "  OUTPUT=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
192	echo "  cat /dev/null > \$$OUTPUT" >> $(ALL_SCRIPT)
193	echo "else" >> $(ALL_SCRIPT)
194	echo "  OUTPUT=/dev/stdout" >> $(ALL_SCRIPT)
195	echo "fi" >> $(ALL_SCRIPT)
196	echo "export KSFT_TAP_LEVEL=1" >> $(ALL_SCRIPT)
197	echo "export skip=4" >> $(ALL_SCRIPT)
198
199	for TARGET in $(TARGETS); do \
200		BUILD_TARGET=$$BUILD/$$TARGET;	\
201		echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT);	\
202		echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
203		echo "echo ========================================" >> $(ALL_SCRIPT); \
204		echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
205		echo "cd $$TARGET" >> $(ALL_SCRIPT); \
206		make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
207		echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
208	done;
209
210	chmod u+x $(ALL_SCRIPT)
211else
212	$(error Error: set INSTALL_PATH to use install)
213endif
214
215clean:
216	@for TARGET in $(TARGETS); do \
217		BUILD_TARGET=$$BUILD/$$TARGET;	\
218		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
219	done;
220
221.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean
222