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
19 source $DIR/scripts/function.sh
21 [ -f $DIR/testing.conf ] || die "Configuration file 'testing.conf' not found"
22 [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
23 [ -d $DIR/tests ] || die "Directory 'tests' not found"
25 source $DIR/testing.conf
28 ##############################################################################
29 # test if UMLs have been built at all
32 [ -d $BUILDDIR ] || die "Directory '$BUILDDIR' does not exist. Please run 'make-testing'first."
35 ##############################################################################
36 # take care of new path and file variables
39 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
41 TESTDATE=`date +%Y%m%d-%H%M`
43 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
45 TESTRESULTSHTML=$TODAYDIR/all.html
46 INDEX=$TODAYDIR/index.html
47 DEFAULTTESTSDIR=$UMLTESTDIR/testing/tests
49 SOURCEIP_ROUTING_TABLE=@IPSEC_ROUTING_TABLE@
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 }'`"
82 eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
83 eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
90 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
91 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
94 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
95 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
103 ##############################################################################
104 # create header for the results html file
107 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
108 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
113 <title>strongSwan UML Tests</title>
116 <h2>strongSwan UML Tests</h2>
117 <table border="0" cellspacing="2">
119 <td><b>Host:</b></td>
120 <td colspan="3">`uname -a`</td>
123 <td><b>UML kernel: </b></td>
124 <td colspan="3">$KERNEL_VERSION</td>
127 <td><b>IPsec:</b></td>
128 <td colspan="3">$IPSEC_VERSION</td>
131 <td><b>Date:</b></td>
132 <td colspan="3">$TESTDATE</td>
135 <td width="100"> </td>
136 <td width="200"> </td>
137 <td width=" 50"> </td>
142 cat $INDEX > $TESTRESULTSHTML
143 cat >> $TESTRESULTSHTML <<@EOF
147 <th colspan="2">Result</th>
151 cecho "UML kernel: $KERNEL_VERSION"
152 cecho "IPsec: $IPSEC_VERSION"
153 cecho "Date: $TESTDATE"
157 ##############################################################################
158 # enter specific test directory
164 elif [ $SELECTEDTESTSONLY = "yes" ]
166 # set internal field seperator
169 # set internal field seperator
170 TESTS="`ls $DEFAULTTESTSDIR`"
175 SUBTESTS="`basename $SUBDIR`"
177 if [ $SUBTESTS = $SUBDIR ]
179 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
181 SUBDIR="`dirname $SUBDIR`"
184 if [ ! -d $TODAYDIR/$SUBDIR ]
186 mkdir $TODAYDIR/$SUBDIR
187 if [ $testnumber == 0 ]
189 FIRST="<b>Category:</b"
193 echo " <tr>" >> $INDEX
194 echo " <td>$FIRST</td>">> $INDEX
195 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
196 echo " <td align=\"right\">x</td>" >> $INDEX
197 echo " <td> </td>" >> $INDEX
198 echo " </tr>" >> $INDEX
199 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
200 cat > $SUBTESTSINDEX <<@EOF
203 <title>strongSwan $SUBDIR Tests</title>
206 <h2>strongSwan $SUBDIR Tests</h2>
207 <table border="0" cellspacing="2">
209 <td><b>UML kernel: </b></td>
210 <td colspan="3">$KERNEL_VERSION</td>
213 <td><b>IPsec:</b></td>
214 <td colspan="3">$IPSEC_VERSION</td>
217 <td><b>Date:</b></td>
218 <td colspan="3">$TESTDATE</td>
221 <td width="100"> </td>
222 <td width="200"> </td>
223 <td width=" 50"> </td>
229 <th colspan="2">Result</th>
234 for name in $SUBTESTS
236 let "testnumber += 1"
237 testname=$SUBDIR/$name
238 cecho-n " $testnumber $testname.."
240 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
242 cecho "is missing..skipped"
246 if [ $SUBDIR = "ipv6" -o $name = "rw-psk-ipv6" ]
253 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
254 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
255 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
256 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
257 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
259 TESTRESULTDIR=$TODAYDIR/$testname
260 mkdir -p $TESTRESULTDIR
261 CONSOLE_LOG=$TESTRESULTDIR/console.log
264 TESTDIR=$TESTSDIR/${testname}
267 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
270 ##############################################################################
271 # replace IP wildcards with actual IPv4 and IPv6 addresses
274 for host in $STRONGSWANHOSTS
278 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
279 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
280 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
281 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
284 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
285 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
286 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
287 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
290 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
291 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
292 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
293 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
296 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
297 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
300 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
301 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
304 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
305 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
306 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
307 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
310 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
311 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
312 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
313 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
316 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
317 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
323 ##########################################################################
324 # copy test specific configurations to uml hosts and clear auth.log files
327 $DIR/scripts/load-testconfig $testname
328 source $TESTDIR/test.conf
331 ##########################################################################
332 # run tcpdump in the background
335 if [ "$TCPDUMPHOSTS" != "" ]
337 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
339 for host_iface in $TCPDUMPHOSTS
341 host=`echo $host_iface | awk -F ":" '{print $1}'`
342 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
343 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
344 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
345 ssh root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
346 eval TDUP_${host}="true"
351 ##########################################################################
352 # execute pre-test commands
356 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
361 printf("echo \"%s# %s\"; ", $1, $2)
362 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
365 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
368 ##########################################################################
372 function stop_tcpdump {
373 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
374 eval ssh root@\$ipv4_${1} killall tcpdump
375 eval TDUP_${1}="false"
380 ##########################################################################
381 # get and evaluate test results
385 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
396 if (command == "tcpdump")
398 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
399 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
400 printf("ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
404 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
405 printf("ssh root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
407 printf("cmd_exit=\044?; ")
409 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
410 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
411 printf("; then STATUS=\"failed\"; fi; \n")
413 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
416 ##########################################################################
420 if [ $STATUS = "failed" ]
422 let "failed_cnt += 1"
424 let "passed_cnt += 1"
428 ##########################################################################
429 # log statusall and listall output
430 # get copies of ipsec.conf, ipsec.secrets
431 # create index.html for the given test case
433 cat > $TESTRESULTDIR/index.html <<@EOF
436 <title>Test $testname</title>
439 <table border="0" width="600">
441 <h2>Test $testname</h2>
445 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
447 cat >> $TESTRESULTDIR/index.html <<@EOF
449 <li><a href="console.log">console.log</a></li>
451 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
454 for host in $IPSECHOSTS
456 eval HOSTLOGIN=root@\$ipv4_${host}
458 for command in statusall listall
460 ssh $HOSTLOGIN ipsec $command \
461 > $TESTRESULTDIR/${host}.$command 2>/dev/null
464 for file in strongswan.conf ipsec.conf ipsec.secrets
466 scp $HOSTLOGIN:/etc/$file \
467 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
470 scp $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
471 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
473 ssh $HOSTLOGIN ip -s xfrm policy \
474 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
475 ssh $HOSTLOGIN ip -s xfrm state \
476 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
477 ssh $HOSTLOGIN ip route list table $SOURCEIP_ROUTING_TABLE \
478 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
479 ssh $HOSTLOGIN $IPTABLES -v -n -L \
480 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
481 chmod a+r $TESTRESULTDIR/*
482 cat >> $TESTRESULTDIR/index.html <<@EOF
484 <table border="0" cellspacing="0" width="600">
488 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
489 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
490 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
491 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
496 <li><a href="$host.statusall">ipsec statusall</a></li>
497 <li><a href="$host.listall">ipsec listall</a></li>
498 <li><a href="$host.auth.log">auth.log</a></li>
499 <li><a href="$host.daemon.log">daemon.log</a></li>
504 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
505 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
506 <li><a href="$host.ip.route">ip route list table $SOURCEIP_ROUTING_TABLE</a></li>
507 <li><a href="$host.iptables">$IPTABLES -L</a></li>
516 cat >> $TESTRESULTDIR/index.html <<@EOF
518 <tr><td align="right">
519 <b><a href="../index.html">Back</a></b>
527 ##########################################################################
528 # execute post-test commands
532 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
537 printf("echo \"%s# %s\"; ", $1, $2)
538 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
541 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
544 ##########################################################################
545 # get a copy of /var/log/auth.log
548 for host in $IPSECHOSTS
550 eval HOSTLOGIN=root@\$ipv4_${host}
551 ssh $HOSTLOGIN grep pluto /var/log/auth.log \
552 > $TESTRESULTDIR/${host}.auth.log
553 echo >> $TESTRESULTDIR/${host}.auth.log
554 ssh $HOSTLOGIN grep charon /var/log/auth.log \
555 >> $TESTRESULTDIR/${host}.auth.log
559 ##########################################################################
560 # get a copy of /var/log/daemon.log
563 for host in $IPSECHOSTS
565 eval HOSTLOGIN=root@\$ipv4_${host}
566 ssh $HOSTLOGIN grep pluto /var/log/daemon.log \
567 > $TESTRESULTDIR/${host}.daemon.log
568 echo >> $TESTRESULTDIR/${host}.daemon.log
569 ssh $HOSTLOGIN grep charon /var/log/daemon.log \
570 >> $TESTRESULTDIR/${host}.daemon.log
574 ##########################################################################
575 # stop tcpdump if necessary
578 for host in $TCPDUMPHOSTS
580 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
582 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
583 eval ssh root@\$ipv4_$host killall tcpdump
584 eval TDUP_${host}="false"
589 ##########################################################################
590 # copy default host config back if necessary
593 $DIR/scripts/restore-defaults $testname
596 ##########################################################################
597 # write test status to html file
600 if [ $STATUS = "passed" ]
603 cecho "\033[1;32m$STATUS"
609 cat >> $TESTRESULTSHTML << @EOF
612 <td><a href="$testname/">$testname</a></td>
613 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
617 cat >> $SUBTESTSINDEX << @EOF
620 <td><a href="$name/">$name</a></td>
621 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
631 ##############################################################################
632 # finish the results html file
635 cat >> $TESTRESULTSHTML << @EOF
638 <b>Passed: <font color="green">$passed_cnt</font></b><br>
639 <b>Failed: <font color="red">$failed_cnt</font></b><br>
645 let "all_cnt = $passed_cnt + $failed_cnt"
647 cat >> $INDEX << @EOF
650 <td><a href="all.html"><b>all</b></a></td>
651 <td align="right"><b>$all_cnt</b></td>
655 <td><b>Failed:</b></td>
657 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
666 cecho "\033[1;32mPassed: $passed_cnt"
667 cecho "Failed: $failed_cnt"
671 ##############################################################################
672 # copy the test results to the apache server
675 HTDOCS="/var/www/localhost/htdocs"
677 cecho-n "Copying test results to winnetou.."
678 ssh root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
679 scp -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
680 ssh root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
683 cecho "The results are available in $TODAYDIR"
684 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"