75e37b2572e56a9f18f0d3c63bbfafdb6e6a2c6d
[freeradius.git] / src / tests / keywords / all.mk
1 #
2 #  Unit tests for unlang keywords
3 #
4
5 #
6 #  The test files are files without extensions.
7 #  The list is unordered.  The order is added in the next step by looking
8 #  at precursors.
9 #
10 KEYWORD_FILES := $(filter-out %.conf %.md %.attrs %.mk %~ %.rej,$(subst $(DIR)/,,$(wildcard $(DIR)/*)))
11
12 ifeq "$(OPENSSL_LIBS)" ""
13 KEYWORD_FILES := $(filter-out pap-ssha2,$(KEYWORD_FILES))
14 endif
15
16 #
17 #  Create the output directory
18 #
19 .PHONY: $(BUILD_DIR)/tests/keywords
20 $(BUILD_DIR)/tests/keywords:
21         @mkdir -p $@
22
23 #
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.
27 #
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))
31
32 #
33 #  For each file, look for precursor test.
34 #  Ensure that each test depends on its precursors.
35 #
36 -include $(BUILD_DIR)/tests/keywords/depends.mk
37
38 export OPENSSL_LIBS
39
40 $(BUILD_DIR)/tests/keywords/depends.mk: $(addprefix $(DIR)/,$(KEYWORD_FILES)) | $(BUILD_DIR)/tests/keywords
41         @rm -f $@
42         @for x in $^; do \
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" >> $@; \
47                         echo "" >> $@; \
48                 fi \
49         done
50
51 #
52 #  These ones get copied over from the default input
53 #
54 $(BOOTSTRAP): $(DIR)/default-input.attrs | $(BUILD_DIR)/tests/keywords
55         @cp $< $@
56
57 #
58 #  These ones get copied over from their original files
59 #
60 $(BUILD_DIR)/tests/keywords/%.attrs: $(DIR)/%.attrs | $(BUILD_DIR)/tests/keywords
61         @cp $< $@
62
63 #
64 #  Don't auto-remove the files copied by the rule just above.
65 #  It's unnecessary, and it clutters the output with crap.
66 #
67 .PRECIOUS: $(BUILD_DIR)/tests/keywords/%.attrs
68
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
72
73 #
74 #  Files in the output dir depend on the unit tests
75 #
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
80 #
81 #  Auto-depend on modules via $(shell grep INCLUDE $(DIR)/radiusd.conf | grep mods-enabled | sed 's/.*}/raddb/'))
82 #
83 #  If the test fails, then look for ERROR in the input.  No error
84 #  means it's unexpected, so we die.
85 #
86 #  Otherwise, check the log file for a parse error which matches the
87 #  ERROR line in the input.
88 #
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 \
93                         cat $@.log; \
94                         echo "# $@.log"; \
95                         echo KEYWORD=$(notdir $@) $(TESTBIN)/unittest -D share -d src/tests/keywords/ -i $@.attrs -f $@.attrs -xx; \
96                         exit 1; \
97                 fi; \
98                 FOUND=$$(grep ^$< $@.log | head -1 | sed 's/:.*//;s/.*\[//;s/\].*//'); \
99                 EXPECTED=$$(grep -n ERROR $< | sed 's/:.*//'); \
100                 if [ "$$EXPECTED" != "$$FOUND" ]; then \
101                         cat $@.log; \
102                         echo "# $@.log"; \
103                         echo KEYWORD=$(notdir $@) $(TESTBIN)/unittest -D share -d src/tests/keywords/ -i $@.attrs -f $@.attrs -xx; \
104                         exit 1; \
105                 fi \
106         fi
107         @touch $@
108
109 #
110 #  Get all of the unit test output files
111 #
112 TESTS.KEYWORDS_FILES := $(addprefix $(BUILD_DIR)/tests/keywords/,$(KEYWORD_FILES))
113
114 #
115 #  Depend on the output files, and create the directory first.
116 #
117 tests.keywords: $(TESTS.KEYWORDS_FILES)
118
119 $(TESTS.KEYWORDS_FILES): $(TESTS.UNIT_FILES)
120
121 .PHONY: clean.tests.keywords
122 clean.tests.keywords:
123         @rm -rf $(BUILD_DIR)/tests/keywords/