ae736c07b235d0bdc7e7519482906ac41775197e
[freeradius.git] / src / tests / Makefile
1 # -*- text -*-
2 ##
3 ## Makefile -- Build and run tests for the server.
4 ##
5 ##      http://www.freeradius.org/
6 ##      $Id$
7 ##
8 #
9 include ../../Make.inc
10
11 BUILD_PATH := $(top_builddir)/build
12 TEST_PATH := $(top_builddir)/src/tests
13 BIN_PATH := $(BUILD_PATH)/bin/local
14 LIB_PATH := $(BUILD_PATH)/lib/local/.libs/
15 DYLD_LIBRARY_PATH := $(DYLD_LIBRARY_PATH):$(LIB_PATH)
16
17 export DYLD_LIBRARY_PATH
18
19 RADDB_PATH := $(top_builddir)/raddb
20
21 TESTS   = user_password chap mschapv1 digest-01/digest* test.example.com \
22         wimax
23
24 PORT     = 12340
25 #PORT    = 1812
26 ACCTPORT = $(shell expr $(PORT) + 1)
27
28 #       example.com stripped.example.com
29
30 EAPOL_TEST = eapol_test
31
32 EAP_TLS_TESTS = eap-ttls-pap.conf eap-mschapv2.conf \
33               eap-ttls-mschapv2.conf peap-mschapv2.conf
34
35 SECRET  = testing123
36
37 .PHONY: all eap dictionary clean
38
39 #
40 #       Build the directory for testing the server
41 #
42 all: tests
43
44 clean:
45         @rm -f $(RADDB_PATH)/test.conf test.conf dictionary
46
47 dictionary:
48         @echo "# test dictionary not install.  Delete at any time." > dictionary
49         @echo '$$INCLUDE ' $(top_builddir)/share/dictionary >> dictionary
50         @echo '$$INCLUDE ' $(top_builddir)/src/tests/dictionary.test >> dictionary
51
52 test.conf: dictionary
53         @echo "# test configuration file.  Do not install.  Delete at any time." > test.conf
54         @echo "libdir =" $(LIB_PATH) >> test.conf
55         @echo "testdir =" $(TEST_PATH) >> test.conf
56         @echo 'dictionary = $${testdir}' >> test.conf
57         @echo 'logdir = $${testdir}' >> test.conf
58         @echo 'radacctdir = $${testdir}' >> test.conf
59         @echo 'pidfile = $${testdir}/radiusd.pid' >> test.conf
60         @echo '$$INCLUDE radiusd.conf' >> test.conf
61         @echo '$$INCLUDE $${testdir}/config/' >> test.conf
62
63 radiusd.pid: $(RADDB_PATH)/test.conf test.conf raddb
64         @$(BIN_PATH)/radiusd -txxl $(TEST_PATH)/radius.log -md $(RADDB_PATH) -n test -i 127.0.0.1 -p $(PORT) || tail -n 20 $(TEST_PATH)/radius.log
65
66 # We can't make this depend on radiusd.pid, because then make will create
67 # radiusd.pid when we make radiusd.kill, which we don't want.
68 .PHONY: radiusd.kill
69 radiusd.kill:
70         @if [ -f radiusd.pid ]; then \
71                 (kill -TERM `cat radiusd.pid` >/dev/null 2>&1) || exit 0; \
72         fi
73         @rm -f radiusd.pid
74
75 # As test.conf includes radiusd.conf and as radiusd.conf includes everything in
76 # mods-enabled and sites-enable we need to ensure those directories have been
77 # created and are up to date.
78 .PHONY: raddb
79 raddb:
80         @$(MAKE) -C $(RADDB_PATH) mods-enabled sites-enabled
81
82 #  Link from the main database directory to here
83 $(RADDB_PATH)/test.conf: test.conf
84         @[ -f $(RADDB_PATH)/test.conf ] || ln -s ../src/tests/test.conf $(RADDB_PATH)/
85
86 # kill the server (if it's running)
87 # start the server
88 # run the tests (ignoring any failures)
89 # kill the server
90 # remove the changes to raddb/
91 tests: $(RADDB_PATH)/test.conf radiusd.kill
92         @chmod a+x runtests.sh
93         @rm -f radius.log
94         @$(MAKE) radiusd.pid
95         @BIN_PATH="$(BIN_PATH)" PORT="$(PORT)" ./runtests.sh $(TESTS)
96         @$(MAKE) radiusd.kill
97         @rm -f $(RADDB_PATH)/test.conf
98
99 tests.eap: $(RADDB_PATH)/test.conf radiusd.kill
100         @chmod a+x runtests.sh
101         @rm -f radius.log
102         @$(MAKE) radiusd.pid
103         @$(MAKE) eap
104         @$(MAKE) radiusd.kill
105         @rm -f $(RADDB_PATH)/test.conf
106
107 eap: $(EAP_TLS_TESTS)
108         for x in $(EAP_TLS_TESTS); do \
109                 $(EAPOL_TEST) -c $$x -p $(PORT) -s $(SECRET); \
110         done
111
112 md5:
113         $(EAPOL_TEST) -c eap-md5.conf -s $(SECRET) 
114
115 tls:
116         $(EAPOL_TEST) -c eap-ttls-tls.conf -s $(SECRET)
117
118 ttls:
119         $(EAPOL_TEST) -c eap-ttls-pap.conf -s $(SECRET)
120
121 peap:
122         $(EAPOL_TEST) -c peap-mschapv2.conf -s $(SECRET)
123
124 leap:
125         $(EAPOL_TEST) -c leap.conf -s $(SECRET)
126
127 ATTRS   := rfc.txt errors.txt extended.txt lucent.txt wimax.txt
128
129 attrs:  $(ATTRS) ../main/radattr
130         ../main/radattr -d ../../share rfc.txt
131
132 ${LIBRADIUS}: $(wildcard ../include/*.h) $(wildcard ../lib/*.c)
133         $(MAKE) -C ../lib all
134
135 ../main/radattr: ${LIBRADIUS} ../main/radattr.c
136         $(MAKE) -C ../main radattr