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
9 ifneq ($(KBUILD_OUTPUT),)
10 OUTPUT := $(KBUILD_OUTPUT)
12 OUTPUT := $(shell pwd)
13 DEFAULT_INSTALL_HDR_PATH := 1
17 selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST))))
19 # The following are built by lib.mk common compile rules.
20 # TEST_CUSTOM_PROGS should be used by tests that require
21 # custom build rule and prevent common build rule use.
22 # TEST_PROGS are for test shell scripts.
23 # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests
24 # and install targets. Common clean doesn't touch them.
25 TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
26 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
27 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
29 ifdef KSFT_KHDR_INSTALL
30 top_srcdir ?= ../../../..
31 include $(top_srcdir)/scripts/subarch.include
34 # set default goal to all, so make without a target runs all, even when
35 # all isn't the first target in the file.
38 # Invoke headers install with --no-builtin-rules to avoid circular
39 # dependency in "make kselftest" case. In this case, second level
40 # make inherits builtin-rules which will use the rule generate
41 # Makefile.o and runs into
42 # "Circular Makefile.o <- prepare dependency dropped."
43 # and headers_install fails and test compile fails.
44 # O= KBUILD_OUTPUT cases don't run into this error, since main Makefile
45 # invokes them as sub-makes and --no-builtin-rules is not necessary,
46 # but doesn't cause any failures. Keep it simple and use the same
47 # flags in both cases.
48 # Note that the support to install headers from lib.mk is necessary
49 # when test Makefile is run directly with "make -C".
50 # When local build is done, headers are installed in the default
51 # INSTALL_HDR_PATH usr/include.
54 ifndef KSFT_KHDR_INSTALL_DONE
55 ifeq (1,$(DEFAULT_INSTALL_HDR_PATH))
56 make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install
58 make --no-builtin-rules INSTALL_HDR_PATH=$$OUTPUT/usr \
59 ARCH=$(ARCH) -C $(top_srcdir) headers_install
63 all: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
65 all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
70 @export KSFT_TAP_LEVEL=`echo 1`; \
72 . $(selfdir)/kselftest/runner.sh; \
73 echo "TAP version 13"; \
74 for TEST in $(1); do \
75 BASENAME_TEST=`basename $$TEST`; \
76 test_num=`echo $$test_num+1 | bc`; \
77 if [ "X$(summary)" != "X" ]; then \
78 logfile="/tmp/$$BASENAME_TEST"; \
79 cat /dev/null > "$$logfile"; \
81 run_one "$$BASENAME_TEST" "$$test_num"; \
86 ifneq ($(KBUILD_SRC),)
87 @if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then
88 @rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT)
90 @if [ "X$(TEST_PROGS)" != "X" ]; then
91 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS))
93 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS))
96 $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS))
100 @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
101 mkdir -p ${INSTALL_PATH}; \
102 echo "rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
103 rsync -a $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
105 @if [ "X$(TEST_GEN_PROGS)$(TEST_CUSTOM_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \
106 mkdir -p ${INSTALL_PATH}; \
107 echo "rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \
108 rsync -a $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \
116 $(error Error: set INSTALL_PATH to use install)
120 @test_num=`echo 0`; \
121 for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \
122 BASENAME_TEST=`basename $$TEST`; \
123 test_num=`echo $$test_num+1 | bc`; \
124 TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST"; \
125 echo "echo $$TEST_HDR_MSG"; \
126 if [ ! -x $$TEST ]; then \
127 echo "echo \"$$TEST_HDR_MSG: Warning: file $$BASENAME_TEST is not executable, correct this.\""; \
128 echo "echo \"not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]\""; \
130 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;)"; \
138 # define if isn't already. It is undefined in make O= case.
144 $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
150 # When make O= with kselftest target from main level
151 # the following aren't defined.
153 ifneq ($(KBUILD_SRC),)
154 LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
155 COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
156 LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
159 # Selftest makefiles can override those targets by setting
160 # OVERRIDE_TARGETS = 1.
161 ifeq ($(OVERRIDE_TARGETS),)
163 $(LINK.c) $^ $(LDLIBS) -o $@
166 $(COMPILE.S) $^ -o $@
169 $(LINK.S) $^ $(LDLIBS) -o $@
172 .PHONY: run_tests all clean install emit_tests