Merge branch 'master' of github.com:FreeRADIUS/freeradius-server
[freeradius.git] / src / tests / runtests.sh
1 #!/bin/bash
2
3 # BIN_PATH should be specified by the caller
4 #BIN_PATH=../main/
5
6 PORT=12340
7 HOME_PORT=12350
8 SECRET=testing123
9
10 rm -f verbose.log
11 RCODE=0
12
13 rm -rf .cache
14 mkdir .cache
15
16 #
17 #  Bootstrap the tests
18 #
19 for NAME in $@
20 do
21   TOTAL=`grep TESTS $NAME | sed 's/.*TESTS//'`
22
23   #
24   #  Each test may have multiple variants.
25   #
26   for NUMBER in `echo $TOTAL`
27   do
28     cp $NAME .request
29     BASE=`echo $NAME | sed 's,.*/,,'`
30
31     #
32     #  Add the name of the test, and the variant to the request
33     #
34     echo "Test-Name = \"$BASE\"," >> .request
35     echo 'Test-Number = ' $NUMBER >> .request
36
37     mv .request .cache/$BASE:$NUMBER
38   done
39 done
40
41 echo "Running tests..."
42
43 (cd .cache;ls -1  > ../.foo)
44 rm -f .bar
45 for x in `cat .foo`
46 do
47    echo "-f .cache/$x" >> .bar
48 done
49
50 $BIN_PATH/radclient `cat .bar` -xFd . 127.0.0.1:$PORT auth $SECRET > radclient.log 2>&1
51 if [ "$?" != "0" ]; then
52   echo "Failed running $BIN_PATH/radclient"
53   exit 1
54 fi
55
56 for x in `cat .foo`
57 do
58   RESULT=`egrep ^\\.cache/$x radclient.log | sed 's/.* //'`
59   if [ "$RESULT" = "2" ]; then
60       echo "$x : Success"
61     else
62       echo "$x : FAILED"
63       RCODE=1
64   fi
65 done
66
67
68 if [ "$RCODE" = "0" ]
69 then
70     rm -f radiusd.log radclient.log 
71     echo "All tests succeeded"
72 else
73     echo "See radclient.log for more details"
74 fi
75
76 exit $RCODE