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 ALLHTML=$TODAYDIR/all.html
49 DEFAULTTESTSDIR=$UMLTESTDIR/testing/tests
56 ##############################################################################
57 # copy default tests to $BUILDDIR
60 TESTSDIR=$BUILDDIR/tests
61 [ -d $TESTSDIR ] || mkdir $TESTSDIR
63 ##############################################################################
64 # assign IP for each host to hostname
67 for host in $STRONGSWANHOSTS
69 eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
70 eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
74 eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
75 eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
78 eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
79 eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
88 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
89 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
92 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
93 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
101 ##############################################################################
102 # create header for the results html file
105 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
106 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
108 cat > $TESTRESULTSHTML <<@EOF
111 <title>strongSwan UML Testing</title>
114 <h2>strongSwan UML Testing</h2>
115 <table border="0" cellspacing="2">
116 <tr><td><b>Host:</b></td><td>`uname -a`</td></tr>
117 <tr><td><b>UML kernel: </b></td><td>$KERNEL_VERSION</td></tr>
118 <tr><td><b>IPsec:</b></td><td>$IPSEC_VERSION</td></tr>
119 <tr><td><b>Date:</b></td><td>$TESTDATE</td></tr>
122 <table border="0" width="500">
123 <thead align="left"><th>Number</th><th>Test</th><th>Result</th></thead>
126 cat > $ALLHTML <<@EOF
129 <title>strongSwan UML Testing</title>
132 <h2>strongSwan UML Testing</h2>
133 <table border="0" cellspacing="2">
134 <tr><td><b>Host:</b></td><td>`uname -a`</td></tr>
135 <tr><td><b>UML kernel: </b></td><td>$KERNEL_VERSION</td></tr>
136 <tr><td><b>IPsec:</b></td><td>$IPSEC_VERSION</td></tr>
137 <tr><td><b>Date:</b></td><td>$TESTDATE</td></tr>
138 <tr><td colspan="2"> </td></tr>
141 cecho "UML kernel: $KERNEL_VERSION"
142 cecho "IPsec: $IPSEC_VERSION"
143 cecho "Date: $TESTDATE"
147 ##############################################################################
148 # enter specific test directory
154 elif [ $SELECTEDTESTSONLY = "yes" ]
156 # set internal field seperator
159 # set internal field seperator
160 TESTS="`ls $DEFAULTTESTSDIR`"
165 SUBTESTS="`basename $SUBDIR`"
167 if [ $SUBTESTS = $SUBDIR ]
169 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
171 SUBDIR="`dirname $SUBDIR`"
174 if [ ! -d $TODAYDIR/$SUBDIR ]
176 mkdir $TODAYDIR/$SUBDIR
177 echo "<tr><td> </td><td><a href=\"$SUBDIR\">$SUBDIR</a></td>" >> $ALLHTML
180 for name in $SUBTESTS
182 let "testnumber += 1"
183 testname=$SUBDIR/$name
184 cecho-n " $testnumber $testname.."
186 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
188 cecho "is missing..skipped"
192 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
193 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
194 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
195 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
196 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
198 TESTRESULTDIR=$TODAYDIR/$testname
199 mkdir -p $TESTRESULTDIR
200 CONSOLE_LOG=$TESTRESULTDIR/console.log
203 TESTDIR=$TESTSDIR/${testname}
206 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
209 ##############################################################################
210 # replace IP wildcards with actual IPv4 and IPv6 addresses
213 for host in $STRONGSWANHOSTS
217 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
218 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
219 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
220 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
223 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
224 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
225 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
226 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
229 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
230 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
233 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
234 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
237 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
238 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
241 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
242 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
243 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
244 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
247 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
248 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
249 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
250 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
253 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
254 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
260 ##########################################################################
261 # copy test specific configurations to uml hosts and clear auth.log files
264 $DIR/scripts/load-testconfig $testname
265 source $TESTDIR/test.conf
268 ##########################################################################
269 # run tcpdump in the background
272 if [ "$TCPDUMPHOSTS" != "" ]
274 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
276 for host_iface in $TCPDUMPHOSTS
278 host=`echo $host_iface | awk -F ":" '{print $1}'`
279 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
280 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
281 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
282 ssh root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
283 eval TDUP_${host}="true"
288 ##########################################################################
289 # execute pre-test commands
293 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
298 printf("echo \"%s# %s\"; ", $1, $2)
299 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
302 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
305 ##########################################################################
309 function stop_tcpdump {
310 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
311 eval ssh root@\$ipv4_${1} killall tcpdump
312 eval TDUP_${1}="false"
317 ##########################################################################
318 # get and evaluate test results
322 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
333 if (command == "tcpdump")
335 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
336 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
337 printf("ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
341 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
342 printf("ssh root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
344 printf("cmd_exit=\044?; ")
346 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
347 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
348 printf("; then STATUS=\"failed\"; fi; \n")
350 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
353 ##########################################################################
357 if [ $STATUS = "failed" ]
359 let "failed_cnt += 1"
361 let "passed_cnt += 1"
365 ##########################################################################
366 # log statusall and listall output
367 # get copies of ipsec.conf, ipsec.secrets
368 # create index.html for the given test case
370 cat > $TESTRESULTDIR/index.html <<@EOF
373 <title>Test $testname</title>
376 <table border="0" width="600">
378 <h2>Test $testname</h2>
382 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
384 cat >> $TESTRESULTDIR/index.html <<@EOF
386 <li><a href="console.log">console.log</a></li>
388 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
391 for host in $IPSECHOSTS
393 eval HOSTLOGIN=root@\$ipv4_${host}
395 for command in statusall listall
397 ssh $HOSTLOGIN ipsec $command \
398 > $TESTRESULTDIR/${host}.$command 2>/dev/null
401 for file in ipsec.conf ipsec.secrets
403 scp $HOSTLOGIN:/etc/$file \
404 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
407 ssh $HOSTLOGIN ip route list \
408 > $TESTRESULTDIR/${host}.iproute 2>/dev/null
409 ssh $HOSTLOGIN iptables -v -n -L \
410 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
411 cat >> $TESTRESULTDIR/index.html <<@EOF
413 <table border="0" cellspacing="0" width="400">
417 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
418 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
419 <li><a href="$host.statusall">ipsec statusall</a></li>
420 <li><a href="$host.listall">ipsec listall</a></li>
425 <li><a href="$host.auth.log">auth.log</a></li>
426 <li><a href="$host.daemon.log">daemon.log</a></li>
427 <li><a href="$host.iproute">ip route list</a></li>
428 <li><a href="$host.iptables">iptables -L</a></li>
437 cat >> $TESTRESULTDIR/index.html <<@EOF
439 <tr><td align="right">
440 <b><a href="../index.html">Back</a></b>
448 ##########################################################################
449 # execute post-test commands
453 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
458 printf("echo \"%s# %s\"; ", $1, $2)
459 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
462 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
465 ##########################################################################
466 # get a copy of /var/log/auth.log
469 for host in $IPSECHOSTS
471 eval HOSTLOGIN=root@\$ipv4_${host}
472 ssh $HOSTLOGIN grep pluto /var/log/auth.log \
473 > $TESTRESULTDIR/${host}.auth.log
474 echo >> $TESTRESULTDIR/${host}.auth.log
475 ssh $HOSTLOGIN grep charon /var/log/auth.log \
476 >> $TESTRESULTDIR/${host}.auth.log
480 ##########################################################################
481 # get a copy of /var/log/daemon.log
484 for host in $IPSECHOSTS
486 eval HOSTLOGIN=root@\$ipv4_${host}
487 ssh $HOSTLOGIN grep pluto /var/log/daemon.log \
488 > $TESTRESULTDIR/${host}.daemon.log
489 echo >> $TESTRESULTDIR/${host}.daemon.log
490 ssh $HOSTLOGIN grep charon /var/log/daemon.log \
491 >> $TESTRESULTDIR/${host}.daemon.log
495 ##########################################################################
496 # stop tcpdump if necessary
499 for host in $TCPDUMPHOSTS
501 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
503 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
504 eval ssh root@\$ipv4_$host killall tcpdump
505 eval TDUP_${host}="false"
510 ##########################################################################
511 # copy default host config back if necessary
514 $DIR/scripts/restore-defaults $testname
517 ##########################################################################
518 # write test status to html file
522 if [ $STATUS = "passed" ]
529 cat >> $TESTRESULTSHTML << @EOF
532 <td><a href="$testname/">$testname</a></td>
533 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
541 ##############################################################################
542 # finish the results html file
545 cat >> $TESTRESULTSHTML << @EOF
548 <b>Passed: $passed_cnt</b><br>
549 <b>Failed: $failed_cnt</b><br>
555 cat >> $ALLHTML << @EOF
562 cecho "Passed: $passed_cnt"
563 cecho "Failed: $failed_cnt"
567 ##############################################################################
568 # copy the test results to the apache server
571 HTDOCS="/var/www/localhost/htdocs"
573 cecho-n "Copying test results to winnetou.."
574 ssh root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
575 scp -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
576 ssh root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
579 cecho "The results are available in $TODAYDIR"
580 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"