2 # Automatically execute the strongSwan test cases
4 # Copyright (C) 2004 Eric Marchionni, Patrik Rayo
5 # Zuercher Hochschule Winterthur
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 2 of the License, or (at your
10 # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 # RCSID $Id: do-tests,v 1.20 2006/02/08 21:27:59 as Exp $
21 source $DIR/scripts/function.sh
23 [ -f $DIR/testing.conf ] || die "Configuration file 'testing.conf' not found"
24 [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
25 [ -d $DIR/tests ] || die "Directory 'tests' not found"
27 source $DIR/testing.conf
30 ##############################################################################
31 # test if UMLs have been built at all
34 [ -d $BUILDDIR ] || die "Directory '$BUILDDIR' does not exist. Please run 'make-testing'first."
37 ##############################################################################
38 # take care of new path and file variables
41 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
43 TESTDATE=`date +%Y%m%d-%H%M`
45 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
47 TESTRESULTSHTML=$TODAYDIR/index.html
48 DEFAULTTESTSDIR=$UMLTESTDIR/testing/tests
55 ##############################################################################
56 # copy default tests to $BUILDDIR
59 TESTSDIR=$BUILDDIR/tests
60 [ -d $TESTSDIR ] || mkdir $TESTSDIR
62 cp -rfp $DEFAULTTESTSDIR/* $TESTSDIR
65 ##############################################################################
66 # assign IP for each host to hostname
69 for host in $STRONGSWANHOSTS
71 eval ip_${host}="`echo $HOSTNAMEIPS | sed -n -e "s/^.*${host}://gp" | awk -F : '{ print $1 }' | awk '{ print $1 }'`"
74 eval ip1_${host}="`echo $HOSTNAMEIPS | sed -n -e "s/^.*${host}://gp" | awk -F : '{ print $2 }' | awk '{ print $1 }'`"
75 searchandreplace PH_IP_MOON $ip_moon $TESTSDIR
76 searchandreplace PH_IP1_MOON $ip1_moon $TESTSDIR
79 eval ip1_${host}="`echo $HOSTNAMEIPS | sed -n -e "s/^.*${host}://gp" | awk -F : '{ print $2 }' | awk '{ print $1 }'`"
80 searchandreplace PH_IP_SUN $ip_sun $TESTSDIR
81 searchandreplace PH_IP1_SUN $ip1_sun $TESTSDIR
84 searchandreplace PH_IP_ALICE $ip_alice $TESTSDIR
87 searchandreplace PH_IP_VENUS $ip_venus $TESTSDIR
90 searchandreplace PH_IP_BOB $ip_bob $TESTSDIR
93 eval ip1_${host}="`echo $HOSTNAMEIPS | sed -n -e "s/^.*${host}://gp" | awk -F : '{ print $2 }' | awk '{ print $1 }'`"
94 searchandreplace PH_IP_CAROL $ip_carol $TESTSDIR
95 searchandreplace PH_IP1_CAROL $ip1_carol $TESTSDIR
98 eval ip1_${host}="`echo $HOSTNAMEIPS | sed -n -e "s/^.*${host}://gp" | awk -F : '{ print $2 }' | awk '{ print $1 }'`"
99 searchandreplace PH_IP_DAVE $ip_dave $TESTSDIR
100 searchandreplace PH_IP1_DAVE $ip1_dave $TESTSDIR
103 searchandreplace PH_IP_WINNETOU $ip_winnetou $TESTSDIR
109 ##############################################################################
110 # create header for the results html file
113 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
114 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
116 cat > $TESTRESULTSHTML <<@EOF
119 <title>strongSwan UML Testing</title>
122 <h2>strongSwan UML Testing</h2>
123 <table border="0" cellspacing="2">
124 <tr><td><b>Host:</b></td><td>`uname -a`</td></tr>
125 <tr><td><b>UML kernel: </b></td><td>$KERNEL_VERSION</td></tr>
126 <tr><td><b>IPsec:</b></td><td>$IPSEC_VERSION</td></tr>
127 <tr><td><b>Date:</b></td><td>$TESTDATE</td></tr>
130 <table border="0" width="500">
131 <thead align="left"><th>Number</th><th>Test</th><th>Result</th></thead>
134 cecho "UML kernel: $KERNEL_VERSION"
135 cecho "IPsec: $IPSEC_VERSION"
136 cecho "Date: $TESTDATE"
140 ##############################################################################
141 # enter specific test directory
147 elif [ $SELECTEDTESTSONLY = "yes" ]
149 # set internal field seperator
152 # set internal field seperator
153 TESTS="`ls $TESTSDIR`"
156 for testname in $TESTS
158 let "testnumber += 1"
159 cecho-n " $testnumber $testname.."
161 if [ ! -d $TESTSDIR/${testname} ]
163 cecho "is missing..skipped"
167 [ -f $TESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
168 [ -f $TESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
169 [ -f $TESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
170 [ -f $TESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
171 [ -f $TESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
173 TESTRESULTDIR=$TODAYDIR/$testname
175 CONSOLE_LOG=$TESTRESULTDIR/console.log
179 ##########################################################################
180 # copy test specific configurations to uml hosts and clear auth.log files
183 $DIR/scripts/load-testconfig $testname
184 source $TESTSDIR/$testname/test.conf
187 ##########################################################################
188 # run tcpdump in the background
191 if [ "$TCPDUMPHOSTS" != "" ]
193 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
195 for host_iface in $TCPDUMPHOSTS
197 host=`echo $host_iface | awk -F ":" '{print $1}'`
198 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
199 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
200 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
201 ssh root@`eval echo \\\$ip_$host '$tcpdump_cmd'`
202 eval TDUP_${host}="true"
206 ##########################################################################
207 # execute pre-test commands
211 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
216 printf("echo \"%s# %s\"; ", $1, $2)
217 printf("ssh root@\044ip_%s \"%s\"; ", $1, $2)
220 }' $TESTSDIR/${testname}/pretest.dat` >> $CONSOLE_LOG 2>&1
223 ##########################################################################
227 function stop_tcpdump {
228 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
229 eval ssh root@\$ip_${1} killall tcpdump
230 eval TDUP_${1}="false"
235 ##########################################################################
236 # get and evaluate test results
240 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
251 if (command == "tcpdump")
253 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
254 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
255 printf("ssh root@\044ip_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
259 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
260 printf("ssh root@\044ip_%s %s | grep \"%s\"; ", host, command, pattern)
262 printf("cmd_exit=\044?; ")
264 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
265 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
266 printf("; then STATUS=\"failed\"; fi; \n")
269 }' $TESTSDIR/${testname}/evaltest.dat` >> $CONSOLE_LOG 2>&1
272 ##########################################################################
276 if [ $STATUS = "failed" ]
278 let "failed_cnt += 1"
280 let "passed_cnt += 1"
284 ##########################################################################
285 # log statusall and listall output
286 # get copies of ipsec.conf, ipsec.secrets
287 # create index.html for the given test case
289 cat > $TESTRESULTDIR/index.html <<@EOF
292 <title>Test $testname</title>
295 <table border="0" width="600">
297 <h2>Test $testname</h2>
301 cat $TESTSDIR/${testname}/description.txt >> $TESTRESULTDIR/index.html
303 cat >> $TESTRESULTDIR/index.html <<@EOF
305 <li><a href="console.log">console.log</a></li>
307 <img src="../images/$DIAGRAM" alt="$UMLHOSTS">
311 for host in $IPSECHOSTS
313 eval HOSTLOGIN=root@\$ip_${host}
315 for command in statusall listall
317 ssh $HOSTLOGIN ipsec $command \
318 > $TESTRESULTDIR/${host}.$command 2>/dev/null
321 for file in ipsec.conf ipsec.secrets
323 scp $HOSTLOGIN:/etc/$file \
324 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
327 cat >> $TESTRESULTDIR/index.html <<@EOF
330 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
331 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
332 <li><a href="$host.statusall">ipsec statusall</a></li>
333 <li><a href="$host.listall">ipsec listall</a></li>
334 <li><a href="$host.auth.log">auth.log</a></li>
340 cat >> $TESTRESULTDIR/index.html <<@EOF
342 <tr><td align="right">
343 <b><a href="../index.html">Back</a></b>
351 ##########################################################################
352 # execute post-test commands
356 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
361 printf("echo \"%s# %s\"; ", $1, $2)
362 printf("ssh root@\044ip_%s \"%s\"; ", $1, $2)
365 }' $TESTSDIR/${testname}/posttest.dat` >> $CONSOLE_LOG 2>&1
368 ##########################################################################
369 # get a copy of /var/log/auth.log
372 for host in $IPSECHOSTS
374 eval HOSTLOGIN=root@\$ip_${host}
375 ssh $HOSTLOGIN grep pluto /var/log/auth.log \
376 > $TESTRESULTDIR/${host}.auth.log
377 echo >> $TESTRESULTDIR/${host}.auth.log
378 ssh $HOSTLOGIN grep charon /var/log/auth.log \
379 >> $TESTRESULTDIR/${host}.auth.log
383 ##########################################################################
384 # stop tcpdump if necessary
387 for host in $TCPDUMPHOSTS
389 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
391 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
392 eval ssh root@\$ip_$host killall tcpdump
393 eval TDUP_${host}="false"
398 ##########################################################################
399 # copy default host config back if necessary
402 $DIR/scripts/restore-defaults $testname
405 ##########################################################################
406 # write test status to html file
410 if [ $STATUS = "passed" ]
417 cat >> $TESTRESULTSHTML << @EOF
420 <td><a href="$testname/">$testname</a></td>
421 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
428 ##############################################################################
429 # finish the results html file
432 cat >> $TESTRESULTSHTML << @EOF
435 <b>Passed: $passed_cnt</b><br>
436 <b>Failed: $failed_cnt</b><br>
443 cecho "Passed: $passed_cnt"
444 cecho "Failed: $failed_cnt"
448 ##############################################################################
449 # copy the test results to the apache server
452 HTDOCS="/var/www/localhost/htdocs"
454 cecho-n "Copying test results to winnetou.."
455 ssh root@${ip_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
456 scp -r $TODAYDIR root@${ip_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
457 ssh root@${ip_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
460 cecho "The results are available in $TODAYDIR"
461 cecho "or via the link http://$ip_winnetou/testresults/$TESTDATE"