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 IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
272 IPROUTE_DSP=$IPROUTE_CMD
273 IPTABLES_CMD="ip6tables -v -n -L"
274 IPTABLES_DSP="ip6tables -L"
276 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
277 IPROUTE_DSP=$IPROUTE_CMD
278 IPTABLES_CMD="iptables -v -n -L"
279 IPTABLES_DSP="iptables -L"
282 if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
284 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
285 IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
286 IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
287 IPTABLES_DSP="iptables -L ; ip6tables -L"
290 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
291 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
292 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
293 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
294 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
296 TESTRESULTDIR=$TODAYDIR/$testname
297 mkdir -p $TESTRESULTDIR
298 CONSOLE_LOG=$TESTRESULTDIR/console.log
301 TESTDIR=$TESTSDIR/${testname}
304 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
307 ##############################################################################
308 # replace IP wildcards with actual IPv4 and IPv6 addresses
311 for host in $STRONGSWANHOSTS
315 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
316 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
317 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
318 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
321 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
322 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
323 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
324 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
327 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
328 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
329 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
330 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
333 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
334 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
337 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
338 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
341 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
342 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
343 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
344 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
347 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
348 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
349 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
350 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
353 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
354 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
360 ##########################################################################
361 # copy test specific configurations to uml hosts and clear auth.log files
364 $DIR/scripts/load-testconfig $testname
366 source $TESTDIR/test.conf
369 ##########################################################################
370 # run tcpdump in the background
373 if [ "$TCPDUMPHOSTS" != "" ]
375 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
377 for host_iface in $TCPDUMPHOSTS
379 host=`echo $host_iface | awk -F ":" '{print $1}'`
380 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
381 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain > /tmp/tcpdump.log 2>&1 &"
382 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
383 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
384 eval TDUP_${host}="true"
389 ##########################################################################
390 # execute pre-test commands
394 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
399 printf("echo \"%s# %s\"; ", $1, $2)
400 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
403 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
406 ##########################################################################
410 function stop_tcpdump {
411 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
412 eval ssh $SSHCONF root@\$ipv4_${1} killall tcpdump
413 eval TDUP_${1}="false"
418 ##########################################################################
419 # get and evaluate test results
423 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
434 if (command == "tcpdump")
436 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
437 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
438 printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
442 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
443 printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
445 printf("cmd_exit=\044?; ")
447 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
448 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
449 printf("; then STATUS=\"failed\"; fi; \n")
451 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
454 ##########################################################################
458 if [ $STATUS = "failed" ]
460 let "failed_cnt += 1"
462 let "passed_cnt += 1"
466 ##########################################################################
467 # log statusall and listall output
468 # get copies of ipsec.conf, ipsec.secrets
469 # create index.html for the given test case
471 cat > $TESTRESULTDIR/index.html <<@EOF
474 <title>Test $testname</title>
477 <table border="0" cellpadding="0" cellspacing="0" width="600">
479 <div><a href="../../index.html">strongSwan UML Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
480 <h2>Test $testname</h2>
484 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
486 cat >> $TESTRESULTDIR/index.html <<@EOF
488 <li><a href="console.log">console.log</a></li>
490 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
493 for host in $IPSECHOSTS
495 eval HOSTLOGIN=root@\$ipv4_${host}
497 for command in statusall listall
499 ssh $SSHCONF $HOSTLOGIN ipsec $command \
500 > $TESTRESULTDIR/${host}.$command 2>/dev/null
503 for file in strongswan.conf ipsec.conf ipsec.secrets
505 scp $SSHCONF $HOSTLOGIN:/etc/$file \
506 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
509 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
510 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
512 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
513 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
514 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
515 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
516 ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
517 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
518 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
519 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
520 chmod a+r $TESTRESULTDIR/*
521 cat >> $TESTRESULTDIR/index.html <<@EOF
523 <table border="0" cellspacing="0" width="600">
527 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
528 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
529 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
530 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
535 <li><a href="$host.statusall">ipsec statusall</a></li>
536 <li><a href="$host.listall">ipsec listall</a></li>
537 <li><a href="$host.auth.log">auth.log</a></li>
538 <li><a href="$host.daemon.log">daemon.log</a></li>
543 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
544 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
545 <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
546 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
555 for host in $RADIUSHOSTS
557 eval HOSTLOGIN=root@\$ipv4_${host}
559 for file in clients.conf eap.conf radiusd.conf proxy.conf users
561 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
562 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
565 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
566 $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
568 scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
569 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
571 chmod a+r $TESTRESULTDIR/*
572 cat >> $TESTRESULTDIR/index.html <<@EOF
574 <table border="0" cellspacing="0" width="600">
578 <li><a href="$host.clients.conf">clients.conf</a></li>
579 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
580 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
585 <li><a href="$host.eap.conf">eap.conf</a></li>
586 <li><a href="$host.radius.log">radius.log</a></li>
591 <li><a href="$host.proxy.conf">proxy.conf</a></li>
592 <li><a href="$host.users">users</a></li>
601 cat >> $TESTRESULTDIR/index.html <<@EOF
609 ##########################################################################
610 # execute post-test commands
614 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
619 printf("echo \"%s# %s\"; ", $1, $2)
620 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
623 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
626 ##########################################################################
627 # get a copy of /var/log/auth.log
630 for host in $IPSECHOSTS
632 eval HOSTLOGIN=root@\$ipv4_${host}
633 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated' \
634 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
638 ##########################################################################
639 # get a copy of /var/log/daemon.log
642 for host in $IPSECHOSTS
644 eval HOSTLOGIN=root@\$ipv4_${host}
645 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated' \
646 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
650 ##########################################################################
651 # stop tcpdump if necessary
654 for host in $TCPDUMPHOSTS
656 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
658 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
659 eval ssh $SSHCONF root@\$ipv4_$host killall tcpdump
660 eval TDUP_${host}="false"
665 ##########################################################################
666 # copy default host config back if necessary
669 $DIR/scripts/restore-defaults $testname
672 ##########################################################################
673 # write test status to html file
676 if [ $STATUS = "passed" ]
679 cecho "\033[1;32m$STATUS"
685 cat >> $TESTRESULTSHTML << @EOF
688 <td><a href="$testname/index.html">$testname</a></td>
689 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
693 cat >> $SUBTESTSINDEX << @EOF
696 <td><a href="$name/index.html">$name</a></td>
697 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
703 ##########################################################################
704 # remove any charon.pid files that still may exist
707 for host in $IPSECHOSTS
709 eval HOSTLOGIN=root@\$ipv4_${host}
710 ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
718 ##############################################################################
719 # finish the results html file
722 cat >> $TESTRESULTSHTML << @EOF
724 <td> </td><td> </td><td> </td><td> </td>
727 <td><b>Passed:</b></td><td><b><font color="green">$passed_cnt</font></b></td><td> </td><td> </td>
730 <td><b>Failed:</b></td><td><b><font color="red">$failed_cnt</font></b></td><td> </td><td> </td>
737 let "all_cnt = $passed_cnt + $failed_cnt"
739 cat >> $INDEX << @EOF
742 <td><a href="all.html"><b>all</b></a></td>
743 <td align="right"><b>$all_cnt</b></td>
747 <td><b>Failed:</b></td>
749 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
758 cecho "\033[1;32mPassed: $passed_cnt"
759 cecho "Failed: $failed_cnt"
763 ##############################################################################
764 # copy the test results to the apache server
769 cecho-n "Copying test results to winnetou.."
770 ssh $SSHCONF root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
771 scp $SSHCONF -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
772 ssh $SSHCONF root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
775 cecho "The results are available in $TODAYDIR"
776 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
779 ##########################################################################
782 for host in $STRONGSWANHOSTS
784 kill `eval echo \\\$ssh_pid_$host`