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