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