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
21 source $DIR/scripts/function.sh
23 [ -f $DIR/testing.conf ] || die "Configuration file 'testing.conf' not found"
24 [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
25 [ -d $DIR/tests ] || die "Directory 'tests' not found"
27 source $DIR/testing.conf
30 ##############################################################################
31 # test if UMLs have been built at all
34 [ -d $BUILDDIR ] || die "Directory '$BUILDDIR' does not exist. Please run 'make-testing'first."
37 ##############################################################################
38 # take care of new path and file variables
41 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
43 TESTDATE=`date +%Y%m%d-%H%M`
45 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
47 TESTRESULTSHTML=$TODAYDIR/all.html
48 INDEX=$TODAYDIR/index.html
49 DEFAULTTESTSDIR=$UMLTESTDIR/testing/tests
51 SOURCEIP_ROUTING_TABLE=@IPSEC_ROUTING_TABLE@
58 ##############################################################################
59 # copy default tests to $BUILDDIR
62 TESTSDIR=$BUILDDIR/tests
63 [ -d $TESTSDIR ] || mkdir $TESTSDIR
65 ##############################################################################
66 # assign IP for each host to hostname
69 for host in $STRONGSWANHOSTS
71 eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
72 eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
76 eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
77 eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
80 eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
81 eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
84 eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
85 eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
92 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
93 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
96 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
97 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
105 ##############################################################################
106 # create header for the results html file
109 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
110 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
115 <title>strongSwan UML Tests</title>
118 <h2>strongSwan UML Tests</h2>
119 <table border="0" cellspacing="2">
121 <td><b>Host:</b></td>
122 <td colspan="3">`uname -a`</td>
125 <td><b>UML kernel: </b></td>
126 <td colspan="3">$KERNEL_VERSION</td>
129 <td><b>IPsec:</b></td>
130 <td colspan="3">$IPSEC_VERSION</td>
133 <td><b>Date:</b></td>
134 <td colspan="3">$TESTDATE</td>
137 <td width="100"> </td>
138 <td width="200"> </td>
139 <td width=" 50"> </td>
144 cat $INDEX > $TESTRESULTSHTML
145 cat >> $TESTRESULTSHTML <<@EOF
149 <th colspan="2">Result</th>
153 cecho "UML kernel: $KERNEL_VERSION"
154 cecho "IPsec: $IPSEC_VERSION"
155 cecho "Date: $TESTDATE"
159 ##############################################################################
160 # enter specific test directory
166 elif [ $SELECTEDTESTSONLY = "yes" ]
168 # set internal field seperator
171 # set internal field seperator
172 TESTS="`ls $DEFAULTTESTSDIR`"
177 SUBTESTS="`basename $SUBDIR`"
179 if [ $SUBTESTS = $SUBDIR ]
181 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
183 SUBDIR="`dirname $SUBDIR`"
186 if [ ! -d $TODAYDIR/$SUBDIR ]
188 mkdir $TODAYDIR/$SUBDIR
189 if [ $testnumber == 0 ]
191 FIRST="<b>Category:</b"
195 echo " <tr>" >> $INDEX
196 echo " <td>$FIRST</td>">> $INDEX
197 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
198 echo " <td align=\"right\">x</td>" >> $INDEX
199 echo " <td> </td>" >> $INDEX
200 echo " </tr>" >> $INDEX
201 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
202 cat > $SUBTESTSINDEX <<@EOF
205 <title>strongSwan $SUBDIR Tests</title>
208 <h2>strongSwan $SUBDIR Tests</h2>
209 <table border="0" cellspacing="2">
211 <td><b>UML kernel: </b></td>
212 <td colspan="3">$KERNEL_VERSION</td>
215 <td><b>IPsec:</b></td>
216 <td colspan="3">$IPSEC_VERSION</td>
219 <td><b>Date:</b></td>
220 <td colspan="3">$TESTDATE</td>
223 <td width="100"> </td>
224 <td width="200"> </td>
225 <td width=" 50"> </td>
231 <th colspan="2">Result</th>
236 for name in $SUBTESTS
238 let "testnumber += 1"
239 testname=$SUBDIR/$name
240 cecho-n " $testnumber $testname.."
242 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
244 cecho "is missing..skipped"
248 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
249 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
250 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
251 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
252 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
254 TESTRESULTDIR=$TODAYDIR/$testname
255 mkdir -p $TESTRESULTDIR
256 CONSOLE_LOG=$TESTRESULTDIR/console.log
259 TESTDIR=$TESTSDIR/${testname}
262 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
265 ##############################################################################
266 # replace IP wildcards with actual IPv4 and IPv6 addresses
269 for host in $STRONGSWANHOSTS
273 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
274 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
275 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
276 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
279 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
280 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
281 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
282 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
285 searchandreplace PH_IP_ALICE1 $ipv4_alice1 $TESTDIR
286 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
287 searchandreplace PH_IP6_ALICE1 $ipv6_alice1 $TESTDIR
288 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
291 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
292 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
295 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
296 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
299 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
300 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
301 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
302 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
305 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
306 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
307 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
308 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
311 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
312 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
318 ##########################################################################
319 # copy test specific configurations to uml hosts and clear auth.log files
322 $DIR/scripts/load-testconfig $testname
323 source $TESTDIR/test.conf
326 ##########################################################################
327 # run tcpdump in the background
330 if [ "$TCPDUMPHOSTS" != "" ]
332 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
334 for host_iface in $TCPDUMPHOSTS
336 host=`echo $host_iface | awk -F ":" '{print $1}'`
337 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
338 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
339 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
340 ssh root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
341 eval TDUP_${host}="true"
346 ##########################################################################
347 # execute pre-test commands
351 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
356 printf("echo \"%s# %s\"; ", $1, $2)
357 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
360 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
363 ##########################################################################
367 function stop_tcpdump {
368 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
369 eval ssh root@\$ipv4_${1} killall tcpdump
370 eval TDUP_${1}="false"
375 ##########################################################################
376 # get and evaluate test results
380 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
391 if (command == "tcpdump")
393 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
394 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
395 printf("ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
399 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
400 printf("ssh root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
402 printf("cmd_exit=\044?; ")
404 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
405 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
406 printf("; then STATUS=\"failed\"; fi; \n")
408 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
411 ##########################################################################
415 if [ $STATUS = "failed" ]
417 let "failed_cnt += 1"
419 let "passed_cnt += 1"
423 ##########################################################################
424 # log statusall and listall output
425 # get copies of ipsec.conf, ipsec.secrets
426 # create index.html for the given test case
428 cat > $TESTRESULTDIR/index.html <<@EOF
431 <title>Test $testname</title>
434 <table border="0" width="600">
436 <h2>Test $testname</h2>
440 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
442 cat >> $TESTRESULTDIR/index.html <<@EOF
444 <li><a href="console.log">console.log</a></li>
446 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
449 for host in $IPSECHOSTS
451 eval HOSTLOGIN=root@\$ipv4_${host}
453 for command in statusall listall
455 ssh $HOSTLOGIN ipsec $command \
456 > $TESTRESULTDIR/${host}.$command 2>/dev/null
459 for file in ipsec.conf ipsec.secrets
461 scp $HOSTLOGIN:/etc/$file \
462 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
465 ssh $HOSTLOGIN ip route list table $SOURCEIP_ROUTING_TABLE \
466 > $TESTRESULTDIR/${host}.iproute 2>/dev/null
467 ssh $HOSTLOGIN iptables -v -n -L \
468 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
469 cat >> $TESTRESULTDIR/index.html <<@EOF
471 <table border="0" cellspacing="0" width="400">
475 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
476 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
477 <li><a href="$host.statusall">ipsec statusall</a></li>
478 <li><a href="$host.listall">ipsec listall</a></li>
483 <li><a href="$host.auth.log">auth.log</a></li>
484 <li><a href="$host.daemon.log">daemon.log</a></li>
485 <li><a href="$host.iproute">ip route list table $SOURCEIP_ROUTING_TABLE</a></li>
486 <li><a href="$host.iptables">iptables -L</a></li>
495 cat >> $TESTRESULTDIR/index.html <<@EOF
497 <tr><td align="right">
498 <b><a href="../index.html">Back</a></b>
506 ##########################################################################
507 # execute post-test commands
511 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
516 printf("echo \"%s# %s\"; ", $1, $2)
517 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
520 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
523 ##########################################################################
524 # get a copy of /var/log/auth.log
527 for host in $IPSECHOSTS
529 eval HOSTLOGIN=root@\$ipv4_${host}
530 ssh $HOSTLOGIN grep pluto /var/log/auth.log \
531 > $TESTRESULTDIR/${host}.auth.log
532 echo >> $TESTRESULTDIR/${host}.auth.log
533 ssh $HOSTLOGIN grep charon /var/log/auth.log \
534 >> $TESTRESULTDIR/${host}.auth.log
538 ##########################################################################
539 # get a copy of /var/log/daemon.log
542 for host in $IPSECHOSTS
544 eval HOSTLOGIN=root@\$ipv4_${host}
545 ssh $HOSTLOGIN grep pluto /var/log/daemon.log \
546 > $TESTRESULTDIR/${host}.daemon.log
547 echo >> $TESTRESULTDIR/${host}.daemon.log
548 ssh $HOSTLOGIN grep charon /var/log/daemon.log \
549 >> $TESTRESULTDIR/${host}.daemon.log
553 ##########################################################################
554 # stop tcpdump if necessary
557 for host in $TCPDUMPHOSTS
559 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
561 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
562 eval ssh root@\$ipv4_$host killall tcpdump
563 eval TDUP_${host}="false"
568 ##########################################################################
569 # copy default host config back if necessary
572 $DIR/scripts/restore-defaults $testname
575 ##########################################################################
576 # write test status to html file
579 if [ $STATUS = "passed" ]
582 cecho "\033[1;32m$STATUS"
588 cat >> $TESTRESULTSHTML << @EOF
591 <td><a href="$testname/">$testname</a></td>
592 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
596 cat >> $SUBTESTSINDEX << @EOF
599 <td><a href="$name/">$name</a></td>
600 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
610 ##############################################################################
611 # finish the results html file
614 cat >> $TESTRESULTSHTML << @EOF
617 <b>Passed: <font color="green">$passed_cnt</font></b><br>
618 <b>Failed: <font color="red">$failed_cnt</font></b><br>
624 let "all_cnt = $passed_cnt + $failed_cnt"
626 cat >> $INDEX << @EOF
629 <td><a href="all.html"><b>all</b></a></td>
630 <td align="right"><b>$all_cnt</b></td>
634 <td><b>Failed:</b></td>
636 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
645 cecho "\033[1;32mPassed: $passed_cnt"
646 cecho "Failed: $failed_cnt"
650 ##############################################################################
651 # copy the test results to the apache server
654 HTDOCS="/var/www/localhost/htdocs"
656 cecho-n "Copying test results to winnetou.."
657 ssh root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
658 scp -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
659 ssh root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
662 cecho "The results are available in $TODAYDIR"
663 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"