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=220
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 ENVIRONMENT_HEADER=$(cat <<@EOF
118 <table border="0" cellspacing="2" cellpadding="2">
121 <td colspan="3">`uname -a`</td>
124 <td><b>UML kernel</b></td>
125 <td colspan="3">$KERNELVERSION</td>
128 <td><b>strongSwan</b></td>
129 <td colspan="3">$SWANVERSION</td>
133 <td colspan="3">$TESTDATE</td>
136 <td width="100"> </td>
137 <td width="300"> </td>
138 <td width=" 50"> </td>
147 <title>strongSwan UML Tests</title>
150 <h2>strongSwan UML Tests</h2>
154 cat > $TESTRESULTSHTML <<@EOF
157 <title>strongSwan UML Tests - All Tests</title>
160 <div><a href="index.html">strongSwan UML Tests</a> / All Tests</div>
166 <th colspan="2">Result</th>
170 cecho "UML kernel : $KERNELVERSION"
171 cecho "strongSwan : $SWANVERSION"
172 cecho "Date : $TESTDATE"
176 ##############################################################################
177 # enter specific test directory
183 elif [ $SELECTEDTESTSONLY = "yes" ]
185 # set internal field seperator
188 # set internal field seperator
189 TESTS="`ls $DEFAULTTESTSDIR`"
194 SUBTESTS="`basename $SUBDIR`"
196 if [ $SUBTESTS = $SUBDIR ]
198 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
200 SUBDIR="`dirname $SUBDIR`"
203 if [ ! -d $TODAYDIR/$SUBDIR ]
205 mkdir $TODAYDIR/$SUBDIR
206 if [ $testnumber == 0 ]
208 FIRST="<b>Category</b>"
212 echo " <tr>" >> $INDEX
213 echo " <td>$FIRST</td>">> $INDEX
214 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
215 echo " <td align=\"right\">x</td>" >> $INDEX
216 echo " <td> </td>" >> $INDEX
217 echo " </tr>" >> $INDEX
218 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
219 cat > $SUBTESTSINDEX <<@EOF
222 <title>strongSwan $SUBDIR Tests</title>
225 <div><a href="../index.html">strongSwan UML Tests</a> / $SUBDIR</div>
226 <h2>strongSwan $SUBDIR Tests</h2>
227 <table border="0" cellspacing="2" cellpadding="2">
229 <td><b>UML kernel</b></td>
230 <td colspan="3">$KERNELVERSION</td>
233 <td><b>strongSwan</b></td>
234 <td colspan="3">$SWANVERSION</td>
238 <td colspan="3">$TESTDATE</td>
241 <td width="100"> </td>
242 <td width="300"> </td>
243 <td width=" 50"> </td>
249 <th colspan="2">Result</th>
254 for name in $SUBTESTS
256 let "testnumber += 1"
257 testname=$SUBDIR/$name
258 cecho-n " $testnumber $testname.."
260 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
262 cecho "is missing..skipped"
266 if [ $SUBDIR = "ipv6" -o $name = "rw-psk-ipv6" ]
268 IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
269 IPROUTE_DSP=$IPROUTE_CMD
270 IPTABLES_CMD="ip6tables -v -n -L"
271 IPTABLES_DSP="ip6tables -L"
273 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
274 IPROUTE_DSP=$IPROUTE_CMD
275 IPTABLES_CMD="iptables -v -n -L"
276 IPTABLES_DSP="iptables -L"
279 if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
281 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
282 IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
283 IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
284 IPTABLES_DSP="iptables -L ; ip6tables -L"
287 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
288 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
289 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
290 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
291 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
293 TESTRESULTDIR=$TODAYDIR/$testname
294 mkdir -p $TESTRESULTDIR
295 CONSOLE_LOG=$TESTRESULTDIR/console.log
298 TESTDIR=$TESTSDIR/${testname}
301 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
304 ##############################################################################
305 # replace IP wildcards with actual IPv4 and IPv6 addresses
308 for host in $STRONGSWANHOSTS
312 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
313 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
314 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
315 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
318 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
319 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
320 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
321 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
324 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
325 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
326 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
327 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
330 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
331 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
334 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
335 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
338 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
339 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
340 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
341 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
344 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
345 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
346 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
347 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
350 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
351 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
357 ##########################################################################
358 # copy test specific configurations to uml hosts and clear auth.log files
361 $DIR/scripts/load-testconfig $testname
363 source $TESTDIR/test.conf
366 ##########################################################################
367 # run tcpdump in the background
370 if [ "$TCPDUMPHOSTS" != "" ]
372 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
374 for host_iface in $TCPDUMPHOSTS
376 host=`echo $host_iface | awk -F ":" '{print $1}'`
377 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
378 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain > /tmp/tcpdump.log 2>&1 &"
379 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
380 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
381 eval TDUP_${host}="true"
386 ##########################################################################
387 # execute pre-test commands
391 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
396 printf("echo \"%s# %s\"; ", $1, $2)
397 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
400 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
403 ##########################################################################
407 function stop_tcpdump {
408 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
409 eval ssh $SSHCONF root@\$ipv4_${1} killall tcpdump
410 eval TDUP_${1}="false"
415 ##########################################################################
416 # get and evaluate test results
420 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
431 if (command == "tcpdump")
433 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
434 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
435 printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
439 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
440 printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
442 printf("cmd_exit=\044?; ")
444 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
445 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
446 printf("; then STATUS=\"failed\"; fi; \n")
448 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
451 ##########################################################################
455 if [ $STATUS = "failed" ]
457 let "failed_cnt += 1"
459 let "passed_cnt += 1"
463 ##########################################################################
464 # log statusall and listall output
465 # get copies of ipsec.conf, ipsec.secrets
466 # create index.html for the given test case
468 cat > $TESTRESULTDIR/index.html <<@EOF
471 <title>Test $testname</title>
474 <table border="0" cellpadding="0" cellspacing="0" width="600">
476 <div><a href="../../index.html">strongSwan UML Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
477 <h2>Test $testname</h2>
481 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
483 cat >> $TESTRESULTDIR/index.html <<@EOF
485 <li><a href="console.log">console.log</a></li>
487 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
490 for host in $IPSECHOSTS
492 eval HOSTLOGIN=root@\$ipv4_${host}
494 for command in statusall listall
496 ssh $SSHCONF $HOSTLOGIN ipsec $command \
497 > $TESTRESULTDIR/${host}.$command 2>/dev/null
500 for file in strongswan.conf ipsec.conf ipsec.secrets
502 scp $SSHCONF $HOSTLOGIN:/etc/$file \
503 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
506 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
507 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
509 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
510 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
511 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
512 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
513 ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
514 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
515 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
516 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
517 chmod a+r $TESTRESULTDIR/*
518 cat >> $TESTRESULTDIR/index.html <<@EOF
520 <table border="0" cellspacing="0" width="600">
524 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
525 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
526 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
527 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
532 <li><a href="$host.statusall">ipsec statusall</a></li>
533 <li><a href="$host.listall">ipsec listall</a></li>
534 <li><a href="$host.auth.log">auth.log</a></li>
535 <li><a href="$host.daemon.log">daemon.log</a></li>
540 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
541 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
542 <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
543 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
552 for host in $RADIUSHOSTS
554 eval HOSTLOGIN=root@\$ipv4_${host}
556 for file in clients.conf eap.conf radiusd.conf proxy.conf users
558 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
559 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
562 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
563 $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
565 scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
566 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
568 chmod a+r $TESTRESULTDIR/*
569 cat >> $TESTRESULTDIR/index.html <<@EOF
571 <table border="0" cellspacing="0" width="600">
575 <li><a href="$host.clients.conf">clients.conf</a></li>
576 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
577 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
582 <li><a href="$host.eap.conf">eap.conf</a></li>
583 <li><a href="$host.radius.log">radius.log</a></li>
588 <li><a href="$host.proxy.conf">proxy.conf</a></li>
589 <li><a href="$host.users">users</a></li>
598 cat >> $TESTRESULTDIR/index.html <<@EOF
603 for host in $TCPDUMPHOSTS
605 eval HOSTLOGIN=root@\$ipv4_${host}
607 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
608 $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
610 cat >> $TESTRESULTDIR/index.html <<@EOF
611 <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
616 cat >> $TESTRESULTDIR/index.html <<@EOF
620 cat >> $TESTRESULTDIR/index.html <<@EOF
628 ##########################################################################
629 # execute post-test commands
633 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
638 printf("echo \"%s# %s\"; ", $1, $2)
639 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
642 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
645 ##########################################################################
646 # get a copy of /var/log/auth.log
649 for host in $IPSECHOSTS
651 eval HOSTLOGIN=root@\$ipv4_${host}
652 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated' \
653 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
657 ##########################################################################
658 # get a copy of /var/log/daemon.log
661 for host in $IPSECHOSTS
663 eval HOSTLOGIN=root@\$ipv4_${host}
664 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated' \
665 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
669 ##########################################################################
670 # stop tcpdump if necessary
673 for host in $TCPDUMPHOSTS
675 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
677 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
678 eval ssh $SSHCONF root@\$ipv4_$host killall tcpdump
679 eval TDUP_${host}="false"
684 ##########################################################################
685 # copy default host config back if necessary
688 $DIR/scripts/restore-defaults $testname
691 ##########################################################################
692 # write test status to html file
695 if [ $STATUS = "passed" ]
698 cecho "\033[1;32m$STATUS"
704 cat >> $TESTRESULTSHTML << @EOF
707 <td><a href="$testname/index.html">$testname</a></td>
708 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
712 cat >> $SUBTESTSINDEX << @EOF
715 <td><a href="$name/index.html">$name</a></td>
716 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
722 ##########################################################################
723 # remove any charon.pid files that still may exist
726 for host in $IPSECHOSTS
728 eval HOSTLOGIN=root@\$ipv4_${host}
729 ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
737 ##############################################################################
738 # finish the results html file
741 cat >> $TESTRESULTSHTML << @EOF
743 <td> </td><td> </td><td> </td><td> </td>
746 <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td> </td><td> </td>
749 <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td> </td><td> </td>
756 let "all_cnt = $passed_cnt + $failed_cnt"
758 cat >> $INDEX << @EOF
761 <td><a href="all.html"><b>all</b></a></td>
762 <td align="right"><b>$all_cnt</b></td>
766 <td><b>Failed</b></td>
768 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
777 cecho "\033[1;32mPassed: $passed_cnt"
778 cecho "Failed: $failed_cnt"
782 ##############################################################################
783 # copy the test results to the apache server
788 cecho-n "Copying test results to winnetou.."
789 ssh $SSHCONF root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
790 scp $SSHCONF -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
791 ssh $SSHCONF root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
794 cecho "The results are available in $TODAYDIR"
795 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
797 ENDDATE=`date +%Y%m%d-%H%M`
799 cecho "Finished: $ENDDATE"
801 ##########################################################################
804 for host in $STRONGSWANHOSTS
806 kill `eval echo \\\$ssh_pid_$host`