Allow the use of valgrind
[pazpar2-moved-to-github.git] / test / test_http.sh
1 #!/bin/sh
2 # $Id: test_http.sh,v 1.10 2007-08-13 12:51:00 adam Exp $
3 #
4 # Regression test using pazpar2 against z3950.indexdata.com/marc
5 # Reads Pazpar2 URLs from test_http_urls
6 #            Outputs to test_http_<no>.log
7 #            Matches against results in test_http_<no>.res
8 #
9
10
11 # srcdir might be set by make
12 srcdir=${srcdir:-"."}
13
14 wget=""
15 lynx=""
16 if test -x /usr/bin/wget; then
17     wget=/usr/bin/wget
18 fi
19 if test -x /usr/bin/lynx; then
20     lynx=/usr/bin/lynx
21 fi
22
23 # Fire up pazpar2
24 rm -f pazpar2.log
25
26 if test "$usevalgrind"; then
27     valgrind --log-file=valgrind ../src/pazpar2 -X -l pazpar2.log -f ${srcdir}/test_http.cfg -t ${srcdir}/test_http.xml >extra_pazpar2.log 2>&1 &
28 else
29     ../src/pazpar2 -X -l pazpar2.log -f ${srcdir}/test_http.cfg -t ${srcdir}/test_http.xml >extra_pazpar2.log 2>&1 &
30 fi
31
32
33 PP2PID=$!
34
35 # Give it a chance to start properly..
36 sleep 3
37
38 # Set to success by default.. Will be set to non-zero in case of failure
39 code=0
40
41 if ps -p $PP2PID >/dev/null 2>&1; then
42     :
43 else
44     code=1
45     PP2PID=""
46     echo "pazpar2 failed to start"
47 fi
48
49 # We can start test for real
50
51 oIFS="$IFS"
52 IFS='
53 '
54
55 testno=1
56 for f in `cat ${srcdir}/test_http_urls`; do
57     if echo $f | grep '^http' >/dev/null; then
58         OUT1=${srcdir}/test_http_${testno}.res
59         OUT2=test_http_${testno}.log
60         DIFF=test_http_${testno}.dif
61         if test -f $OUT1; then
62             rm -f $OUT2
63             if test -n "${wget}"; then
64                 ${wget} -q -O $OUT2 $f
65             elif test -n "${lynx}"; then
66                 ${lynx} -dump $f >$OUT2
67             else
68                 break
69             fi
70             if diff $OUT1 $OUT2 >$DIFF; then
71                 :
72             else
73                 echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
74                 code=1
75             fi
76         else
77             echo "Test $testno: Making for the first time"
78             ${wget} -q -O $OUT1 $f
79             code=1
80         fi
81         testno=`expr $testno + 1`
82     else
83         sleep $f
84     fi
85     if ps -p $PP2PID >/dev/null 2>&1; then
86         :
87     else
88         echo "pazpar2 died"
89     fi
90 done
91 IFS="$oIFS"
92
93 sleep 1
94 # Kill programs
95
96 if test -n "$PP2PID"; then
97     kill $PP2PID
98 fi
99
100 exit $code
101
102 # Local Variables:
103 # mode:shell-script
104 # sh-indentation: 2
105 # sh-basic-offset: 4
106 # End: