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 ln -sfT $DIR $TESTDIR/testing
28 ##############################################################################
29 # take care of new path and file variables
32 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
34 TESTDATE=`date +%Y%m%d-%H%M`
36 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
38 TESTRESULTSHTML=$TODAYDIR/all.html
39 INDEX=$TODAYDIR/index.html
40 DEFAULTTESTSDIR=$TESTDIR/testing/tests
42 SOURCEIP_ROUTING_TABLE=220
49 ##############################################################################
50 # copy default tests to $BUILDDIR
53 TESTSDIR=$BUILDDIR/tests
54 [ -d $TESTSDIR ] || mkdir $TESTSDIR
56 ##############################################################################
57 # assign IP for each host to hostname
60 for host in $STRONGSWANHOSTS
62 eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
63 eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
67 eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
68 eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
71 eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
72 eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
75 eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
76 eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
83 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
84 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
87 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
88 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
96 ##############################################################################
99 for host in $STRONGSWANHOSTS
101 ssh $SSHCONF -N root@`eval echo \\\$ipv4_$host` >/dev/null 2>&1 &
102 eval ssh_pid_$host="`echo $!`"
103 do_on_exit kill `eval echo \\\$ssh_pid_$host`
107 ##############################################################################
108 # create header for the results html file
111 ENVIRONMENT_HEADER=$(cat <<@EOF
112 <table border="0" cellspacing="2" cellpadding="2">
115 <td colspan="3">`uname -a`</td>
118 <td><b>Guest kernel</b></td>
119 <td colspan="3">$KERNELVERSION</td>
122 <td><b>strongSwan</b></td>
123 <td colspan="3">$SWANVERSION</td>
127 <td colspan="3">$TESTDATE</td>
130 <td width="100"> </td>
131 <td width="300"> </td>
132 <td width=" 50"> </td>
141 <title>strongSwan KVM Tests</title>
144 <h2>strongSwan KVM Tests</h2>
148 cat > $TESTRESULTSHTML <<@EOF
151 <title>strongSwan KVM Tests - All Tests</title>
154 <div><a href="index.html">strongSwan KVM Tests</a> / All Tests</div>
160 <th colspan="2">Result</th>
164 echo "Guest kernel : $KERNELVERSION"
165 echo "strongSwan : $SWANVERSION"
166 echo "Date : $TESTDATE"
170 ##############################################################################
171 # enter specific test directory
178 # set internal field seperator
179 TESTS="`ls $DEFAULTTESTSDIR`"
184 SUBTESTS="`basename $SUBDIR`"
186 if [ $SUBTESTS = $SUBDIR ]
188 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
190 SUBDIR="`dirname $SUBDIR`"
193 if [ ! -d $TODAYDIR/$SUBDIR ]
195 mkdir $TODAYDIR/$SUBDIR
196 if [ $testnumber == 0 ]
198 FIRST="<b>Category</b>"
202 echo " <tr>" >> $INDEX
203 echo " <td>$FIRST</td>">> $INDEX
204 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
205 echo " <td align=\"right\">x</td>" >> $INDEX
206 echo " <td> </td>" >> $INDEX
207 echo " </tr>" >> $INDEX
208 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
209 cat > $SUBTESTSINDEX <<@EOF
212 <title>strongSwan $SUBDIR Tests</title>
215 <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
216 <h2>strongSwan $SUBDIR Tests</h2>
217 <table border="0" cellspacing="2" cellpadding="2">
219 <td><b>Guest kernel</b></td>
220 <td colspan="3">$KERNELVERSION</td>
223 <td><b>strongSwan</b></td>
224 <td colspan="3">$SWANVERSION</td>
228 <td colspan="3">$TESTDATE</td>
231 <td width="100"> </td>
232 <td width="300"> </td>
233 <td width=" 50"> </td>
239 <th colspan="2">Result</th>
244 for name in $SUBTESTS
246 let "testnumber += 1"
247 testname=$SUBDIR/$name
248 log_action " $testnumber $testname:"
250 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
252 echo "is missing..skipped"
256 if [ $SUBDIR = "ipv6" -o $name = "rw-psk-ipv6" ]
258 IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
259 IPROUTE_DSP=$IPROUTE_CMD
260 IPTABLES_CMD="ip6tables -v -n -L"
261 IPTABLES_DSP="ip6tables -L"
263 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
264 IPROUTE_DSP=$IPROUTE_CMD
265 IPTABLES_CMD="iptables -v -n -L"
266 IPTABLES_DSP="iptables -L"
269 if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
271 IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
272 IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
273 IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
274 IPTABLES_DSP="iptables -L ; ip6tables -L"
277 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
278 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
279 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
280 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
281 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
283 TESTRESULTDIR=$TODAYDIR/$testname
284 mkdir -p $TESTRESULTDIR
285 CONSOLE_LOG=$TESTRESULTDIR/console.log
288 TESTDIR=$TESTSDIR/${testname}
291 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
294 ##############################################################################
295 # replace IP wildcards with actual IPv4 and IPv6 addresses
298 for host in $STRONGSWANHOSTS
302 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
303 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
304 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
305 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
308 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
309 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
310 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
311 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
314 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
315 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
316 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
317 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
320 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
321 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
324 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
325 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
328 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
329 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
330 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
331 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
334 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
335 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
336 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
337 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
340 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
341 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
347 ##########################################################################
348 # copy test specific configurations to uml hosts and clear auth.log files
351 $DIR/scripts/load-testconfig $testname
353 source $TESTDIR/test.conf
356 ##########################################################################
357 # run tcpdump in the background
360 if [ "$TCPDUMPHOSTS" != "" ]
362 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
364 for host_iface in $TCPDUMPHOSTS
366 host=`echo $host_iface | awk -F ":" '{print $1}'`
367 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
368 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain > /tmp/tcpdump.log 2>&1 &"
369 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
370 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
371 eval TDUP_${host}="true"
376 ##########################################################################
377 # execute pre-test commands
381 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
386 printf("echo \"%s# %s\"; ", $1, $2)
387 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
390 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
393 ##########################################################################
397 function stop_tcpdump {
398 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
399 eval ssh $SSHCONF root@\$ipv4_${1} killall tcpdump
400 eval TDUP_${1}="false"
405 ##########################################################################
406 # get and evaluate test results
410 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
421 if (command == "tcpdump")
423 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
424 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
425 printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
429 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
430 printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
432 printf("cmd_exit=\044?; ")
434 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
435 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
436 printf("; then STATUS=\"failed\"; fi; \n")
438 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
441 ##########################################################################
445 if [ $STATUS = "failed" ]
447 let "failed_cnt += 1"
449 let "passed_cnt += 1"
453 ##########################################################################
454 # log statusall and listall output
455 # get copies of ipsec.conf, ipsec.secrets
456 # create index.html for the given test case
458 cat > $TESTRESULTDIR/index.html <<@EOF
461 <title>Test $testname</title>
464 <table border="0" cellpadding="0" cellspacing="0" width="600">
466 <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
467 <h2>Test $testname</h2>
471 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
473 cat >> $TESTRESULTDIR/index.html <<@EOF
475 <li><a href="console.log">console.log</a></li>
477 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
480 for host in $IPSECHOSTS
482 eval HOSTLOGIN=root@\$ipv4_${host}
484 for command in statusall listall
486 ssh $SSHCONF $HOSTLOGIN ipsec $command \
487 > $TESTRESULTDIR/${host}.$command 2>/dev/null
490 for file in strongswan.conf ipsec.conf ipsec.secrets
492 scp $SSHCONF $HOSTLOGIN:/etc/$file \
493 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
496 scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
497 $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
499 ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
500 > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
501 ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
502 > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
503 ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
504 > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
505 ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
506 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
507 chmod a+r $TESTRESULTDIR/*
508 cat >> $TESTRESULTDIR/index.html <<@EOF
510 <table border="0" cellspacing="0" width="600">
514 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
515 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
516 <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
517 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
522 <li><a href="$host.statusall">ipsec statusall</a></li>
523 <li><a href="$host.listall">ipsec listall</a></li>
524 <li><a href="$host.auth.log">auth.log</a></li>
525 <li><a href="$host.daemon.log">daemon.log</a></li>
530 <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
531 <li><a href="$host.ip.state">ip -s xfrm state</a></li>
532 <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
533 <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
542 for host in $RADIUSHOSTS
544 eval HOSTLOGIN=root@\$ipv4_${host}
546 for file in clients.conf eap.conf radiusd.conf proxy.conf users
548 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
549 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
552 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
553 $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
555 scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
556 $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
558 ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
559 >> $TESTRESULTDIR/${host}.daemon.log
561 chmod a+r $TESTRESULTDIR/*
562 cat >> $TESTRESULTDIR/index.html <<@EOF
564 <table border="0" cellspacing="0" width="600">
568 <li><a href="$host.clients.conf">clients.conf</a></li>
569 <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
570 <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
575 <li><a href="$host.eap.conf">eap.conf</a></li>
576 <li><a href="$host.radius.log">radius.log</a></li>
577 <li><a href="$host.daemon.log">daemon.log</a></li>
582 <li><a href="$host.proxy.conf">proxy.conf</a></li>
583 <li><a href="$host.users">users</a></li>
592 cat >> $TESTRESULTDIR/index.html <<@EOF
597 for host in $TCPDUMPHOSTS
599 eval HOSTLOGIN=root@\$ipv4_${host}
601 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
602 $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
604 cat >> $TESTRESULTDIR/index.html <<@EOF
605 <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
610 cat >> $TESTRESULTDIR/index.html <<@EOF
614 cat >> $TESTRESULTDIR/index.html <<@EOF
622 ##########################################################################
623 # execute post-test commands
627 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
632 printf("echo \"%s# %s\"; ", $1, $2)
633 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
636 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
639 ##########################################################################
640 # get a copy of /var/log/auth.log
643 for host in $IPSECHOSTS
645 eval HOSTLOGIN=root@\$ipv4_${host}
646 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated' \
647 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
651 ##########################################################################
652 # get a copy of /var/log/daemon.log
655 for host in $IPSECHOSTS
657 eval HOSTLOGIN=root@\$ipv4_${host}
658 ssh $SSHCONF $HOSTLOGIN "grep -E 'charon|last message repeated' \
659 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
663 ##########################################################################
664 # stop tcpdump if necessary
667 for host in $TCPDUMPHOSTS
669 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
671 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
672 eval ssh $SSHCONF root@\$ipv4_$host killall tcpdump
673 eval TDUP_${host}="false"
678 ##########################################################################
679 # copy default host config back if necessary
682 $DIR/scripts/restore-defaults $testname
685 ##########################################################################
686 # write test status to html file
689 if [ $STATUS = "passed" ]
698 cat >> $TESTRESULTSHTML << @EOF
701 <td><a href="$testname/index.html">$testname</a></td>
702 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
706 cat >> $SUBTESTSINDEX << @EOF
709 <td><a href="$name/index.html">$name</a></td>
710 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
716 ##########################################################################
717 # remove any charon.pid files that still may exist
720 for host in $IPSECHOSTS
722 eval HOSTLOGIN=root@\$ipv4_${host}
723 ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
731 ##############################################################################
732 # finish the results html file
735 cat >> $TESTRESULTSHTML << @EOF
737 <td> </td><td> </td><td> </td><td> </td>
740 <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td> </td><td> </td>
743 <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td> </td><td> </td>
750 let "all_cnt = $passed_cnt + $failed_cnt"
752 cat >> $INDEX << @EOF
755 <td><a href="all.html"><b>all</b></a></td>
756 <td align="right"><b>$all_cnt</b></td>
760 <td><b>Failed</b></td>
762 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
771 echo_ok "Passed : $passed_cnt"
772 echo_failed "Failed : $failed_cnt"
776 ##############################################################################
777 # copy the test results to the apache server
782 ssh $SSHCONF root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
783 scp $SSHCONF -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
784 ssh $SSHCONF root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
786 echo "The results are available in $TODAYDIR"
787 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
789 ENDDATE=`date +%Y%m%d-%H%M`
791 echo "Finished : $ENDDATE"