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`
120 ENVIRONMENT_HEADER=$(cat <<@EOF
121 <table border="0" cellspacing="2">
123 <td><b>Host:</b></td>
124 <td colspan="3">`uname -a`</td>
127 <td><b>UML kernel: </b></td>
128 <td colspan="3">$KERNEL_VERSION</td>
131 <td><b>IPsec:</b></td>
132 <td colspan="3">$IPSEC_VERSION</td>
135 <td><b>Date:</b></td>
136 <td colspan="3">$TESTDATE</td>
139 <td width="100"> </td>
140 <td width="200"> </td>
141 <td width=" 50"> </td>
150 <title>strongSwan UML Tests</title>
153 <h2>strongSwan UML Tests</h2>
157 cat > $TESTRESULTSHTML <<@EOF
160 <title>strongSwan UML Tests - All Tests</title>
163 <div><a href="index.html">strongSwan UML Tests</a> / All Tests</div>
169 <th colspan="2">Result</th>
173 cecho "UML kernel: $KERNEL_VERSION"
174 cecho "IPsec: $IPSEC_VERSION"
175 cecho "Date: $TESTDATE"
179 ##############################################################################
180 # enter specific test directory
186 elif [ $SELECTEDTESTSONLY = "yes" ]
188 # set internal field seperator
191 # set internal field seperator
192 TESTS="`ls $DEFAULTTESTSDIR`"
197 SUBTESTS="`basename $SUBDIR`"
199 if [ $SUBTESTS = $SUBDIR ]
201 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
203 SUBDIR="`dirname $SUBDIR`"
206 if [ ! -d $TODAYDIR/$SUBDIR ]
208 mkdir $TODAYDIR/$SUBDIR
209 if [ $testnumber == 0 ]
211 FIRST="<b>Category:</b"
215 echo " <tr>" >> $INDEX
216 echo " <td>$FIRST</td>">> $INDEX
217 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
218 echo " <td align=\"right\">x</td>" >> $INDEX
219 echo " <td> </td>" >> $INDEX
220 echo " </tr>" >> $INDEX
221 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
222 cat > $SUBTESTSINDEX <<@EOF
225 <title>strongSwan $SUBDIR Tests</title>
228 <div><a href="../index.html">strongSwan UML Tests</a> / $SUBDIR</div>
229 <h2>strongSwan $SUBDIR Tests</h2>
230 <table border="0" cellspacing="2">
232 <td><b>UML kernel: </b></td>
233 <td colspan="3">$KERNEL_VERSION</td>
236 <td><b>IPsec:</b></td>
237 <td colspan="3">$IPSEC_VERSION</td>
240 <td><b>Date:</b></td>
241 <td colspan="3">$TESTDATE</td>
244 <td width="100"> </td>
245 <td width="200"> </td>
246 <td width=" 50"> </td>
252 <th colspan="2">Result</th>
257 for name in $SUBTESTS
259 let "testnumber += 1"
260 testname=$SUBDIR/$name
261 cecho-n " $testnumber $testname.."
263 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
265 cecho "is missing..skipped"
269 if [ $SUBDIR = "ipv6" -o $name = "rw-psk-ipv6" ]
271 IPTABLES_CMD="ip6tables -v -n -L"
272 IPTABLES_DSP="ip6tables -L"
274 IPTABLES_CMD="iptables -v -n -L"
275 IPTABLES_DSP="iptables -L"
278 if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
280 IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
281 IPTABLES_DSP="iptables -L ; ip6tables -L"
284 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
285 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
286 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
287 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
288 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
290 TESTRESULTDIR=$TODAYDIR/$testname
291 mkdir -p $TESTRESULTDIR
292 CONSOLE_LOG=$TESTRESULTDIR/console.log
295 TESTDIR=$TESTSDIR/${testname}
298 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
301 ##############################################################################
302 # replace IP wildcards with actual IPv4 and IPv6 addresses
305 for host in $STRONGSWANHOSTS
309 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
310 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
311 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
312 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
315 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
316 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
317 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
318 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
321 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
322 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
323 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
324 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
327 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
328 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
331 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
332 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
335 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
336 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
337 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
338 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
341 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
342 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
343 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
344 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
347 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
348 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
354 ##########################################################################
355 # copy test specific configurations to uml hosts and clear auth.log files
358 $DIR/scripts/load-testconfig $testname
360 source $TESTDIR/test.conf
363 ##########################################################################
364 # run tcpdump in the background
367 if [ "$TCPDUMPHOSTS" != "" ]
369 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
371 for host_iface in $TCPDUMPHOSTS
373 host=`echo $host_iface | awk -F ":" '{print $1}'`
374 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
375 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain > /tmp/tcpdump.log 2>&1 &"
376 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
377 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
378 eval TDUP_${host}="true"
383 ##########################################################################
384 # execute pre-test commands
388 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
393 printf("echo \"%s# %s\"; ", $1, $2)
394 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
397 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
400 ##########################################################################
404 function stop_tcpdump {
405 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
406 eval ssh $SSHCONF root@\$ipv4_${1} killall tcpdump
407 eval TDUP_${1}="false"
412 ##########################################################################
413 # get and evaluate test results
417 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
428 if (command == "tcpdump")
430 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
431 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
432 printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
436 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
437 printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
439 printf("cmd_exit=\044?; ")
441 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
442 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
443 printf("; then STATUS=\"failed\"; fi; \n")
445 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
448 ##########################################################################
452 if [ $STATUS = "failed" ]
454 let "failed_cnt += 1"
456 let "passed_cnt += 1"
460 ##########################################################################
461 # log statusall and listall output
462 # get copies of ipsec.conf, ipsec.secrets
463 # create index.html for the given test case
465 cat > $TESTRESULTDIR/index.html <<@EOF
468 <title>Test $testname</title>
471 <table border="0" cellpadding="0" cellspacing="0" width="600">
473 <div><a href="../../index.html">strongSwan UML Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
474 <h2>Test $testname</h2>
478 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
480 cat >> $TESTRESULTDIR/index.html <<@EOF
482 <li><a href="console.log">console.log</a></li>
484 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
487 for host in $IPSECHOSTS
489 eval HOSTLOGIN=root@\$ipv4_${host}
491 for command in statusall listall
493 ssh $SSHCONF $HOSTLOGIN ipsec $command \
494 > $TESTRESULTDIR/${host}.$command 2>/dev/null
497 for file in strongswan.conf ipsec.conf ipsec.secrets
499 scp $SSHCONF $HOSTLOGIN:/etc/$file \
500 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
503 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
504 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
506 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
507 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
508 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
509 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
510 ssh $SSHCONF $HOSTLOGIN ip route list table $SOURCEIP_ROUTING_TABLE \
511 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
512 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
513 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
514 chmod a+r $TESTRESULTDIR/*
515 cat >> $TESTRESULTDIR/index.html <<@EOF
517 <table border="0" cellspacing="0" width="600">
521 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
522 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
523 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
524 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
529 <li><a href="$host.statusall">ipsec statusall</a></li>
530 <li><a href="$host.listall">ipsec listall</a></li>
531 <li><a href="$host.auth.log">auth.log</a></li>
532 <li><a href="$host.daemon.log">daemon.log</a></li>
537 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
538 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
539 <li><a href="$host.ip.route">ip route list table $SOURCEIP_ROUTING_TABLE</a></li>
540 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
549 for host in $RADIUSHOSTS
551 eval HOSTLOGIN=root@\$ipv4_${host}
553 for file in clients.conf eap.conf radiusd.conf proxy.conf users
555 scp $SSHCONF $HOSTLOGIN:/etc/raddb/$file \
556 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
559 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
560 $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
562 scp $SSHCONF $HOSTLOGIN:/var/log/radius/radius.log \
563 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
565 chmod a+r $TESTRESULTDIR/*
566 cat >> $TESTRESULTDIR/index.html <<@EOF
568 <table border="0" cellspacing="0" width="600">
572 <li><a href="$host.clients.conf">clients.conf</a></li>
573 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
574 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
579 <li><a href="$host.eap.conf">eap.conf</a></li>
580 <li><a href="$host.radius.log">radius.log</a></li>
581 <li><a href="$host.daemon.log">daemon.log</a></li>
586 <li><a href="$host.proxy.conf">proxy.conf</a></li>
587 <li><a href="$host.users">users</a></li>
596 cat >> $TESTRESULTDIR/index.html <<@EOF
604 ##########################################################################
605 # execute post-test commands
609 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
614 printf("echo \"%s# %s\"; ", $1, $2)
615 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
618 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
621 ##########################################################################
622 # get a copy of /var/log/auth.log
625 for host in $IPSECHOSTS
627 eval HOSTLOGIN=root@\$ipv4_${host}
628 ssh $SSHCONF $HOSTLOGIN grep pluto /var/log/auth.log \
629 > $TESTRESULTDIR/${host}.auth.log
630 echo >> $TESTRESULTDIR/${host}.auth.log
631 ssh $SSHCONF $HOSTLOGIN grep charon /var/log/auth.log \
632 >> $TESTRESULTDIR/${host}.auth.log
636 ##########################################################################
637 # get a copy of /var/log/daemon.log
640 for host in $IPSECHOSTS
642 eval HOSTLOGIN=root@\$ipv4_${host}
643 ssh $SSHCONF $HOSTLOGIN grep pluto /var/log/daemon.log \
644 > $TESTRESULTDIR/${host}.daemon.log
645 echo >> $TESTRESULTDIR/${host}.daemon.log
646 ssh $SSHCONF $HOSTLOGIN grep charon /var/log/daemon.log \
647 >> $TESTRESULTDIR/${host}.daemon.log
651 ##########################################################################
652 # get a copy of /var/log/daemon.log
655 for host in $RADIUSHOSTS
657 eval HOSTLOGIN=root@\$ipv4_${host}
658 ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
659 >> $TESTRESULTDIR/${host}.daemon.log
663 ##########################################################################
664 # stop tcpdump if necessary
667 for host in $TCPDUMPHOSTS
669 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
671 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
672 eval ssh $SSHCONF root@\$ipv4_$host killall tcpdump
673 eval TDUP_${host}="false"
678 ##########################################################################
679 # copy default host config back if necessary
682 $DIR/scripts/restore-defaults $testname
685 ##########################################################################
686 # write test status to html file
689 if [ $STATUS = "passed" ]
692 cecho "\033[1;32m$STATUS"
698 cat >> $TESTRESULTSHTML << @EOF
701 <td><a href="$testname/index.html">$testname</a></td>
702 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
706 cat >> $SUBTESTSINDEX << @EOF
709 <td><a href="$name/index.html">$name</a></td>
710 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
716 ##########################################################################
717 # remove any charon.pid files that still may exist
720 for host in $IPSECHOSTS
722 eval HOSTLOGIN=root@\$ipv4_${host}
723 ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
731 ##############################################################################
732 # finish the results html file
735 cat >> $TESTRESULTSHTML << @EOF
737 <td> </td><td> </td><td> </td><td> </td>
740 <td><b>Passed:</b></td><td><b><font color="green">$passed_cnt</font></b></td><td> </td><td> </td>
743 <td><b>Failed:</b></td><td><b><font color="red">$failed_cnt</font></b></td><td> </td><td> </td>
750 let "all_cnt = $passed_cnt + $failed_cnt"
752 cat >> $INDEX << @EOF
755 <td><a href="all.html"><b>all</b></a></td>
756 <td align="right"><b>$all_cnt</b></td>
760 <td><b>Failed:</b></td>
762 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
771 cecho "\033[1;32mPassed: $passed_cnt"
772 cecho "Failed: $failed_cnt"
776 ##############################################################################
777 # copy the test results to the apache server
780 HTDOCS="/var/www/localhost/htdocs"
782 cecho-n "Copying test results to winnetou.."
783 ssh $SSHCONF root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
784 scp $SSHCONF -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
785 ssh $SSHCONF root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
788 cecho "The results are available in $TODAYDIR"
789 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
792 ##########################################################################
795 for host in $STRONGSWANHOSTS
797 kill `eval echo \\\$ssh_pid_$host`