2 # Unit tests for unlang keywords
6 # The test files are files without extensions.
7 # The list is unordered. The order is added in the next step by looking
10 KEYWORD_FILES := $(filter-out %.conf %.md %.attrs %.mk %~ %.rej,$(subst $(DIR)/,,$(wildcard $(DIR)/*)))
12 ifeq "$(OPENSSL_LIBS)" ""
13 KEYWORD_FILES := $(filter-out pap-ssha2,$(KEYWORD_FILES))
17 # Create the output directory
19 .PHONY: $(BUILD_DIR)/tests/keywords
20 $(BUILD_DIR)/tests/keywords:
24 # Find which input files are needed by the tests
25 # strip out the ones which exist
26 # move the filenames to the build directory.
28 BOOTSTRAP_EXISTS := $(addprefix $(DIR)/,$(addsuffix .attrs,$(KEYWORD_FILES)))
29 BOOTSTRAP_NEEDS := $(filter-out $(wildcard $(BOOTSTRAP_EXISTS)),$(BOOTSTRAP_EXISTS))
30 BOOTSTRAP := $(subst $(DIR),$(BUILD_DIR)/tests/keywords,$(BOOTSTRAP_NEEDS))
33 # For each file, look for precursor test.
34 # Ensure that each test depends on its precursors.
36 -include $(BUILD_DIR)/tests/keywords/depends.mk
40 $(BUILD_DIR)/tests/keywords/depends.mk: $(addprefix $(DIR)/,$(KEYWORD_FILES)) | $(BUILD_DIR)/tests/keywords
43 y=`grep 'PRE: ' $$x | sed 's/.*://;s/ / /g;s, , $(BUILD_DIR)/tests/keywords/,g'`; \
44 if [ "$$y" != "" ]; then \
45 z=`echo $$x | sed 's,src/,$(BUILD_DIR)/',`; \
46 echo "$$z: $$y" >> $@; \
52 # These ones get copied over from the default input
54 $(BOOTSTRAP): $(DIR)/default-input.attrs | $(BUILD_DIR)/tests/keywords
58 # These ones get copied over from their original files
60 $(BUILD_DIR)/tests/keywords/%.attrs: $(DIR)/%.attrs | $(BUILD_DIR)/tests/keywords
64 # Don't auto-remove the files copied by the rule just above.
65 # It's unnecessary, and it clutters the output with crap.
67 .PRECIOUS: $(BUILD_DIR)/tests/keywords/%.attrs
69 KEYWORD_MODULES := $(shell grep -- mods-enabled src/tests/keywords/radiusd.conf | sed 's,.*/,,')
70 KEYWORD_RADDB := $(addprefix raddb/mods-enabled/,$(KEYWORD_MODULES))
71 KEYWORD_LIBS := $(addsuffix .la,$(addprefix rlm_,$(KEYWORD_MODULES))) rlm_example.la rlm_cache.la
74 # Files in the output dir depend on the unit tests
76 # src/tests/keywords/FOO unlang for the test
77 # src/tests/keywords/FOO.attrs input RADIUS and output filter
78 # build/tests/keywords/FOO updated if the test succeeds
79 # build/tests/keywords/FOO.log debug output for the test
81 # Auto-depend on modules via $(shell grep INCLUDE $(DIR)/radiusd.conf | grep mods-enabled | sed 's/.*}/raddb/'))
83 # If the test fails, then look for ERROR in the input. No error
84 # means it's unexpected, so we die.
86 # Otherwise, check the log file for a parse error which matches the
87 # ERROR line in the input.
89 $(BUILD_DIR)/tests/keywords/%: $(DIR)/% $(BUILD_DIR)/tests/keywords/%.attrs $(TESTBINDIR)/unittest | $(BUILD_DIR)/tests/keywords $(KEYWORD_RADDB) $(KEYWORD_LIBS) build.raddb rlm_cache_rbtree.la rlm_test.la
90 @echo UNIT-TEST $(notdir $@)
91 @if ! KEYWORD=$(notdir $@) $(TESTBIN)/unittest -D share -d src/tests/keywords/ -i $@.attrs -f $@.attrs -xx > $@.log 2>&1; then \
92 if ! grep ERROR $< 2>&1 > /dev/null; then \
95 echo KEYWORD=$(notdir $@) $(TESTBIN)/unittest -D share -d src/tests/keywords/ -i $@.attrs -f $@.attrs -xx; \
98 FOUND=$$(grep ^$< $@.log | head -1 | sed 's/:.*//;s/.*\[//;s/\].*//'); \
99 EXPECTED=$$(grep -n ERROR $< | sed 's/:.*//'); \
100 if [ "$$EXPECTED" != "$$FOUND" ]; then \
103 echo KEYWORD=$(notdir $@) $(TESTBIN)/unittest -D share -d src/tests/keywords/ -i $@.attrs -f $@.attrs -xx; \
110 # Get all of the unit test output files
112 TESTS.KEYWORDS_FILES := $(addprefix $(BUILD_DIR)/tests/keywords/,$(KEYWORD_FILES))
115 # Depend on the output files, and create the directory first.
117 tests.keywords: $(TESTS.KEYWORDS_FILES)
119 $(TESTS.KEYWORDS_FILES): $(TESTS.UNIT_FILES)
121 .PHONY: clean.tests.keywords
122 clean.tests.keywords:
123 @rm -rf $(BUILD_DIR)/tests/keywords/