blob: 0a8e75886224b371f6da30f7a01d10f652313b66 [file] [log] [blame]
Michael Ellerman84f887b2015-03-04 21:41:31 +11001# 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
Shuah Khane53aff42017-03-01 15:15:07 -07005ifeq (0,$(MAKELEVEL))
6OUTPUT := $(shell pwd)
7endif
8
Shuah Khanbe16a242017-09-11 13:06:33 -06009# 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.
Michael Ellermand83c3ba2017-02-09 19:56:26 +110015TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
Shuah Khan8050ef22017-09-06 18:36:22 -060016TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
Michael Ellermand83c3ba2017-02-09 19:56:26 +110017TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
18
Anders Roxellb2d35fa2018-09-04 12:47:21 +020019top_srcdir ?= ../../../..
20include $(top_srcdir)/scripts/subarch.include
21ARCH ?= $(SUBARCH)
22
Michael Ellermand83c3ba2017-02-09 19:56:26 +110023all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
24
Anders Roxellb2d35fa2018-09-04 12:47:21 +020025.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
Shuah Khan1f87c7c2017-08-23 18:46:00 -060033.ONESHELL:
Shuah Khan (Samsung OSG)7afed3d2018-04-25 09:32:20 -060034define RUN_TEST_PRINT_RESULT
Shuah Khan (Samsung OSG)cfe84602018-04-25 17:45:48 -060035 TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST"; \
36 echo $$TEST_HDR_MSG; \
Shuah Khan (Samsung OSG)7afed3d2018-04-25 09:32:20 -060037 echo "========================================"; \
38 if [ ! -x $$TEST ]; then \
Shuah Khan (Samsung OSG)cfe84602018-04-25 17:45:48 -060039 echo "$$TEST_HDR_MSG: Warning: file $$BASENAME_TEST is not executable, correct this.";\
40 echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]"; \
Shuah Khan (Samsung OSG)7afed3d2018-04-25 09:32:20 -060041 else \
42 cd `dirname $$TEST` > /dev/null; \
43 if [ "X$(summary)" != "X" ]; then \
44 (./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && \
Shuah Khan (Samsung OSG)cfe84602018-04-25 17:45:48 -060045 echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") || \
Shuah Khan (Samsung OSG)7afed3d2018-04-25 09:32:20 -060046 (if [ $$? -eq $$skip ]; then \
Shuah Khan (Samsung OSG)cfe84602018-04-25 17:45:48 -060047 echo "not ok 1..$$test_num $$TEST_HDR_MSG [SKIP]"; \
48 else echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]"; \
Shuah Khan (Samsung OSG)7afed3d2018-04-25 09:32:20 -060049 fi;) \
50 else \
51 (./$$BASENAME_TEST && \
Shuah Khan (Samsung OSG)cfe84602018-04-25 17:45:48 -060052 echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") || \
Shuah Khan (Samsung OSG)7afed3d2018-04-25 09:32:20 -060053 (if [ $$? -eq $$skip ]; then \
Shuah Khan (Samsung OSG)cfe84602018-04-25 17:45:48 -060054 echo "not ok 1..$$test_num $$TEST_HDR_MSG [SKIP]"; \
55 else echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]"; \
Shuah Khan (Samsung OSG)7afed3d2018-04-25 09:32:20 -060056 fi;) \
57 fi; \
58 cd - > /dev/null; \
59 fi;
60endef
61
Michael Ellerman5e29a912015-03-11 15:05:59 +110062define RUN_TESTS
Mathieu Desnoyersa3355442018-04-27 17:55:41 -040063 @export KSFT_TAP_LEVEL=`echo 1`; \
64 test_num=`echo 0`; \
Shuah Khan (Samsung OSG)3f4435b2018-04-24 14:57:36 -060065 skip=`echo 4`; \
Mathieu Desnoyersa3355442018-04-27 17:55:41 -040066 echo "TAP version 13"; \
67 for TEST in $(1); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +080068 BASENAME_TEST=`basename $$TEST`; \
Shuah Khan1f87c7c2017-08-23 18:46:00 -060069 test_num=`echo $$test_num+1 | bc`; \
Shuah Khan (Samsung OSG)7afed3d2018-04-25 09:32:20 -060070 $(call RUN_TEST_PRINT_RESULT,$(TEST),$(BASENAME_TEST),$(test_num),$(skip)) \
Michael Ellerman5e29a912015-03-11 15:05:59 +110071 done;
72endef
73
74run_tests: all
Shuah Khan1a940682017-09-11 19:03:11 -060075ifneq ($(KBUILD_SRC),)
76 @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
77 @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
78 fi
79 @if [ "X$(TEST_PROGS)" != "X" ]; then
80 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
81 else
82 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
83 fi
84else
Shuah Khanbe16a242017-09-11 13:06:33 -060085 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
Shuah Khan1a940682017-09-11 19:03:11 -060086endif
Michael Ellerman5e29a912015-03-11 15:05:59 +110087
Michael Ellerman32dcfba2015-03-11 15:06:00 +110088define INSTALL_RULE
Bamvor Jian Zhang900d65e2015-09-09 21:06:28 +080089 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
90 mkdir -p ${INSTALL_PATH}; \
bamvor.zhangjian@huawei.com5fe59792016-11-29 19:55:48 +080091 echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
92 rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +080093 fi
Shuah Khanbe16a242017-09-11 13:06:33 -060094 @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +080095 mkdir -p ${INSTALL_PATH}; \
Shuah Khanbe16a242017-09-11 13:06:33 -060096 echo "rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \
97 rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \
Bamvor Jian Zhanga7d0f072015-08-14 21:43:35 +080098 fi
Michael Ellerman32dcfba2015-03-11 15:06:00 +110099endef
100
101install: all
102ifdef INSTALL_PATH
103 $(INSTALL_RULE)
104else
105 $(error Error: set INSTALL_PATH to use install)
106endif
107
108define EMIT_TESTS
Shuah Khan (Samsung OSG)3df61312018-05-01 12:15:34 -0600109 @test_num=`echo 0`; \
110 for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800111 BASENAME_TEST=`basename $$TEST`; \
Shuah Khan (Samsung OSG)3df61312018-05-01 12:15:34 -0600112 test_num=`echo $$test_num+1 | bc`; \
113 TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST"; \
114 echo "echo $$TEST_HDR_MSG"; \
Shuah Khan (Samsung OSG)a548de02018-05-01 14:38:47 -0600115 if [ ! -x $$TEST ]; then \
116 echo "echo \"$$TEST_HDR_MSG: Warning: file $$BASENAME_TEST is not executable, correct this.\""; \
117 echo "echo \"not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]\""; \
118 else
119 echo "(./$$BASENAME_TEST >> \$$OUTPUT 2>&1 && echo \"ok 1..$$test_num $$TEST_HDR_MSG [PASS]\") || (if [ \$$? -eq \$$skip ]; then echo \"not ok 1..$$test_num $$TEST_HDR_MSG [SKIP]\"; else echo \"not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]\"; fi;)"; \
120 fi; \
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100121 done;
122endef
123
124emit_tests:
125 $(EMIT_TESTS)
126
Shuah Khan8050ef22017-09-06 18:36:22 -0600127# define if isn't already. It is undefined in make O= case.
128ifeq ($(RM),)
129RM := rm -f
130endif
131
Shuah Khandf6438f2017-04-21 16:07:51 -0600132define CLEAN
bamvor.zhangjian@huawei.com80d443e82016-11-29 19:55:51 +0800133 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
Shuah Khandf6438f2017-04-21 16:07:51 -0600134endef
135
136clean:
137 $(CLEAN)
bamvor.zhangjian@huawei.com88baa782016-11-29 19:55:47 +0800138
Shuah Khan8050ef22017-09-06 18:36:22 -0600139# When make O= with kselftest target from main level
140# the following aren't defined.
141#
142ifneq ($(KBUILD_SRC),)
143LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
144COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
145LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
146endif
147
Mathieu Desnoyers4e49ed22018-06-02 08:44:03 -0400148# Selftest makefiles can override those targets by setting
149# OVERRIDE_TARGETS = 1.
150ifeq ($(OVERRIDE_TARGETS),)
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800151$(OUTPUT)/%:%.c
Michael Ellerman2047f1d2017-02-09 19:56:27 +1100152 $(LINK.c) $^ $(LDLIBS) -o $@
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800153
154$(OUTPUT)/%.o:%.S
Michael Ellerman634ce972017-02-09 19:56:28 +1100155 $(COMPILE.S) $^ -o $@
bamvor.zhangjian@huawei.coma8ba7982016-11-29 19:55:52 +0800156
157$(OUTPUT)/%:%.S
Michael Ellerman634ce972017-02-09 19:56:28 +1100158 $(LINK.S) $^ $(LDLIBS) -o $@
Mathieu Desnoyers4e49ed22018-06-02 08:44:03 -0400159endif
bamvor.zhangjian@huawei.com7d758af2016-11-29 19:55:49 +0800160
Michael Ellerman32dcfba2015-03-11 15:06:00 +1100161.PHONY: run_tests all clean install emit_tests