testing: Report number of tests per subdirectory in main index
[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 ##############################################################################
187 # enter specific test directory
188 #
189 if [ $# -gt 0 ]
190 then
191     TESTS=$(printf "%s\n" $* | sort -u)
192 else
193     TESTS=$(ls $DEFAULTTESTSDIR)
194 fi
195
196 for SUBDIR in $TESTS
197 do
198     SUBTESTS="`basename $SUBDIR`"
199
200     if [ $SUBTESTS = $SUBDIR ]
201     then
202         SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
203     else
204         SUBDIR="`dirname $SUBDIR`"
205     fi
206
207     if [ ! -d $TODAYDIR/$SUBDIR ]
208     then
209         mkdir $TODAYDIR/$SUBDIR
210         if [ $testnumber == 0 ]
211         then
212             FIRST="<b>Category</b>"
213         else
214             FIRST="&nbsp;"
215         fi
216
217         if [ $subdir_cnt != 0 ]
218         then
219             echo "      <td align=\"right\">$subdir_cnt</td>" >> $INDEX
220             echo "      <td>&nbsp;</td>" >> $INDEX
221             echo "    </tr>" >> $INDEX
222             subdir_cnt="0"
223         fi
224         echo "    <tr>" >> $INDEX
225     echo "      <td>$FIRST</td>">> $INDEX
226     echo "      <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
227
228         SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
229         cat > $SUBTESTSINDEX <<@EOF
230 <html>
231 <head>
232   <title>strongSwan $SUBDIR Tests</title>
233 </head>
234 <body>
235   <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
236   <h2>strongSwan $SUBDIR Tests</h2>
237   <table border="0" cellspacing="2" cellpadding="2">
238     <tr valign="top">
239       <td><b>Guest kernel</b></td>
240       <td colspan="3">$KERNELVERSION</td>
241     </tr>
242     <tr valign="top">
243       <td><b>strongSwan</b></td>
244       <td colspan="3">$SWANVERSION</td>
245     </tr>
246     <tr valign="top">
247       <td><b>Date</b></td>
248       <td colspan="3">$TESTDATE</td>
249     </tr>
250     <tr>
251       <td width="100">&nbsp;</td>
252       <td width="300">&nbsp;</td>
253       <td width=" 50">&nbsp;</td>
254       <td >&nbsp;</td>
255     </tr>
256     <tr align="left">
257        <th>Number</th>
258        <th>Test</th>
259        <th colspan="2">Result</th>
260     </tr>
261 @EOF
262     fi
263
264     for name in $SUBTESTS
265     do
266         let "testnumber += 1"
267         let "subdir_cnt += 1"
268         testname=$SUBDIR/$name
269         log_action " $testnumber $testname:"
270
271         teststart=$(date +%s)
272
273         if [ ! -d $DEFAULTTESTSDIR/${testname} ]
274         then
275             echo "is missing..skipped"
276             continue
277         fi
278
279         [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
280         [ -f $DEFAULTTESTSDIR/${testname}/test.conf ]       || die "!! File 'test.conf' is missing"
281         [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ]     || die "!! File 'pretest.dat' is missing"
282         [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ]    || die "!! File 'posttest.dat' is missing"
283         [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ]    || die "!! File 'evaltest.dat' is missing"
284
285         TESTRESULTDIR=$TODAYDIR/$testname
286         mkdir -p $TESTRESULTDIR
287         CONSOLE_LOG=$TESTRESULTDIR/console.log
288         touch $CONSOLE_LOG
289
290         TESTDIR=$TESTSDIR/${testname}
291         rm -rf $TESTDIR
292         mkdir -p $TESTDIR
293         cp -rfp $DEFAULTTESTSDIR/${testname}/* $TESTDIR
294
295
296         ##############################################################################
297         # replace IP wildcards with actual IPv4 and IPv6 addresses
298         #
299
300         for host in $STRONGSWANHOSTS
301         do
302             case $host in
303             moon)
304                 searchandreplace PH_IP_MOON1     $ipv4_moon1 $TESTDIR
305                 searchandreplace PH_IP_MOON      $ipv4_moon  $TESTDIR
306                 searchandreplace PH_IP6_MOON1    $ipv6_moon1 $TESTDIR
307                 searchandreplace PH_IP6_MOON     $ipv6_moon  $TESTDIR
308                 ;;
309             sun)
310                 searchandreplace PH_IP_SUN1      $ipv4_sun1 $TESTDIR
311                 searchandreplace PH_IP_SUN       $ipv4_sun  $TESTDIR
312                 searchandreplace PH_IP6_SUN1     $ipv6_sun1 $TESTDIR
313                 searchandreplace PH_IP6_SUN      $ipv6_sun  $TESTDIR
314                 ;;
315             alice)
316                 searchandreplace PH_IP_ALICE1    $ipv4_alice1 $TESTDIR
317                 searchandreplace PH_IP_ALICE     $ipv4_alice  $TESTDIR
318                 searchandreplace PH_IP6_ALICE1   $ipv6_alice1 $TESTDIR
319                 searchandreplace PH_IP6_ALICE    $ipv6_alice  $TESTDIR
320                 ;;
321             venus)
322                 searchandreplace PH_IP_VENUS     $ipv4_venus $TESTDIR
323                 searchandreplace PH_IP6_VENUS    $ipv6_venus $TESTDIR
324                 ;;
325             bob)
326                 searchandreplace PH_IP_BOB       $ipv4_bob $TESTDIR
327                 searchandreplace PH_IPV6_BOB     $ipv6_bob $TESTDIR
328                 ;;
329             carol)
330                 searchandreplace PH_IP_CAROL1    $ipv4_carol1 $TESTDIR
331                 searchandreplace PH_IP_CAROL     $ipv4_carol  $TESTDIR
332                 searchandreplace PH_IP6_CAROL1   $ipv6_carol1 $TESTDIR
333                 searchandreplace PH_IP6_CAROL    $ipv6_carol  $TESTDIR
334                 ;;
335             dave)
336                 searchandreplace PH_IP_DAVE1     $ipv4_dave1 $TESTDIR
337                 searchandreplace PH_IP_DAVE      $ipv4_dave  $TESTDIR
338                 searchandreplace PH_IP6_DAVE1    $ipv6_dave1 $TESTDIR
339                 searchandreplace PH_IP6_DAVE     $ipv6_dave  $TESTDIR
340                 ;;
341             winnetou)
342                 searchandreplace PH_IP_WINNETOU  $ipv4_winnetou $TESTDIR
343                 searchandreplace PH_IP6_WINNETOU $ipv6_winnetou $TESTDIR
344                 ;;
345             esac
346         done
347
348
349         ##########################################################################
350         # copy test specific configurations to uml hosts and clear auth.log files
351         #
352
353         DBDIR=/etc/db.d
354
355         $DIR/scripts/load-testconfig $testname
356         unset RADIUSHOSTS
357         unset DBHOSTS
358         unset IPV6
359         unset SWANCTL
360         source $TESTDIR/test.conf
361
362
363         ##########################################################################
364         # run tcpdump in the background
365         #
366
367         if [ "$TCPDUMPHOSTS" != "" ]
368         then
369             echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
370
371             for host_iface in $TCPDUMPHOSTS
372             do
373                 host=`echo $host_iface | awk -F ":" '{print $1}'`
374                 iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
375                 tcpdump_cmd="tcpdump -l $TCPDUMP_IM -i $iface not port ssh and not port domain >/tmp/tcpdump.log 2>/tmp/tcpdump.err.log &"
376                 echo "${host}# $tcpdump_cmd" >> $CONSOLE_LOG
377                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
378                 eval TDUP_${host}="true"
379             done
380         fi
381
382         ##########################################################################
383         # create database directory in RAM
384         #
385
386         for host in $DBHOSTS
387         do
388                 eval HOSTLOGIN=root@\$ipv4_${host}
389             ssh $SSHCONF $HOSTLOGIN "mkdir -p $DBDIR; mount -t ramfs -o size=5m ramfs $DBDIR" >/dev/null 2>&1
390             ssh $SSHCONF $HOSTLOGIN "chgrp www-data $DBDIR; chmod g+w $DBDIR" >/dev/null 2>&1
391         done
392
393         ##########################################################################
394         # flush conntrack table on all hosts
395         #
396
397         for host in $STRONGSWANHOSTS
398         do
399                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'conntrack -F' >/dev/null 2>&1
400         done
401
402         ##########################################################################
403         # flush IPsec state on all hosts
404         #
405
406         for host in $STRONGSWANHOSTS
407         do
408                 ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'ip xfrm state flush; ip xfrm policy flush' >/dev/null 2>&1
409         done
410
411         ##########################################################################
412         # execute pre-test commands
413         #
414
415         echo -n "pre.."
416         echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
417
418         eval `awk -F "::" '{
419             if ($2 != "")
420             {
421                 printf("echo \"%s# %s\"; ", $1, $2)
422                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
423                 printf("echo;\n")
424             }
425         }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
426
427
428         ##########################################################################
429         # stop tcpdump
430         #
431
432         function stop_tcpdump {
433             # wait for packets to get processed, but don't wait longer than 1s
434             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;\""
435             echo "${1}# killall tcpdump" >> $CONSOLE_LOG
436             eval ssh $SSHCONF root@\$ipv4_${1} "\"killall tcpdump; while true; do killall -q -0 tcpdump || break; sleep 0.01; done;\""
437             eval TDUP_${1}="false"
438             echo "" >> $CONSOLE_LOG
439         }
440
441
442         ##########################################################################
443         # get and evaluate test results
444         #
445
446         echo -n "test.."
447         echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
448
449         STATUS="passed"
450
451         eval `awk -F "::" '{
452             host=$1
453             command=$2
454             pattern=$3
455             hit=$4
456             if (command != "")
457             {
458                 if (command == "tcpdump")
459                 {
460                     printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
461                     printf("echo \"%s# cat /tmp/tcpdump.log | grep \047%s\047  [%s]\"; ", host, pattern, hit)
462                     printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log | grep \"%s\"; ", host, pattern)
463                 }
464                 else
465                 {
466                     printf("echo \"%s# %s | grep \047%s\047  [%s]\"; ", host, command, pattern, hit)
467                     printf("ssh \044SSHCONF root@\044ipv4_%s %s | grep \"%s\"; ",  host, command, pattern)
468                 }
469                 printf("cmd_exit=\044?; ")
470                 printf("echo; ")
471                 printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\"  ] ", hit)
472                 printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
473                 printf("; then STATUS=\"failed\"; fi; \n")
474             }
475         }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
476
477
478         ##########################################################################
479         # set counters
480         #
481
482         if [ $STATUS = "failed" ]
483         then
484             let "failed_cnt += 1"
485         else
486             let "passed_cnt += 1"
487         fi
488
489
490         ##########################################################################
491         # log statusall and listall output
492         # get copies of ipsec.conf, ipsec.secrets
493         # create index.html for the given test case
494
495         cat > $TESTRESULTDIR/index.html <<@EOF
496 <html>
497 <head>
498   <title>Test $testname</title>
499 </head>
500 <body>
501 <table border="0" cellpadding="0" cellspacing="0" width="600">
502   <tr><td>
503     <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
504     <h2>Test $testname</h2>
505     <h3>Description</h3>
506 @EOF
507
508         cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
509
510         cat >> $TESTRESULTDIR/index.html <<@EOF
511     <ul>
512       <li><a href="console.log">console.log</a></li>
513     </ul>
514     <img src="../../images/$DIAGRAM" alt="$VIRTHOSTS">
515 @EOF
516
517         if [ -n "$IPV6" ]
518         then
519             IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
520             IPROUTE_DSP=$IPROUTE_CMD
521             IPTABLES_CMD="ip6tables -v -n -L"
522             IPTABLES_DSP="ip6tables -L"
523         else
524             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
525             IPROUTE_DSP=$IPROUTE_CMD
526             IPTABLES_CMD="iptables -v -n -L"
527             IPTABLES_DSP="iptables -L"
528         fi
529
530         if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
531         then
532             IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
533             IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
534             IPTABLES_CMD="iptables -v -n -L ; echo ; ip6tables -v -n -L"
535             IPTABLES_DSP="iptables -L ; ip6tables -L"
536         fi
537
538         for host in $DBHOSTS
539         do
540             eval HOSTLOGIN=root@\$ipv4_${host}
541
542                 scp $SSHCONF $HOSTLOGIN:/etc/db.d/ipsec.sql \
543                     $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
544         done
545
546         for host in $IPSECHOSTS
547         do
548             eval HOSTLOGIN=root@\$ipv4_${host}
549
550                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
551                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
552                 if [  -n "$SWANCTL" ]
553                 then
554                         scp $SSHCONF $HOSTLOGIN:/etc/swanctl/swanctl.conf \
555                         $TESTRESULTDIR/${host}.swanctl.conf  > /dev/null 2>&1
556
557                         for subsys in conns algs certs pools authorities sas pols
558                         do
559                                 ssh $SSHCONF $HOSTLOGIN swanctl --list-$subsys \
560                                         > $TESTRESULTDIR/${host}.swanctl.$subsys 2>/dev/null
561                         done
562
563                         ssh $SSHCONF $HOSTLOGIN swanctl --stats \
564                                 > $TESTRESULTDIR/${host}.swanctl.stats 2>/dev/null
565
566                         echo "" >> $TESTRESULTDIR/${host}.swanctl.sas
567                         cat $TESTRESULTDIR/${host}.swanctl.pols >> \
568                                 $TESTRESULTDIR/${host}.swanctl.sas
569                         cat $TESTRESULTDIR/${host}.swanctl.algs >> \
570                                 $TESTRESULTDIR/${host}.swanctl.stats
571                 else
572                     for file in ipsec.conf ipsec.secrets
573                     do
574                                 scp $SSHCONF $HOSTLOGIN:/etc/$file \
575                             $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
576                     done
577
578                     for command in statusall listall
579                     do
580                                 ssh $SSHCONF $HOSTLOGIN ipsec $command \
581                             > $TESTRESULTDIR/${host}.$command 2>/dev/null
582                     done
583                 fi
584
585                 if (! [ -f $TESTRESULTDIR/${host}.ipsec.sql ] ) then
586                         scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
587                                 $TESTRESULTDIR/${host}.ipsec.sql  > /dev/null 2>&1
588                 fi
589
590             ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
591                     > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
592             ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
593                     > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
594             ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
595                     > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
596             ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
597                     > $TESTRESULTDIR/${host}.iptables 2>/dev/null
598             chmod a+r $TESTRESULTDIR/*
599
600                 if [ -n "$SWANCTL" ]
601                 then
602                     cat >> $TESTRESULTDIR/index.html <<@EOF
603     <h3>$host</h3>
604       <table border="0" cellspacing="0" width="600">
605       <tr>
606         <td valign="top">
607           <ul>
608             <li><a href="$host.swanctl.conf">swanctl.conf</a></li>
609             <li><a href="$host.swanctl.conns">swanctl --list-conns</a></li>
610             <li><a href="$host.swanctl.certs">swanctl --list-certs</a></li>
611             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
612             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
613           </ul>
614         </td>
615         <td valign="top">
616           <ul>
617             <li><a href="$host.swanctl.sas">swanctl --list-sas|--list-pols</a></li>
618             <li><a href="$host.swanctl.pools">swanctl --list-pools</a></li>
619             <li><a href="$host.swanctl.authorities">swanctl --list-authorities</a></li>
620             <li><a href="$host.swanctl.stats">swanctl --stats|--list-algs</a></li>
621             <li><a href="$host.daemon.log">daemon.log</a></li>
622           </ul>
623       </td>
624         <td valign="top">
625           <ul>
626             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
627             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
628             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
629             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
630             <li><a href="$host.auth.log">auth.log</a></li>
631           </ul>
632           &nbsp;
633       </td>
634     </tr>
635     </table>
636 @EOF
637
638                 else
639                     cat >> $TESTRESULTDIR/index.html <<@EOF
640     <h3>$host</h3>
641       <table border="0" cellspacing="0" width="600">
642       <tr>
643         <td valign="top">
644           <ul>
645             <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
646             <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
647             <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
648             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
649           </ul>
650         </td>
651         <td valign="top">
652           <ul>
653             <li><a href="$host.statusall">ipsec statusall</a></li>
654             <li><a href="$host.listall">ipsec listall</a></li>
655             <li><a href="$host.auth.log">auth.log</a></li>
656             <li><a href="$host.daemon.log">daemon.log</a></li>
657           </ul>
658       </td>
659         <td valign="top">
660           <ul>
661             <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
662             <li><a href="$host.ip.state">ip -s xfrm state</a></li>
663             <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
664             <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
665           </ul>
666       </td>
667     </tr>
668     </table>
669 @EOF
670                 fi
671         done
672
673         for host in $RADIUSHOSTS
674         do
675             eval HOSTLOGIN=root@\$ipv4_${host}
676
677             for file in clients.conf eap.conf radiusd.conf proxy.conf users
678             do
679                 scp $SSHCONF $HOSTLOGIN:/etc/freeradius/$file \
680                     $TESTRESULTDIR/${host}.$file  > /dev/null 2>&1
681             done
682
683                 scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
684                     $TESTRESULTDIR/${host}.strongswan.conf  > /dev/null 2>&1
685
686             scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
687                 $TESTRESULTDIR/${host}.radius.log  > /dev/null 2>&1
688
689             ssh $SSHCONF $HOSTLOGIN grep imcv /var/log/daemon.log \
690                 >> $TESTRESULTDIR/${host}.daemon.log 2>/dev/null
691
692             chmod a+r $TESTRESULTDIR/*
693             cat >> $TESTRESULTDIR/index.html <<@EOF
694     <h3>$host</h3>
695       <table border="0" cellspacing="0" width="600">
696       <tr>
697         <td valign="top">
698           <ul>
699             <li><a href="$host.clients.conf">clients.conf</a></li>
700             <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
701             <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
702           </ul>
703         </td>
704         <td valign="top">
705           <ul>
706             <li><a href="$host.eap.conf">eap.conf</a></li>
707             <li><a href="$host.radius.log">radius.log</a></li>
708             <li><a href="$host.daemon.log">daemon.log</a></li>
709           </ul>
710       </td>
711         <td valign="top">
712           <ul>
713             <li><a href="$host.proxy.conf">proxy.conf</a></li>
714             <li><a href="$host.users">users</a></li>
715           </ul>
716       </td>
717     </tr>
718     </table>
719 @EOF
720
721         done
722
723         cat >> $TESTRESULTDIR/index.html <<@EOF
724         <h3>tcpdump</h3>
725         <ul>
726 @EOF
727
728         for host in $TCPDUMPHOSTS
729         do
730             cat >> $TESTRESULTDIR/index.html <<@EOF
731             <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
732 @EOF
733         done
734
735         cat >> $TESTRESULTDIR/index.html <<@EOF
736         </ul>
737 @EOF
738
739         cat >> $TESTRESULTDIR/index.html <<@EOF
740   </td></tr>
741 </table>
742 </body>
743 </html>
744 @EOF
745
746
747         ##########################################################################
748         # execute post-test commands
749         #
750
751         echo -n "post"
752         echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
753
754         eval `awk -F "::" '{
755             if ($2 != "")
756             {
757                 printf("echo \"%s# %s\"; ", $1, $2)
758                 printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
759                 printf("echo;\n")
760             }
761         }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
762
763         ##########################################################################
764         # check that IPsec state was cleaned up properly
765         #
766
767         for host in $IPSECHOSTS
768         do
769                 eval HOSTLOGIN=root@\$ipv4_${host}
770                 IPSECSTATE=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm state'`
771                 IPSECPOLICY=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm policy'`
772                 if [ -n "$IPSECSTATE" -o -n "$IPSECPOLICY" ]
773                 then
774                         echo -e "\n$host# ip xfrm state [NO]" >> $CONSOLE_LOG
775                         echo "$IPSECSTATE" >> $CONSOLE_LOG
776                         echo -e "\n$host# ip xfrm policy [NO]" >> $CONSOLE_LOG
777                         echo "$IPSECPOLICY" >> $CONSOLE_LOG
778                         STATUS="failed"
779                 fi
780         done
781
782         ##########################################################################
783         # get a copy of /var/log/auth.log
784         #
785
786         for host in $IPSECHOSTS
787         do
788             eval HOSTLOGIN=root@\$ipv4_${host}
789             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv|pt-tls-client' \
790                 /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
791         done
792
793
794         ##########################################################################
795         # get a copy of /var/log/daemon.log
796         #
797
798         for host in $IPSECHOSTS
799         do
800             eval HOSTLOGIN=root@\$ipv4_${host}
801             ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv' \
802                 /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
803         done
804
805
806         ##########################################################################
807         # stop tcpdump if necessary
808         #
809
810         for host in $TCPDUMPHOSTS
811         do
812             if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
813             then
814                         stop_tcpdump $host
815             fi
816             eval HOSTLOGIN=root@\$ipv4_${host}
817                 scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
818                         $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
819         done
820
821         ##########################################################################
822         # remove database directory if needed
823         #
824
825         for host in $DBHOSTS
826         do
827                 eval HOSTLOGIN=root@\$ipv4_${host}
828             ssh $SSHCONF $HOSTLOGIN "umount $DBDIR; rm -r $DBDIR" > /dev/null 2>&1
829         done
830
831         ##########################################################################
832         # copy default host config back if necessary
833         #
834
835         $DIR/scripts/restore-defaults $testname
836
837
838         ##########################################################################
839         # write test status to html file
840         #
841         testend=$(date +%s)
842         let "testend -= teststart"
843         let "timetotal += testend"
844
845         if [ $STATUS = "passed" ]
846         then
847                 COLOR="green"
848                 log_status 0
849         else
850                 COLOR="red"
851                 log_status 1
852         fi
853
854         cat >> $TESTRESULTSHTML << @EOF
855   <tr>
856     <td>$testnumber</td>
857     <td><a href="$testname/index.html">$testname</a></td>
858     <td align="right">$testend</td>
859     <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
860   </tr>
861 @EOF
862         cat >> $SUBTESTSINDEX << @EOF
863   <tr>
864     <td>$testnumber</td>
865     <td><a href="$name/index.html">$name</a></td>
866     <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
867     <td>&nbsp;</td>
868   </tr>
869 @EOF
870
871
872         ##########################################################################
873         # remove any charon.pid files that still may exist
874         #
875
876         for host in $IPSECHOSTS
877         do
878             eval HOSTLOGIN=root@\$ipv4_${host}
879             ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo "    removed charon.pid on `hostname`"; fi'
880         done
881
882     done
883
884 done
885
886
887 ##############################################################################
888 # finish the results html file
889 #
890
891 cat >> $TESTRESULTSHTML << @EOF
892     <tr>
893       <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
894     </tr>
895     <tr>
896       <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
897     </tr>
898     <tr>
899       <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
900     </tr>
901     <tr>
902       <td><b>Time [s]</b></td><td><b><font color="blue">$timetotal</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
903     </tr>
904   </table>
905 </body>
906 </html>
907 @EOF
908
909 if [ $subdir_cnt != 0 ]
910 then
911 cat >> $INDEX << @EOF
912       <td align="right">$subdir_cnt</td>
913       <td>&nbsp;</td>
914     </tr>
915 @EOF
916 fi
917
918 let "all_cnt = $passed_cnt + $failed_cnt"
919
920 cat >> $INDEX << @EOF
921     <tr>
922       <td>&nbsp;</td>
923       <td><a href="all.html"><b>all</b></a></td>
924       <td align="right"><b>$all_cnt</b></td>
925       <td>&nbsp;</td>
926     </tr>
927     <tr>
928       <td><b>Failed</b></td>
929       <td>&nbsp;</td>
930       <td align="right"><b><font color="red">$failed_cnt</font></b></td>
931       <td>&nbsp;</td>
932     </tr>
933   </table>
934 </body>
935 </html>
936 @EOF
937
938 echo
939 echo_ok     "Passed : $passed_cnt"
940 echo_failed "Failed : $failed_cnt"
941
942 echo
943 echo "The results are available in $TODAYDIR"
944 echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
945
946 ENDDATE=`date +%Y%m%d-%H%M-%S`
947 echo
948 echo "Finished : $ENDDATE"