Initial stab at an automated test harness for FreeRADIUS.
[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/ -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 cp users raddb/
72 start_radiusd
73 echo "Running tests..."
74
75
76 (cd .cache;ls -1  > ../.foo)
77 rm -f .bar
78 for x in `cat .foo`
79 do
80    echo "-f .cache/$x" >> .bar
81 done
82
83 ../main/radclient `cat .bar` -xFd ./raddb 127.0.0.1:$PORT auth testing123 > radclient.log 2>&1
84
85 for x in `cat .foo`
86 do
87   RESULT=`egrep ^\\.cache/$x radclient.log | sed 's/.* //'`
88   if [ "$RESULT" = "2" ]; then
89       echo "$x : Success"
90     else
91       echo "$x : FAILED"
92       RCODE=1
93   fi
94 done
95
96
97 pidkill $PID
98
99 if [ "$RCODE" = "0" ]
100 then
101     rm -f radiusd.log radclient.log 
102     echo "All tests succeeded"
103 else
104     echo "See radclient.log for more details"
105 fi
106
107 exit $RCODE