~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/lib.mk

Version: ~ [ linux-6.4-rc3 ] ~ [ linux-6.3.4 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.30 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.113 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.180 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.243 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.283 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.315 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 ifdef KSFT_KHDR_INSTALL
 20 top_srcdir ?= ../../../..
 21 include $(top_srcdir)/scripts/subarch.include
 22 ARCH            ?= $(SUBARCH)
 23 
 24 .PHONY: khdr
 25 khdr:
 26         make ARCH=$(ARCH) -C $(top_srcdir) headers_install
 27 
 28 all: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
 29 else
 30 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
 31 endif
 32 
 33 .ONESHELL:
 34 define RUN_TEST_PRINT_RESULT
 35         TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST";  \
 36         echo $$TEST_HDR_MSG;                                    \
 37         echo "========================================";        \
 38         if [ ! -x $$TEST ]; then        \
 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]"; \
 41         else                                    \
 42                 cd `dirname $$TEST` > /dev/null; \
 43                 if [ "X$(summary)" != "X" ]; then       \
 44                         (./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && \
 45                         echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") || \
 46                         (if [ $$? -eq $$skip ]; then    \
 47                                 echo "not ok 1..$$test_num $$TEST_HDR_MSG [SKIP]";                              \
 48                         else echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]";                                 \
 49                         fi;)                    \
 50                 else                            \
 51                         (./$$BASENAME_TEST &&   \
 52                         echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") ||                                               \
 53                         (if [ $$? -eq $$skip ]; then \
 54                                 echo "not ok 1..$$test_num $$TEST_HDR_MSG [SKIP]"; \
 55                         else echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]";                         \
 56                         fi;)            \
 57                 fi;                             \
 58                 cd - > /dev/null;               \
 59         fi;
 60 endef
 61 
 62 define RUN_TESTS
 63         @export KSFT_TAP_LEVEL=`echo 1`;                \
 64         test_num=`echo 0`;                              \
 65         skip=`echo 4`;                                  \
 66         echo "TAP version 13";                          \
 67         for TEST in $(1); do                            \
 68                 BASENAME_TEST=`basename $$TEST`;        \
 69                 test_num=`echo $$test_num+1 | bc`;      \
 70                 $(call RUN_TEST_PRINT_RESULT,$(TEST),$(BASENAME_TEST),$(test_num),$(skip))                                              \
 71         done;
 72 endef
 73 
 74 run_tests: all
 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
 85         $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
 86 endif
 87 
 88 define INSTALL_RULE
 89         @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then                                        \
 90                 mkdir -p ${INSTALL_PATH};                                                                               \
 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)/;           \
 93         fi
 94         @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then                                        \
 95                 mkdir -p ${INSTALL_PATH};                                                                               \
 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)/;          \
 98         fi
 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
109         @test_num=`echo 0`;                             \
110         for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
111                 BASENAME_TEST=`basename $$TEST`;        \
112                 test_num=`echo $$test_num+1 | bc`;      \
113                 TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST";  \
114                 echo "echo $$TEST_HDR_MSG";     \
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;             \
121         done;
122 endef
123 
124 emit_tests:
125         $(EMIT_TESTS)
126 
127 # define if isn't already. It is undefined in make O= case.
128 ifeq ($(RM),)
129 RM := rm -f
130 endif
131 
132 define CLEAN
133         $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
134 endef
135 
136 clean:
137         $(CLEAN)
138 
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 
148 # Selftest makefiles can override those targets by setting
149 # OVERRIDE_TARGETS = 1.
150 ifeq ($(OVERRIDE_TARGETS),)
151 $(OUTPUT)/%:%.c
152         $(LINK.c) $^ $(LDLIBS) -o $@
153 
154 $(OUTPUT)/%.o:%.S
155         $(COMPILE.S) $^ -o $@
156 
157 $(OUTPUT)/%:%.S
158         $(LINK.S) $^ $(LDLIBS) -o $@
159 endif
160 
161 .PHONY: run_tests all clean install emit_tests

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp