File: lr_run_tests.in

package info (click to toggle)
lire 20020214-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,180 kB
  • ctags: 1,245
  • sloc: perl: 11,637; xml: 5,725; sh: 3,458; makefile: 1,008
file content (249 lines) | stat: -rw-r--r-- 7,019 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/bin/sh -e

# $Id: lr_run_tests.in,v 1.6 2002/02/13 17:14:08 flacoste Exp $

#
# Copyright (C) 2001 Stichting LogReport Foundation LogReport@LogReport.org
# 
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
# 
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with this program (see COPYING); if not, check with
#     http://www.gnu.org/copyleft/gpl.html or write to the Free Software 
#     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
#

PROGRAM=lr_run_tests

# dereference sysconfdir's prefix dependency
prefix="@prefix@"
etcdir="@sysconfdir@/@PACKAGE@"
. $etcdir/profile_lean
. $etcdir/defaults

tag="all all ${LR_ID:-UNSET} $PROGRAM"

echo >&2 "$tag info started with $*"

addressfile=@sysconfdir@/@PACKAGE@/address.cf
if test ! -r "$addressfile"
then
    echo >&2 "$tag crit cannot read $addressfile, exiting"
    exit 1
fi

if test $# -lt 1
then
  echo >&2 "$tag err expecting argument. syntax: $PROGRAM testdir"
  exit 1
fi
testdir="$1"
shift

for d in logs mail output tmp
do
    if test ! -d $testdir/$d
    then
	echo >&2 "$tag err no $d/ subdirectory in $testdir. Exiting"
	exit 1
    fi
done

if ls -- $testdir/logs/*.log > /dev/null 2>&1
then
    logs=`ls -- $testdir/logs/*.log`
else
    echo >&2 "$tag warning no logs in $testdir/logs were found"
    logs=""
fi

if ls -- $testdir/mail/*.mail > /dev/null 2>&1
then
    mail=`ls -- $testdir/mail/*.mail`
else
    echo >&2 "$tag warning no mail in $testdir/mail were found."
    mail=""
fi

# Create the output directories
for d in xml html html-i pdf pdf-i xhtml xhtml-i txt mail
do
    # Cleanup from previous run
    rm -fr $testdir/output/$d
    mkdir -p $testdir/output/$d
done

# Create a temporary Lire configuration directory
mkdir -p $testdir/tmp/.lire/etc
mkdir -p $testdir/tmp/.lire/data

cat > $testdir/tmp/.lire/etc/defaults <<EOF
DEBUG=
KEEP=
ARCHIVE=
INCLUDEIMAGES=
LR_ARCHIVEDIR="$testdir/tmp/.lire/data"
EOF
HOME="$testdir/tmp"
export HOME

# The way the tests are run, we aren't covering the
# -o and -i switches of lr_log2report

# Create an XML report and ASCII report for each log type
for l in $logs
do
    service=`basename $l |sed -e 's,[-.].*$,,'`
    base=`basename $l .log`
    flags=`lr_addresses2serviceflags $service < $addressfile`
    outputbase="$testdir/output/xml/$base"

    echo >&2 "$tag info generating XML report for $base"
    lr_run lr_log2report -o xml $outputbase.error $flags < $l \
	3> $outputbase.xml 2>&1 1>&3 3>&- | tee $outputbase.log

    if test -s $outputbase.error
    then
	echo >&2 "$tag info XML report for $base generated an error file: $outputbase.error" 
    fi
    if grep ' warning \| crit \| err ' $outputbase.log > /dev/null 2> /dev/null
    then
	echo >&2 "$tag info XML report for $base generated warnings in $outputbase.log" 
    fi

    # If we have an XML report, create all ascii reports
    xmlreport="$outputbase.xml"
    if test -s "$outputbase.xml"
    then
	outputbase="$testdir/output/txt/$base"

	# Starts with ASCII
	echo >&2 "$tag info generating ASCII report for $base"
	lr_run lr_xml2ascii < $xmlreport 3> $outputbase.txt 2>&1 1>&3 3>&- |
	    tee $outputbase.log

	if grep ' warning \| crit \| err ' $outputbase.log > /dev/null 2> /dev/null
	then
	    echo >&2 "$tag info ASCII report for $base generated warnings in $outputbase.log" 
	fi
    else
	# Delete empty XML report
	rm -f $outputbase.xml
    fi
done

# Test other formats
for format in html xhtml pdf
do
    if ! lr_check_prereq $format 2> /dev/null
    then
	echo >&2 "$tag info skipping $format tests because of unavailable requirements"
	continue
    fi

    for l in $logs
    do
	service=`basename $l |sed -e 's,[-.].*$,,'`
	base=`basename $l .log`
	xmlreport="$testdir/output/xml/$base.xml"
 	outputbase="$testdir/output/$format/$base"

	test -s $xmlreport || continue

	if test $format = "xhtml" || test $format = "html"
	then
	    ext="tar"
	else
	    ext="$format"
	fi
	echo >&2 "$tag info generating $format report for $base"
	lr_run "lr_xml2$format" $xmlreport 3> $outputbase.$ext \
	    2>&1 1>&3 3>&- | tee $outputbase.log
	if grep ' warning \| crit \| err ' $outputbase.log > /dev/null 2> /dev/null
	then
	    echo >&2 "$tag info $format report for $base generated warnings in $outputbase.log" 
	fi

	# Handle (X)HTML tar file
	test -s $outputbase.tar || continue
	olddir=`pwd`
	cd $testdir/output/$format
	tar xf $outputbase.tar
	mv report $base
	cd $olddir
	rm -f $outputbase.tar
    done

    # Check with images
    if ! lr_check_prereq -i $format 2> /dev/null
    then
	echo >&2 "$tag info skipping $format (with images) tests because of unavailable requirements"
	continue
    fi
    
    for l in $logs
    do
	service=`basename $l |sed -e 's,[-.].*$,,'`
	base=`basename $l .log`
	xmlreport="$testdir/output/xml/$base.xml"
	outputbase="$testdir/output/$format-i/$base"

	test -s $xmlreport || continue
	
	echo >&2 "$tag info generating $format report (with images) for $base"
	case $format in
	html|xhtml)
	    lr_run lr_xml2$format -i $xmlreport 3> $outputbase.tar \
		2>&1 1>&3 3>&- | tee $outputbase.log
	    if grep ' warning \| crit \| err ' $outputbase.log > /dev/null 2> /dev/null
	    then
		echo >&2 "$tag info $format report (with images) for $base generated warnings in $outputbase.log" 
	    fi
	    test -s $outputbase.tar || continue
	    olddir=`pwd`
	    cd $testdir/output/$format-i
	    tar xf $outputbase.tar
	    mv report $base
	    cd $olddir
	    rm -f $outputbase.tar
	    ;;
	pdf)
	    lr_run lr_xml2$format -i $xmlreport 3> $outputbase.pdf \
		2>&1 1>&3 3>&- | tee $outputbase.log
	    if grep ' warning \| crit \| err ' $outputbase.log > /dev/null 2> /dev/null
	    then
		echo >&2 "$tag info $format report (with images) for $base generated warnings in $outputbase.log" 
	    fi
	    ;;
	esac
    done
done

# Test most responder code, lr_spoold and lr_spool aren't tested by this test
for m in $mail
do
    service=`basename $m |sed -e 's,[-.].*$,,'`
    base=`basename $m .mail`
    flags=`lr_addresses2serviceflags $service < $addressfile`
    outputbase=$testdir/output/mail/$base

    echo >&2 "$tag info testing lr_processmail on $base"
    lr_run lr_processmail $flags < $m 2>&1 | tee $outputbase.log
    if grep ' warning \| crit \| err ' $outputbase.log > /dev/null 2> /dev/null
    then
	echo >&2 "$tag info $format report (with images) for $base generated warnings in $outputbase.log" 
    fi
done

# Cleanup empty files
find $testdir/output -size 0 -exec rm {} \;
rm -fr $testdir/tmp/.lire
rm -fr $testdir/tmp/tmp