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=@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 ##############################################################################
106 for host in $STRONGSWANHOSTS
108 ssh $SSHCONF -N root@`eval echo \\\$ipv4_$host` &
109 eval ssh_pid_$host="`echo $!`"
113 ##############################################################################
114 # create header for the results html file
117 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
118 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
123 <title>strongSwan UML Tests</title>
126 <h2>strongSwan UML Tests</h2>
127 <table border="0" cellspacing="2">
129 <td><b>Host:</b></td>
130 <td colspan="3">`uname -a`</td>
133 <td><b>UML kernel: </b></td>
134 <td colspan="3">$KERNEL_VERSION</td>
137 <td><b>IPsec:</b></td>
138 <td colspan="3">$IPSEC_VERSION</td>
141 <td><b>Date:</b></td>
142 <td colspan="3">$TESTDATE</td>
145 <td width="100"> </td>
146 <td width="200"> </td>
147 <td width=" 50"> </td>
152 cat $INDEX > $TESTRESULTSHTML
153 cat >> $TESTRESULTSHTML <<@EOF
157 <th colspan="2">Result</th>
161 cecho "UML kernel: $KERNEL_VERSION"
162 cecho "IPsec: $IPSEC_VERSION"
163 cecho "Date: $TESTDATE"
167 ##############################################################################
168 # enter specific test directory
174 elif [ $SELECTEDTESTSONLY = "yes" ]
176 # set internal field seperator
179 # set internal field seperator
180 TESTS="`ls $DEFAULTTESTSDIR`"
185 SUBTESTS="`basename $SUBDIR`"
187 if [ $SUBTESTS = $SUBDIR ]
189 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
191 SUBDIR="`dirname $SUBDIR`"
194 if [ ! -d $TODAYDIR/$SUBDIR ]
196 mkdir $TODAYDIR/$SUBDIR
197 if [ $testnumber == 0 ]
199 FIRST="<b>Category:</b"
203 echo " <tr>" >> $INDEX
204 echo " <td>$FIRST</td>">> $INDEX
205 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
206 echo " <td align=\"right\">x</td>" >> $INDEX
207 echo " <td> </td>" >> $INDEX
208 echo " </tr>" >> $INDEX
209 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
210 cat > $SUBTESTSINDEX <<@EOF
213 <title>strongSwan $SUBDIR Tests</title>
216 <h2>strongSwan $SUBDIR Tests</h2>
217 <table border="0" cellspacing="2">
219 <td><b>UML kernel: </b></td>
220 <td colspan="3">$KERNEL_VERSION</td>
223 <td><b>IPsec:</b></td>
224 <td colspan="3">$IPSEC_VERSION</td>
227 <td><b>Date:</b></td>
228 <td colspan="3">$TESTDATE</td>
231 <td width="100"> </td>
232 <td width="200"> </td>
233 <td width=" 50"> </td>
239 <th colspan="2">Result</th>
244 for name in $SUBTESTS
246 let "testnumber += 1"
247 testname=$SUBDIR/$name
248 cecho-n " $testnumber $testname.."
250 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
252 cecho "is missing..skipped"
256 if [ $SUBDIR = "ipv6" -o $name = "rw-psk-ipv6" ]
258 IPTABLES_CMD="ip6tables -v -n -L"
259 IPTABLES_DSP="ip6tables -L"
261 IPTABLES_CMD="iptables -v -n -L"
262 IPTABLES_DSP="iptables -L"
265 if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
267 IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
268 IPTABLES_DSP="iptables -L ; ip6tables -L"
271 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
272 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
273 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
274 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
275 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
277 TESTRESULTDIR=$TODAYDIR/$testname
278 mkdir -p $TESTRESULTDIR
279 CONSOLE_LOG=$TESTRESULTDIR/console.log
282 TESTDIR=$TESTSDIR/${testname}
285 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
288 ##############################################################################
289 # replace IP wildcards with actual IPv4 and IPv6 addresses
292 for host in $STRONGSWANHOSTS
296 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
297 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
298 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
299 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
302 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
303 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
304 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
305 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
308 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
309 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
310 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
311 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
314 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
315 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
318 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
319 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
322 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
323 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
324 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
325 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
328 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
329 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
330 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
331 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
334 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
335 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
341 ##########################################################################
342 # copy test specific configurations to uml hosts and clear auth.log files
345 $DIR/scripts/load-testconfig $testname
346 source $TESTDIR/test.conf
349 ##########################################################################
350 # run tcpdump in the background
353 if [ "$TCPDUMPHOSTS" != "" ]
355 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
357 for host_iface in $TCPDUMPHOSTS
359 host=`echo $host_iface | awk -F ":" '{print $1}'`
360 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
361 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain > /tmp/tcpdump.log 2>&1 &"
362 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
363 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
364 eval TDUP_${host}="true"
369 ##########################################################################
370 # execute pre-test commands
374 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
379 printf("echo \"%s# %s\"; ", $1, $2)
380 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
383 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
386 ##########################################################################
390 function stop_tcpdump {
391 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
392 eval ssh $SSHCONF root@\$ipv4_${1} killall tcpdump
393 eval TDUP_${1}="false"
398 ##########################################################################
399 # get and evaluate test results
403 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
414 if (command == "tcpdump")
416 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
417 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
418 printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
422 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
423 printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
425 printf("cmd_exit=\044?; ")
427 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
428 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
429 printf("; then STATUS=\"failed\"; fi; \n")
431 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
434 ##########################################################################
438 if [ $STATUS = "failed" ]
440 let "failed_cnt += 1"
442 let "passed_cnt += 1"
446 ##########################################################################
447 # log statusall and listall output
448 # get copies of ipsec.conf, ipsec.secrets
449 # create index.html for the given test case
451 cat > $TESTRESULTDIR/index.html <<@EOF
454 <title>Test $testname</title>
457 <table border="0" width="600">
459 <h2>Test $testname</h2>
463 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
465 cat >> $TESTRESULTDIR/index.html <<@EOF
467 <li><a href="console.log">console.log</a></li>
469 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
472 for host in $IPSECHOSTS
474 eval HOSTLOGIN=root@\$ipv4_${host}
476 for command in statusall listall
478 ssh $SSHCONF $HOSTLOGIN ipsec $command \
479 > $TESTRESULTDIR/${host}.$command 2>/dev/null
482 for file in strongswan.conf ipsec.conf ipsec.secrets
484 scp $SSHCONF $HOSTLOGIN:/etc/$file \
485 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
488 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
489 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
491 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
492 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
493 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
494 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
495 ssh $SSHCONF $HOSTLOGIN ip route list table $SOURCEIP_ROUTING_TABLE \
496 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
497 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
498 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
499 chmod a+r $TESTRESULTDIR/*
500 cat >> $TESTRESULTDIR/index.html <<@EOF
502 <table border="0" cellspacing="0" width="600">
506 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
507 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
508 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
509 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
514 <li><a href="$host.statusall">ipsec statusall</a></li>
515 <li><a href="$host.listall">ipsec listall</a></li>
516 <li><a href="$host.auth.log">auth.log</a></li>
517 <li><a href="$host.daemon.log">daemon.log</a></li>
522 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
523 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
524 <li><a href="$host.ip.route">ip route list table $SOURCEIP_ROUTING_TABLE</a></li>
525 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
534 for host in $RADIUSHOSTS
536 eval HOSTLOGIN=root@\$ipv4_${host}
538 for file in clients.conf eap.conf radiusd.conf proxy.conf users
540 scp $SSHCONF $HOSTLOGIN:/etc/raddb/$file \
541 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
544 scp $SSHCONF $HOSTLOGIN:/var/log/radius/radius.log \
545 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
547 chmod a+r $TESTRESULTDIR/*
548 cat >> $TESTRESULTDIR/index.html <<@EOF
550 <table border="0" cellspacing="0" width="600">
554 <li><a href="$host.clients.conf">clients.conf</a></li>
555 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
560 <li><a href="$host.eap.conf">eap.conf</a></li>
561 <li><a href="$host.radius.log">radius.log</a></li>
566 <li><a href="$host.proxy.conf">proxy.conf</a></li>
567 <li><a href="$host.users">users</a></li>
576 cat >> $TESTRESULTDIR/index.html <<@EOF
578 <tr><td align="right">
579 <b><a href="../index.html">Back</a></b>
587 ##########################################################################
588 # execute post-test commands
592 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
597 printf("echo \"%s# %s\"; ", $1, $2)
598 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
601 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
604 ##########################################################################
605 # get a copy of /var/log/auth.log
608 for host in $IPSECHOSTS
610 eval HOSTLOGIN=root@\$ipv4_${host}
611 ssh $SSHCONF $HOSTLOGIN grep pluto /var/log/auth.log \
612 > $TESTRESULTDIR/${host}.auth.log
613 echo >> $TESTRESULTDIR/${host}.auth.log
614 ssh $SSHCONF $HOSTLOGIN grep charon /var/log/auth.log \
615 >> $TESTRESULTDIR/${host}.auth.log
619 ##########################################################################
620 # get a copy of /var/log/daemon.log
623 for host in $IPSECHOSTS
625 eval HOSTLOGIN=root@\$ipv4_${host}
626 ssh $SSHCONF $HOSTLOGIN grep pluto /var/log/daemon.log \
627 > $TESTRESULTDIR/${host}.daemon.log
628 echo >> $TESTRESULTDIR/${host}.daemon.log
629 ssh $SSHCONF $HOSTLOGIN grep charon /var/log/daemon.log \
630 >> $TESTRESULTDIR/${host}.daemon.log
634 ##########################################################################
635 # stop tcpdump if necessary
638 for host in $TCPDUMPHOSTS
640 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
642 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
643 eval ssh $SSHCONF root@\$ipv4_$host killall tcpdump
644 eval TDUP_${host}="false"
649 ##########################################################################
650 # copy default host config back if necessary
653 $DIR/scripts/restore-defaults $testname
656 ##########################################################################
657 # write test status to html file
660 if [ $STATUS = "passed" ]
663 cecho "\033[1;32m$STATUS"
669 cat >> $TESTRESULTSHTML << @EOF
672 <td><a href="$testname/">$testname</a></td>
673 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
677 cat >> $SUBTESTSINDEX << @EOF
680 <td><a href="$name/">$name</a></td>
681 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
687 ##########################################################################
688 # remove any charon.pid files that still may exist
691 for host in $IPSECHOSTS
693 eval HOSTLOGIN=root@\$ipv4_${host}
694 ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
702 ##############################################################################
703 # finish the results html file
706 cat >> $TESTRESULTSHTML << @EOF
709 <b>Passed: <font color="green">$passed_cnt</font></b><br>
710 <b>Failed: <font color="red">$failed_cnt</font></b><br>
716 let "all_cnt = $passed_cnt + $failed_cnt"
718 cat >> $INDEX << @EOF
721 <td><a href="all.html"><b>all</b></a></td>
722 <td align="right"><b>$all_cnt</b></td>
726 <td><b>Failed:</b></td>
728 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
737 cecho "\033[1;32mPassed: $passed_cnt"
738 cecho "Failed: $failed_cnt"
742 ##############################################################################
743 # copy the test results to the apache server
746 HTDOCS="/var/www/localhost/htdocs"
748 cecho-n "Copying test results to winnetou.."
749 ssh $SSHCONF root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
750 scp $SSHCONF -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
751 ssh $SSHCONF root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
754 cecho "The results are available in $TODAYDIR"
755 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
758 ##########################################################################
761 for host in $STRONGSWANHOSTS
763 kill `eval echo \\\$ssh_pid_$host`