]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/testing/selftests/lib.mk
selftests: add headers_install to lib.mk
[mirror_ubuntu-bionic-kernel.git] / tools / testing / selftests / lib.mk
CommitLineData
84f887bf
ME
1# This mimics the top-level Makefile. We do it explicitly here so that this
2# Makefile can operate with or without the kbuild infrastructure.
3CC := $(CROSS_COMPILE)gcc
4
e53aff45
SK
5ifeq (0,$(MAKELEVEL))
6OUTPUT := $(shell pwd)
7endif
8
be16a244
SK
9# The following are built by lib.mk common compile rules.
10# TEST_CUSTOM_PROGS should be used by tests that require
11# custom build rule and prevent common build rule use.
12# TEST_PROGS are for test shell scripts.
13# TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
14# and install targets. Common clean doesn't touch them.
d83c3ba0 15TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
8050ef2b 16TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
d83c3ba0
ME
17TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
18
01bbc2b2
AR
19top_srcdir ?= ../../../..
20include $(top_srcdir)/scripts/subarch.include
21ARCH ?= $(SUBARCH)
22
d83c3ba0
ME
23all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
24
01bbc2b2
AR
25.PHONY: khdr
26khdr:
27 make ARCH=$(ARCH) -C $(top_srcdir) headers_install
28
29ifdef KSFT_KHDR_INSTALL
30$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES):| khdr
31endif
32
1f87c7c1 33.ONESHELL:
5e29a910 34define RUN_TESTS
1f87c7c1
SK
35 @test_num=`echo 0`;
36 @echo "TAP version 13";
37 @for TEST in $(1); do \
a8ba798b 38 BASENAME_TEST=`basename $$TEST`; \
1f87c7c1
SK
39 test_num=`echo $$test_num+1 | bc`; \
40 echo "selftests: $$BASENAME_TEST"; \
41 echo "========================================"; \
e0a5696a 42 if [ ! -x $$TEST ]; then \
43c64374 43 echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\
1f87c7c1 44 echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \
43c64374 45 else \
a323335e
SK
46 if [ "X$(summary)" != "X" ]; then \
47 cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\
48 else \
49 cd `dirname $$TEST` > /dev/null; (./$$BASENAME_TEST && echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; cd - > /dev/null;\
50 fi; \
43c64374 51 fi; \
5e29a910
ME
52 done;
53endef
54
55run_tests: all
1a940687
SK
56ifneq ($(KBUILD_SRC),)
57 @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
58 @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
59 fi
60 @if [ "X$(TEST_PROGS)" != "X" ]; then
61 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
62 else
63 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
64 fi
65else
be16a244 66 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
1a940687 67endif
5e29a910 68
32dcfba6 69define INSTALL_RULE
900d65ee
BJZ
70 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
71 mkdir -p ${INSTALL_PATH}; \
5fe59799 72 echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
73 rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
88baa78d 74 fi
be16a244 75 @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \
88baa78d 76 mkdir -p ${INSTALL_PATH}; \
be16a244
SK
77 echo "rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \
78 rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \
a7d0f078 79 fi
32dcfba6
ME
80endef
81
82install: all
83ifdef INSTALL_PATH
84 $(INSTALL_RULE)
85else
86 $(error Error: set INSTALL_PATH to use install)
87endif
88
89define EMIT_TESTS
be16a244 90 @for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
a8ba798b 91 BASENAME_TEST=`basename $$TEST`; \
fbcab13d 92 echo "(./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \
32dcfba6
ME
93 done;
94endef
95
96emit_tests:
97 $(EMIT_TESTS)
98
8050ef2b
SK
99# define if isn't already. It is undefined in make O= case.
100ifeq ($(RM),)
101RM := rm -f
102endif
103
df6438f9 104define CLEAN
80d443e8 105 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
df6438f9
SK
106endef
107
108clean:
109 $(CLEAN)
88baa78d 110
8050ef2b
SK
111# When make O= with kselftest target from main level
112# the following aren't defined.
113#
114ifneq ($(KBUILD_SRC),)
115LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
116COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
117LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
118endif
119
a8ba798b 120$(OUTPUT)/%:%.c
2047f1d8 121 $(LINK.c) $^ $(LDLIBS) -o $@
a8ba798b 122
123$(OUTPUT)/%.o:%.S
634ce97c 124 $(COMPILE.S) $^ -o $@
a8ba798b 125
126$(OUTPUT)/%:%.S
634ce97c 127 $(LINK.S) $^ $(LDLIBS) -o $@
7d758af2 128
32dcfba6 129.PHONY: run_tests all clean install emit_tests