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
21 [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
22 [ -d $DIR/tests ] || die "Directory 'tests' not found"
24 die "Directory '$BUILDDIR' does not exist, please run make-testing first"
26 ##############################################################################
27 # take care of new path and file variables
30 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
32 TESTDATE=`date +%Y%m%d-%H%M`
34 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
36 TESTRESULTSHTML=$TODAYDIR/all.html
37 INDEX=$TODAYDIR/index.html
38 DEFAULTTESTSDIR=$TESTDIR/testing/tests
40 SOURCEIP_ROUTING_TABLE=220
47 ##############################################################################
48 # copy default tests to $BUILDDIR
51 TESTSDIR=$BUILDDIR/tests
52 [ -d $TESTSDIR ] || mkdir $TESTSDIR
54 ##############################################################################
55 # assign IP for each host to hostname
58 for host in $STRONGSWANHOSTS
60 eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
61 eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
65 eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
66 eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
69 eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
70 eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
73 eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
74 eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
81 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
82 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
85 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
86 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
94 ##############################################################################
97 for host in $STRONGSWANHOSTS
99 ssh $SSHCONF -N root@`eval echo \\\$ipv4_$host` >/dev/null 2>&1 &
100 eval ssh_pid_$host="`echo $!`"
101 do_on_exit kill `eval echo \\\$ssh_pid_$host`
105 ##############################################################################
106 # create header for the results html file
109 ENVIRONMENT_HEADER=$(cat <<@EOF
110 <table border="0" cellspacing="2" cellpadding="2">
113 <td colspan="3">`uname -a`</td>
116 <td><b>Guest kernel</b></td>
117 <td colspan="3">$KERNELVERSION</td>
120 <td><b>strongSwan</b></td>
121 <td colspan="3">$SWANVERSION</td>
125 <td colspan="3">$TESTDATE</td>
128 <td width="100"> </td>
129 <td width="300"> </td>
130 <td width=" 50"> </td>
139 <title>strongSwan KVM Tests</title>
142 <h2>strongSwan KVM Tests</h2>
146 cat > $TESTRESULTSHTML <<@EOF
149 <title>strongSwan KVM Tests - All Tests</title>
152 <div><a href="index.html">strongSwan KVM Tests</a> / All Tests</div>
158 <th colspan="2">Result</th>
162 echo "Guest kernel : $KERNELVERSION"
163 echo "strongSwan : $SWANVERSION"
164 echo "Date : $TESTDATE"
168 ##############################################################################
169 # enter specific test directory
176 # set internal field seperator
177 TESTS="`ls $DEFAULTTESTSDIR`"
182 SUBTESTS="`basename $SUBDIR`"
184 if [ $SUBTESTS = $SUBDIR ]
186 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
188 SUBDIR="`dirname $SUBDIR`"
191 if [ ! -d $TODAYDIR/$SUBDIR ]
193 mkdir $TODAYDIR/$SUBDIR
194 if [ $testnumber == 0 ]
196 FIRST="<b>Category</b>"
200 echo " <tr>" >> $INDEX
201 echo " <td>$FIRST</td>">> $INDEX
202 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
203 echo " <td align=\"right\">x</td>" >> $INDEX
204 echo " <td> </td>" >> $INDEX
205 echo " </tr>" >> $INDEX
206 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
207 cat > $SUBTESTSINDEX <<@EOF
210 <title>strongSwan $SUBDIR Tests</title>
213 <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
214 <h2>strongSwan $SUBDIR Tests</h2>
215 <table border="0" cellspacing="2" cellpadding="2">
217 <td><b>Guest kernel</b></td>
218 <td colspan="3">$KERNELVERSION</td>
221 <td><b>strongSwan</b></td>
222 <td colspan="3">$SWANVERSION</td>
226 <td colspan="3">$TESTDATE</td>
229 <td width="100"> </td>
230 <td width="300"> </td>
231 <td width=" 50"> </td>
237 <th colspan="2">Result</th>
242 for name in $SUBTESTS
244 let "testnumber += 1"
245 testname=$SUBDIR/$name
246 log_action " $testnumber $testname:"
248 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
250 echo "is missing..skipped"
254 if [ $SUBDIR = "ipv6" -o $name = "rw-psk-ipv6" ]
256 IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
257 IPROUTE_DSP=$IPROUTE_CMD
258 IPTABLES_CMD="ip6tables -v -n -L"
259 IPTABLES_DSP="ip6tables -L"
261 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
262 IPROUTE_DSP=$IPROUTE_CMD
263 IPTABLES_CMD="iptables -v -n -L"
264 IPTABLES_DSP="iptables -L"
267 if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
269 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
270 IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
271 IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
272 IPTABLES_DSP="iptables -L ; ip6tables -L"
275 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
276 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
277 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
278 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
279 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
281 TESTRESULTDIR=$TODAYDIR/$testname
282 mkdir -p $TESTRESULTDIR
283 CONSOLE_LOG=$TESTRESULTDIR/console.log
286 TESTDIR=$TESTSDIR/${testname}
289 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
292 ##############################################################################
293 # replace IP wildcards with actual IPv4 and IPv6 addresses
296 for host in $STRONGSWANHOSTS
300 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
301 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
302 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
303 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
306 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
307 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
308 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
309 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
312 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
313 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
314 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
315 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
318 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
319 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
322 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
323 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
326 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
327 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
328 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
329 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
332 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
333 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
334 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
335 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
338 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
339 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
345 ##########################################################################
346 # copy test specific configurations to uml hosts and clear auth.log files
349 $DIR/scripts/load-testconfig $testname
351 source $TESTDIR/test.conf
354 ##########################################################################
355 # run tcpdump in the background
358 if [ "$TCPDUMPHOSTS" != "" ]
360 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
362 for host_iface in $TCPDUMPHOSTS
364 host=`echo $host_iface | awk -F ":" '{print $1}'`
365 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
366 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain > /tmp/tcpdump.log 2>&1 &"
367 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
368 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
369 eval TDUP_${host}="true"
374 ##########################################################################
375 # execute pre-test commands
379 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
384 printf("echo \"%s# %s\"; ", $1, $2)
385 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
388 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
391 ##########################################################################
395 function stop_tcpdump {
396 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
397 eval ssh $SSHCONF root@\$ipv4_${1} killall tcpdump
398 eval TDUP_${1}="false"
403 ##########################################################################
404 # get and evaluate test results
408 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
419 if (command == "tcpdump")
421 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
422 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
423 printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
427 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
428 printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
430 printf("cmd_exit=\044?; ")
432 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
433 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
434 printf("; then STATUS=\"failed\"; fi; \n")
436 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
439 ##########################################################################
443 if [ $STATUS = "failed" ]
445 let "failed_cnt += 1"
447 let "passed_cnt += 1"
451 ##########################################################################
452 # log statusall and listall output
453 # get copies of ipsec.conf, ipsec.secrets
454 # create index.html for the given test case
456 cat > $TESTRESULTDIR/index.html <<@EOF
459 <title>Test $testname</title>
462 <table border="0" cellpadding="0" cellspacing="0" width="600">
464 <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
465 <h2>Test $testname</h2>
469 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
471 cat >> $TESTRESULTDIR/index.html <<@EOF
473 <li><a href="console.log">console.log</a></li>
475 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
478 for host in $IPSECHOSTS
480 eval HOSTLOGIN=root@\$ipv4_${host}
482 for command in statusall listall
484 ssh $SSHCONF $HOSTLOGIN ipsec $command \
485 > $TESTRESULTDIR/${host}.$command 2>/dev/null
488 for file in strongswan.conf ipsec.conf ipsec.secrets
490 scp $SSHCONF $HOSTLOGIN:/etc/$file \
491 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
494 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
495 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
497 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
498 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
499 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
500 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
501 ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
502 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
503 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
504 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
505 chmod a+r $TESTRESULTDIR/*
506 cat >> $TESTRESULTDIR/index.html <<@EOF
508 <table border="0" cellspacing="0" width="600">
512 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
513 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
514 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
515 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
520 <li><a href="$host.statusall">ipsec statusall</a></li>
521 <li><a href="$host.listall">ipsec listall</a></li>
522 <li><a href="$host.auth.log">auth.log</a></li>
523 <li><a href="$host.daemon.log">daemon.log</a></li>
528 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
529 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
530 <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
531 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
540 for host in $RADIUSHOSTS
542 eval HOSTLOGIN=root@\$ipv4_${host}
544 for file in clients.conf eap.conf radiusd.conf proxy.conf users
546 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
547 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
550 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
551 $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
553 scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
554 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
556 ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
557 >> $TESTRESULTDIR/${host}.daemon.log
559 chmod a+r $TESTRESULTDIR/*
560 cat >> $TESTRESULTDIR/index.html <<@EOF
562 <table border="0" cellspacing="0" width="600">
566 <li><a href="$host.clients.conf">clients.conf</a></li>
567 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
568 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
573 <li><a href="$host.eap.conf">eap.conf</a></li>
574 <li><a href="$host.radius.log">radius.log</a></li>
575 <li><a href="$host.daemon.log">daemon.log</a></li>
580 <li><a href="$host.proxy.conf">proxy.conf</a></li>
581 <li><a href="$host.users">users</a></li>
590 cat >> $TESTRESULTDIR/index.html <<@EOF
595 for host in $TCPDUMPHOSTS
597 eval HOSTLOGIN=root@\$ipv4_${host}
599 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
600 $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
602 cat >> $TESTRESULTDIR/index.html <<@EOF
603 <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
608 cat >> $TESTRESULTDIR/index.html <<@EOF
612 cat >> $TESTRESULTDIR/index.html <<@EOF
620 ##########################################################################
621 # execute post-test commands
625 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
630 printf("echo \"%s# %s\"; ", $1, $2)
631 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
634 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
637 ##########################################################################
638 # get a copy of /var/log/auth.log
641 for host in $IPSECHOSTS
643 eval HOSTLOGIN=root@\$ipv4_${host}
644 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated' \
645 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
649 ##########################################################################
650 # get a copy of /var/log/daemon.log
653 for host in $IPSECHOSTS
655 eval HOSTLOGIN=root@\$ipv4_${host}
656 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated' \
657 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
661 ##########################################################################
662 # stop tcpdump if necessary
665 for host in $TCPDUMPHOSTS
667 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
669 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
670 eval ssh $SSHCONF root@\$ipv4_$host killall tcpdump
671 eval TDUP_${host}="false"
676 ##########################################################################
677 # copy default host config back if necessary
680 $DIR/scripts/restore-defaults $testname
683 ##########################################################################
684 # write test status to html file
687 if [ $STATUS = "passed" ]
696 cat >> $TESTRESULTSHTML << @EOF
699 <td><a href="$testname/index.html">$testname</a></td>
700 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
704 cat >> $SUBTESTSINDEX << @EOF
707 <td><a href="$name/index.html">$name</a></td>
708 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
714 ##########################################################################
715 # remove any charon.pid files that still may exist
718 for host in $IPSECHOSTS
720 eval HOSTLOGIN=root@\$ipv4_${host}
721 ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
729 ##############################################################################
730 # finish the results html file
733 cat >> $TESTRESULTSHTML << @EOF
735 <td> </td><td> </td><td> </td><td> </td>
738 <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td> </td><td> </td>
741 <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td> </td><td> </td>
748 let "all_cnt = $passed_cnt + $failed_cnt"
750 cat >> $INDEX << @EOF
753 <td><a href="all.html"><b>all</b></a></td>
754 <td align="right"><b>$all_cnt</b></td>
758 <td><b>Failed</b></td>
760 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
769 echo_ok "Passed : $passed_cnt"
770 echo_failed "Failed : $failed_cnt"
774 ##############################################################################
775 # copy the test results to the apache server
780 ssh $SSHCONF root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
781 scp $SSHCONF -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
782 ssh $SSHCONF root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
784 echo "The results are available in $TODAYDIR"
785 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
787 ENDDATE=`date +%Y%m%d-%H%M`
789 echo "Finished : $ENDDATE"