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 . $PWD/scripts/function.sh
21 [ -d $PWD/hosts ] || die "Directory 'hosts' not found"
22 [ -d $PWD/tests ] || die "Directory 'tests' not found"
23 [ -d $BUILDDIR ] || 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 UML Tests</title>
142 <h2>strongSwan UML Tests</h2>
146 cat > $TESTRESULTSHTML <<@EOF
149 <title>strongSwan UML Tests - All Tests</title>
152 <div><a href="index.html">strongSwan UML 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
175 elif [ $SELECTEDTESTSONLY = "yes" ]
177 # set internal field seperator
180 # set internal field seperator
181 TESTS="`ls $DEFAULTTESTSDIR`"
186 SUBTESTS="`basename $SUBDIR`"
188 if [ $SUBTESTS = $SUBDIR ]
190 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
192 SUBDIR="`dirname $SUBDIR`"
195 if [ ! -d $TODAYDIR/$SUBDIR ]
197 mkdir $TODAYDIR/$SUBDIR
198 if [ $testnumber == 0 ]
200 FIRST="<b>Category</b>"
204 echo " <tr>" >> $INDEX
205 echo " <td>$FIRST</td>">> $INDEX
206 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
207 echo " <td align=\"right\">x</td>" >> $INDEX
208 echo " <td> </td>" >> $INDEX
209 echo " </tr>" >> $INDEX
210 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
211 cat > $SUBTESTSINDEX <<@EOF
214 <title>strongSwan $SUBDIR Tests</title>
217 <div><a href="../index.html">strongSwan UML Tests</a> / $SUBDIR</div>
218 <h2>strongSwan $SUBDIR Tests</h2>
219 <table border="0" cellspacing="2" cellpadding="2">
221 <td><b>UML kernel</b></td>
222 <td colspan="3">$KERNELVERSION</td>
225 <td><b>strongSwan</b></td>
226 <td colspan="3">$SWANVERSION</td>
230 <td colspan="3">$TESTDATE</td>
233 <td width="100"> </td>
234 <td width="300"> </td>
235 <td width=" 50"> </td>
241 <th colspan="2">Result</th>
246 for name in $SUBTESTS
248 let "testnumber += 1"
249 testname=$SUBDIR/$name
250 log_action " $testnumber $testname:"
252 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
254 echo "is missing..skipped"
258 if [ $SUBDIR = "ipv6" -o $name = "rw-psk-ipv6" ]
260 IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
261 IPROUTE_DSP=$IPROUTE_CMD
262 IPTABLES_CMD="ip6tables -v -n -L"
263 IPTABLES_DSP="ip6tables -L"
265 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
266 IPROUTE_DSP=$IPROUTE_CMD
267 IPTABLES_CMD="iptables -v -n -L"
268 IPTABLES_DSP="iptables -L"
271 if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
273 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
274 IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
275 IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
276 IPTABLES_DSP="iptables -L ; ip6tables -L"
279 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
280 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
281 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
282 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
283 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
285 TESTRESULTDIR=$TODAYDIR/$testname
286 mkdir -p $TESTRESULTDIR
287 CONSOLE_LOG=$TESTRESULTDIR/console.log
290 TESTDIR=$TESTSDIR/${testname}
293 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
296 ##############################################################################
297 # replace IP wildcards with actual IPv4 and IPv6 addresses
300 for host in $STRONGSWANHOSTS
304 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
305 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
306 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
307 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
310 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
311 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
312 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
313 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
316 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
317 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
318 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
319 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
322 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
323 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
326 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
327 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
330 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
331 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
332 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
333 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
336 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
337 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
338 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
339 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
342 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
343 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
349 ##########################################################################
350 # copy test specific configurations to uml hosts and clear auth.log files
353 $DIR/scripts/load-testconfig $testname
355 source $TESTDIR/test.conf
358 ##########################################################################
359 # run tcpdump in the background
362 if [ "$TCPDUMPHOSTS" != "" ]
364 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
366 for host_iface in $TCPDUMPHOSTS
368 host=`echo $host_iface | awk -F ":" '{print $1}'`
369 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
370 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain > /tmp/tcpdump.log 2>&1 &"
371 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
372 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
373 eval TDUP_${host}="true"
378 ##########################################################################
379 # execute pre-test commands
383 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
388 printf("echo \"%s# %s\"; ", $1, $2)
389 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
392 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
395 ##########################################################################
399 function stop_tcpdump {
400 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
401 eval ssh $SSHCONF root@\$ipv4_${1} killall tcpdump
402 eval TDUP_${1}="false"
407 ##########################################################################
408 # get and evaluate test results
412 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
423 if (command == "tcpdump")
425 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
426 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
427 printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
431 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
432 printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
434 printf("cmd_exit=\044?; ")
436 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
437 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
438 printf("; then STATUS=\"failed\"; fi; \n")
440 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
443 ##########################################################################
447 if [ $STATUS = "failed" ]
449 let "failed_cnt += 1"
451 let "passed_cnt += 1"
455 ##########################################################################
456 # log statusall and listall output
457 # get copies of ipsec.conf, ipsec.secrets
458 # create index.html for the given test case
460 cat > $TESTRESULTDIR/index.html <<@EOF
463 <title>Test $testname</title>
466 <table border="0" cellpadding="0" cellspacing="0" width="600">
468 <div><a href="../../index.html">strongSwan UML Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
469 <h2>Test $testname</h2>
473 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
475 cat >> $TESTRESULTDIR/index.html <<@EOF
477 <li><a href="console.log">console.log</a></li>
479 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
482 for host in $IPSECHOSTS
484 eval HOSTLOGIN=root@\$ipv4_${host}
486 for command in statusall listall
488 ssh $SSHCONF $HOSTLOGIN ipsec $command \
489 > $TESTRESULTDIR/${host}.$command 2>/dev/null
492 for file in strongswan.conf ipsec.conf ipsec.secrets
494 scp $SSHCONF $HOSTLOGIN:/etc/$file \
495 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
498 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
499 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
501 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
502 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
503 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
504 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
505 ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
506 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
507 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
508 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
509 chmod a+r $TESTRESULTDIR/*
510 cat >> $TESTRESULTDIR/index.html <<@EOF
512 <table border="0" cellspacing="0" width="600">
516 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
517 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
518 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
519 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
524 <li><a href="$host.statusall">ipsec statusall</a></li>
525 <li><a href="$host.listall">ipsec listall</a></li>
526 <li><a href="$host.auth.log">auth.log</a></li>
527 <li><a href="$host.daemon.log">daemon.log</a></li>
532 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
533 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
534 <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
535 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
544 for host in $RADIUSHOSTS
546 eval HOSTLOGIN=root@\$ipv4_${host}
548 for file in clients.conf eap.conf radiusd.conf proxy.conf users
550 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
551 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
554 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
555 $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
557 scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
558 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
560 chmod a+r $TESTRESULTDIR/*
561 cat >> $TESTRESULTDIR/index.html <<@EOF
563 <table border="0" cellspacing="0" width="600">
567 <li><a href="$host.clients.conf">clients.conf</a></li>
568 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
569 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
574 <li><a href="$host.eap.conf">eap.conf</a></li>
575 <li><a href="$host.radius.log">radius.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"