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

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

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/lib.mk (Version linux-6.12-rc7) and /tools/testing/selftests/lib.mk (Version linux-4.18.20)


  1 # This mimics the top-level Makefile. We do it      1 # This mimics the top-level Makefile. We do it explicitly here so that this
  2 # Makefile can operate with or without the kbu      2 # Makefile can operate with or without the kbuild infrastructure.
  3 ifneq ($(LLVM),)                               << 
  4 ifneq ($(filter %/,$(LLVM)),)                  << 
  5 LLVM_PREFIX := $(LLVM)                         << 
  6 else ifneq ($(filter -%,$(LLVM)),)             << 
  7 LLVM_SUFFIX := $(LLVM)                         << 
  8 endif                                          << 
  9                                                << 
 10 CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX)     << 
 11                                                << 
 12 CLANG_TARGET_FLAGS_arm          := arm-linux-g << 
 13 CLANG_TARGET_FLAGS_arm64        := aarch64-lin << 
 14 CLANG_TARGET_FLAGS_hexagon      := hexagon-lin << 
 15 CLANG_TARGET_FLAGS_i386         := i386-linux- << 
 16 CLANG_TARGET_FLAGS_m68k         := m68k-linux- << 
 17 CLANG_TARGET_FLAGS_mips         := mipsel-linu << 
 18 CLANG_TARGET_FLAGS_powerpc      := powerpc64le << 
 19 CLANG_TARGET_FLAGS_riscv        := riscv64-lin << 
 20 CLANG_TARGET_FLAGS_s390         := s390x-linux << 
 21 CLANG_TARGET_FLAGS_x86          := x86_64-linu << 
 22 CLANG_TARGET_FLAGS_x86_64       := x86_64-linu << 
 23                                                << 
 24 # Default to host architecture if ARCH is not  << 
 25 ifeq ($(ARCH),)                                << 
 26 CLANG_TARGET_FLAGS := $(shell $(CLANG) -print- << 
 27 else                                           << 
 28 CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(A << 
 29 endif                                          << 
 30                                                << 
 31 ifeq ($(CROSS_COMPILE),)                       << 
 32 ifeq ($(CLANG_TARGET_FLAGS),)                  << 
 33 $(error Specify CROSS_COMPILE or add '--target << 
 34 else                                           << 
 35 CLANG_FLAGS     += --target=$(CLANG_TARGET_FLA << 
 36 endif # CLANG_TARGET_FLAGS                     << 
 37 else                                           << 
 38 CLANG_FLAGS     += --target=$(notdir $(CROSS_C << 
 39 endif # CROSS_COMPILE                          << 
 40                                                << 
 41 # gcc defaults to silence (off) for the follow << 
 42 # to the opposite. The warnings are not useful << 
 43 # why they have remained disabled in gcc for t << 
 44 # only due to including kernel data structures << 
 45 # warnings from clang. Therefore, disable the  << 
 46 CFLAGS += -Wno-address-of-packed-member        << 
 47 CFLAGS += -Wno-gnu-variable-sized-type-not-at- << 
 48                                                << 
 49 CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as  << 
 50 else                                           << 
 51 CC := $(CROSS_COMPILE)gcc                           3 CC := $(CROSS_COMPILE)gcc
 52 endif # LLVM                                   << 
 53                                                     4 
 54 ifeq (0,$(MAKELEVEL))                               5 ifeq (0,$(MAKELEVEL))
 55     ifeq ($(OUTPUT),)                          !!   6 OUTPUT := $(shell pwd)
 56         OUTPUT := $(shell pwd)                 !!   7 endif
 57         DEFAULT_INSTALL_HDR_PATH := 1          << 
 58     endif                                      << 
 59 endif                                          << 
 60 selfdir = $(realpath $(dir $(filter %/lib.mk,$ << 
 61 top_srcdir = $(selfdir)/../../..               << 
 62                                                << 
 63 # msg: emit succinct information message descr << 
 64 # $1 - generic step name (e.g., CC, LINK, etc) << 
 65 # $2 - optional "flavor" specifier; if provide << 
 66 # $3 - target (assumed to be file); only file  << 
 67 # $4 - optional extra arg, emitted as-is, if p << 
 68 ifeq ($(V),1)                                  << 
 69 Q =                                            << 
 70 msg =                                          << 
 71 else                                           << 
 72 Q = @                                          << 
 73 msg = @printf '  %-8s%s %s%s\n' "$(1)" "$(if $ << 
 74 MAKEFLAGS += --no-print-directory              << 
 75 endif                                          << 
 76                                                << 
 77 ifeq ($(KHDR_INCLUDES),)                       << 
 78 KHDR_INCLUDES := -isystem $(top_srcdir)/usr/in << 
 79 endif                                          << 
 80                                                << 
 81 # In order to use newer items that haven't yet << 
 82 # header files, add $(TOOLS_INCLUDES) to the c << 
 83 # each selftest.                               << 
 84 # You may need to add files to that location,  << 
 85 # order to do that, run "make headers" from $( << 
 86 # header file that you want from $(top_srcdir) << 
 87 # subdir in $(TOOLS_INCLUDE).                  << 
 88 TOOLS_INCLUDES := -isystem $(top_srcdir)/tools << 
 89                                                     8 
 90 # The following are built by lib.mk common com      9 # The following are built by lib.mk common compile rules.
 91 # TEST_CUSTOM_PROGS should be used by tests th     10 # TEST_CUSTOM_PROGS should be used by tests that require
 92 # custom build rule and prevent common build r     11 # custom build rule and prevent common build rule use.
 93 # TEST_PROGS are for test shell scripts.           12 # TEST_PROGS are for test shell scripts.
 94 # TEST_CUSTOM_PROGS and TEST_PROGS will be run     13 # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
 95 # and install targets. Common clean doesn't to     14 # and install targets. Common clean doesn't touch them.
 96 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(T     15 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
 97 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTP     16 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
 98 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(T     17 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
 99                                                    18 
100 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTEND !!  19 top_srcdir ?= ../../../..
101         $(if $(TEST_GEN_MODS_DIR),gen_mods_dir !!  20 include $(top_srcdir)/scripts/subarch.include
102                                                !!  21 ARCH            ?= $(SUBARCH)
103 define RUN_TESTS                               !!  22 
104         BASE_DIR="$(selfdir)";                 !!  23 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
105         . $(selfdir)/kselftest/runner.sh;      !!  24 
106         if [ "X$(summary)" != "X" ]; then      !!  25 .PHONY: khdr
107                 per_test_logging=1;            !!  26 khdr:
108         fi;                                    !!  27         make ARCH=$(ARCH) -C $(top_srcdir) headers_install
109         run_many $(1)                          !!  28 
                                                   >>  29 ifdef KSFT_KHDR_INSTALL
                                                   >>  30 $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES):| khdr
                                                   >>  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;
110 endef                                              60 endef
111                                                    61 
112 define INSTALL_INCLUDES                        !!  62 define RUN_TESTS
113         $(if $(TEST_INCLUDES), \               !!  63         @export KSFT_TAP_LEVEL=`echo 1`;                \
114                 relative_files=""; \           !!  64         test_num=`echo 0`;                              \
115                 for entry in $(TEST_INCLUDES); !!  65         skip=`echo 4`;                                  \
116                         entry_dir=$$(readlink  !!  66         echo "TAP version 13";                          \
117                         entry_name=$$(basename !!  67         for TEST in $(1); do                            \
118                         relative_dir=$${entry_ !!  68                 BASENAME_TEST=`basename $$TEST`;        \
119                         if [ "$$relative_dir"  !!  69                 test_num=`echo $$test_num+1 | bc`;      \
120                                 echo "Error: T !!  70                 $(call RUN_TEST_PRINT_RESULT,$(TEST),$(BASENAME_TEST),$(test_num),$(skip))                                              \
121                                 exit 1; \      !!  71         done;
122                         fi; \                  << 
123                         relative_files="$$rela << 
124                 done; \                        << 
125                 cd $(SRC_PATH) && rsync -aR $$ << 
126         )                                      << 
127 endef                                              72 endef
128                                                    73 
129 run_tests: all                                     74 run_tests: all
130 ifdef building_out_of_srctree                  !!  75 ifneq ($(KBUILD_SRC),)
131         @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTE !!  76         @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
132                 rsync -aq --copy-unsafe-links  !!  77                 @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
133         fi                                         78         fi
134         @$(INSTALL_INCLUDES)                   !!  79         @if [ "X$(TEST_PROGS)" != "X" ]; then
135         @if [ "X$(TEST_PROGS)" != "X" ]; then  !!  80                 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
136                 $(call RUN_TESTS, $(TEST_GEN_P !!  81         else
137                                   $(addprefix  !!  82                 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
138         else \                                 << 
139                 $(call RUN_TESTS, $(TEST_GEN_P << 
140         fi                                         83         fi
141 else                                               84 else
142         @$(call RUN_TESTS, $(TEST_GEN_PROGS) $ !!  85         $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
143 endif                                              86 endif
144                                                    87 
145 gen_mods_dir:                                  << 
146         $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR)    << 
147                                                << 
148 clean_mods_dir:                                << 
149         $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) cl << 
150                                                << 
151 define INSTALL_SINGLE_RULE                     << 
152         $(if $(INSTALL_LIST),@mkdir -p $(INSTA << 
153         $(if $(INSTALL_LIST),rsync -a --copy-u << 
154 endef                                          << 
155                                                << 
156 define INSTALL_MODS_RULE                       << 
157         $(if $(INSTALL_LIST),@mkdir -p $(INSTA << 
158         $(if $(INSTALL_LIST),rsync -a --copy-u << 
159 endef                                          << 
160                                                << 
161 define INSTALL_RULE                                88 define INSTALL_RULE
162         $(eval INSTALL_LIST = $(TEST_PROGS)) $ !!  89         @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then                                        \
163         $(eval INSTALL_LIST = $(TEST_PROGS_EXT !!  90                 mkdir -p ${INSTALL_PATH};                                                                               \
164         $(eval INSTALL_LIST = $(TEST_FILES)) $ !!  91                 echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/";    \
165         $(eval INSTALL_LIST = $(TEST_GEN_PROGS !!  92                 rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/;           \
166         $(eval INSTALL_LIST = $(TEST_CUSTOM_PR !!  93         fi
167         $(eval INSTALL_LIST = $(TEST_GEN_PROGS !!  94         @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then                                        \
168         $(eval INSTALL_LIST = $(TEST_GEN_FILES !!  95                 mkdir -p ${INSTALL_PATH};                                                                               \
169         $(eval INSTALL_LIST = $(notdir $(TEST_ !!  96                 echo "rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/";   \
170         $(eval INSTALL_LIST = $(wildcard confi !!  97                 rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/;          \
                                                   >>  98         fi
171 endef                                              99 endef
172                                                   100 
173 install: all                                      101 install: all
174 ifdef INSTALL_PATH                                102 ifdef INSTALL_PATH
175         $(INSTALL_RULE)                           103         $(INSTALL_RULE)
176         $(INSTALL_INCLUDES)                    << 
177 else                                              104 else
178         $(error Error: set INSTALL_PATH to use    105         $(error Error: set INSTALL_PATH to use install)
179 endif                                             106 endif
180                                                   107 
181 emit_tests:                                    !! 108 define EMIT_TESTS
                                                   >> 109         @test_num=`echo 0`;                             \
182         for TEST in $(TEST_GEN_PROGS) $(TEST_C    110         for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
183                 BASENAME_TEST=`basename $$TEST    111                 BASENAME_TEST=`basename $$TEST`;        \
184                 echo "$(COLLECTION):$$BASENAME !! 112                 test_num=`echo $$test_num+1 | bc`;      \
185         done                                   !! 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)
186                                                   126 
187 # define if isn't already. It is undefined in     127 # define if isn't already. It is undefined in make O= case.
188 ifeq ($(RM),)                                     128 ifeq ($(RM),)
189 RM := rm -f                                       129 RM := rm -f
190 endif                                             130 endif
191                                                   131 
192 define CLEAN                                      132 define CLEAN
193         $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_    133         $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
194 endef                                             134 endef
195                                                   135 
196 clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_di !! 136 clean:
197         $(CLEAN)                                  137         $(CLEAN)
198                                                   138 
199 # Build with _GNU_SOURCE by default            << 
200 CFLAGS += -D_GNU_SOURCE=                       << 
201                                                << 
202 # Enables to extend CFLAGS and LDFLAGS from co << 
203 # make USERCFLAGS=-Werror USERLDFLAGS=-static  << 
204 CFLAGS += $(USERCFLAGS)                        << 
205 LDFLAGS += $(USERLDFLAGS)                      << 
206                                                << 
207 # When make O= with kselftest target from main    139 # When make O= with kselftest target from main level
208 # the following aren't defined.                   140 # the following aren't defined.
209 #                                                 141 #
210 ifdef building_out_of_srctree                  !! 142 ifneq ($(KBUILD_SRC),)
211 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS    143 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
212 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TAR    144 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
213 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAG    145 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
214 endif                                             146 endif
215                                                   147 
216 # Selftest makefiles can override those target    148 # Selftest makefiles can override those targets by setting
217 # OVERRIDE_TARGETS = 1.                           149 # OVERRIDE_TARGETS = 1.
218 ifeq ($(OVERRIDE_TARGETS),)                       150 ifeq ($(OVERRIDE_TARGETS),)
219 LOCAL_HDRS += $(selfdir)/kselftest_harness.h $ !! 151 $(OUTPUT)/%:%.c
220 $(OUTPUT)/%:%.c $(LOCAL_HDRS)                  !! 152         $(LINK.c) $^ $(LDLIBS) -o $@
221         $(call msg,CC,,$@)                     << 
222         $(Q)$(LINK.c) $(filter-out $(LOCAL_HDR << 
223                                                   153 
224 $(OUTPUT)/%.o:%.S                                 154 $(OUTPUT)/%.o:%.S
225         $(COMPILE.S) $^ -o $@                     155         $(COMPILE.S) $^ -o $@
226                                                   156 
227 $(OUTPUT)/%:%.S                                   157 $(OUTPUT)/%:%.S
228         $(LINK.S) $^ $(LDLIBS) -o $@              158         $(LINK.S) $^ $(LDLIBS) -o $@
229 endif                                             159 endif
230                                                   160 
231 .PHONY: run_tests all clean install emit_tests !! 161 .PHONY: run_tests all clean install emit_tests
                                                      

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php