Much better way of starting the server and running the tests
authoraland <aland>
Tue, 1 Jan 2008 15:25:22 +0000 (15:25 +0000)
committeraland <aland>
Tue, 1 Jan 2008 15:25:22 +0000 (15:25 +0000)
src/tests/Makefile
src/tests/runtests.sh

index c84958b..6917afd 100644 (file)
@@ -4,6 +4,8 @@ TESTS   = user_password chap mschapv1 digest-auth-MD5 digest-auth-int \
        digest-auth-noalgo digest-md5-sess digest-auth-MD5_Sess \
        digest-auth_int-MD5 digest-auth_int-MD5_Sess digest-auth_int-noalgo
 
+PORT   = 12340
+
 #      example.com stripped.example.com
 
 EAPOL_TEST = eapol_test
@@ -12,7 +14,7 @@ EAP_TLS_TESTS = eap-ttls-pap.conf eap-ttls-mschapv2.conf peap-mschapv2.conf
 
 SECRET = testing123
 
-.PHONY: all eap test.conf dictionary clean
+.PHONY: all eap dictionary clean
 
 #
 #      Build the directory for testing the server
@@ -22,20 +24,37 @@ all: tests
 clean:
        @rm -f ../../raddb/test.conf test.conf dictionary
 
-test.conf:
+dictionary:
+       @echo "# test dictionary not install.  Delete at any time." > dictionary
+       @echo '$$INCLUDE ' $(top_builddir)/share/dictionary >> dictionary
+       @echo '$$INCLUDE ' $(top_builddir)/src/tests/dictionary.test >> dictionary
+
+test.conf: dictionary
        @echo "# test configuration file.  Do not install.  Delete at any time." > test.conf
        @echo "libdir =" $(top_builddir)/src/modules/lib >> test.conf
-       @echo "dictionary =" $(top_builddir)/src/tests/ >> test.conf
        @echo "testdir =" $(top_builddir)/src/tests/ >> test.conf
+       @echo 'dictionary = $${testdir}' >> test.conf
+       @echo 'logdir = $${testdir}' >> test.conf
+       @echo 'pidfile = $${testdir}/radiusd.pid' >> test.conf
        @echo '$$INCLUDE radiusd.conf' >> test.conf
        @echo '$$INCLUDE $${testdir}/config/' >> test.conf
        @[ -f ../../raddb/test.conf ] || ln -s ../src/tests/test.conf ../../raddb/
 
-dictionary:
-       @echo '$$INCLUDE ' $(top_builddir)/share/dictionary > dictionary
-       @echo '$$INCLUDE ' $(top_builddir)/src/tests/dictionary.test >> dictionary
+radiusd.pid: test.conf
+       @../main/radiusd -md ../../raddb/ -n test -i 127.0.0.1 -p $(PORT)
+
+# We can't make this depend on radiusd.pid, because then make will create
+# radiusd.pid when we make radiusd.kill, which we don't want.
+.PHONY: radiusd.kill
+radiusd.kill:
+       @if [ -f radiusd.pid ]; then \
+               kill -TERM `cat radiusd.pid`; \
+       fi
+       @rm -f radiusd.pid
 
 tests: test.conf dictionary
+       @$(MAKE) radiusd.kill
+       @$(MAKE) radiusd.pid
        @chmod a+x runtests.sh
        ./runtests.sh $(TESTS)
 
index f073392..4e9bb26 100644 (file)
@@ -3,37 +3,6 @@
 PORT=12340
 HOME_PORT=12350
 
-# Sends a signal which checks if the process is active (doesn't kill anything)
-function pidactive () {
-    kill -0 $1 2> /dev/null
-    return
-}
-
-# Kill a particular process
-function pidkill () {
-    kill $1 || return
-    #adjust depending how long it takes to die gracefully
-    sleep 1    
-    if pidactive $1; then
-        #escalating
-        kill -9 $1
-    fi  
-}
-
-# Starts the server
-function start_radiusd () {
-    ../main/radiusd -Xmd ../../raddb/ -n test -i 127.0.0.1 -p $PORT > radiusd.log 2>&1 &
-    PID=$!
-#wait for the process to startup or die...
-    sleep 3
-    if ! pidactive $PID; then
-       wait $PID
-       tail -5 radiusd.log
-       echo "Command failed with $?"
-        exit 1
-    fi
-}
-
 rm -f verbose.log
 RCODE=0
 
@@ -64,14 +33,8 @@ do
   done
 done
 
-#
-#  Now run the tests
-#
-echo "Starting radiusd..."
-start_radiusd
 echo "Running tests..."
 
-
 (cd .cache;ls -1  > ../.foo)
 rm -f .bar
 for x in `cat .foo`
@@ -93,8 +56,6 @@ do
 done
 
 
-pidkill $PID
-
 if [ "$RCODE" = "0" ]
 then
     rm -f radiusd.log radclient.log