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
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/all.html
48 INDEX=$TODAYDIR/index.html
49 DEFAULTTESTSDIR=$UMLTESTDIR/testing/tests
51 SOURCEIP_ROUTING_TABLE=@IPSEC_ROUTING_TABLE@
58 ##############################################################################
59 # copy default tests to $BUILDDIR
62 TESTSDIR=$BUILDDIR/tests
63 [ -d $TESTSDIR ] || mkdir $TESTSDIR
65 ##############################################################################
66 # assign IP for each host to hostname
69 for host in $STRONGSWANHOSTS
71 eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
72 eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
76 eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
77 eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
80 eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
81 eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
84 eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
85 eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
92 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
93 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
96 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
97 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
105 ##############################################################################
106 # create header for the results html file
109 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
110 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
115 <title>strongSwan UML Tests</title>
118 <h2>strongSwan UML Tests</h2>
119 <table border="0" cellspacing="2">
121 <td><b>Host:</b></td>
122 <td colspan="3">`uname -a`</td>
125 <td><b>UML kernel: </b></td>
126 <td colspan="3">$KERNEL_VERSION</td>
129 <td><b>IPsec:</b></td>
130 <td colspan="3">$IPSEC_VERSION</td>
133 <td><b>Date:</b></td>
134 <td colspan="3">$TESTDATE</td>
137 <td width="100"> </td>
138 <td width="200"> </td>
139 <td width=" 50"> </td>
144 cat $INDEX > $TESTRESULTSHTML
145 cat >> $TESTRESULTSHTML <<@EOF
149 <th colspan="2">Result</th>
153 cecho "UML kernel: $KERNEL_VERSION"
154 cecho "IPsec: $IPSEC_VERSION"
155 cecho "Date: $TESTDATE"
159 ##############################################################################
160 # enter specific test directory
166 elif [ $SELECTEDTESTSONLY = "yes" ]
168 # set internal field seperator
171 # set internal field seperator
172 TESTS="`ls $DEFAULTTESTSDIR`"
177 SUBTESTS="`basename $SUBDIR`"
179 if [ $SUBTESTS = $SUBDIR ]
181 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
183 SUBDIR="`dirname $SUBDIR`"
186 if [ ! -d $TODAYDIR/$SUBDIR ]
188 mkdir $TODAYDIR/$SUBDIR
189 if [ $testnumber == 0 ]
191 FIRST="<b>Category:</b"
195 echo " <tr>" >> $INDEX
196 echo " <td>$FIRST</td>">> $INDEX
197 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
198 echo " <td align=\"right\">x</td>" >> $INDEX
199 echo " <td> </td>" >> $INDEX
200 echo " </tr>" >> $INDEX
201 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
202 cat > $SUBTESTSINDEX <<@EOF
205 <title>strongSwan $SUBDIR Tests</title>
208 <h2>strongSwan $SUBDIR Tests</h2>
209 <table border="0" cellspacing="2">
211 <td><b>UML kernel: </b></td>
212 <td colspan="3">$KERNEL_VERSION</td>
215 <td><b>IPsec:</b></td>
216 <td colspan="3">$IPSEC_VERSION</td>
219 <td><b>Date:</b></td>
220 <td colspan="3">$TESTDATE</td>
223 <td width="100"> </td>
224 <td width="200"> </td>
225 <td width=" 50"> </td>
231 <th colspan="2">Result</th>
236 if [ $SUBDIR = "ipv6" ]
243 for name in $SUBTESTS
245 let "testnumber += 1"
246 testname=$SUBDIR/$name
247 cecho-n " $testnumber $testname.."
249 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
251 cecho "is missing..skipped"
255 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
256 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
257 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
258 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
259 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
261 TESTRESULTDIR=$TODAYDIR/$testname
262 mkdir -p $TESTRESULTDIR
263 CONSOLE_LOG=$TESTRESULTDIR/console.log
266 TESTDIR=$TESTSDIR/${testname}
269 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
272 ##############################################################################
273 # replace IP wildcards with actual IPv4 and IPv6 addresses
276 for host in $STRONGSWANHOSTS
280 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
281 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
282 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
283 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
286 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
287 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
288 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
289 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
292 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
293 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
294 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
295 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
298 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
299 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
302 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
303 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
306 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
307 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
308 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
309 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
312 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
313 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
314 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
315 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
318 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
319 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
325 ##########################################################################
326 # copy test specific configurations to uml hosts and clear auth.log files
329 $DIR/scripts/load-testconfig $testname
330 source $TESTDIR/test.conf
333 ##########################################################################
334 # run tcpdump in the background
337 if [ "$TCPDUMPHOSTS" != "" ]
339 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
341 for host_iface in $TCPDUMPHOSTS
343 host=`echo $host_iface | awk -F ":" '{print $1}'`
344 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
345 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
346 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
347 ssh root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
348 eval TDUP_${host}="true"
353 ##########################################################################
354 # execute pre-test commands
358 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
363 printf("echo \"%s# %s\"; ", $1, $2)
364 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
367 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
370 ##########################################################################
374 function stop_tcpdump {
375 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
376 eval ssh root@\$ipv4_${1} killall tcpdump
377 eval TDUP_${1}="false"
382 ##########################################################################
383 # get and evaluate test results
387 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
398 if (command == "tcpdump")
400 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
401 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
402 printf("ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
406 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
407 printf("ssh root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
409 printf("cmd_exit=\044?; ")
411 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
412 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
413 printf("; then STATUS=\"failed\"; fi; \n")
415 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
418 ##########################################################################
422 if [ $STATUS = "failed" ]
424 let "failed_cnt += 1"
426 let "passed_cnt += 1"
430 ##########################################################################
431 # log statusall and listall output
432 # get copies of ipsec.conf, ipsec.secrets
433 # create index.html for the given test case
435 cat > $TESTRESULTDIR/index.html <<@EOF
438 <title>Test $testname</title>
441 <table border="0" width="600">
443 <h2>Test $testname</h2>
447 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
449 cat >> $TESTRESULTDIR/index.html <<@EOF
451 <li><a href="console.log">console.log</a></li>
453 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
456 for host in $IPSECHOSTS
458 eval HOSTLOGIN=root@\$ipv4_${host}
460 for command in statusall listall
462 ssh $HOSTLOGIN ipsec $command \
463 > $TESTRESULTDIR/${host}.$command 2>/dev/null
466 for file in strongswan.conf ipsec.conf ipsec.secrets
468 scp $HOSTLOGIN:/etc/$file \
469 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
472 if [ $SUBDIR = "sql" ]
474 scp $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
475 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
477 touch $TESTRESULTDIR/${host}.ipsec.sql
480 ssh $HOSTLOGIN ip xfrm policy \
481 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
482 ssh $HOSTLOGIN ip xfrm state \
483 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
484 ssh $HOSTLOGIN ip route list table $SOURCEIP_ROUTING_TABLE \
485 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
486 ssh $HOSTLOGIN $IPTABLES -v -n -L \
487 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
488 cat >> $TESTRESULTDIR/index.html <<@EOF
490 <table border="0" cellspacing="0" width="600">
494 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
495 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
496 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
497 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
502 <li><a href="$host.statusall">ipsec statusall</a></li>
503 <li><a href="$host.listall">ipsec listall</a></li>
504 <li><a href="$host.auth.log">auth.log</a></li>
505 <li><a href="$host.daemon.log">daemon.log</a></li>
510 <li><a href="$host.ip.policy">ip xfrm policy</a></li>
511 <li><a href="$host.ip.state">ip xfrm state</a></li>
512 <li><a href="$host.ip.route">ip route list table $SOURCEIP_ROUTING_TABLE</a></li>
513 <li><a href="$host.iptables">$IPTABLES -L</a></li>
522 cat >> $TESTRESULTDIR/index.html <<@EOF
524 <tr><td align="right">
525 <b><a href="../index.html">Back</a></b>
533 ##########################################################################
534 # execute post-test commands
538 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
543 printf("echo \"%s# %s\"; ", $1, $2)
544 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
547 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
550 ##########################################################################
551 # get a copy of /var/log/auth.log
554 for host in $IPSECHOSTS
556 eval HOSTLOGIN=root@\$ipv4_${host}
557 ssh $HOSTLOGIN grep pluto /var/log/auth.log \
558 > $TESTRESULTDIR/${host}.auth.log
559 echo >> $TESTRESULTDIR/${host}.auth.log
560 ssh $HOSTLOGIN grep charon /var/log/auth.log \
561 >> $TESTRESULTDIR/${host}.auth.log
565 ##########################################################################
566 # get a copy of /var/log/daemon.log
569 for host in $IPSECHOSTS
571 eval HOSTLOGIN=root@\$ipv4_${host}
572 ssh $HOSTLOGIN grep pluto /var/log/daemon.log \
573 > $TESTRESULTDIR/${host}.daemon.log
574 echo >> $TESTRESULTDIR/${host}.daemon.log
575 ssh $HOSTLOGIN grep charon /var/log/daemon.log \
576 >> $TESTRESULTDIR/${host}.daemon.log
580 ##########################################################################
581 # stop tcpdump if necessary
584 for host in $TCPDUMPHOSTS
586 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
588 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
589 eval ssh root@\$ipv4_$host killall tcpdump
590 eval TDUP_${host}="false"
595 ##########################################################################
596 # copy default host config back if necessary
599 $DIR/scripts/restore-defaults $testname
602 ##########################################################################
603 # write test status to html file
606 if [ $STATUS = "passed" ]
609 cecho "\033[1;32m$STATUS"
615 cat >> $TESTRESULTSHTML << @EOF
618 <td><a href="$testname/">$testname</a></td>
619 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
623 cat >> $SUBTESTSINDEX << @EOF
626 <td><a href="$name/">$name</a></td>
627 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
637 ##############################################################################
638 # finish the results html file
641 cat >> $TESTRESULTSHTML << @EOF
644 <b>Passed: <font color="green">$passed_cnt</font></b><br>
645 <b>Failed: <font color="red">$failed_cnt</font></b><br>
651 let "all_cnt = $passed_cnt + $failed_cnt"
653 cat >> $INDEX << @EOF
656 <td><a href="all.html"><b>all</b></a></td>
657 <td align="right"><b>$all_cnt</b></td>
661 <td><b>Failed:</b></td>
663 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
672 cecho "\033[1;32mPassed: $passed_cnt"
673 cecho "Failed: $failed_cnt"
677 ##############################################################################
678 # copy the test results to the apache server
681 HTDOCS="/var/www/localhost/htdocs"
683 cecho-n "Copying test results to winnetou.."
684 ssh root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
685 scp -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
686 ssh root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
689 cecho "The results are available in $TODAYDIR"
690 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"