Michael Ellerman | 84f887b | 2015-03-04 21:41:31 +1100 | [diff] [blame] | 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 | |
Shuah Khan | e53aff4 | 2017-03-01 15:15:07 -0700 | [diff] [blame] | 5 | ifeq (0,$(MAKELEVEL)) |
| 6 | OUTPUT := $(shell pwd) |
| 7 | endif |
| 8 | |
Shuah Khan | be16a24 | 2017-09-11 13:06:33 -0600 | [diff] [blame] | 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. |
Michael Ellerman | d83c3ba | 2017-02-09 19:56:26 +1100 | [diff] [blame] | 15 | TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) |
Shuah Khan | 8050ef2 | 2017-09-06 18:36:22 -0600 | [diff] [blame] | 16 | TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) |
Michael Ellerman | d83c3ba | 2017-02-09 19:56:26 +1100 | [diff] [blame] | 17 | TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) |
| 18 | |
Anders Roxell | b2d35fa | 2018-09-04 12:47:21 +0200 | [diff] [blame^] | 19 | top_srcdir ?= ../../../.. |
| 20 | include $(top_srcdir)/scripts/subarch.include |
| 21 | ARCH ?= $(SUBARCH) |
| 22 | |
Michael Ellerman | d83c3ba | 2017-02-09 19:56:26 +1100 | [diff] [blame] | 23 | all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) |
| 24 | |
Anders Roxell | b2d35fa | 2018-09-04 12:47:21 +0200 | [diff] [blame^] | 25 | .PHONY: khdr |
| 26 | khdr: |
| 27 | make ARCH=$(ARCH) -C $(top_srcdir) headers_install |
| 28 | |
| 29 | ifdef KSFT_KHDR_INSTALL |
| 30 | $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES):| khdr |
| 31 | endif |
| 32 | |
Shuah Khan | 1f87c7c | 2017-08-23 18:46:00 -0600 | [diff] [blame] | 33 | .ONESHELL: |
Shuah Khan (Samsung OSG) | 7afed3d | 2018-04-25 09:32:20 -0600 | [diff] [blame] | 34 | define RUN_TEST_PRINT_RESULT |
Shuah Khan (Samsung OSG) | cfe8460 | 2018-04-25 17:45:48 -0600 | [diff] [blame] | 35 | TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST"; \ |
| 36 | echo $$TEST_HDR_MSG; \ |
Shuah Khan (Samsung OSG) | 7afed3d | 2018-04-25 09:32:20 -0600 | [diff] [blame] | 37 | echo "========================================"; \ |
| 38 | if [ ! -x $$TEST ]; then \ |
Shuah Khan (Samsung OSG) | cfe8460 | 2018-04-25 17:45:48 -0600 | [diff] [blame] | 39 | 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) | 7afed3d | 2018-04-25 09:32:20 -0600 | [diff] [blame] | 41 | 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) | cfe8460 | 2018-04-25 17:45:48 -0600 | [diff] [blame] | 45 | echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") || \ |
Shuah Khan (Samsung OSG) | 7afed3d | 2018-04-25 09:32:20 -0600 | [diff] [blame] | 46 | (if [ $$? -eq $$skip ]; then \ |
Shuah Khan (Samsung OSG) | cfe8460 | 2018-04-25 17:45:48 -0600 | [diff] [blame] | 47 | 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) | 7afed3d | 2018-04-25 09:32:20 -0600 | [diff] [blame] | 49 | fi;) \ |
| 50 | else \ |
| 51 | (./$$BASENAME_TEST && \ |
Shuah Khan (Samsung OSG) | cfe8460 | 2018-04-25 17:45:48 -0600 | [diff] [blame] | 52 | echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") || \ |
Shuah Khan (Samsung OSG) | 7afed3d | 2018-04-25 09:32:20 -0600 | [diff] [blame] | 53 | (if [ $$? -eq $$skip ]; then \ |
Shuah Khan (Samsung OSG) | cfe8460 | 2018-04-25 17:45:48 -0600 | [diff] [blame] | 54 | 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) | 7afed3d | 2018-04-25 09:32:20 -0600 | [diff] [blame] | 56 | fi;) \ |
| 57 | fi; \ |
| 58 | cd - > /dev/null; \ |
| 59 | fi; |
| 60 | endef |
| 61 | |
Michael Ellerman | 5e29a91 | 2015-03-11 15:05:59 +1100 | [diff] [blame] | 62 | define RUN_TESTS |
Mathieu Desnoyers | a335544 | 2018-04-27 17:55:41 -0400 | [diff] [blame] | 63 | @export KSFT_TAP_LEVEL=`echo 1`; \ |
| 64 | test_num=`echo 0`; \ |
Shuah Khan (Samsung OSG) | 3f4435b | 2018-04-24 14:57:36 -0600 | [diff] [blame] | 65 | skip=`echo 4`; \ |
Mathieu Desnoyers | a335544 | 2018-04-27 17:55:41 -0400 | [diff] [blame] | 66 | echo "TAP version 13"; \ |
| 67 | for TEST in $(1); do \ |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 68 | BASENAME_TEST=`basename $$TEST`; \ |
Shuah Khan | 1f87c7c | 2017-08-23 18:46:00 -0600 | [diff] [blame] | 69 | test_num=`echo $$test_num+1 | bc`; \ |
Shuah Khan (Samsung OSG) | 7afed3d | 2018-04-25 09:32:20 -0600 | [diff] [blame] | 70 | $(call RUN_TEST_PRINT_RESULT,$(TEST),$(BASENAME_TEST),$(test_num),$(skip)) \ |
Michael Ellerman | 5e29a91 | 2015-03-11 15:05:59 +1100 | [diff] [blame] | 71 | done; |
| 72 | endef |
| 73 | |
| 74 | run_tests: all |
Shuah Khan | 1a94068 | 2017-09-11 19:03:11 -0600 | [diff] [blame] | 75 | ifneq ($(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 |
| 84 | else |
Shuah Khan | be16a24 | 2017-09-11 13:06:33 -0600 | [diff] [blame] | 85 | $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) |
Shuah Khan | 1a94068 | 2017-09-11 19:03:11 -0600 | [diff] [blame] | 86 | endif |
Michael Ellerman | 5e29a91 | 2015-03-11 15:05:59 +1100 | [diff] [blame] | 87 | |
Michael Ellerman | 32dcfba | 2015-03-11 15:06:00 +1100 | [diff] [blame] | 88 | define INSTALL_RULE |
Bamvor Jian Zhang | 900d65e | 2015-09-09 21:06:28 +0800 | [diff] [blame] | 89 | @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ |
| 90 | mkdir -p ${INSTALL_PATH}; \ |
bamvor.zhangjian@huawei.com | 5fe5979 | 2016-11-29 19:55:48 +0800 | [diff] [blame] | 91 | 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.com | 88baa78 | 2016-11-29 19:55:47 +0800 | [diff] [blame] | 93 | fi |
Shuah Khan | be16a24 | 2017-09-11 13:06:33 -0600 | [diff] [blame] | 94 | @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \ |
bamvor.zhangjian@huawei.com | 88baa78 | 2016-11-29 19:55:47 +0800 | [diff] [blame] | 95 | mkdir -p ${INSTALL_PATH}; \ |
Shuah Khan | be16a24 | 2017-09-11 13:06:33 -0600 | [diff] [blame] | 96 | 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 Zhang | a7d0f07 | 2015-08-14 21:43:35 +0800 | [diff] [blame] | 98 | fi |
Michael Ellerman | 32dcfba | 2015-03-11 15:06:00 +1100 | [diff] [blame] | 99 | endef |
| 100 | |
| 101 | install: all |
| 102 | ifdef INSTALL_PATH |
| 103 | $(INSTALL_RULE) |
| 104 | else |
| 105 | $(error Error: set INSTALL_PATH to use install) |
| 106 | endif |
| 107 | |
| 108 | define EMIT_TESTS |
Shuah Khan (Samsung OSG) | 3df6131 | 2018-05-01 12:15:34 -0600 | [diff] [blame] | 109 | @test_num=`echo 0`; \ |
| 110 | for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 111 | BASENAME_TEST=`basename $$TEST`; \ |
Shuah Khan (Samsung OSG) | 3df6131 | 2018-05-01 12:15:34 -0600 | [diff] [blame] | 112 | 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) | a548de0 | 2018-05-01 14:38:47 -0600 | [diff] [blame] | 115 | 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 Ellerman | 32dcfba | 2015-03-11 15:06:00 +1100 | [diff] [blame] | 121 | done; |
| 122 | endef |
| 123 | |
| 124 | emit_tests: |
| 125 | $(EMIT_TESTS) |
| 126 | |
Shuah Khan | 8050ef2 | 2017-09-06 18:36:22 -0600 | [diff] [blame] | 127 | # define if isn't already. It is undefined in make O= case. |
| 128 | ifeq ($(RM),) |
| 129 | RM := rm -f |
| 130 | endif |
| 131 | |
Shuah Khan | df6438f | 2017-04-21 16:07:51 -0600 | [diff] [blame] | 132 | define CLEAN |
bamvor.zhangjian@huawei.com | 80d443e8 | 2016-11-29 19:55:51 +0800 | [diff] [blame] | 133 | $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) |
Shuah Khan | df6438f | 2017-04-21 16:07:51 -0600 | [diff] [blame] | 134 | endef |
| 135 | |
| 136 | clean: |
| 137 | $(CLEAN) |
bamvor.zhangjian@huawei.com | 88baa78 | 2016-11-29 19:55:47 +0800 | [diff] [blame] | 138 | |
Shuah Khan | 8050ef2 | 2017-09-06 18:36:22 -0600 | [diff] [blame] | 139 | # When make O= with kselftest target from main level |
| 140 | # the following aren't defined. |
| 141 | # |
| 142 | ifneq ($(KBUILD_SRC),) |
| 143 | LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) |
| 144 | COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c |
| 145 | LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) |
| 146 | endif |
| 147 | |
Mathieu Desnoyers | 4e49ed2 | 2018-06-02 08:44:03 -0400 | [diff] [blame] | 148 | # Selftest makefiles can override those targets by setting |
| 149 | # OVERRIDE_TARGETS = 1. |
| 150 | ifeq ($(OVERRIDE_TARGETS),) |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 151 | $(OUTPUT)/%:%.c |
Michael Ellerman | 2047f1d | 2017-02-09 19:56:27 +1100 | [diff] [blame] | 152 | $(LINK.c) $^ $(LDLIBS) -o $@ |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 153 | |
| 154 | $(OUTPUT)/%.o:%.S |
Michael Ellerman | 634ce97 | 2017-02-09 19:56:28 +1100 | [diff] [blame] | 155 | $(COMPILE.S) $^ -o $@ |
bamvor.zhangjian@huawei.com | a8ba798 | 2016-11-29 19:55:52 +0800 | [diff] [blame] | 156 | |
| 157 | $(OUTPUT)/%:%.S |
Michael Ellerman | 634ce97 | 2017-02-09 19:56:28 +1100 | [diff] [blame] | 158 | $(LINK.S) $^ $(LDLIBS) -o $@ |
Mathieu Desnoyers | 4e49ed2 | 2018-06-02 08:44:03 -0400 | [diff] [blame] | 159 | endif |
bamvor.zhangjian@huawei.com | 7d758af | 2016-11-29 19:55:49 +0800 | [diff] [blame] | 160 | |
Michael Ellerman | 32dcfba | 2015-03-11 15:06:00 +1100 | [diff] [blame] | 161 | .PHONY: run_tests all clean install emit_tests |