]>
Commit | Line | Data |
---|---|---|
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. | |
3 | CC := $(CROSS_COMPILE)gcc | |
4 | ||
e53aff45 SK |
5 | ifeq (0,$(MAKELEVEL)) |
6 | OUTPUT := $(shell pwd) | |
7 | endif | |
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 | 15 | TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) |
8050ef2b | 16 | TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) |
d83c3ba0 ME |
17 | TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) |
18 | ||
19 | all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) | |
20 | ||
1f87c7c1 | 21 | .ONESHELL: |
5e29a910 | 22 | define RUN_TESTS |
a3355440 MD |
23 | @export KSFT_TAP_LEVEL=`echo 1`; \ |
24 | test_num=`echo 0`; \ | |
25 | echo "TAP version 13"; \ | |
26 | for TEST in $(1); do \ | |
a8ba798b | 27 | BASENAME_TEST=`basename $$TEST`; \ |
1f87c7c1 SK |
28 | test_num=`echo $$test_num+1 | bc`; \ |
29 | echo "selftests: $$BASENAME_TEST"; \ | |
30 | echo "========================================"; \ | |
e0a5696a | 31 | if [ ! -x $$TEST ]; then \ |
43c64374 | 32 | echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\ |
1f87c7c1 | 33 | echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \ |
43c64374 | 34 | else \ |
a323335e SK |
35 | if [ "X$(summary)" != "X" ]; then \ |
36 | 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;\ | |
37 | else \ | |
38 | 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;\ | |
39 | fi; \ | |
43c64374 | 40 | fi; \ |
5e29a910 ME |
41 | done; |
42 | endef | |
43 | ||
44 | run_tests: all | |
1a940687 SK |
45 | ifneq ($(KBUILD_SRC),) |
46 | @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then | |
47 | @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT) | |
48 | fi | |
49 | @if [ "X$(TEST_PROGS)" != "X" ]; then | |
50 | $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS)) | |
51 | else | |
52 | $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)) | |
53 | fi | |
54 | else | |
be16a244 | 55 | $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) |
1a940687 | 56 | endif |
5e29a910 | 57 | |
32dcfba6 | 58 | define INSTALL_RULE |
900d65ee BJZ |
59 | @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ |
60 | mkdir -p ${INSTALL_PATH}; \ | |
5fe59799 | 61 | echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \ |
62 | rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \ | |
88baa78d | 63 | fi |
be16a244 | 64 | @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \ |
88baa78d | 65 | mkdir -p ${INSTALL_PATH}; \ |
be16a244 SK |
66 | echo "rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \ |
67 | rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \ | |
a7d0f078 | 68 | fi |
32dcfba6 ME |
69 | endef |
70 | ||
71 | install: all | |
72 | ifdef INSTALL_PATH | |
73 | $(INSTALL_RULE) | |
74 | else | |
75 | $(error Error: set INSTALL_PATH to use install) | |
76 | endif | |
77 | ||
78 | define EMIT_TESTS | |
be16a244 | 79 | @for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ |
a8ba798b | 80 | BASENAME_TEST=`basename $$TEST`; \ |
14f1889f | 81 | echo "(./$$BASENAME_TEST >> \$$OUTPUT 2>&1 && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo \"selftests: $$BASENAME_TEST [FAIL]\""; \ |
32dcfba6 ME |
82 | done; |
83 | endef | |
84 | ||
85 | emit_tests: | |
86 | $(EMIT_TESTS) | |
87 | ||
8050ef2b SK |
88 | # define if isn't already. It is undefined in make O= case. |
89 | ifeq ($(RM),) | |
90 | RM := rm -f | |
91 | endif | |
92 | ||
df6438f9 | 93 | define CLEAN |
80d443e8 | 94 | $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) |
df6438f9 SK |
95 | endef |
96 | ||
97 | clean: | |
98 | $(CLEAN) | |
88baa78d | 99 | |
8050ef2b SK |
100 | # When make O= with kselftest target from main level |
101 | # the following aren't defined. | |
102 | # | |
103 | ifneq ($(KBUILD_SRC),) | |
104 | LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) | |
105 | COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c | |
106 | LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) | |
107 | endif | |
108 | ||
4e49ed2f MD |
109 | # Selftest makefiles can override those targets by setting |
110 | # OVERRIDE_TARGETS = 1. | |
111 | ifeq ($(OVERRIDE_TARGETS),) | |
a8ba798b | 112 | $(OUTPUT)/%:%.c |
2047f1d8 | 113 | $(LINK.c) $^ $(LDLIBS) -o $@ |
a8ba798b | 114 | |
115 | $(OUTPUT)/%.o:%.S | |
634ce97c | 116 | $(COMPILE.S) $^ -o $@ |
a8ba798b | 117 | |
118 | $(OUTPUT)/%:%.S | |
634ce97c | 119 | $(LINK.S) $^ $(LDLIBS) -o $@ |
4e49ed2f | 120 | endif |
7d758af2 | 121 | |
32dcfba6 | 122 | .PHONY: run_tests all clean install emit_tests |