]> git.ipfire.org Git - thirdparty/strongswan.git/blob - testing/do-tests
fixed html output
[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/all.html
48 INDEX=$TODAYDIR/index.html
49 DEFAULTTESTSDIR=$UMLTESTDIR/testing/tests
50
51 testnumber="0"
52 failed_cnt="0"
53 passed_cnt="0"
54
55
56 ##############################################################################
57 # copy default tests to $BUILDDIR
58 #
59
60 TESTSDIR=$BUILDDIR/tests
61 [ -d $TESTSDIR ] || mkdir $TESTSDIR
62
63 ##############################################################################
64 # assign IP for each host to hostname
65 #
66
67 for host in $STRONGSWANHOSTS
68 do
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 }'`"
71
72 case $host in
73 moon)
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 }'`"
76 ;;
77 sun)
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 }'`"
80 ;;
81 alice)
82 ;;
83 venus)
84 ;;
85 bob)
86 ;;
87 carol)
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 }'`"
90 ;;
91 dave)
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 }'`"
94 ;;
95 winnetou)
96 ;;
97 esac
98 done
99
100
101 ##############################################################################
102 # create header for the results html file
103 #
104
105 KERNEL_VERSION=`basename $KERNEL .tar.bz2`
106 IPSEC_VERSION=`basename $STRONGSWAN .tar.bz2`
107
108 cat > $INDEX <<@EOF
109 <html>
110 <head>
111 <title>strongSwan UML Tests</title>
112 </head>
113 <body>
114 <h2>strongSwan UML Tests</h2>
115 <table border="0" cellspacing="2">
116 <tr valign="top">
117 <td><b>Host:</b></td>
118 <td colspan="3">`uname -a`</td>
119 </tr>
120 <tr valign="top">
121 <td><b>UML kernel: &nbsp;</b></td>
122 <td colspan="3">$KERNEL_VERSION</td>
123 </tr>
124 <tr valign="top">
125 <td><b>IPsec:</b></td>
126 <td colspan="3">$IPSEC_VERSION</td>
127 </tr>
128 <tr valign="top">
129 <td><b>Date:</b></td>
130 <td colspan="3">$TESTDATE</td>
131 </tr>
132 <tr>
133 <td width="100">&nbsp;</td>
134 <td width="200">&nbsp;</td>
135 <td width=" 50">&nbsp;</td>
136 <td >&nbsp;</td>
137 </tr>
138 @EOF
139
140 cat $INDEX > $TESTRESULTSHTML
141 cat >> $TESTRESULTSHTML <<@EOF
142 <tr align="left">
143 <th>Number</th>
144 <th>Test</th>
145 <th colspan="2">Result</th>
146 </tr>
147 @EOF
148
149 cecho "UML kernel: $KERNEL_VERSION"
150 cecho "IPsec: $IPSEC_VERSION"
151 cecho "Date: $TESTDATE"
152 cecho ""
153
154
155 ##############################################################################
156 # enter specific test directory
157 #
158
159 if [ $# -gt 0 ]
160 then
161 TESTS=$*
162 elif [ $SELECTEDTESTSONLY = "yes" ]
163 then
164 # set internal field seperator
165 TESTS=$SELECTEDTESTS
166 else
167 # set internal field seperator
168 TESTS="`ls $DEFAULTTESTSDIR`"
169 fi
170
171 for SUBDIR in $TESTS
172 do
173 SUBTESTS="`basename $SUBDIR`"
174
175 if [ $SUBTESTS = $SUBDIR ]
176 then
177 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
178 else
179 SUBDIR="`dirname $SUBDIR`"
180 fi
181
182 if [ ! -d $TODAYDIR/$SUBDIR ]
183 then
184 mkdir $TODAYDIR/$SUBDIR
185 if [ $testnumber == 0 ]
186 then
187 FIRST="<b>Category:</b"
188 else
189 FIRST="&nbsp;"
190 fi
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>&nbsp;</td>" >> $INDEX
196 echo " </tr>" >> $INDEX
197 SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
198 cat > $SUBTESTSINDEX <<@EOF
199 <html>
200 <head>
201 <title>strongSwan $SUBDIR Tests</title>
202 </head>
203 <body>
204 <h2>strongSwan $SUBDIR Tests</h2>
205 <table border="0" cellspacing="2">
206 <tr valign="top">
207 <td><b>UML kernel: &nbsp;</b></td>
208 <td colspan="3">$KERNEL_VERSION</td>
209 </tr>
210 <tr valign="top">
211 <td><b>IPsec:</b></td>
212 <td colspan="3">$IPSEC_VERSION</td>
213 </tr>
214 <tr valign="top">
215 <td><b>Date:</b></td>
216 <td colspan="3">$TESTDATE</td>
217 </tr>
218 <tr>
219 <td width="100">&nbsp;</td>
220 <td width="200">&nbsp;</td>
221 <td width=" 50">&nbsp;</td>
222 <td >&nbsp;</td>
223 </tr>
224 <tr align="left">
225 <th>Number</th>
226 <th>Test</th>
227 <th colspan="2">Result</th>
228 </tr>
229 @EOF
230 fi
231
232 for name in $SUBTESTS
233 do
234 let "testnumber += 1"
235 testname=$SUBDIR/$name
236 cecho-n " $testnumber $testname.."
237
238 if [ ! -d $DEFAULTTESTSDIR/${testname} ]
239 then
240 cecho "is missing..skipped"
241 continue
242 fi
243
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"
249
250 TESTRESULTDIR=$TODAYDIR/$testname
251 mkdir -p $TESTRESULTDIR
252 CONSOLE_LOG=$TESTRESULTDIR/console.log
253 touch $CONSOLE_LOG
254
255 TESTDIR=$TESTSDIR/${testname}
256 rm -rf $TESTDIR
257 mkdir -p $TESTDIR
258 cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
259
260
261 ##############################################################################
262 # replace IP wildcards with actual IPv4 and IPv6 addresses
263 #
264
265 for host in $STRONGSWANHOSTS
266 do
267 case $host in
268 moon)
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
273 ;;
274 sun)
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
279 ;;
280 alice)
281 searchandreplace PH_IP_ALICE $ipv4_alice $TESTDIR
282 searchandreplace PH_IP6_ALICE $ipv6_alice $TESTDIR
283 ;;
284 venus)
285 searchandreplace PH_IP_VENUS $ipv4_venus $TESTDIR
286 searchandreplace PH_IP6_VENUS $ipv6_venus $TESTDIR
287 ;;
288 bob)
289 searchandreplace PH_IP_BOB $ipv4_bob $TESTDIR
290 searchandreplace PH_IPV6_BOB $ipv6_bob $TESTDIR
291 ;;
292 carol)
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
297 ;;
298 dave)
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
303 ;;
304 winnetou)
305 searchandreplace PH_IP_WINNETOU $ipv4_winnetou $TESTDIR
306 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
307 ;;
308 esac
309 done
310
311
312 ##########################################################################
313 # copy test specific configurations to uml hosts and clear auth.log files
314 #
315
316 $DIR/scripts/load-testconfig $testname
317 source $TESTDIR/test.conf
318
319
320 ##########################################################################
321 # run tcpdump in the background
322 #
323
324 if [ "$TCPDUMPHOSTS" != "" ]
325 then
326 echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
327
328 for host_iface in $TCPDUMPHOSTS
329 do
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"
336 done
337 fi
338
339
340 ##########################################################################
341 # execute pre-test commands
342 #
343
344 cecho-n "pre.."
345 echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
346
347 eval `awk -F "::" '{
348 if ($2 != "")
349 {
350 printf("echo \"%s# %s\"; ", $1, $2)
351 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
352 printf("echo;\n")
353 }
354 }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
355
356
357 ##########################################################################
358 # stop tcpdump
359 #
360
361 function stop_tcpdump {
362 echo "${1}# killall tcpdump" >> $CONSOLE_LOG
363 eval ssh root@\$ipv4_${1} killall tcpdump
364 eval TDUP_${1}="false"
365 echo ""
366 }
367
368
369 ##########################################################################
370 # get and evaluate test results
371 #
372
373 cecho-n "test.."
374 echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
375
376 STATUS="passed"
377
378 eval `awk -F "::" '{
379 host=$1
380 command=$2
381 pattern=$3
382 hit=$4
383 if (command != "")
384 {
385 if (command == "tcpdump")
386 {
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)
390 }
391 else
392 {
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)
395 }
396 printf("cmd_exit=\044?; ")
397 printf("echo; ")
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")
401 }
402 }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
403
404
405 ##########################################################################
406 # set counters
407 #
408
409 if [ $STATUS = "failed" ]
410 then
411 let "failed_cnt += 1"
412 else
413 let "passed_cnt += 1"
414 fi
415
416
417 ##########################################################################
418 # log statusall and listall output
419 # get copies of ipsec.conf, ipsec.secrets
420 # create index.html for the given test case
421
422 cat > $TESTRESULTDIR/index.html <<@EOF
423 <html>
424 <head>
425 <title>Test $testname</title>
426 </head>
427 <body>
428 <table border="0" width="600">
429 <tr><td>
430 <h2>Test $testname</h2>
431 <h3>Description</h3>
432 @EOF
433
434 cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
435
436 cat >> $TESTRESULTDIR/index.html <<@EOF
437 <ul>
438 <li><a href="console.log">console.log</a></li>
439 </ul>
440 <img src="../../images/$DIAGRAM" alt="$UMLHOSTS">
441 @EOF
442
443 for host in $IPSECHOSTS
444 do
445 eval HOSTLOGIN=root@\$ipv4_${host}
446
447 for command in statusall listall
448 do
449 ssh $HOSTLOGIN ipsec $command \
450 > $TESTRESULTDIR/${host}.$command 2>/dev/null
451 done
452
453 for file in ipsec.conf ipsec.secrets
454 do
455 scp $HOSTLOGIN:/etc/$file \
456 $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
457 done
458
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
464 <h3>$host</h3>
465 <table border="0" cellspacing="0" width="400">
466 <tr>
467 <td>
468 <ul>
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>
473 </ul>
474 </td>
475 <td>
476 <ul>
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>
481 </ul>
482 </td>
483 </tr>
484 </table>
485 @EOF
486
487 done
488
489 cat >> $TESTRESULTDIR/index.html <<@EOF
490 </td></tr>
491 <tr><td align="right">
492 <b><a href="../index.html">Back</a></b>
493 </td></tr>
494 </table>
495 </body>
496 </html>
497 @EOF
498
499
500 ##########################################################################
501 # execute post-test commands
502 #
503
504 cecho-n "post.."
505 echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
506
507 eval `awk -F "::" '{
508 if ($2 != "")
509 {
510 printf("echo \"%s# %s\"; ", $1, $2)
511 printf("ssh root@\044ipv4_%s \"%s\"; ", $1, $2)
512 printf("echo;\n")
513 }
514 }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
515
516
517 ##########################################################################
518 # get a copy of /var/log/auth.log
519 #
520
521 for host in $IPSECHOSTS
522 do
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
529 done
530
531
532 ##########################################################################
533 # get a copy of /var/log/daemon.log
534 #
535
536 for host in $IPSECHOSTS
537 do
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
544 done
545
546
547 ##########################################################################
548 # stop tcpdump if necessary
549 #
550
551 for host in $TCPDUMPHOSTS
552 do
553 if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
554 then
555 echo "${host}# killall tcpdump" >> $CONSOLE_LOG
556 eval ssh root@\$ipv4_$host killall tcpdump
557 eval TDUP_${host}="false"
558 fi
559 done
560
561
562 ##########################################################################
563 # copy default host config back if necessary
564 #
565
566 $DIR/scripts/restore-defaults $testname
567
568
569 ##########################################################################
570 # write test status to html file
571 #
572
573 if [ $STATUS = "passed" ]
574 then
575 COLOR="green"
576 cecho "\033[1;32m$STATUS"
577 else
578 COLOR="red"
579 cecho "$STATUS"
580 fi
581
582 cat >> $TESTRESULTSHTML << @EOF
583 <tr>
584 <td>$testnumber</td>
585 <td><a href="$testname/">$testname</a></td>
586 <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
587 <td>&nbsp;</td>
588 </tr>
589 @EOF
590 cat >> $SUBTESTSINDEX << @EOF
591 <tr>
592 <td>$testnumber</td>
593 <td><a href="$name/">$name</a></td>
594 <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
595 <td>&nbsp;</td>
596 </tr>
597 @EOF
598
599 done
600
601 done
602
603
604 ##############################################################################
605 # finish the results html file
606 #
607
608 cat >> $TESTRESULTSHTML << @EOF
609 </table>
610 <p>
611 <b>Passed: &nbsp; <font color="green">$passed_cnt</font></b><br>
612 <b>Failed: &nbsp; <font color="red">$failed_cnt</font></b><br>
613 <p>
614 </body>
615 </html>
616 @EOF
617
618 let "all_cnt = $passed_cnt + $failed_cnt"
619
620 cat >> $INDEX << @EOF
621 <tr>
622 <td>&nbsp;</td>
623 <td><a href="all.html"><b>all</b></a></td>
624 <td align="right"><b>$all_cnt</b></td>
625 <td>&nbsp;</td>
626 </tr>
627 <tr>
628 <td><b>Failed:</b></td>
629 <td>&nbsp;</td>
630 <td align="right"><b><font color="red">$failed_cnt</font></b></td>
631 <td>&nbsp;</td>
632 </tr>
633 </table>
634 </body>
635 </html>
636 @EOF
637
638 cecho ""
639 cecho "\033[1;32mPassed: $passed_cnt"
640 cecho "Failed: $failed_cnt"
641 cecho ""
642
643
644 ##############################################################################
645 # copy the test results to the apache server
646 #
647
648 HTDOCS="/var/www/localhost/htdocs"
649
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
654 cecho "done"
655 cecho ""
656 cecho "The results are available in $TODAYDIR"
657 cecho "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"