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
17 DIR=$(dirname `readlink -f $0`)
19 . $DIR/scripts/function.sh
20 SSHCONF="-F $DIR/ssh_config"
22 [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
23 [ -d $DIR/tests ] || die "Directory 'tests' not found"
25 die "Directory '$BUILDDIR' does not exist, please run make-testing first"
27 ln -sfT $DIR $TESTDIR/testing
29 ##############################################################################
30 # take care of new path and file variables
33 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
35 TESTDATE=`date +%Y%m%d-%H%M-%S`
37 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
39 TESTRESULTSHTML=$TODAYDIR/all.html
40 INDEX=$TODAYDIR/index.html
41 DEFAULTTESTSDIR=$TESTDIR/testing/tests
43 SOURCEIP_ROUTING_TABLE=220
50 ##############################################################################
51 # copy default tests to $BUILDDIR
54 TESTSDIR=$BUILDDIR/tests
55 [ -d $TESTSDIR ] || mkdir $TESTSDIR
57 ##############################################################################
58 # assign IP for each host to hostname
61 for host in $STRONGSWANHOSTS
63 eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
64 eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
68 eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
69 eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
72 eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
73 eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
76 eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
77 eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
84 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
85 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
88 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
89 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
97 ##############################################################################
100 for host in $STRONGSWANHOSTS
102 ssh $SSHCONF -N root@`eval echo \\\$ipv4_$host` >/dev/null 2>&1 &
103 eval ssh_pid_$host="`echo $!`"
104 do_on_exit kill `eval echo \\\$ssh_pid_$host`
108 ##############################################################################
109 # create header for the results html file
112 ENVIRONMENT_HEADER=$(cat <<@EOF
113 <table border="0" cellspacing="2" cellpadding="2">
116 <td colspan="3">`uname -a`</td>
119 <td><b>Guest kernel</b></td>
120 <td colspan="3">$KERNELVERSION</td>
123 <td><b>strongSwan</b></td>
124 <td colspan="3">$SWANVERSION</td>
128 <td colspan="3">$TESTDATE</td>
131 <td width="100"> </td>
132 <td width="300"> </td>
133 <td width=" 50"> </td>
142 <title>strongSwan KVM Tests</title>
145 <h2>strongSwan KVM Tests</h2>
149 cat > $TESTRESULTSHTML <<@EOF
152 <title>strongSwan KVM Tests - All Tests</title>
155 <div><a href="index.html">strongSwan KVM Tests</a> / All Tests</div>
161 <th colspan="2">Result</th>
165 echo "Guest kernel : $KERNELVERSION"
166 echo "strongSwan : $SWANVERSION"
167 echo "Date : $TESTDATE"
171 ##############################################################################
172 # enter specific test directory
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 <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
217 <h2>strongSwan $SUBDIR Tests</h2>
218 <table border="0" cellspacing="2" cellpadding="2">
220 <td><b>Guest kernel</b></td>
221 <td colspan="3">$KERNELVERSION</td>
224 <td><b>strongSwan</b></td>
225 <td colspan="3">$SWANVERSION</td>
229 <td colspan="3">$TESTDATE</td>
232 <td width="100"> </td>
233 <td width="300"> </td>
234 <td width=" 50"> </td>
240 <th colspan="2">Result</th>
245 for name in $SUBTESTS
247 let "testnumber += 1"
248 testname=$SUBDIR/$name
249 log_action " $testnumber $testname:"
251 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
253 echo "is missing..skipped"
257 if [ $SUBDIR = "ipv6" -o $name = "rw-psk-ipv6" ]
259 IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
260 IPROUTE_DSP=$IPROUTE_CMD
261 IPTABLES_CMD="ip6tables -v -n -L"
262 IPTABLES_DSP="ip6tables -L"
264 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
265 IPROUTE_DSP=$IPROUTE_CMD
266 IPTABLES_CMD="iptables -v -n -L"
267 IPTABLES_DSP="iptables -L"
270 if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
272 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
273 IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
274 IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
275 IPTABLES_DSP="iptables -L ; ip6tables -L"
278 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
279 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
280 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
281 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
282 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
284 TESTRESULTDIR=$TODAYDIR/$testname
285 mkdir -p $TESTRESULTDIR
286 CONSOLE_LOG=$TESTRESULTDIR/console.log
289 TESTDIR=$TESTSDIR/${testname}
292 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
295 ##############################################################################
296 # replace IP wildcards with actual IPv4 and IPv6 addresses
299 for host in $STRONGSWANHOSTS
303 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
304 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
305 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
306 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
309 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
310 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
311 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
312 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
315 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
316 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
317 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
318 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
321 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
322 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
325 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
326 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
329 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
330 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
331 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
332 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
335 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
336 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
337 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
338 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
341 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
342 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
348 ##########################################################################
349 # copy test specific configurations to uml hosts and clear auth.log files
352 $DIR/scripts/load-testconfig $testname
354 source $TESTDIR/test.conf
357 ##########################################################################
358 # run tcpdump in the background
361 if [ "$TCPDUMPHOSTS" != "" ]
363 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
365 for host_iface in $TCPDUMPHOSTS
367 host=`echo $host_iface | awk -F ":" '{print $1}'`
368 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
369 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain > /tmp/tcpdump.log 2>&1 &"
370 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
371 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
372 eval TDUP_${host}="true"
377 ##########################################################################
378 # execute pre-test commands
382 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
387 printf("echo \"%s# %s\"; ", $1, $2)
388 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
391 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
394 ##########################################################################
398 function stop_tcpdump {
399 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
400 eval ssh $SSHCONF root@\$ipv4_${1} killall tcpdump
401 eval TDUP_${1}="false"
406 ##########################################################################
407 # get and evaluate test results
411 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
422 if (command == "tcpdump")
424 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
425 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
426 printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
430 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
431 printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
433 printf("cmd_exit=\044?; ")
435 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
436 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
437 printf("; then STATUS=\"failed\"; fi; \n")
439 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
442 ##########################################################################
446 if [ $STATUS = "failed" ]
448 let "failed_cnt += 1"
450 let "passed_cnt += 1"
454 ##########################################################################
455 # log statusall and listall output
456 # get copies of ipsec.conf, ipsec.secrets
457 # create index.html for the given test case
459 cat > $TESTRESULTDIR/index.html <<@EOF
462 <title>Test $testname</title>
465 <table border="0" cellpadding="0" cellspacing="0" width="600">
467 <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
468 <h2>Test $testname</h2>
472 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
474 cat >> $TESTRESULTDIR/index.html <<@EOF
476 <li><a href="console.log">console.log</a></li>
478 <img src="../../images/$DIAGRAM" alt="$VIRTHOSTS">
481 for host in $IPSECHOSTS
483 eval HOSTLOGIN=root@\$ipv4_${host}
485 for command in statusall listall
487 ssh $SSHCONF $HOSTLOGIN ipsec $command \
488 > $TESTRESULTDIR/${host}.$command 2>/dev/null
491 for file in strongswan.conf ipsec.conf ipsec.secrets
493 scp $SSHCONF $HOSTLOGIN:/etc/$file \
494 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
497 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
498 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
500 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
501 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
502 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
503 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
504 ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
505 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
506 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
507 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
508 chmod a+r $TESTRESULTDIR/*
509 cat >> $TESTRESULTDIR/index.html <<@EOF
511 <table border="0" cellspacing="0" width="600">
515 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
516 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
517 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
518 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
523 <li><a href="$host.statusall">ipsec statusall</a></li>
524 <li><a href="$host.listall">ipsec listall</a></li>
525 <li><a href="$host.auth.log">auth.log</a></li>
526 <li><a href="$host.daemon.log">daemon.log</a></li>
531 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
532 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
533 <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
534 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
543 for host in $RADIUSHOSTS
545 eval HOSTLOGIN=root@\$ipv4_${host}
547 for file in clients.conf eap.conf radiusd.conf proxy.conf users
549 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
550 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
553 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
554 $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
556 scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
557 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
559 ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
560 >> $TESTRESULTDIR/${host}.daemon.log 2>/dev/null
562 chmod a+r $TESTRESULTDIR/*
563 cat >> $TESTRESULTDIR/index.html <<@EOF
565 <table border="0" cellspacing="0" width="600">
569 <li><a href="$host.clients.conf">clients.conf</a></li>
570 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
571 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
576 <li><a href="$host.eap.conf">eap.conf</a></li>
577 <li><a href="$host.radius.log">radius.log</a></li>
578 <li><a href="$host.daemon.log">daemon.log</a></li>
583 <li><a href="$host.proxy.conf">proxy.conf</a></li>
584 <li><a href="$host.users">users</a></li>
593 cat >> $TESTRESULTDIR/index.html <<@EOF
598 for host in $TCPDUMPHOSTS
600 eval HOSTLOGIN=root@\$ipv4_${host}
602 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
603 $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
605 cat >> $TESTRESULTDIR/index.html <<@EOF
606 <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
611 cat >> $TESTRESULTDIR/index.html <<@EOF
615 cat >> $TESTRESULTDIR/index.html <<@EOF
623 ##########################################################################
624 # execute post-test commands
628 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
633 printf("echo \"%s# %s\"; ", $1, $2)
634 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
637 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
640 ##########################################################################
641 # get a copy of /var/log/auth.log
644 for host in $IPSECHOSTS
646 eval HOSTLOGIN=root@\$ipv4_${host}
647 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated|imcv' \
648 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
652 ##########################################################################
653 # get a copy of /var/log/daemon.log
656 for host in $IPSECHOSTS
658 eval HOSTLOGIN=root@\$ipv4_${host}
659 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated|imcv' \
660 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
664 ##########################################################################
665 # stop tcpdump if necessary
668 for host in $TCPDUMPHOSTS
670 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
672 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
673 eval ssh $SSHCONF root@\$ipv4_$host killall tcpdump
674 eval TDUP_${host}="false"
679 ##########################################################################
680 # copy default host config back if necessary
683 $DIR/scripts/restore-defaults $testname
686 ##########################################################################
687 # write test status to html file
690 if [ $STATUS = "passed" ]
699 cat >> $TESTRESULTSHTML << @EOF
702 <td><a href="$testname/index.html">$testname</a></td>
703 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
707 cat >> $SUBTESTSINDEX << @EOF
710 <td><a href="$name/index.html">$name</a></td>
711 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
717 ##########################################################################
718 # remove any charon.pid files that still may exist
721 for host in $IPSECHOSTS
723 eval HOSTLOGIN=root@\$ipv4_${host}
724 ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
732 ##############################################################################
733 # finish the results html file
736 cat >> $TESTRESULTSHTML << @EOF
738 <td> </td><td> </td><td> </td><td> </td>
741 <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td> </td><td> </td>
744 <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td> </td><td> </td>
751 let "all_cnt = $passed_cnt + $failed_cnt"
753 cat >> $INDEX << @EOF
756 <td><a href="all.html"><b>all</b></a></td>
757 <td align="right"><b>$all_cnt</b></td>
761 <td><b>Failed</b></td>
763 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
772 echo_ok "Passed : $passed_cnt"
773 echo_failed "Failed : $failed_cnt"
777 ##############################################################################
778 # copy the test results to the apache server
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
787 echo "The results are available in $TODAYDIR"
788 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
790 ENDDATE=`date +%Y%m%d-%H%M`
792 echo "Finished : $ENDDATE"