]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - testing/do-tests
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>" >> $INDEX
192 echo " <td>$FIRST</td>">> $INDEX
193 echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
194 echo " <td align=\"right\"></td>" >> $INDEX
195 echo " <td> </td>" >> $INDEX
196 echo " </tr>" >> $INDEX
197 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
198 cat > $SUBTESTSINDEX <<@EOF
201 <title>strongSwan $SUBDIR Tests</title>
204 <h2>strongSwan $SUBDIR Tests</h2>
205 <table border="0" cellspacing="2">
207 <td><b>UML kernel: </b></td>
208 <td colspan="3">$KERNEL_VERSION</td>
211 <td><b>IPsec:</b></td>
212 <td colspan="3">$IPSEC_VERSION</td>
215 <td><b>Date:</b></td>
216 <td colspan="3">$TESTDATE</td>
219 <td width="100"> </td>
220 <td width="200"> </td>
221 <td width=" 50"> </td>
227 <th colspan="2">Result</th>
232 for name in $SUBTESTS
234 let "testnumber += 1"
235 testname=$SUBDIR/$name
236 cecho-n " $testnumber $testname.."
238 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
240 cecho "is missing..skipped"
244 [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
245 [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
246 [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
247 [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
248 [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
250 TESTRESULTDIR=$TODAYDIR/$testname
251 mkdir -p $TESTRESULTDIR
252 CONSOLE_LOG=$TESTRESULTDIR/console.log
255 TESTDIR=$TESTSDIR/${testname}
258 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
261 ##############################################################################
262 # replace IP wildcards with actual IPv4 and IPv6 addresses
265 for host in $STRONGSWANHOSTS
269 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTDIR
270 searchandreplace PH_IP_MOON $ipv4_moon $TESTDIR
271 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTDIR
272 searchandreplace PH_IP6_MOON $ipv6_moon $TESTDIR
275 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTDIR
276 searchandreplace PH_IP_SUN $ipv4_sun $TESTDIR
277 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTDIR
278 searchandreplace PH_IP6_SUN $ipv6_sun $TESTDIR
281 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
282 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
285 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
286 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
289 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
290 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
293 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTDIR
294 searchandreplace PH_IP_CAROL $ipv4_carol $TESTDIR
295 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTDIR
296 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTDIR
299 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTDIR
300 searchandreplace PH_IP_DAVE $ipv4_dave $TESTDIR
301 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTDIR
302 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTDIR
305 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
306 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
312 ##########################################################################
313 # copy test specific configurations to uml hosts and clear auth.log files
316 $DIR/scripts/load-testconfig $testname
317 source $TESTDIR/test.conf
320 ##########################################################################
321 # run tcpdump in the background
324 if [ "$TCPDUMPHOSTS" != "" ]
326 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
328 for host_iface in $TCPDUMPHOSTS
330 host=`echo $host_iface |
awk -F ":" '{print $1}'`
331 iface=`echo $host_iface |
awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
332 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
333 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
334 ssh root@`eval echo \\\
$ipv4_$host '$tcpdump_cmd'`
335 eval TDUP_${host}="true"
340 ##########################################################################
341 # execute pre-test commands
345 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
350 printf("echo \"%s# %s\"; ", $1, $2)
351 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
354 }' $TESTDIR/pretest.dat
` >> $CONSOLE_LOG 2>&1
357 ##########################################################################
361 function stop_tcpdump {
362 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
363 eval ssh root@\$ipv4_${1} killall tcpdump
364 eval TDUP_${1}="false"
369 ##########################################################################
370 # get and evaluate test results
374 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
385 if (command == "tcpdump")
387 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
388 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
389 printf("ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
393 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
394 printf("ssh root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
396 printf("cmd_exit=\044?; ")
398 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
399 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
400 printf("; then STATUS=\"failed\"; fi; \n")
402 }' $TESTDIR/evaltest.dat
` >> $CONSOLE_LOG 2>&1
405 ##########################################################################
409 if [ $STATUS = "failed" ]
411 let "failed_cnt += 1"
413 let "passed_cnt += 1"
417 ##########################################################################
418 # log statusall and listall output
419 # get copies of ipsec.conf, ipsec.secrets
420 # create index.html for the given test case
422 cat > $TESTRESULTDIR/index.html <<@EOF
425 <title>Test $testname</title>
428 <table border="0" width="600">
430 <h2>Test $testname</h2>
434 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
436 cat >> $TESTRESULTDIR/index.html <<@EOF
438 <li><a href="console.log">console.log</a></li>
440 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
443 for host in $IPSECHOSTS
445 eval HOSTLOGIN=root@\$ipv4_${host}
447 for command in statusall listall
449 ssh $HOSTLOGIN ipsec $command \
450 > $TESTRESULTDIR/${host}.$command 2>/dev/null
453 for file in ipsec.conf ipsec.secrets
455 scp $HOSTLOGIN:/etc/$file \
456 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
459 ssh $HOSTLOGIN ip route list \
460 > $TESTRESULTDIR/${host}.iproute 2>/dev/null
461 ssh $HOSTLOGIN iptables -v -n -L \
462 > $TESTRESULTDIR/${host}.iptables 2>/dev/null
463 cat >> $TESTRESULTDIR/index.html <<@EOF
465 <table border="0" cellspacing="0" width="400">
469 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
470 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
471 <li><a href="$host.statusall">ipsec statusall</a></li>
472 <li><a href="$host.listall">ipsec listall</a></li>
477 <li><a href="$host.auth.log">auth.log</a></li>
478 <li><a href="$host.daemon.log">daemon.log</a></li>
479 <li><a href="$host.iproute">ip route list</a></li>
480 <li><a href="$host.iptables">iptables -L</a></li>
489 cat >> $TESTRESULTDIR/index.html <<@EOF
491 <tr><td align="right">
492 <b><a href="../index.html">Back</a></b>
500 ##########################################################################
501 # execute post-test commands
505 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
510 printf("echo \"%s# %s\"; ", $1, $2)
511 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
514 }' $TESTDIR/posttest.dat
` >> $CONSOLE_LOG 2>&1
517 ##########################################################################
518 # get a copy of /var/log/auth.log
521 for host in $IPSECHOSTS
523 eval HOSTLOGIN=root@\$ipv4_${host}
524 ssh $HOSTLOGIN grep pluto /var/log/auth.log \
525 > $TESTRESULTDIR/${host}.auth.log
526 echo >> $TESTRESULTDIR/${host}.auth.log
527 ssh $HOSTLOGIN grep charon /var/log/auth.log \
528 >> $TESTRESULTDIR/${host}.auth.log
532 ##########################################################################
533 # get a copy of /var/log/daemon.log
536 for host in $IPSECHOSTS
538 eval HOSTLOGIN=root@\$ipv4_${host}
539 ssh $HOSTLOGIN grep pluto /var/log/daemon.log \
540 > $TESTRESULTDIR/${host}.daemon.log
541 echo >> $TESTRESULTDIR/${host}.daemon.log
542 ssh $HOSTLOGIN grep charon /var/log/daemon.log \
543 >> $TESTRESULTDIR/${host}.daemon.log
547 ##########################################################################
548 # stop tcpdump if necessary
551 for host in $TCPDUMPHOSTS
553 if [ "`eval echo \\\
$TDUP_${host}`" = "true" ]
555 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
556 eval ssh root@\$ipv4_$host killall tcpdump
557 eval TDUP_${host}="false"
562 ##########################################################################
563 # copy default host config back if necessary
566 $DIR/scripts/restore-defaults $testname
569 ##########################################################################
570 # write test status to html file
573 if [ $STATUS = "passed" ]
576 cecho "\033[1;32m$STATUS"
582 cat >> $TESTRESULTSHTML << @EOF
585 <td><a href="$testname/">$testname</a></td>
586 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
590 cat >> $SUBTESTSINDEX << @EOF
593 <td><a href="$name/">$name</a></td>
594 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
604 ##############################################################################
605 # finish the results html file
608 cat >> $TESTRESULTSHTML << @EOF
611 <b>Passed: <font color="green">$passed_cnt</font></b><br>
612 <b>Failed: <font color="red">$failed_cnt</font></b><br>
618 let "all_cnt = $passed_cnt + $failed_cnt"
620 cat >> $INDEX << @EOF
623 <td><a href="all.html"><b>all</b></a></td>
624 <td align="right"><b>$all_cnt</b></td>
628 <td><b>Failed:</b></td>
630 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
639 cecho "\033[1;32mPassed: $passed_cnt"
640 cecho "Failed: $failed_cnt"
644 ##############################################################################
645 # copy the test results to the apache server
648 HTDOCS="/var/www/localhost/htdocs"
650 cecho-n "Copying test results to winnetou.."
651 ssh root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
652 scp -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
653 ssh root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
656 cecho "The results are available in $TODAYDIR"
657 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"