]> git.ipfire.org Git - thirdparty/strongswan.git/blob - testing/do-tests
created IPv6 environment
[thirdparty/strongswan.git] / testing / do-tests
1 #!/bin/bash
2 # Automatically execute the strongSwan test cases
3 #
4 # Copyright (C) 2004 Eric Marchionni, Patrik Rayo
5 # Zuercher Hochschule Winterthur
6 #
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>.
11 #
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
15 # for more details.
16 #
17 # RCSID $Id: do-tests,v 1.20 2006/02/08 21:27:59 as Exp $
18
19 DIR=`dirname $0`
20
21 source $DIR/scripts/function.sh
22
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"
26
27 source $DIR/testing.conf
28
29
30 ##############################################################################
31 # test if UMLs have been built at all
32 #
33
34 [ -d $BUILDDIR ] || die "Directory '$BUILDDIR' does not exist. Please run 'make-testing'first."
35
36
37 ##############################################################################
38 # take care of new path and file variables
39 #
40
41 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
42
43 TESTDATE=`date +%Y%m%d-%H%M`
44
45 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
46 mkdir $TODAYDIR
47 TESTRESULTSHTML=$TODAYDIR/index.html
48 DEFAULTTESTSDIR=$UMLTESTDIR/testing/tests
49
50 testnumber="0"
51 failed_cnt="0"
52 passed_cnt="0"
53
54
55 ##############################################################################
56 # copy default tests to $BUILDDIR
57 #
58
59 TESTSDIR=$BUILDDIR/tests
60 [ -d $TESTSDIR ] || mkdir $TESTSDIR
61 rm -rf $TESTSDIR/*
62 cp -rfp $DEFAULTTESTSDIR/* $TESTSDIR
63
64
65 ##############################################################################
66 # assign IP for each host to hostname
67 #
68
69 for host in $STRONGSWANHOSTS
70 do
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 }'`"
73 case $host in
74 moon)
75 eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
76 searchandreplace PH_IP_MOON1 $ipv4_moon1 $TESTSDIR
77 searchandreplace PH_IP_MOON $ipv4_moon $TESTSDIR
78 eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
79 searchandreplace PH_IP6_MOON1 $ipv6_moon1 $TESTSDIR
80 searchandreplace PH_IP6_MOON $ipv6_moon $TESTSDIR
81 ;;
82 sun)
83 eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
84 searchandreplace PH_IP_SUN1 $ipv4_sun1 $TESTSDIR
85 searchandreplace PH_IP_SUN $ipv4_sun $TESTSDIR
86 eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
87 searchandreplace PH_IP6_SUN1 $ipv6_sun1 $TESTSDIR
88 searchandreplace PH_IP6_SUN $ipv6_sun $TESTSDIR
89 ;;
90 alice)
91 searchandreplace PH_IP_ALICE $ipv4_alice $TESTSDIR
92 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTSDIR
93 ;;
94 venus)
95 searchandreplace PH_IP_VENUS $ipv4_venus $TESTSDIR
96 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTSDIR
97 ;;
98 bob)
99 searchandreplace PH_IP_BOB $ipv4_bob $TESTSDIR
100 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTSDIR
101 ;;
102 carol)
103 eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
104 searchandreplace PH_IP_CAROL1 $ipv4_carol1 $TESTSDIR
105 searchandreplace PH_IP_CAROL $ipv4_carol $TESTSDIR
106 eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
107 searchandreplace PH_IP6_CAROL1 $ipv6_carol1 $TESTSDIR
108 searchandreplace PH_IP6_CAROL $ipv6_carol $TESTSDIR
109 ;;
110 dave)
111 eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
112 searchandreplace PH_IP_DAVE1 $ipv4_dave1 $TESTSDIR
113 searchandreplace PH_IP_DAVE $ipv4_dave $TESTSDIR
114 eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
115 searchandreplace PH_IP6_DAVE1 $ipv6_dave1 $TESTSDIR
116 searchandreplace PH_IP6_DAVE $ipv6_dave $TESTSDIR
117 ;;
118 winnetou)
119 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTSDIR
120 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTSDIR
121 ;;
122 esac
123 done
124
125
126 ##############################################################################
127 # create header for the results html file
128 #
129
130 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
131 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
132
133 cat > $TESTRESULTSHTML <<@EOF
134 <html>
135 <head>
136 <title>strongSwan UML Testing</title>
137 </head>
138 <body>
139 <h2>strongSwan UML Testing</h2>
140 <table border="0" cellspacing="2">
141 <tr><td><b>Host:</b></td><td>`uname -a`</td></tr>
142 <tr><td><b>UML kernel: &nbsp;</b></td><td>$KERNEL_VERSION</td></tr>
143 <tr><td><b>IPsec:</b></td><td>$IPSEC_VERSION</td></tr>
144 <tr><td><b>Date:</b></td><td>$TESTDATE</td></tr>
145 </table>
146 <p>
147 <table border="0" width="500">
148 <thead align="left"><th>Number</th><th>Test</th><th>Result</th></thead>
149 @EOF
150
151 cecho "UML kernel: $KERNEL_VERSION"
152 cecho "IPsec: $IPSEC_VERSION"
153 cecho "Date: $TESTDATE"
154 cecho ""
155
156
157 ##############################################################################
158 # enter specific test directory
159 #
160
161 if [ $# -gt 0 ]
162 then
163 TESTS=$*
164 elif [ $SELECTEDTESTSONLY = "yes" ]
165 then
166 # set internal field seperator
167 TESTS=$SELECTEDTESTS
168 else
169 # set internal field seperator
170 TESTS="`ls $TESTSDIR`"
171 fi
172
173 for testname in $TESTS
174 do
175 let "testnumber += 1"
176 cecho-n " $testnumber $testname.."
177
178 if [ ! -d $TESTSDIR/${testname} ]
179 then
180 cecho "is missing..skipped"
181 continue
182 fi
183
184 [ -f $TESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
185 [ -f $TESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
186 [ -f $TESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
187 [ -f $TESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
188 [ -f $TESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
189
190 TESTRESULTDIR=$TODAYDIR/$testname
191 mkdir $TESTRESULTDIR
192 CONSOLE_LOG=$TESTRESULTDIR/console.log
193 touch $CONSOLE_LOG
194
195
196 ##########################################################################
197 # copy test specific configurations to uml hosts and clear auth.log files
198 #
199
200 $DIR/scripts/load-testconfig $testname
201 source $TESTSDIR/$testname/test.conf
202
203
204 ##########################################################################
205 # run tcpdump in the background
206 #
207
208 if [ "$TCPDUMPHOSTS" != "" ]
209 then
210 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
211
212 for host_iface in $TCPDUMPHOSTS
213 do
214 host=`echo $host_iface | awk -F ":" '{print $1}'`
215 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
216 tcpdump_cmd="tcpdump -i $iface not port ssh and not port domain and not arp > /tmp/tcpdump.log 2>&1 &"
217 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
218 ssh root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
219 eval TDUP_${host}="true"
220 done
221 fi
222
223 ##########################################################################
224 # execute pre-test commands
225 #
226
227 cecho-n "pre.."
228 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
229
230 eval `awk -F "::" '{
231 if ($2 != "")
232 {
233 printf("echo \"%s# %s\"; ", $1, $2)
234 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
235 printf("echo;\n")
236 }
237 }' $TESTSDIR/${testname}/pretest.dat` >> $CONSOLE_LOG 2>&1
238
239
240 ##########################################################################
241 # stop tcpdump
242 #
243
244 function stop_tcpdump {
245 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
246 eval ssh root@\$ipv4_${1} killall tcpdump
247 eval TDUP_${1}="false"
248 echo ""
249 }
250
251
252 ##########################################################################
253 # get and evaluate test results
254 #
255
256 cecho-n "test.."
257 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
258
259 STATUS="passed"
260
261 eval `awk -F "::" '{
262 host=$1
263 command=$2
264 pattern=$3
265 hit=$4
266 if (command != "")
267 {
268 if (command == "tcpdump")
269 {
270 printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
271 printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
272 printf("ssh root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
273 }
274 else
275 {
276 printf("echo \"%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
277 printf("ssh root@\044ipv4_%s %s | grep \"%s\"; ", host, command, pattern)
278 }
279 printf("cmd_exit=\044?; ")
280 printf("echo; ")
281 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
282 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
283 printf("; then STATUS=\"failed\"; fi; \n")
284
285 }
286 }' $TESTSDIR/${testname}/evaltest.dat` >> $CONSOLE_LOG 2>&1
287
288
289 ##########################################################################
290 # set counters
291 #
292
293 if [ $STATUS = "failed" ]
294 then
295 let "failed_cnt += 1"
296 else
297 let "passed_cnt += 1"
298 fi
299
300
301 ##########################################################################
302 # log statusall and listall output
303 # get copies of ipsec.conf, ipsec.secrets
304 # create index.html for the given test case
305
306 cat > $TESTRESULTDIR/index.html <<@EOF
307 <html>
308 <head>
309 <title>Test $testname</title>
310 </head>
311 <body>
312 <table border="0" width="600">
313 <tr><td>
314 <h2>Test $testname</h2>
315 <h3>Description</h3>
316 @EOF
317
318 cat $TESTSDIR/${testname}/description.txt >> $TESTRESULTDIR/index.html
319
320 cat >> $TESTRESULTDIR/index.html <<@EOF
321 <ul>
322 <li><a href="console.log">console.log</a></li>
323 </ul>
324 <img src="../images/$DIAGRAM" alt="$UMLHOSTS">
325 @EOF
326
327
328 for host in $IPSECHOSTS
329 do
330 eval HOSTLOGIN=root@\$ipv4_${host}
331
332 for command in statusall listall
333 do
334 ssh $HOSTLOGIN ipsec $command \
335 > $TESTRESULTDIR/${host}.$command 2>/dev/null
336 done
337
338 for file in ipsec.conf ipsec.secrets
339 do
340 scp $HOSTLOGIN:/etc/$file \
341 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
342 done
343
344 cat >> $TESTRESULTDIR/index.html <<@EOF
345 <h3>$host</h3>
346 <ul>
347 <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
348 <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
349 <li><a href="$host.statusall">ipsec statusall</a></li>
350 <li><a href="$host.listall">ipsec listall</a></li>
351 <li><a href="$host.auth.log">auth.log</a></li>
352 </ul>
353 @EOF
354
355 done
356
357 cat >> $TESTRESULTDIR/index.html <<@EOF
358 </td></tr>
359 <tr><td align="right">
360 <b><a href="../index.html">Back</a></b>
361 </td></tr>
362 </table>
363 </body>
364 </html>
365 @EOF
366
367
368 ##########################################################################
369 # execute post-test commands
370 #
371
372 cecho-n "post.."
373 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
374
375 eval `awk -F "::" '{
376 if ($2 != "")
377 {
378 printf("echo \"%s# %s\"; ", $1, $2)
379 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
380 printf("echo;\n")
381 }
382 }' $TESTSDIR/${testname}/posttest.dat` >> $CONSOLE_LOG 2>&1
383
384
385 ##########################################################################
386 # get a copy of /var/log/auth.log
387 #
388
389 for host in $IPSECHOSTS
390 do
391 eval HOSTLOGIN=root@\$ipv4_${host}
392 ssh $HOSTLOGIN grep pluto /var/log/auth.log \
393 > $TESTRESULTDIR/${host}.auth.log
394 echo >> $TESTRESULTDIR/${host}.auth.log
395 ssh $HOSTLOGIN grep charon /var/log/auth.log \
396 >> $TESTRESULTDIR/${host}.auth.log
397 done
398
399
400 ##########################################################################
401 # stop tcpdump if necessary
402 #
403
404 for host in $TCPDUMPHOSTS
405 do
406 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
407 then
408 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
409 eval ssh root@\$ipv4_$host killall tcpdump
410 eval TDUP_${host}="false"
411 fi
412 done
413
414
415 ##########################################################################
416 # copy default host config back if necessary
417 #
418
419 $DIR/scripts/restore-defaults $testname
420
421
422 ##########################################################################
423 # write test status to html file
424 #
425
426 cecho "$STATUS"
427 if [ $STATUS = "passed" ]
428 then
429 COLOR="green"
430 else
431 COLOR="red"
432 fi
433
434 cat >> $TESTRESULTSHTML << @EOF
435 <tr>
436 <td>$testnumber</td>
437 <td><a href="$testname/">$testname</a></td>
438 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
439 </tr>
440 @EOF
441
442 done
443
444
445 ##############################################################################
446 # finish the results html file
447 #
448
449 cat >> $TESTRESULTSHTML << @EOF
450 </table>
451 <p>
452 <b>Passed: &nbsp; $passed_cnt</b><br>
453 <b>Failed: &nbsp; $failed_cnt</b><br>
454 <p>
455 </body>
456 </html>
457 @EOF
458
459 cecho ""
460 cecho "Passed: $passed_cnt"
461 cecho "Failed: $failed_cnt"
462 cecho ""
463
464
465 ##############################################################################
466 # copy the test results to the apache server
467 #
468
469 HTDOCS="/var/www/localhost/htdocs"
470
471 cecho-n "Copying test results to winnetou.."
472 ssh root@${ipv4_winnetou} mkdir -p $HTDOCS/testresults > /dev/null 2>&1
473 scp -r $TODAYDIR root@${ipv4_winnetou}:$HTDOCS/testresults > /dev/null 2>&1
474 ssh root@${ipv4_winnetou} ln -s $HTDOCS/images $HTDOCS/testresults/$TESTDATE/images > /dev/null 2>&1
475 cecho "done"
476 cecho ""
477 cecho "The results are available in $TODAYDIR"
478 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"