testing: Add support for counting matching lines in tests
[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 DIR=$(dirname `readlink -f $0`)
18 . $DIR/testing.conf
19 . $DIR/scripts/function.sh
20 SSHCONF="-F $DIR/ssh_config"
21
22 [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
23 [ -d $DIR/tests ] || die "Directory 'tests' not found"
24 [ -d $BUILDDIR ] ||
25         die "Directory '$BUILDDIR' does not exist, please run make-testing first"
26 running_any $STRONGSWANHOSTS || die "Please start test environment before running $0"
27
28 ln -sfT $DIR $TESTDIR/testing
29
30 ##############################################################################
31 # take care of new path and file variables
32 #
33
34 [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
35
36 TESTDATE=`date +%Y%m%d-%H%M-%S`
37
38 TODAYDIR=$TESTRESULTSDIR/$TESTDATE
39 mkdir $TODAYDIR
40 TESTRESULTSHTML=$TODAYDIR/all.html
41 INDEX=$TODAYDIR/index.html
42 DEFAULTTESTSDIR=$TESTDIR/testing/tests
43
44 SOURCEIP_ROUTING_TABLE=220
45
46 testnumber="0"
47 failed_cnt="0"
48 passed_cnt="0"
49 subdir_cnt="0"
50
51 ##############################################################################
52 # copy default tests to $BUILDDIR
53 #
54
55 TESTSDIR=$BUILDDIR/tests
56 [ -d $TESTSDIR ] || mkdir $TESTSDIR
57
58 ##############################################################################
59 # assign IP for each host to hostname
60 #
61
62 for host in $STRONGSWANHOSTS
63 do
64     eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
65     eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
66
67     case $host in
68     moon)
69         eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
70         eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
71         ;;
72     sun)
73         eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
74         eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
75         ;;
76     alice)
77         eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
78         eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
79         ;;
80     venus)
81         ;;
82     bob)
83         ;;
84     carol)
85         eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
86         eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
87          ;;
88     dave)
89         eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
90         eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
91         ;;
92     winnetou)
93         ;;
94     esac
95 done
96
97
98 ##############################################################################
99 # open ssh sessions
100 #
101 for host in $STRONGSWANHOSTS
102 do
103     ssh $SSHCONF -N root@`eval echo \\\$ipv4_$host` >/dev/null 2>&1 &
104     eval ssh_pid_$host="`echo $!`"
105     do_on_exit kill `eval echo \\\$ssh_pid_$host`
106 done
107
108 ##############################################################################
109 # determine actual software versions
110 #
111
112 [ -f $SHAREDDIR/.strongswan-version ] && SWANVERSION=`cat $SHAREDDIR/.strongswan-version`
113 KERNELVERSION=`ssh $SSHCONF root@\$ipv4_winnetou uname -r 2>/dev/null`
114
115 # check if tcpdump supports --immediate-mode
116 ssh $SSHCONF root@$ipv4_winnetou tcpdump --immediate-mode -c 1 >/dev/null 2>&1
117 if [ $? -eq 0 ]
118 then
119         TCPDUMP_IM=--immediate-mode
120 fi
121
122 ##############################################################################
123 # create header for the results html file
124 #
125
126 ENVIRONMENT_HEADER=$(cat <<@EOF
127   <table border="0" cellspacing="2" cellpadding="2">
128     <tr valign="top">
129       <td><b>Host</b></td>
130       <td colspan="3">`uname -a`</td>
131     </tr>
132     <tr valign="top">
133       <td><b>Guest kernel</b></td>
134       <td colspan="3">$KERNELVERSION</td>
135     </tr>
136     <tr valign="top">
137       <td><b>strongSwan</b></td>
138       <td colspan="3">$SWANVERSION</td>
139     </tr>
140     <tr valign="top">
141       <td><b>Date</b></td>
142       <td colspan="3">$TESTDATE</td>
143     </tr>
144     <tr>
145       <td width="100">&nbsp;</td>
146       <td width="300">&nbsp;</td>
147       <td width=" 80">&nbsp;</td>
148       <td >&nbsp;</td>
149     </tr>
150 @EOF
151 )
152
153 cat > $INDEX <<@EOF
154 <html>
155 <head>
156   <title>strongSwan KVM Tests</title>
157 </head>
158 <body>
159   <h2>strongSwan KVM Tests</h2>
160   $ENVIRONMENT_HEADER
161 @EOF
162
163 cat > $TESTRESULTSHTML <<@EOF
164 <html>
165 <head>
166   <title>strongSwan KVM Tests - All Tests</title>
167 </head>
168 <body>
169   <div><a href="index.html">strongSwan KVM Tests</a> / All Tests</div>
170   <h2>All Tests</h2>
171   $ENVIRONMENT_HEADER
172     <tr align="left">
173       <th>Number</th>
174       <th>Test</th>
175       <th align="right">Time [s]</th>
176       <th>Result</th>
177     </tr>
178 @EOF
179
180 echo "Guest kernel : $KERNELVERSION"
181 echo "strongSwan   : $SWANVERSION"
182 echo "Date         : $TESTDATE"
183 echo
184
185 ##############################################################################
186 # trap CTRL-C to properly terminate a long run
187 #
188
189 function abort_tests()
190 {
191         echo -n "...aborting..." > /dev/tty
192         aborted=YES
193 }
194 trap abort_tests INT
195
196 ##############################################################################
197 # enter specific test directory
198 #
199 if [ $# -gt 0 ]
200 then
201     TESTS=$(printf "%s\n" $* | sort -u)
202 else
203     TESTS=$(ls $DEFAULTTESTSDIR)
204 fi
205
206 for SUBDIR in $TESTS
207 do
208     SUBTESTS="`basename $SUBDIR`"
209
210         if [ $SUBTESTS = $SUBDIR ]
211         then
212                 SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
213         else
214                 if [[ $SUBTESTS == *'*'* ]]
215                 then
216                         SUBTESTS="`basename -a $DEFAULTTESTSDIR/$SUBDIR`"
217                 fi
218                 SUBDIR="`dirname $SUBDIR`"
219         fi
220
221     if [ ! -d $TODAYDIR/$SUBDIR ]
222     then
223         mkdir $TODAYDIR/$SUBDIR
224         if [ $testnumber == 0 ]
225         then
226             FIRST="<b>Category</b>"
227         else
228             FIRST="&nbsp;"
229         fi
230
231         if [ $subdir_cnt != 0 ]
232         then
233             echo "      <td align=\"right\">$subdir_cnt</td>" >> $INDEX
234             echo "      <td>&nbsp;</td>" >> $INDEX
235             echo "    </tr>" >> $INDEX
236             subdir_cnt="0"
237         fi
238         echo "    <tr>" >> $INDEX
239     echo "      <td>$FIRST</td>">> $INDEX
240     echo "      <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
241
242         SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
243         cat > $SUBTESTSINDEX <<@EOF
244 <html>
245 <head>
246   <title>strongSwan $SUBDIR Tests</title>
247 </head>
248 <body>
249   <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
250   <h2>strongSwan $SUBDIR Tests</h2>
251   <table border="0" cellspacing="2" cellpadding="2">
252     <tr valign="top">
253       <td><b>Guest kernel</b></td>
254       <td colspan="3">$KERNELVERSION</td>
255     </tr>
256     <tr valign="top">
257       <td><b>strongSwan</b></td>
258       <td colspan="3">$SWANVERSION</td>
259     </tr>
260     <tr valign="top">
261       <td><b>Date</b></td>
262       <td colspan="3">$TESTDATE</td>
263     </tr>
264     <tr>
265       <td width="100">&nbsp;</td>
266       <td width="300">&nbsp;</td>
267       <td width=" 50">&nbsp;</td>
268       <td >&nbsp;</td>
269     </tr>
270     <tr align="left">
271        <th>Number</th>
272        <th>Test</th>
273        <th colspan="2">Result</th>
274     </tr>
275 @EOF
276     fi
277
278     for name in $SUBTESTS
279     do
280         let "testnumber += 1"
281         let "subdir_cnt += 1"
282         testname=$SUBDIR/$name
283         log_action " $testnumber $testname:"
284
285         teststart=$(date +%s)
286
287         if [ ! -d $DEFAULTTESTSDIR/${testname} ]
288         then
289             echo "is missing..skipped"
290             continue
291         fi
292
293         [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
294         [ -f $DEFAULTTESTSDIR/${testname}/test.conf ]       || die "!! File 'test.conf' is missing"
295         [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ]     || die "!! File 'pretest.dat' is missing"
296         [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ]    || die "!! File 'posttest.dat' is missing"
297         [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ]    || die "!! File 'evaltest.dat' is missing"
298
299         TESTRESULTDIR=$TODAYDIR/$testname
300         mkdir -p $TESTRESULTDIR
301         CONSOLE_LOG=$TESTRESULTDIR/console.log
302         touch $CONSOLE_LOG
303
304         TESTDIR=$TESTSDIR/${testname}
305
306         ##########################################################################
307         # copy test specific configurations to hosts and clear log files
308         #
309
310         DBDIR=/etc/db.d
311
312         $DIR/scripts/load-testconfig $testname
313         unset RADIUSHOSTS
314         unset DBHOSTS
315         unset IPV6
316         unset SWANCTL
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 -l $TCPDUMP_IM -i $iface not port ssh and not port domain >/tmp/tcpdump.log 2>/tmp/tcpdump.err.log &"
333                 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
334                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
335                 eval TDUP_${host}="true"
336             done
337         fi
338
339         ##########################################################################
340         # create database directory in RAM
341         #
342
343         for host in $DBHOSTS
344         do
345                 eval HOSTLOGIN=root@\$ipv4_${host}
346             ssh $SSHCONF $HOSTLOGIN "mkdir -p $DBDIR; mount -t ramfs -o size=5m ramfs $DBDIR" >/dev/null 2>&1
347             ssh $SSHCONF $HOSTLOGIN "chgrp www-data $DBDIR; chmod g+w $DBDIR" >/dev/null 2>&1
348         done
349
350         ##########################################################################
351         # flush conntrack table on all hosts
352         #
353
354         for host in $STRONGSWANHOSTS
355         do
356                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'conntrack -F' >/dev/null 2>&1
357         done
358
359         ##########################################################################
360         # remove leak detective log on all hosts
361         #
362
363         export LEAK_DETECTIVE_LOG=/var/log/leak-detective.log
364         for host in $STRONGSWANHOSTS
365         do
366                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'rm -f $LEAK_DETECTIVE_LOG' >/dev/null 2>&1
367         done
368
369         ##########################################################################
370         # flush IPsec state on all hosts
371         #
372
373         for host in $STRONGSWANHOSTS
374         do
375                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'ip xfrm state flush; ip xfrm policy flush' >/dev/null 2>&1
376         done
377
378         ##########################################################################
379         # execute pre-test commands
380         #
381
382         echo -n "pre.."
383         echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
384
385         eval `awk -F "::" '{
386             if ($1 !~ /^#.*/ && $2 != "")
387             {
388                 printf("echo \"%s# %s\"; ", $1, $2)
389                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
390                 printf("echo;\n")
391             }
392         }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
393
394
395         ##########################################################################
396         # stop tcpdump
397         #
398
399         function stop_tcpdump {
400             # wait for packets to get processed, but don't wait longer than 1s
401             eval ssh $SSHCONF root@\$ipv4_${1} "\"i=100; while [ \\\$i -gt 0 ]; do pkill -USR1 tcpdump; tail -1 /tmp/tcpdump.err.log | perl -n -e '/(\\d+).*?(\\d+)/; exit (\\\$1 == \\\$2)' || break; sleep 0.01; i=\\\$((\\\$i-1)); done;\""
402             echo "${1}# killall tcpdump" >> $CONSOLE_LOG
403             eval ssh $SSHCONF root@\$ipv4_${1} "\"killall tcpdump; while true; do killall -q -0 tcpdump || break; sleep 0.01; done;\""
404             eval TDUP_${1}="false"
405             echo "" >> $CONSOLE_LOG
406         }
407
408
409         ##########################################################################
410         # get and evaluate test results
411         #
412
413         echo -n "test.."
414         echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
415
416         STATUS="passed"
417
418         eval `awk -F "::" '{
419                 host=$1
420                 command=$2
421                 pattern=$3
422                 hit=$4
423                 if (host ~ /^#.*/ || command == "")
424                 {
425                         next
426                 }
427                 if (command == "tcpdump")
428                 {
429                         printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
430                         printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047  [%s]\"; ", host, pattern, hit)
431                         printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"); ", host, pattern)
432                 }
433                 else
434                 {
435                         printf("echo \"%s# %s | grep \047%s\047  [%s]\"; ", host, command, pattern, hit)
436                         printf("cmd_out=\044(ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"); ",  host, command, pattern)
437                 }
438                 printf("cmd_exit=\044?; ")
439                 printf("echo \"\044cmd_out\"; ")
440                 printf("echo; ")
441                 if (hit ~ /^[0-9]+$/)
442                 {
443                         printf("if [ \044(echo \"\044cmd_out\" | wc -l) -ne %d ] ", hit)
444                 }
445                 else
446                 {
447                         printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\"  ] ", hit)
448                         printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
449                 }
450                 printf("; then STATUS=\"failed\"; fi; \n")
451         }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
452
453
454         ##########################################################################
455         # log statusall and listall output
456         # get copies of ipsec.conf, ipsec.secrets
457         # create index.html for the given test case
458
459         cat > $TESTRESULTDIR/index.html <<@EOF
460 <html>
461 <head>
462   <title>Test $testname</title>
463 </head>
464 <body>
465 <table border="0" cellpadding="0" cellspacing="0" width="600">
466   <tr><td>
467     <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
468     <h2>Test $testname</h2>
469     <h3>Description</h3>
470 @EOF
471
472         cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
473
474         cat >> $TESTRESULTDIR/index.html <<@EOF
475     <ul>
476       <li><a href="console.log">console.log</a></li>
477     </ul>
478     <img src="../../images/$DIAGRAM" alt="$VIRTHOSTS">
479 @EOF
480
481         IPTABLES_CMD_V4="echo -e '=== filter table ==='; iptables  -v -n -L; echo -e '\n=== nat table ==='; iptables  -v -n -t nat -L; echo -e '\n=== mangle table ==='; iptables  -v -n -t mangle -L"
482         IPTABLES_CMD_V6="echo -e '=== filter table ==='; ip6tables -v -n -L; echo -e '\n=== nat table ==='; ip6tables -v -n -t nat -L; echo -e '\n=== mangle table ==='; ip6tables -v -n -t mangle -L"
483
484         if [ -n "$IPV6" ]
485         then
486             IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
487             IPROUTE_DSP=$IPROUTE_CMD
488             IPTABLES_CMD="$IPTABLES_CMD_V6"
489             IPTABLES_DSP="ip6tables -L"
490             IPTABLES_SAVE_CMD="ip6tables-save"
491             IPTABLES_SAVE_DSP="ip6tables-save"
492         else
493             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
494             IPROUTE_DSP=$IPROUTE_CMD
495             IPTABLES_CMD="$IPTABLES_CMD_V4"
496             IPTABLES_DSP="iptables -L"
497             IPTABLES_SAVE_CMD="iptables-save"
498             IPTABLES_SAVE_DSP="iptables-save"
499         fi
500
501         if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
502         then
503             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
504             IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
505             IPTABLES_CMD="$IPTABLES_CMD_V4; echo; $IPTABLES_CMD_V6"
506             IPTABLES_DSP="iptables -L ; ip6tables -L"
507             IPTABLES_SAVE_CMD="iptables-save; echo; ip6tables-save"
508             IPTABLES_SAVE_DSP="iptables-save ; ip6tables-save"
509         fi
510
511         for host in $DBHOSTS
512         do
513             eval HOSTLOGIN=root@\$ipv4_${host}
514
515                 scp $SSHCONF $HOSTLOGIN:/etc/db.d/ipsec.sql \
516                     $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
517         done
518
519         for host in $IPSECHOSTS
520         do
521             eval HOSTLOGIN=root@\$ipv4_${host}
522
523                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
524                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
525                 if [  -n "$SWANCTL" ]
526                 then
527                         scp $SSHCONF $HOSTLOGIN:/etc/swanctl/swanctl.conf \
528                         $TESTRESULTDIR/${host}.swanctl.conf  > /dev/null 2>&1
529
530                         for subsys in conns algs certs pools authorities sas pols
531                         do
532                                 ssh $SSHCONF $HOSTLOGIN swanctl --list-$subsys \
533                                         > $TESTRESULTDIR/${host}.swanctl.$subsys 2>/dev/null
534                         done
535
536                         ssh $SSHCONF $HOSTLOGIN swanctl --stats \
537                                 > $TESTRESULTDIR/${host}.swanctl.stats 2>/dev/null
538
539                         echo "" >> $TESTRESULTDIR/${host}.swanctl.sas
540                         cat $TESTRESULTDIR/${host}.swanctl.pols >> \
541                                 $TESTRESULTDIR/${host}.swanctl.sas
542                         cat $TESTRESULTDIR/${host}.swanctl.algs >> \
543                                 $TESTRESULTDIR/${host}.swanctl.stats
544                 else
545                     for file in ipsec.conf ipsec.secrets
546                     do
547                                 scp $SSHCONF $HOSTLOGIN:/etc/$file \
548                             $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
549                     done
550
551                     for command in statusall listall
552                     do
553                                 ssh $SSHCONF $HOSTLOGIN ipsec $command \
554                             > $TESTRESULTDIR/${host}.$command 2>/dev/null
555                     done
556                 fi
557
558                 if (! [ -f $TESTRESULTDIR/${host}.ipsec.sql ] ) then
559                         scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
560                                 $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
561                 fi
562
563             ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
564                     > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
565             ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
566                     > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
567             ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
568                     > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
569             ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
570                     > $TESTRESULTDIR/${host}.iptables 2>/dev/null
571                 ssh $SSHCONF $HOSTLOGIN $IPTABLES_SAVE_CMD \
572                     > $TESTRESULTDIR/${host}.iptables-save 2>/dev/null
573             chmod a+r $TESTRESULTDIR/*
574
575                 if [ -n "$SWANCTL" ]
576                 then
577                     cat >> $TESTRESULTDIR/index.html <<@EOF
578     <h3>$host</h3>
579       <table border="0" cellspacing="0" width="600">
580       <tr>
581         <td valign="top">
582           <ul>
583             <li><a href="$host.swanctl.conf">swanctl.conf</a></li>
584             <li><a href="$host.swanctl.conns">swanctl --list-conns</a></li>
585             <li><a href="$host.swanctl.certs">swanctl --list-certs</a></li>
586             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
587             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
588           </ul>
589         </td>
590         <td valign="top">
591           <ul>
592             <li><a href="$host.swanctl.sas">swanctl --list-sas|--list-pols</a></li>
593             <li><a href="$host.swanctl.pools">swanctl --list-pools</a></li>
594             <li><a href="$host.swanctl.authorities">swanctl --list-authorities</a></li>
595             <li><a href="$host.swanctl.stats">swanctl --stats|--list-algs</a></li>
596             <li><a href="$host.auth.log">auth.log</a></li>
597             <li><a href="$host.daemon.log">daemon.log</a></li>
598           </ul>
599       </td>
600         <td valign="top">
601           <ul>
602             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
603             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
604             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
605             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
606             <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
607           </ul>
608           &nbsp;
609       </td>
610     </tr>
611     </table>
612 @EOF
613
614                 else
615                     cat >> $TESTRESULTDIR/index.html <<@EOF
616     <h3>$host</h3>
617       <table border="0" cellspacing="0" width="600">
618       <tr>
619         <td valign="top">
620           <ul>
621             <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
622             <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
623             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
624             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
625           </ul>
626         </td>
627         <td valign="top">
628           <ul>
629             <li><a href="$host.statusall">ipsec statusall</a></li>
630             <li><a href="$host.listall">ipsec listall</a></li>
631             <li><a href="$host.auth.log">auth.log</a></li>
632             <li><a href="$host.daemon.log">daemon.log</a></li>
633           </ul>
634       </td>
635         <td valign="top">
636           <ul>
637             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
638             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
639             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
640             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
641             <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
642           </ul>
643       </td>
644     </tr>
645     </table>
646 @EOF
647                 fi
648         done
649
650         for host in $RADIUSHOSTS
651         do
652             eval HOSTLOGIN=root@\$ipv4_${host}
653
654             for file in clients.conf eap.conf radiusd.conf proxy.conf users
655             do
656                 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
657                     $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
658             done
659
660                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
661                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
662
663             scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
664                 $TESTRESULTDIR/${host}.radius.log  > /dev/null 2>&1
665
666             ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
667                 >> $TESTRESULTDIR/${host}.daemon.log 2>/dev/null
668
669             chmod a+r $TESTRESULTDIR/*
670             cat >> $TESTRESULTDIR/index.html <<@EOF
671     <h3>$host</h3>
672       <table border="0" cellspacing="0" width="600">
673       <tr>
674         <td valign="top">
675           <ul>
676             <li><a href="$host.clients.conf">clients.conf</a></li>
677             <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
678             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
679           </ul>
680         </td>
681         <td valign="top">
682           <ul>
683             <li><a href="$host.eap.conf">eap.conf</a></li>
684             <li><a href="$host.radius.log">radius.log</a></li>
685             <li><a href="$host.daemon.log">daemon.log</a></li>
686           </ul>
687       </td>
688         <td valign="top">
689           <ul>
690             <li><a href="$host.proxy.conf">proxy.conf</a></li>
691             <li><a href="$host.users">users</a></li>
692           </ul>
693       </td>
694     </tr>
695     </table>
696 @EOF
697
698         done
699
700         cat >> $TESTRESULTDIR/index.html <<@EOF
701         <h3>tcpdump</h3>
702         <ul>
703 @EOF
704
705         for host in $TCPDUMPHOSTS
706         do
707             cat >> $TESTRESULTDIR/index.html <<@EOF
708             <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
709 @EOF
710         done
711
712         cat >> $TESTRESULTDIR/index.html <<@EOF
713         </ul>
714 @EOF
715
716         cat >> $TESTRESULTDIR/index.html <<@EOF
717   </td></tr>
718 </table>
719 </body>
720 </html>
721 @EOF
722
723
724         ##########################################################################
725         # execute post-test commands
726         #
727
728         echo -n "post"
729         echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
730
731         eval `awk -F "::" '{
732             if ($1 !~ /^#.*/ && $2 != "")
733             {
734                 printf("echo \"%s# %s\"; ", $1, $2)
735                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
736                 printf("echo;\n")
737             }
738         }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
739
740         ##########################################################################
741         # check that IPsec state was cleaned up properly
742         #
743
744         for host in $IPSECHOSTS
745         do
746                 eval HOSTLOGIN=root@\$ipv4_${host}
747                 IPSECSTATE=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm state'`
748                 IPSECPOLICY=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm policy'`
749                 if [ -n "$IPSECSTATE" -o -n "$IPSECPOLICY" ]
750                 then
751                         echo -e "\n$host# ip xfrm state [NO]" >> $CONSOLE_LOG
752                         echo "$IPSECSTATE" >> $CONSOLE_LOG
753                         echo -e "\n$host# ip xfrm policy [NO]" >> $CONSOLE_LOG
754                         echo "$IPSECPOLICY" >> $CONSOLE_LOG
755                         STATUS="failed"
756                 fi
757         done
758
759
760         ##########################################################################
761         # make sure there were no leaks
762         #
763
764         for host in $STRONGSWANHOSTS
765         do
766                 eval HOSTLOGIN=root@\$ipv4_${host}
767                 LEAKS=`ssh $SSHCONF $HOSTLOGIN 'cat $LEAK_DETECTIVE_LOG 2>/dev/null | grep -v "No leaks detected.*"'`
768                 if [ -n "$LEAKS" ]
769                 then
770                         echo -e "\n$host# cat $LEAK_DETECTIVE_LOG [NO]" >> $CONSOLE_LOG
771                         echo "$LEAKS" >> $CONSOLE_LOG
772                         echo "<<< $host $LEAK_DETECTIVE_LOG >>>" >> $CONSOLE_LOG
773                         STATUS="failed"
774                 fi
775         done
776
777
778         ##########################################################################
779         # get a copy of /var/log/auth.log
780         #
781
782         for host in $IPSECHOSTS
783         do
784             eval HOSTLOGIN=root@\$ipv4_${host}
785             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv|pt-tls-client' \
786                 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
787         done
788
789
790         ##########################################################################
791         # get a copy of /var/log/daemon.log
792         #
793
794         for host in $IPSECHOSTS
795         do
796             eval HOSTLOGIN=root@\$ipv4_${host}
797             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv' \
798                 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
799         done
800
801
802         ##########################################################################
803         # stop tcpdump if necessary
804         #
805
806         for host in $TCPDUMPHOSTS
807         do
808             if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
809             then
810                         stop_tcpdump $host
811             fi
812             eval HOSTLOGIN=root@\$ipv4_${host}
813                 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
814                         $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
815         done
816
817         ##########################################################################
818         # remove database directory if needed
819         #
820
821         for host in $DBHOSTS
822         do
823                 eval HOSTLOGIN=root@\$ipv4_${host}
824             ssh $SSHCONF $HOSTLOGIN "umount $DBDIR; rm -r $DBDIR" > /dev/null 2>&1
825         done
826
827         ##########################################################################
828         # copy default host config back if necessary
829         #
830
831         $DIR/scripts/restore-defaults $testname
832
833
834         ##########################################################################
835         # set counters
836         #
837
838         if [ $STATUS = "failed" ]
839         then
840             let "failed_cnt += 1"
841         else
842             let "passed_cnt += 1"
843         fi
844
845
846         ##########################################################################
847         # write test status to html file
848         #
849         testend=$(date +%s)
850         let "testend -= teststart"
851         let "timetotal += testend"
852
853         if [ $STATUS = "passed" ]
854         then
855                 COLOR="green"
856                 log_status 0
857         else
858                 COLOR="red"
859                 log_status 1
860         fi
861
862         cat >> $TESTRESULTSHTML << @EOF
863   <tr>
864     <td>$testnumber</td>
865     <td><a href="$testname/index.html">$testname</a></td>
866     <td align="right">$testend</td>
867     <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
868   </tr>
869 @EOF
870         cat >> $SUBTESTSINDEX << @EOF
871   <tr>
872     <td>$testnumber</td>
873     <td><a href="$name/index.html">$name</a></td>
874     <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
875     <td>&nbsp;</td>
876   </tr>
877 @EOF
878
879
880         ##########################################################################
881         # remove any charon.pid files that still may exist
882         #
883
884         for host in $IPSECHOSTS
885         do
886             eval HOSTLOGIN=root@\$ipv4_${host}
887             ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo "    removed charon.pid on `hostname`"; fi'
888         done
889
890         if [ -n "$aborted" ]
891         then
892             break 2
893         fi
894
895     done
896
897 done
898
899
900 ##############################################################################
901 # finish the results html file
902 #
903
904 cat >> $TESTRESULTSHTML << @EOF
905     <tr>
906       <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
907     </tr>
908     <tr>
909       <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
910     </tr>
911     <tr>
912       <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
913     </tr>
914     <tr>
915       <td><b>Time [s]</b></td><td><b><font color="blue">$timetotal</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
916     </tr>
917   </table>
918 </body>
919 </html>
920 @EOF
921
922 if [ $subdir_cnt != 0 ]
923 then
924 cat >> $INDEX << @EOF
925       <td align="right">$subdir_cnt</td>
926       <td>&nbsp;</td>
927     </tr>
928 @EOF
929 fi
930
931 let "all_cnt = $passed_cnt + $failed_cnt"
932
933 cat >> $INDEX << @EOF
934     <tr>
935       <td>&nbsp;</td>
936       <td><a href="all.html"><b>all</b></a></td>
937       <td align="right"><b>$all_cnt</b></td>
938       <td>&nbsp;</td>
939     </tr>
940     <tr>
941       <td><b>Failed</b></td>
942       <td>&nbsp;</td>
943       <td align="right"><b><font color="red">$failed_cnt</font></b></td>
944       <td>&nbsp;</td>
945     </tr>
946   </table>
947 </body>
948 </html>
949 @EOF
950
951 echo
952 echo_ok     "Passed : $passed_cnt"
953 echo_failed "Failed : $failed_cnt"
954
955 echo
956 echo "The results are available in $TODAYDIR"
957 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
958
959 ENDDATE=`date +%Y%m%d-%H%M-%S`
960 echo
961 echo "Finished : $ENDDATE"