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
347 source $TESTDIR/test.conf
350 ##########################################################################
351 # run tcpdump in the background
354 if [ "$TCPDUMPHOSTS" != "" ]
356 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
358 for host_iface in $TCPDUMPHOSTS
360 host=`echo $host_iface | awk -F ":" '{print $1}'`
361 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
362 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain > /tmp/tcpdump.log 2>&1 &"
363 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
364 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
365 eval TDUP_${host}="true"
370 ##########################################################################
371 # execute pre-test commands
375 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
380 printf("echo \"%s# %s\"; ", $1, $2)
381 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
384 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
387 ##########################################################################
391 function stop_tcpdump {
392 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
393 eval ssh $SSHCONF root@\$ipv4_${1} killall tcpdump
394 eval TDUP_${1}="false"
399 ##########################################################################
400 # get and evaluate test results
404 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
415 if (command == "tcpdump")
417 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
418 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
419 printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
423 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
424 printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
426 printf("cmd_exit=\044?; ")
428 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
429 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
430 printf("; then STATUS=\"failed\"; fi; \n")
432 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
435 ##########################################################################
439 if [ $STATUS = "failed" ]
441 let "failed_cnt += 1"
443 let "passed_cnt += 1"
447 ##########################################################################
448 # log statusall and listall output
449 # get copies of ipsec.conf, ipsec.secrets
450 # create index.html for the given test case
452 cat > $TESTRESULTDIR/index.html <<@EOF
455 <title>Test $testname</title>
458 <table border="0" width="600">
460 <h2>Test $testname</h2>
464 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
466 cat >> $TESTRESULTDIR/index.html <<@EOF
468 <li><a href="console.log">console.log</a></li>
470 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
473 for host in $IPSECHOSTS
475 eval HOSTLOGIN=root@\$ipv4_${host}
477 for command in statusall listall
479 ssh $SSHCONF $HOSTLOGIN ipsec $command \
480 > $TESTRESULTDIR/${host}.$command 2>/dev/null
483 for file in strongswan.conf ipsec.conf ipsec.secrets
485 scp $SSHCONF $HOSTLOGIN:/etc/$file \
486 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
489 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
490 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
492 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
493 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
494 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
495 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
496 ssh $SSHCONF $HOSTLOGIN ip route list table $SOURCEIP_ROUTING_TABLE \
497 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
498 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
499 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
500 chmod a+r $TESTRESULTDIR/*
501 cat >> $TESTRESULTDIR/index.html <<@EOF
503 <table border="0" cellspacing="0" width="600">
507 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
508 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
509 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
510 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
515 <li><a href="$host.statusall">ipsec statusall</a></li>
516 <li><a href="$host.listall">ipsec listall</a></li>
517 <li><a href="$host.auth.log">auth.log</a></li>
518 <li><a href="$host.daemon.log">daemon.log</a></li>
523 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
524 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
525 <li><a href="$host.ip.route">ip route list table $SOURCEIP_ROUTING_TABLE</a></li>
526 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
535 for host in $RADIUSHOSTS
537 eval HOSTLOGIN=root@\$ipv4_${host}
539 for file in clients.conf eap.conf radiusd.conf proxy.conf users
541 scp $SSHCONF $HOSTLOGIN:/etc/raddb/$file \
542 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
545 scp $SSHCONF $HOSTLOGIN:/var/log/radius/radius.log \
546 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
548 chmod a+r $TESTRESULTDIR/*
549 cat >> $TESTRESULTDIR/index.html <<@EOF
551 <table border="0" cellspacing="0" width="600">
555 <li><a href="$host.clients.conf">clients.conf</a></li>
556 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
561 <li><a href="$host.eap.conf">eap.conf</a></li>
562 <li><a href="$host.radius.log">radius.log</a></li>
567 <li><a href="$host.proxy.conf">proxy.conf</a></li>
568 <li><a href="$host.users">users</a></li>
577 cat >> $TESTRESULTDIR/index.html <<@EOF
579 <tr><td align="right">
580 <b><a href="../index.html">Back</a></b>
588 ##########################################################################
589 # execute post-test commands
593 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
598 printf("echo \"%s# %s\"; ", $1, $2)
599 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
602 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
605 ##########################################################################
606 # get a copy of /var/log/auth.log
609 for host in $IPSECHOSTS
611 eval HOSTLOGIN=root@\$ipv4_${host}
612 ssh $SSHCONF $HOSTLOGIN grep pluto /var/log/auth.log \
613 > $TESTRESULTDIR/${host}.auth.log
614 echo >> $TESTRESULTDIR/${host}.auth.log
615 ssh $SSHCONF $HOSTLOGIN grep charon /var/log/auth.log \
616 >> $TESTRESULTDIR/${host}.auth.log
620 ##########################################################################
621 # get a copy of /var/log/daemon.log
624 for host in $IPSECHOSTS
626 eval HOSTLOGIN=root@\$ipv4_${host}
627 ssh $SSHCONF $HOSTLOGIN grep pluto /var/log/daemon.log \
628 > $TESTRESULTDIR/${host}.daemon.log
629 echo >> $TESTRESULTDIR/${host}.daemon.log
630 ssh $SSHCONF $HOSTLOGIN grep charon /var/log/daemon.log \
631 >> $TESTRESULTDIR/${host}.daemon.log
635 ##########################################################################
636 # stop tcpdump if necessary
639 for host in $TCPDUMPHOSTS
641 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
643 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
644 eval ssh $SSHCONF root@\$ipv4_$host killall tcpdump
645 eval TDUP_${host}="false"
650 ##########################################################################
651 # copy default host config back if necessary
654 $DIR/scripts/restore-defaults $testname
657 ##########################################################################
658 # write test status to html file
661 if [ $STATUS = "passed" ]
664 cecho "\033[1;32m$STATUS"
670 cat >> $TESTRESULTSHTML << @EOF
673 <td><a href="$testname/">$testname</a></td>
674 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
678 cat >> $SUBTESTSINDEX << @EOF
681 <td><a href="$name/">$name</a></td>
682 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
688 ##########################################################################
689 # remove any charon.pid files that still may exist
692 for host in $IPSECHOSTS
694 eval HOSTLOGIN=root@\$ipv4_${host}
695 ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
703 ##############################################################################
704 # finish the results html file
707 cat >> $TESTRESULTSHTML << @EOF
710 <b>Passed: <font color="green">$passed_cnt</font></b><br>
711 <b>Failed: <font color="red">$failed_cnt</font></b><br>
717 let "all_cnt = $passed_cnt + $failed_cnt"
719 cat >> $INDEX << @EOF
722 <td><a href="all.html"><b>all</b></a></td>
723 <td align="right"><b>$all_cnt</b></td>
727 <td><b>Failed:</b></td>
729 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
738 cecho "\033[1;32mPassed: $passed_cnt"
739 cecho "Failed: $failed_cnt"
743 ##############################################################################
744 # copy the test results to the apache server
747 HTDOCS="/var/www/localhost/htdocs"
749 cecho-n "Copying test results to winnetou.."
750 ssh $SSHCONF root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
751 scp $SSHCONF -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
752 ssh $SSHCONF root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
755 cecho "The results are available in $TODAYDIR"
756 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
759 ##########################################################################
762 for host in $STRONGSWANHOSTS
764 kill `eval echo \\\$ssh_pid_$host`