xref: /openbmc/linux/tools/testing/selftests/Makefile (revision 023e4163)
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 += ima
19TARGETS += intel_pstate
20TARGETS += ipc
21TARGETS += ir
22TARGETS += kcmp
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
78BUILD := $(O)
79ifndef BUILD
80  BUILD := $(KBUILD_OUTPUT)
81endif
82ifndef BUILD
83  BUILD := $(shell pwd)
84endif
85
86# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header
87# printing from tests. Applicable to run_tests case where run_tests adds
88# TAP header prior running tests and when a test program invokes another
89# with system() call. Export it here to cover override RUN_TESTS defines.
90export KSFT_TAP_LEVEL=`echo 1`
91
92export BUILD
93all:
94	@for TARGET in $(TARGETS); do		\
95		BUILD_TARGET=$$BUILD/$$TARGET;	\
96		mkdir $$BUILD_TARGET  -p;	\
97		make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
98	done;
99
100run_tests: all
101	@for TARGET in $(TARGETS); do \
102		BUILD_TARGET=$$BUILD/$$TARGET;	\
103		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
104	done;
105
106hotplug:
107	@for TARGET in $(TARGETS_HOTPLUG); do \
108		BUILD_TARGET=$$BUILD/$$TARGET;	\
109		make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
110	done;
111
112run_hotplug: hotplug
113	@for TARGET in $(TARGETS_HOTPLUG); do \
114		BUILD_TARGET=$$BUILD/$$TARGET;	\
115		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
116	done;
117
118clean_hotplug:
119	@for TARGET in $(TARGETS_HOTPLUG); do \
120		BUILD_TARGET=$$BUILD/$$TARGET;	\
121		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
122	done;
123
124run_pstore_crash:
125	make -C pstore run_crash
126
127INSTALL_PATH ?= install
128INSTALL_PATH := $(abspath $(INSTALL_PATH))
129ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
130
131install:
132ifdef INSTALL_PATH
133	@# Ask all targets to install their files
134	mkdir -p $(INSTALL_PATH)
135	@for TARGET in $(TARGETS); do \
136		BUILD_TARGET=$$BUILD/$$TARGET;	\
137		make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
138	done;
139
140	@# Ask all targets to emit their test scripts
141	echo "#!/bin/sh" > $(ALL_SCRIPT)
142	echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT)
143	echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT)
144	echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)
145	echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT)
146	echo "  OUTPUT=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT)
147	echo "  cat /dev/null > \$$OUTPUT" >> $(ALL_SCRIPT)
148	echo "else" >> $(ALL_SCRIPT)
149	echo "  OUTPUT=/dev/stdout" >> $(ALL_SCRIPT)
150	echo "fi" >> $(ALL_SCRIPT)
151	echo "export KSFT_TAP_LEVEL=1" >> $(ALL_SCRIPT)
152	echo "export skip=4" >> $(ALL_SCRIPT)
153
154	for TARGET in $(TARGETS); do \
155		BUILD_TARGET=$$BUILD/$$TARGET;	\
156		echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT);	\
157		echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
158		echo "echo ========================================" >> $(ALL_SCRIPT); \
159		echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
160		echo "cd $$TARGET" >> $(ALL_SCRIPT); \
161		make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
162		echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
163	done;
164
165	chmod u+x $(ALL_SCRIPT)
166else
167	$(error Error: set INSTALL_PATH to use install)
168endif
169
170clean:
171	@for TARGET in $(TARGETS); do \
172		BUILD_TARGET=$$BUILD/$$TARGET;	\
173		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
174	done;
175
176.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean
177