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