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 # RCSID $Id: do-tests,v 1.20 2006/02/08 21:27:59 as Exp $
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
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 }'`"
88 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
89 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
92 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
93 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
101 ##############################################################################
102 # create header for the results html file
105 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
106 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
111 <title>strongSwan UML Tests</title>
114 <h2>strongSwan UML Tests</h2>
115 <table border="0" cellspacing="2">
117 <td><b>Host:</b></td>
118 <td colspan="3">`uname -a`</td>
121 <td><b>UML kernel: </b></td>
122 <td colspan="3">$KERNEL_VERSION</td>
125 <td><b>IPsec:</b></td>
126 <td colspan="3">$IPSEC_VERSION</td>
129 <td><b>Date:</b></td>
130 <td colspan="3">$TESTDATE</td>
133 <td width="100"> </td>
134 <td width="200"> </td>
135 <td width=" 50"> </td>
140 cat $INDEX > $TESTRESULTSHTML
141 cat >> $TESTRESULTSHTML <<@EOF
145 <th colspan="2">Result</th>
149 cecho "UML kernel: $KERNEL_VERSION"
150 cecho "IPsec: $IPSEC_VERSION"
151 cecho "Date: $TESTDATE"
155 ##############################################################################
156 # enter specific test directory
162 elif [ $SELECTEDTESTSONLY = "yes" ]
164 # set internal field seperator
167 # set internal field seperator
168 TESTS="`ls $DEFAULTTESTSDIR`"
173 SUBTESTS="`basename $SUBDIR`"
175 if [ $SUBTESTS = $SUBDIR ]
177 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
179 SUBDIR="`dirname $SUBDIR`"
182 if [ ! -d $TODAYDIR/$SUBDIR ]
184 mkdir $TODAYDIR/$SUBDIR
185 if [ $testnumber == 0 ]
187 FIRST="<b>Category:</b"
191 echo " <tr><td>$FIRST</td><td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td></tr>" >> $INDEX
192 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
193 cat > $SUBTESTSINDEX <<@EOF
196 <title>strongSwan $SUBDIR Tests</title>
199 <h2>strongSwan $SUBDIR Tests</h2>
200 <table border="0" cellspacing="2">
202 <td><b>UML kernel: </b></td>
203 <td colspan="3">$KERNEL_VERSION</td>
206 <td><b>IPsec:</b></td>
207 <td colspan="3">$IPSEC_VERSION</td>
210 <td><b>Date:</b></td>
211 <td colspan="3">$TESTDATE</td>
214 <td width="100"> </td>
215 <td width="200"> </td>
216 <td width=" 50"> </td>
222 <th colspan="2">Result</th>
227 for name in $SUBTESTS
229 let "testnumber += 1"
230 testname=$SUBDIR/$name
231 cecho-n " $testnumber $testname.."
233 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
235 cecho "is missing..skipped"
239 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
240 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
241 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
242 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
243 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
245 TESTRESULTDIR=$TODAYDIR/$testname
246 mkdir -p $TESTRESULTDIR
247 CONSOLE_LOG=$TESTRESULTDIR/console.log
250 TESTDIR=$TESTSDIR/${testname}
253 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
256 ##############################################################################
257 # replace IP wildcards with actual IPv4 and IPv6 addresses
260 for host in $STRONGSWANHOSTS
264 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
265 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
266 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
267 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
270 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
271 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
272 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
273 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
276 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
277 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
280 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
281 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
284 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
285 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
288 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
289 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
290 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
291 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
294 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
295 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
296 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
297 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
300 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
301 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
307 ##########################################################################
308 # copy test specific configurations to uml hosts and clear auth.log files
311 $DIR/scripts/load-testconfig $testname
312 source $TESTDIR/test.conf
315 ##########################################################################
316 # run tcpdump in the background
319 if [ "$TCPDUMPHOSTS" != "" ]
321 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
323 for host_iface in $TCPDUMPHOSTS
325 host=`echo $host_iface | awk -F ":" '{print $1}'`
326 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
327 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
328 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
329 ssh root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
330 eval TDUP_${host}="true"
335 ##########################################################################
336 # execute pre-test commands
340 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
345 printf("echo \"%s# %s\"; ", $1, $2)
346 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
349 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
352 ##########################################################################
356 function stop_tcpdump {
357 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
358 eval ssh root@\$ipv4_${1} killall tcpdump
359 eval TDUP_${1}="false"
364 ##########################################################################
365 # get and evaluate test results
369 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
380 if (command == "tcpdump")
382 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
383 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
384 printf("ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
388 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
389 printf("ssh root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
391 printf("cmd_exit=\044?; ")
393 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
394 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
395 printf("; then STATUS=\"failed\"; fi; \n")
397 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
400 ##########################################################################
404 if [ $STATUS = "failed" ]
406 let "failed_cnt += 1"
408 let "passed_cnt += 1"
412 ##########################################################################
413 # log statusall and listall output
414 # get copies of ipsec.conf, ipsec.secrets
415 # create index.html for the given test case
417 cat > $TESTRESULTDIR/index.html <<@EOF
420 <title>Test $testname</title>
423 <table border="0" width="600">
425 <h2>Test $testname</h2>
429 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
431 cat >> $TESTRESULTDIR/index.html <<@EOF
433 <li><a href="console.log">console.log</a></li>
435 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
438 for host in $IPSECHOSTS
440 eval HOSTLOGIN=root@\$ipv4_${host}
442 for command in statusall listall
444 ssh $HOSTLOGIN ipsec $command \
445 > $TESTRESULTDIR/${host}.$command 2>/dev/null
448 for file in ipsec.conf ipsec.secrets
450 scp $HOSTLOGIN:/etc/$file \
451 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
454 ssh $HOSTLOGIN ip route list \
455 > $TESTRESULTDIR/${host}.iproute 2>/dev/null
456 ssh $HOSTLOGIN iptables -v -n -L \
457 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
458 cat >> $TESTRESULTDIR/index.html <<@EOF
460 <table border="0" cellspacing="0" width="400">
464 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
465 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
466 <li><a href="$host.statusall">ipsec statusall</a></li>
467 <li><a href="$host.listall">ipsec listall</a></li>
472 <li><a href="$host.auth.log">auth.log</a></li>
473 <li><a href="$host.daemon.log">daemon.log</a></li>
474 <li><a href="$host.iproute">ip route list</a></li>
475 <li><a href="$host.iptables">iptables -L</a></li>
484 cat >> $TESTRESULTDIR/index.html <<@EOF
486 <tr><td align="right">
487 <b><a href="../index.html">Back</a></b>
495 ##########################################################################
496 # execute post-test commands
500 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
505 printf("echo \"%s# %s\"; ", $1, $2)
506 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
509 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
512 ##########################################################################
513 # get a copy of /var/log/auth.log
516 for host in $IPSECHOSTS
518 eval HOSTLOGIN=root@\$ipv4_${host}
519 ssh $HOSTLOGIN grep pluto /var/log/auth.log \
520 > $TESTRESULTDIR/${host}.auth.log
521 echo >> $TESTRESULTDIR/${host}.auth.log
522 ssh $HOSTLOGIN grep charon /var/log/auth.log \
523 >> $TESTRESULTDIR/${host}.auth.log
527 ##########################################################################
528 # get a copy of /var/log/daemon.log
531 for host in $IPSECHOSTS
533 eval HOSTLOGIN=root@\$ipv4_${host}
534 ssh $HOSTLOGIN grep pluto /var/log/daemon.log \
535 > $TESTRESULTDIR/${host}.daemon.log
536 echo >> $TESTRESULTDIR/${host}.daemon.log
537 ssh $HOSTLOGIN grep charon /var/log/daemon.log \
538 >> $TESTRESULTDIR/${host}.daemon.log
542 ##########################################################################
543 # stop tcpdump if necessary
546 for host in $TCPDUMPHOSTS
548 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
550 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
551 eval ssh root@\$ipv4_$host killall tcpdump
552 eval TDUP_${host}="false"
557 ##########################################################################
558 # copy default host config back if necessary
561 $DIR/scripts/restore-defaults $testname
564 ##########################################################################
565 # write test status to html file
569 if [ $STATUS = "passed" ]
576 cat >> $TESTRESULTSHTML << @EOF
579 <td><a href="$testname/">$testname</a></td>
580 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
584 cat >> $SUBTESTSINDEX << @EOF
587 <td><a href="$name/">$name</a></td>
588 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
598 ##############################################################################
599 # finish the results html file
602 cat >> $TESTRESULTSHTML << @EOF
605 <b>Passed: <font color="green">$passed_cnt</font></b><br>
606 <b>Failed: <font color="red">$failed_cnt</font></b><br>
612 let "all_cnt = $passed_cnt + $failed_cnt"
614 cat >> $INDEX << @EOF
617 <td><a href="all.html"><b>all</b></a></td>
622 <td><b>Failed:</b></td>
624 <td><b><font color="red">$failed_cnt</font></b></td>
633 cecho "Passed: $passed_cnt"
634 cecho "Failed: $failed_cnt"
638 ##############################################################################
639 # copy the test results to the apache server
642 HTDOCS="/var/www/localhost/htdocs"
644 cecho-n "Copying test results to winnetou.."
645 ssh root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
646 scp -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
647 ssh root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
650 cecho "The results are available in $TODAYDIR"
651 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"