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/index.html
48 DEFAULTTESTSDIR=$UMLTESTDIR/testing/tests
55 ##############################################################################
56 # copy default tests to $BUILDDIR
59 TESTSDIR=$BUILDDIR/tests
60 [ -d $TESTSDIR ] || mkdir $TESTSDIR
62 ##############################################################################
63 # assign IP for each host to hostname
66 for host in $STRONGSWANHOSTS
68 eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
69 eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
73 eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
74 eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
77 eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
78 eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
87 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
88 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
91 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
92 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
100 ##############################################################################
101 # create header for the results html file
104 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
105 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
107 cat > $TESTRESULTSHTML <<@EOF
110 <title>strongSwan UML Testing</title>
113 <h2>strongSwan UML Testing</h2>
114 <table border="0" cellspacing="2">
115 <tr><td><b>Host:</b></td><td>`uname -a`</td></tr>
116 <tr><td><b>UML kernel: </b></td><td>$KERNEL_VERSION</td></tr>
117 <tr><td><b>IPsec:</b></td><td>$IPSEC_VERSION</td></tr>
118 <tr><td><b>Date:</b></td><td>$TESTDATE</td></tr>
121 <table border="0" width="500">
122 <thead align="left"><th>Number</th><th>Test</th><th>Result</th></thead>
125 cecho "UML kernel: $KERNEL_VERSION"
126 cecho "IPsec: $IPSEC_VERSION"
127 cecho "Date: $TESTDATE"
131 ##############################################################################
132 # enter specific test directory
138 elif [ $SELECTEDTESTSONLY = "yes" ]
140 # set internal field seperator
143 # set internal field seperator
144 TESTS="`ls $DEFAULTTESTSDIR`"
149 SUBTESTS="`basename $SUBDIR`"
151 if [ $SUBTESTS = $SUBDIR ]
153 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
155 SUBDIR="`dirname $SUBDIR`"
158 for name in $SUBTESTS
160 let "testnumber += 1"
161 testname=$SUBDIR/$name
162 cecho-n " $testnumber $testname.."
164 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
166 cecho "is missing..skipped"
170 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
171 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
172 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
173 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
174 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
176 TESTRESULTDIR=$TODAYDIR/$testname
177 mkdir -p $TESTRESULTDIR
178 CONSOLE_LOG=$TESTRESULTDIR/console.log
181 TESTDIR=$TESTSDIR/${testname}
184 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
187 ##############################################################################
188 # replace IP wildcards with actual IPv4 and IPv6 addresses
191 for host in $STRONGSWANHOSTS
195 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
196 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
197 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
198 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
201 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
202 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
203 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
204 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
207 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
208 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
211 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
212 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
215 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
216 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
219 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
220 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
221 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
222 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
225 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
226 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
227 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
228 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
231 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
232 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
238 ##########################################################################
239 # copy test specific configurations to uml hosts and clear auth.log files
242 $DIR/scripts/load-testconfig $testname
243 source $TESTDIR/test.conf
246 ##########################################################################
247 # run tcpdump in the background
250 if [ "$TCPDUMPHOSTS" != "" ]
252 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
254 for host_iface in $TCPDUMPHOSTS
256 host=`echo $host_iface | awk -F ":" '{print $1}'`
257 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
258 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
259 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
260 ssh root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
261 eval TDUP_${host}="true"
266 ##########################################################################
267 # execute pre-test commands
271 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
276 printf("echo \"%s# %s\"; ", $1, $2)
277 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
280 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
283 ##########################################################################
287 function stop_tcpdump {
288 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
289 eval ssh root@\$ipv4_${1} killall tcpdump
290 eval TDUP_${1}="false"
295 ##########################################################################
296 # get and evaluate test results
300 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
311 if (command == "tcpdump")
313 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
314 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
315 printf("ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
317 else if (command == "tcpdumpcount")
319 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
320 printf("echo -e \"%s# [ \\\\140cat /tmp/tcpdump.log | grep \047%s\047 | tee -a /dev/stderr | wc -l\\\\140 -eq %s ] [YES]\"; ", host, pattern, hit)
321 printf("tcpdumpcount=\`ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\" | tee -a /dev/stderr | wc -l\`; ", host, pattern)
322 printf("[ \044tcpdumpcount -eq %s ]; ", hit)
325 else if (command == "cmd")
327 printf("echo \"%s# %s [%s]\"; ", host, pattern, hit)
328 printf("ssh root@\044ipv4_%s %s; ", host, pattern)
332 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
333 printf("ssh root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
335 printf("cmd_exit=\044?; ")
337 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
338 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
339 printf("; then STATUS=\"failed\"; fi; \n")
341 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
344 ##########################################################################
348 if [ $STATUS = "failed" ]
350 let "failed_cnt += 1"
352 let "passed_cnt += 1"
356 ##########################################################################
357 # log statusall and listall output
358 # get copies of ipsec.conf, ipsec.secrets
359 # create index.html for the given test case
361 cat > $TESTRESULTDIR/index.html <<@EOF
364 <title>Test $testname</title>
367 <table border="0" width="600">
369 <h2>Test $testname</h2>
373 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
375 cat >> $TESTRESULTDIR/index.html <<@EOF
377 <li><a href="console.log">console.log</a></li>
379 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
382 for host in $IPSECHOSTS
384 eval HOSTLOGIN=root@\$ipv4_${host}
386 for command in statusall listall
388 ssh $HOSTLOGIN ipsec $command \
389 > $TESTRESULTDIR/${host}.$command 2>/dev/null
392 for file in ipsec.conf ipsec.secrets
394 scp $HOSTLOGIN:/etc/$file \
395 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
398 cat >> $TESTRESULTDIR/index.html <<@EOF
401 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
402 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
403 <li><a href="$host.statusall">ipsec statusall</a></li>
404 <li><a href="$host.listall">ipsec listall</a></li>
405 <li><a href="$host.auth.log">auth.log</a></li>
411 cat >> $TESTRESULTDIR/index.html <<@EOF
413 <tr><td align="right">
414 <b><a href="../index.html">Back</a></b>
422 ##########################################################################
423 # execute post-test commands
427 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
432 printf("echo \"%s# %s\"; ", $1, $2)
433 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
436 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
439 ##########################################################################
440 # get a copy of /var/log/auth.log
443 for host in $IPSECHOSTS
445 eval HOSTLOGIN=root@\$ipv4_${host}
446 ssh $HOSTLOGIN grep pluto /var/log/auth.log \
447 > $TESTRESULTDIR/${host}.auth.log
448 echo >> $TESTRESULTDIR/${host}.auth.log
449 ssh $HOSTLOGIN grep charon /var/log/auth.log \
450 >> $TESTRESULTDIR/${host}.auth.log
454 ##########################################################################
455 # stop tcpdump if necessary
458 for host in $TCPDUMPHOSTS
460 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
462 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
463 eval ssh root@\$ipv4_$host killall tcpdump
464 eval TDUP_${host}="false"
469 ##########################################################################
470 # copy default host config back if necessary
473 $DIR/scripts/restore-defaults $testname
476 ##########################################################################
477 # write test status to html file
481 if [ $STATUS = "passed" ]
488 cat >> $TESTRESULTSHTML << @EOF
491 <td><a href="$testname/">$testname</a></td>
492 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
500 ##############################################################################
501 # finish the results html file
504 cat >> $TESTRESULTSHTML << @EOF
507 <b>Passed: $passed_cnt</b><br>
508 <b>Failed: $failed_cnt</b><br>
515 cecho "Passed: $passed_cnt"
516 cecho "Failed: $failed_cnt"
520 ##############################################################################
521 # copy the test results to the apache server
524 HTDOCS="/var/www/localhost/htdocs"
526 cecho-n "Copying test results to winnetou.."
527 ssh root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
528 scp -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
529 ssh root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
532 cecho "The results are available in $TODAYDIR"
533 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"