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