| .. | .. | 
|---|
| 7 | 7 | endif | 
|---|
| 8 | 8 |  | 
|---|
| 9 | 9 | ifeq (0,$(MAKELEVEL)) | 
|---|
| 10 |  | -OUTPUT := $(shell pwd) | 
|---|
|  | 10 | +    ifeq ($(OUTPUT),) | 
|---|
|  | 11 | +	OUTPUT := $(shell pwd) | 
|---|
|  | 12 | +	DEFAULT_INSTALL_HDR_PATH := 1 | 
|---|
|  | 13 | +    endif | 
|---|
| 11 | 14 | endif | 
|---|
|  | 15 | +selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) | 
|---|
| 12 | 16 |  | 
|---|
| 13 | 17 | # The following are built by lib.mk common compile rules. | 
|---|
| 14 | 18 | # TEST_CUSTOM_PROGS should be used by tests that require | 
|---|
| .. | .. | 
|---|
| 25 | 29 | include $(top_srcdir)/scripts/subarch.include | 
|---|
| 26 | 30 | ARCH		?= $(SUBARCH) | 
|---|
| 27 | 31 |  | 
|---|
|  | 32 | +# set default goal to all, so make without a target runs all, even when | 
|---|
|  | 33 | +# all isn't the first target in the file. | 
|---|
|  | 34 | +.DEFAULT_GOAL := all | 
|---|
|  | 35 | + | 
|---|
|  | 36 | +# Invoke headers install with --no-builtin-rules to avoid circular | 
|---|
|  | 37 | +# dependency in "make kselftest" case. In this case, second level | 
|---|
|  | 38 | +# make inherits builtin-rules which will use the rule generate | 
|---|
|  | 39 | +# Makefile.o and runs into | 
|---|
|  | 40 | +# "Circular Makefile.o <- prepare dependency dropped." | 
|---|
|  | 41 | +# and headers_install fails and test compile fails. | 
|---|
|  | 42 | +# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile | 
|---|
|  | 43 | +# invokes them as sub-makes and --no-builtin-rules is not necessary, | 
|---|
|  | 44 | +# but doesn't cause any failures. Keep it simple and use the same | 
|---|
|  | 45 | +# flags in both cases. | 
|---|
|  | 46 | +# Note that the support to install headers from lib.mk is necessary | 
|---|
|  | 47 | +# when test Makefile is run directly with "make -C". | 
|---|
|  | 48 | +# When local build is done, headers are installed in the default | 
|---|
|  | 49 | +# INSTALL_HDR_PATH usr/include. | 
|---|
| 28 | 50 | .PHONY: khdr | 
|---|
| 29 | 51 | .NOTPARALLEL: | 
|---|
| 30 | 52 | khdr: | 
|---|
| 31 |  | -	make ARCH=$(ARCH) -C $(top_srcdir) headers_install | 
|---|
|  | 53 | +ifndef KSFT_KHDR_INSTALL_DONE | 
|---|
|  | 54 | +ifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) | 
|---|
|  | 55 | +	$(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install | 
|---|
|  | 56 | +else | 
|---|
|  | 57 | +	$(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$OUTPUT/usr \ | 
|---|
|  | 58 | +		ARCH=$(ARCH) -C $(top_srcdir) headers_install | 
|---|
|  | 59 | +endif | 
|---|
|  | 60 | +endif | 
|---|
| 32 | 61 |  | 
|---|
| 33 | 62 | all: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) | 
|---|
| 34 | 63 | else | 
|---|
| 35 | 64 | all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) | 
|---|
| 36 | 65 | endif | 
|---|
| 37 | 66 |  | 
|---|
| 38 |  | -.ONESHELL: | 
|---|
| 39 |  | -define RUN_TEST_PRINT_RESULT | 
|---|
| 40 |  | -	TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST";	\ | 
|---|
| 41 |  | -	echo $$TEST_HDR_MSG;					\ | 
|---|
| 42 |  | -	echo "========================================";	\ | 
|---|
| 43 |  | -	if [ ! -x $$TEST ]; then	\ | 
|---|
| 44 |  | -		echo "$$TEST_HDR_MSG: Warning: file $$BASENAME_TEST is not executable, correct this.";\ | 
|---|
| 45 |  | -		echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]"; \ | 
|---|
| 46 |  | -	else					\ | 
|---|
| 47 |  | -		cd `dirname $$TEST` > /dev/null; \ | 
|---|
| 48 |  | -		if [ "X$(summary)" != "X" ]; then	\ | 
|---|
| 49 |  | -			(./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && \ | 
|---|
| 50 |  | -			echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") || \ | 
|---|
| 51 |  | -			(if [ $$? -eq $$skip ]; then	\ | 
|---|
| 52 |  | -				echo "not ok 1..$$test_num $$TEST_HDR_MSG [SKIP]";				\ | 
|---|
| 53 |  | -			else echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]";					\ | 
|---|
| 54 |  | -			fi;)			\ | 
|---|
| 55 |  | -		else				\ | 
|---|
| 56 |  | -			(./$$BASENAME_TEST &&	\ | 
|---|
| 57 |  | -			echo "ok 1..$$test_num $$TEST_HDR_MSG [PASS]") ||						\ | 
|---|
| 58 |  | -			(if [ $$? -eq $$skip ]; then \ | 
|---|
| 59 |  | -				echo "not ok 1..$$test_num $$TEST_HDR_MSG [SKIP]"; \ | 
|---|
| 60 |  | -			else echo "not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]";				\ | 
|---|
| 61 |  | -			fi;)		\ | 
|---|
| 62 |  | -		fi;				\ | 
|---|
| 63 |  | -		cd - > /dev/null;		\ | 
|---|
| 64 |  | -	fi; | 
|---|
| 65 |  | -endef | 
|---|
| 66 |  | - | 
|---|
| 67 | 67 | define RUN_TESTS | 
|---|
| 68 |  | -	@export KSFT_TAP_LEVEL=`echo 1`;		\ | 
|---|
| 69 |  | -	test_num=`echo 0`;				\ | 
|---|
| 70 |  | -	skip=`echo 4`;					\ | 
|---|
| 71 |  | -	echo "TAP version 13";				\ | 
|---|
| 72 |  | -	for TEST in $(1); do				\ | 
|---|
| 73 |  | -		BASENAME_TEST=`basename $$TEST`;	\ | 
|---|
| 74 |  | -		test_num=`echo $$test_num+1 | bc`;	\ | 
|---|
| 75 |  | -		$(call RUN_TEST_PRINT_RESULT,$(TEST),$(BASENAME_TEST),$(test_num),$(skip))						\ | 
|---|
| 76 |  | -	done; | 
|---|
|  | 68 | +	BASE_DIR="$(selfdir)";			\ | 
|---|
|  | 69 | +	. $(selfdir)/kselftest/runner.sh;	\ | 
|---|
|  | 70 | +	if [ "X$(summary)" != "X" ]; then       \ | 
|---|
|  | 71 | +		per_test_logging=1;		\ | 
|---|
|  | 72 | +	fi;                                     \ | 
|---|
|  | 73 | +	run_many $(1) | 
|---|
| 77 | 74 | endef | 
|---|
| 78 | 75 |  | 
|---|
| 79 | 76 | run_tests: all | 
|---|
| 80 |  | -ifneq ($(KBUILD_SRC),) | 
|---|
| 81 |  | -	@if [ "X$(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)" != "X" ]; then | 
|---|
| 82 |  | -		@rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT) | 
|---|
|  | 77 | +ifdef building_out_of_srctree | 
|---|
|  | 78 | +	@if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ | 
|---|
|  | 79 | +		rsync -aq $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ | 
|---|
| 83 | 80 | fi | 
|---|
| 84 |  | -	@if [ "X$(TEST_PROGS)" != "X" ]; then | 
|---|
| 85 |  | -		$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(OUTPUT)/$(TEST_PROGS)) | 
|---|
| 86 |  | -	else | 
|---|
| 87 |  | -		$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)) | 
|---|
|  | 81 | +	@if [ "X$(TEST_PROGS)" != "X" ]; then \ | 
|---|
|  | 82 | +		$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ | 
|---|
|  | 83 | +				  $(addprefix $(OUTPUT)/,$(TEST_PROGS))) ; \ | 
|---|
|  | 84 | +	else \ | 
|---|
|  | 85 | +		$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS)); \ | 
|---|
| 88 | 86 | fi | 
|---|
| 89 | 87 | else | 
|---|
| 90 |  | -	$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) | 
|---|
|  | 88 | +	@$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) | 
|---|
| 91 | 89 | endif | 
|---|
| 92 | 90 |  | 
|---|
| 93 | 91 | define INSTALL_SINGLE_RULE | 
|---|
| 94 | 92 | $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) | 
|---|
| 95 |  | -	$(if $(INSTALL_LIST),@echo rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) | 
|---|
| 96 |  | -	$(if $(INSTALL_LIST),@rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) | 
|---|
|  | 93 | +	$(if $(INSTALL_LIST),rsync -a $(INSTALL_LIST) $(INSTALL_PATH)/) | 
|---|
| 97 | 94 | endef | 
|---|
| 98 | 95 |  | 
|---|
| 99 | 96 | define INSTALL_RULE | 
|---|
| .. | .. | 
|---|
| 113 | 110 | $(error Error: set INSTALL_PATH to use install) | 
|---|
| 114 | 111 | endif | 
|---|
| 115 | 112 |  | 
|---|
| 116 |  | -define EMIT_TESTS | 
|---|
| 117 |  | -	@test_num=`echo 0`;				\ | 
|---|
|  | 113 | +emit_tests: | 
|---|
| 118 | 114 | for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ | 
|---|
| 119 | 115 | BASENAME_TEST=`basename $$TEST`;	\ | 
|---|
| 120 |  | -		test_num=`echo $$test_num+1 | bc`;	\ | 
|---|
| 121 |  | -		TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST";	\ | 
|---|
| 122 |  | -		echo "echo $$TEST_HDR_MSG";	\ | 
|---|
| 123 |  | -		if [ ! -x $$TEST ]; then	\ | 
|---|
| 124 |  | -			echo "echo \"$$TEST_HDR_MSG: Warning: file $$BASENAME_TEST is not executable, correct this.\"";		\ | 
|---|
| 125 |  | -			echo "echo \"not ok 1..$$test_num $$TEST_HDR_MSG [FAIL]\""; \ | 
|---|
| 126 |  | -		else | 
|---|
| 127 |  | -			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;)"; \ | 
|---|
| 128 |  | -		fi;		\ | 
|---|
| 129 |  | -	done; | 
|---|
| 130 |  | -endef | 
|---|
| 131 |  | - | 
|---|
| 132 |  | -emit_tests: | 
|---|
| 133 |  | -	$(EMIT_TESTS) | 
|---|
|  | 116 | +		echo "$(COLLECTION):$$BASENAME_TEST";	\ | 
|---|
|  | 117 | +	done | 
|---|
| 134 | 118 |  | 
|---|
| 135 | 119 | # define if isn't already. It is undefined in make O= case. | 
|---|
| 136 | 120 | ifeq ($(RM),) | 
|---|
| .. | .. | 
|---|
| 147 | 131 | # When make O= with kselftest target from main level | 
|---|
| 148 | 132 | # the following aren't defined. | 
|---|
| 149 | 133 | # | 
|---|
| 150 |  | -ifneq ($(KBUILD_SRC),) | 
|---|
|  | 134 | +ifdef building_out_of_srctree | 
|---|
| 151 | 135 | LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) | 
|---|
| 152 | 136 | COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c | 
|---|
| 153 | 137 | LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) | 
|---|
| .. | .. | 
|---|
| 156 | 140 | # Selftest makefiles can override those targets by setting | 
|---|
| 157 | 141 | # OVERRIDE_TARGETS = 1. | 
|---|
| 158 | 142 | ifeq ($(OVERRIDE_TARGETS),) | 
|---|
| 159 |  | -$(OUTPUT)/%:%.c | 
|---|
| 160 |  | -	$(LINK.c) $^ $(LDLIBS) -o $@ | 
|---|
|  | 143 | +LOCAL_HDRS := $(selfdir)/kselftest_harness.h $(selfdir)/kselftest.h | 
|---|
|  | 144 | +$(OUTPUT)/%:%.c $(LOCAL_HDRS) | 
|---|
|  | 145 | +	$(LINK.c) $(filter-out $(LOCAL_HDRS),$^) $(LDLIBS) -o $@ | 
|---|
| 161 | 146 |  | 
|---|
| 162 | 147 | $(OUTPUT)/%.o:%.S | 
|---|
| 163 | 148 | $(COMPILE.S) $^ -o $@ | 
|---|