2 # Add the module tests to the overall dependencies
4 tests.modules: tests.unit tests.keywords tests.auth
6 # If module requires test server, make sure TEST_SERVER of <MODULE>_TEST_SERVER variables are defined
7 # If TEST_SERVER is defined, define <MODULE>_TEST_SERVER for all modules that have CHECK_MODULE_TEST_CAN_BE_RUN
8 define CHECK_MODULE_TEST_CAN_BE_RUN
9 ifndef ${1}_require_test_server
10 tests.modules: ${1}.test
13 tests.modules: ${1}.test
14 export $(shell echo ${1} | tr a-z A-Z)_TEST_SERVER := $(TEST_SERVER)
16 ifdef $(shell echo ${1} | tr a-z A-Z)_TEST_SERVER
17 tests.modules: ${1}.test
21 $(foreach x,$(TEST_BUILT) $(TEST_SUBBUILT),$(eval $(call CHECK_MODULE_TEST_CAN_BE_RUN,$x)))
23 ######################################################################
25 # And now more makefile magic to automatically run the tests
30 ifeq "$(wildcard ${1}.attrs)"
33 src/tests/modules/default-input.attrs
38 # Files in the output dir depend on the unit tests
40 # src/tests/$(MODULE_DIR)/FOO.unlang unlang for the test
41 # src/tests/$(MODULE_DIR)/FOO.attrs input RADIUS and output filter
42 # build/tests/$(MODULE_DIR)/FOO.out updated if the test succeeds
43 # build/tests/$(MODULE_DIR)/FOO.log debug output for the test
45 # If the test fails, then look for ERROR in the input. No error
46 # means it's unexpected, so we die.
48 # Otherwise, check the log file for a parse error which matches the
49 # ERROR line in the input.
51 $(BUILD_DIR)/tests/modules/%: src/tests/modules/%.unlang $(BUILD_DIR)/tests/modules/%.attrs $(TESTBINDIR)/unittest | build.raddb
53 @echo MODULE-TEST $(lastword $(subst /, ,$(dir $@))) $(basename $(notdir $@))
54 @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 \
55 if ! grep ERROR $< 2>&1 > /dev/null; then \
58 echo MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< $(TESTBIN)/unittest -D share -d src/tests/modules/ -i $@.attrs -f $@.attrs -xx; \
61 FOUND=$$(grep ^$< $@.log | head -1 | sed 's/:.*//;s/.*\[//;s/\].*//'); \
62 EXPECTED=$$(grep -n ERROR $< | sed 's/:.*//'); \
63 if [ "$$EXPECTED" != "$$FOUND" ]; then \
66 echo MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< $(TESTBIN)/unittest -D share -d src/tests/modules/ -i $@.attrs -f $@.attrs -xx; \
73 # Sometimes we have a default input. So use that. Otherwise, use
74 # the input specific to the test.
76 MODULE_UNLANG := $(wildcard src/tests/modules/*/*.unlang src/tests/modules/*/*/*.unlang)
77 MODULE_ATTRS_REQUIRES := $(patsubst %.unlang,%.attrs,$(MODULE_UNLANG))
78 MODULE_ATTRS_EXISTS := $(wildcard src/tests/modules/*/*.attrs src/tests/modules/*/*/*.attrs)
79 MODULE_ATTRS_NEEDS := $(filter-out $(MODULE_ATTRS_EXISTS),$(MODULE_ATTRS_REQUIRES))
81 MODULE_CONF_REQUIRES := $(patsubst %.unlang,%.conf,$(MODULE_UNLANG))
82 MODULE_CONF_EXISTS := $(wildcard src/tests/modules/*/*.conf src/tests/modules/*/*/*.attrs)
83 MODULE_CONF_NEEDS := $(filter-out $(MODULE_CONF_EXISTS),$(MODULE_CONF_REQUIRES))
86 # The complete list of tests which are to be run
88 MODULE_TESTS := $(patsubst src/tests/modules/%/all.mk,%,$(wildcard src/tests/modules/*/all.mk))
92 # Target-specific rules
94 define MODULE_COPY_FILE
95 $(BUILD_DIR)/${1}: src/${1}
104 define MODULE_COPY_ATTR
105 $(BUILD_DIR)/${1}: src/tests/modules/default-input.attrs
111 # FIXME: get this working
113 define MODULE_COPY_CONF
114 $(BUILD_DIR)/${1}: src/tests/modules/${2}/module.conf
119 define MODULE_FILE_TARGET
120 $(BUILD_DIR)/${1}: src/${1}.unlang $(BUILD_DIR)/${1}.attrs
124 define MODULE_TEST_TARGET
125 ${1}.test: $(patsubst %.unlang,%,$(subst src,$(BUILD_DIR),$(filter src/tests/modules/${1}/%,$(MODULE_UNLANG))))
130 # Create the rules from the list of input files
132 $(foreach x,$(MODULE_ATTRS_EXISTS),$(eval $(call MODULE_COPY_FILE,$(subst src/,,$x))))
133 $(foreach x,$(MODULE_CONF_EXISTS),$(eval $(call MODULE_COPY_FILE,$(subst src/,,$x))))
135 $(foreach x,$(MODULE_ATTRS_NEEDS),$(eval $(call MODULE_COPY_ATTR,$(subst src/,,$x))))
136 # FIXME: copy src/tests/modules/*/module.conf to the right place, too
138 $(foreach x,$(MODULE_UNLANG),$(eval $(call MODULE_FILE_TARGET,$(patsubst %.unlang,%,$(subst src/,,$x)))))
139 $(foreach x,$(MODULE_TESTS),$(eval $(call MODULE_TEST_TARGET,$x)))
141 .PHONY: clean.modules.test
143 @rm -rf $(BUILD_DIR)/tests/modules/
146 # For each file, look for precursor test.
147 # Ensure that each test depends on its precursors.
149 -include $(BUILD_DIR)/tests/modules/depends.mk
151 $(BUILD_DIR)/tests/modules/depends.mk: $(MODULE_UNLANG) | $(BUILD_DIR)/tests/modules
154 y=`grep PRE $$x | awk '{ print $$3 }'`; \
155 if [ "$$y" != "" ]; then \
156 z=`echo $$x | sed 's,src/,$(BUILD_DIR)/', | sed 's/.unlang//'`; \
157 d=$$(basename $$(dirname $$x)); \
158 echo "$$z: $(BUILD_DIR)/tests/modules/$$d/$$y" >> $@; \