Better test harness using virtual servers
[freeradius.git] / src / tests / runtests.sh
1 #!/bin/bash
2
3 PORT=12340
4 HOME_PORT=12350
5
6 # Sends a signal which checks if the process is active (doesn't kill anything)
7 function pidactive () {
8     kill -0 $1 2> /dev/null
9     return
10 }
11
12 # Kill a particular process
13 function pidkill () {
14     kill $1 || return
15     #adjust depending how long it takes to die gracefully
16     sleep 1    
17     if pidactive $1; then
18         #escalating
19         kill -9 $1
20     fi  
21 }
22
23 # Starts the server
24 function start_radiusd () {
25     ../main/radiusd -Xmd ../../raddb/ -n test -i 127.0.0.1 -p $PORT > radiusd.log 2>&1 &
26     PID=$!
27 #wait for the process to startup or die...
28     sleep 3
29     if ! pidactive $PID; then
30         wait $PID
31         tail -5 radiusd.log
32         echo "Command failed with $?"
33         exit 1
34     fi
35 }
36
37 rm -f verbose.log
38 RCODE=0
39
40 rm -rf .cache
41 mkdir .cache
42
43 #
44 #  Bootstrap the tests
45 #
46 for NAME in $@
47 do
48   TOTAL=`grep TESTS $NAME | sed 's/.*TESTS//'`
49
50   #
51   #  Each test may have multiple variants.
52   #
53   for NUMBER in `echo $TOTAL`
54   do
55     cp $NAME .request
56
57     #
58     #  Add the name of the test, and the variant to the request
59     #
60     echo "Test-Name = \"$NAME\"," >> .request
61     echo 'Test-Number = ' $NUMBER >> .request
62
63     mv .request .cache/$NAME:$NUMBER
64   done
65 done
66
67 #
68 #  Now run the tests
69 #
70 echo "Starting radiusd..."
71 start_radiusd
72 echo "Running tests..."
73
74
75 (cd .cache;ls -1  > ../.foo)
76 rm -f .bar
77 for x in `cat .foo`
78 do
79    echo "-f .cache/$x" >> .bar
80 done
81
82 ../main/radclient `cat .bar` -xFd . 127.0.0.1:$PORT auth testing123 > radclient.log 2>&1
83
84 for x in `cat .foo`
85 do
86   RESULT=`egrep ^\\.cache/$x radclient.log | sed 's/.* //'`
87   if [ "$RESULT" = "2" ]; then
88       echo "$x : Success"
89     else
90       echo "$x : FAILED"
91       RCODE=1
92   fi
93 done
94
95
96 pidkill $PID
97
98 if [ "$RCODE" = "0" ]
99 then
100     rm -f radiusd.log radclient.log 
101     echo "All tests succeeded"
102 else
103     echo "See radclient.log for more details"
104 fi
105
106 exit $RCODE