]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - tools/testing/selftests/lib.mk
Merge remote-tracking branch 'asoc/fix/pcm' into asoc-linus
[mirror_ubuntu-focal-kernel.git] / tools / testing / selftests / lib.mk
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.
3 CC := $(CROSS_COMPILE)gcc
4
5 ifeq (0,$(MAKELEVEL))
6 OUTPUT := $(shell pwd)
7 endif
8
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.
15 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
16 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
17 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
18
19 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
20
21 .ONESHELL:
22 define RUN_TESTS
23 @test_num=`echo 0`;
24 @echo "TAP version 13";
25 @for TEST in $(1); do \
26 BASENAME_TEST=`basename $$TEST`; \
27 test_num=`echo $$test_num+1 | bc`; \
28 echo "selftests: $$BASENAME_TEST"; \
29 echo "========================================"; \
30 if [ ! -x $$TEST ]; then \
31 echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\
32 echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \
33 else \
34 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;\
35 fi; \
36 done;
37 endef
38
39 run_tests: all
40 ifneq ($(KBUILD_SRC),)
41 @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
42 @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
43 fi
44 @if [ "X$(TEST_PROGS)" != "X" ]; then
45 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
46 else
47 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
48 fi
49 else
50 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
51 endif
52
53 define INSTALL_RULE
54 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
55 mkdir -p ${INSTALL_PATH}; \
56 echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
57 rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
58 fi
59 @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \
60 mkdir -p ${INSTALL_PATH}; \
61 echo "rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \
62 rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \
63 fi
64 endef
65
66 install: all
67 ifdef INSTALL_PATH
68 $(INSTALL_RULE)
69 else
70 $(error Error: set INSTALL_PATH to use install)
71 endif
72
73 define EMIT_TESTS
74 @for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
75 BASENAME_TEST=`basename $$TEST`; \
76 echo "(./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \
77 done;
78 endef
79
80 emit_tests:
81 $(EMIT_TESTS)
82
83 # define if isn't already. It is undefined in make O= case.
84 ifeq ($(RM),)
85 RM := rm -f
86 endif
87
88 define CLEAN
89 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
90 endef
91
92 clean:
93 $(CLEAN)
94
95 # When make O= with kselftest target from main level
96 # the following aren't defined.
97 #
98 ifneq ($(KBUILD_SRC),)
99 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
100 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
101 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
102 endif
103
104 $(OUTPUT)/%:%.c
105 $(LINK.c) $^ $(LDLIBS) -o $@
106
107 $(OUTPUT)/%.o:%.S
108 $(COMPILE.S) $^ -o $@
109
110 $(OUTPUT)/%:%.S
111 $(LINK.S) $^ $(LDLIBS) -o $@
112
113 .PHONY: run_tests all clean install emit_tests