2 # Add the module tests to the overall dependencies
7 # If module requires test server, make sure TEST_SERVER of <MODULE>_TEST_SERVER variables are defined
8 # If TEST_SERVER is defined, define <MODULE>_TEST_SERVER for all modules that have CHECK_MODULE_TEST_CAN_BE_RUN
9 define CHECK_MODULE_TEST_CAN_BE_RUN
10 ifndef ${1}_require_test_server
11 tests.modules: ${1}.test
14 tests.modules: ${1}.test
15 export $(shell echo ${1} | tr a-z A-Z)_TEST_SERVER := $(TEST_SERVER)
17 ifdef $(shell echo ${1} | tr a-z A-Z)_TEST_SERVER
18 tests.modules: ${1}.test
22 $(foreach x,$(TEST_BUILT) $(TEST_SUBBUILT),$(eval $(call CHECK_MODULE_TEST_CAN_BE_RUN,$x)))
24 ######################################################################
26 # And now more makefile magic to automatically run the tests
31 ifeq "$(wildcard ${1}.attrs)"
34 src/tests/modules/default-input.attrs
39 # Files in the output dir depend on the unit tests
41 # src/tests/$(MODULE_DIR)/FOO.unlang unlang for the test
42 # src/tests/$(MODULE_DIR)/FOO.attrs input RADIUS and output filter
43 # build/tests/$(MODULE_DIR)/FOO.out updated if the test succeeds
44 # build/tests/$(MODULE_DIR)/FOO.log debug output for the test
46 # If the test fails, then look for ERROR in the input. No error
47 # means it's unexpected, so we die.
49 # Otherwise, check the log file for a parse error which matches the
50 # ERROR line in the input.
52 $(BUILD_DIR)/tests/modules/%: src/tests/modules/%.unlang $(BUILD_DIR)/tests/modules/%.attrs $(TESTBINDIR)/unittest | build.raddb
54 @echo MODULE-TEST $(lastword $(subst /, ,$(dir $@))) $(basename $(notdir $@))
55 @if ! MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< $(TESTBIN)/unittest -D share -d src/tests/modules/ -i $@.attrs -f $@.attrs -xxx > $@.log 2>&1; then \
56 if ! grep ERROR $< 2>&1 > /dev/null; then \
59 echo MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< $(TESTBIN)/unittest -D share -d src/tests/modules/ -i $@.attrs -f $@.attrs -xx; \
62 FOUND=$$(grep ^$< $@.log | head -1 | sed 's/:.*//;s/.*\[//;s/\].*//'); \
63 EXPECTED=$$(grep -n ERROR $< | sed 's/:.*//'); \
64 if [ "$$EXPECTED" != "$$FOUND" ]; then \
67 echo MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< $(TESTBIN)/unittest -D share -d src/tests/modules/ -i $@.attrs -f $@.attrs -xx; \
74 # Sometimes we have a default input. So use that. Otherwise, use
75 # the input specific to the test.
77 MODULE_UNLANG := $(wildcard src/tests/modules/*/*.unlang src/tests/modules/*/*/*.unlang)
78 MODULE_ATTRS_REQUIRES := $(patsubst %.unlang,%.attrs,$(MODULE_UNLANG))
79 MODULE_ATTRS_EXISTS := $(wildcard src/tests/modules/*/*.attrs src/tests/modules/*/*/*.attrs)
80 MODULE_ATTRS_NEEDS := $(filter-out $(MODULE_ATTRS_EXISTS),$(MODULE_ATTRS_REQUIRES))
82 MODULE_CONF_REQUIRES := $(patsubst %.unlang,%.conf,$(MODULE_UNLANG))
83 MODULE_CONF_EXISTS := $(wildcard src/tests/modules/*/*.conf src/tests/modules/*/*/*.attrs)
84 MODULE_CONF_NEEDS := $(filter-out $(MODULE_CONF_EXISTS),$(MODULE_CONF_REQUIRES))
87 # The complete list of tests which are to be run
89 MODULE_TESTS := $(patsubst src/tests/modules/%/all.mk,%,$(wildcard src/tests/modules/*/all.mk))
93 # Target-specific rules
95 define MODULE_COPY_FILE
96 $(BUILD_DIR)/${1}: src/${1}
105 define MODULE_COPY_ATTR
106 $(BUILD_DIR)/${1}: src/tests/modules/default-input.attrs
112 # FIXME: get this working
114 define MODULE_COPY_CONF
115 $(BUILD_DIR)/${1}: src/tests/modules/${2}/module.conf
120 define MODULE_FILE_TARGET
121 $(BUILD_DIR)/${1}: src/${1}.unlang $(BUILD_DIR)/${1}.attrs
125 define MODULE_TEST_TARGET
126 ${1}.test: $(patsubst %.unlang,%,$(subst src,$(BUILD_DIR),$(filter src/tests/modules/${1}/%,$(MODULE_UNLANG))))
128 TESTS.MODULES_FILES += $(patsubst %.unlang,%,$(subst src,$(BUILD_DIR),$(filter src/tests/modules/${1}/%,$(MODULE_UNLANG))))
132 # Create the rules from the list of input files
134 $(foreach x,$(MODULE_ATTRS_EXISTS),$(eval $(call MODULE_COPY_FILE,$(subst src/,,$x))))
135 $(foreach x,$(MODULE_CONF_EXISTS),$(eval $(call MODULE_COPY_FILE,$(subst src/,,$x))))
137 $(foreach x,$(MODULE_ATTRS_NEEDS),$(eval $(call MODULE_COPY_ATTR,$(subst src/,,$x))))
138 # FIXME: copy src/tests/modules/*/module.conf to the right place, too
140 $(foreach x,$(MODULE_UNLANG),$(eval $(call MODULE_FILE_TARGET,$(patsubst %.unlang,%,$(subst src/,,$x)))))
141 $(foreach x,$(MODULE_TESTS),$(eval $(call MODULE_TEST_TARGET,$x)))
143 $(TESTS.MODULES_FILES): $(TESTS.AUTH_FILES)
145 .PHONY: clean.modules.test
147 @rm -rf $(BUILD_DIR)/tests/modules/
150 # For each file, look for precursor test.
151 # Ensure that each test depends on its precursors.
153 -include $(BUILD_DIR)/tests/modules/depends.mk
155 $(BUILD_DIR)/tests/modules/depends.mk: $(MODULE_UNLANG) | $(BUILD_DIR)/tests/modules
158 y=`grep PRE $$x | awk '{ print $$3 }'`; \
159 if [ "$$y" != "" ]; then \
160 z=`echo $$x | sed 's,src/,$(BUILD_DIR)/', | sed 's/.unlang//'`; \
161 d=$$(basename $$(dirname $$x)); \
162 echo "$$z: $(BUILD_DIR)/tests/modules/$$d/$$y" >> $@; \