Fix check for yaz-ztest. Fixed make distcheck.
[pazpar2-moved-to-github.git] / test / test_http.sh
1 #!/bin/sh
2 # $Id: test_http.sh,v 1.3 2007-05-15 21:40:57 adam Exp $
3 #
4 # Regression test using pazpar2 against yaz-ztest
5 # Reads Pazpar2 URLs from test_http_urls
6 #            Outputs to test_http_<no>.log
7 #            Matches against results in test_htttp_<no>.res
8 #
9
10
11 # srcdir might be set by make
12 srcdir=${srcdir:-"."}
13
14 # Find a suitable yaz-ztest
15 yt=""
16 for d in /usr/bin /usr/local/bin ${srcdir}/../../yaz/ztest ${srcdir}/../../../yaz/ztest; do
17     yt=${d}/yaz-ztest
18     if test -x ${yt}; then
19         break
20     fi
21 done
22 if test ! -x "${yt}"; then
23     echo "No yaz-ztest found. Skipping"
24     exit 0
25 fi
26
27 # Fire up yaz-ztest (should match port in test_http.xml)
28 $yt -l test_http_ztest.log tcp:@:9764 &
29 YTPID=$!
30
31 # Fire yp pazpar2
32 rm -f pazpar2.log
33 ../src/pazpar2 -l pazpar2.log -f ${srcdir}/test_http.cfg -t ${srcdir}/test_http.xml >extra_pazpar2.log 2>&1 &
34 PP2PID=$!
35
36 # Give both programs room to start properly..
37 sleep 1
38
39 # Set to success by default.. Will be set to non-zero in case of failure
40 code=0
41
42 if ps -p $PP2PID >/dev/null 2>&1; then
43     :
44 else
45     code=1
46     PP2PID=""
47     echo "pazpar2 failed to start"
48 fi
49
50 if ps -p $YTPID >/dev/null 2>&1; then
51     :
52 else
53     code=1
54     YTPID=""
55     echo "yaz-ztest failed to start"
56 fi
57 # We can start test for real
58
59 testno=1
60 for f in `cat ${srcdir}/test_http_urls`; do
61     OUT1=${srcdir}/test_http_${testno}.res
62     OUT2=test_http_${testno}.log
63     DIFF=test_http_${testno}.dif
64     if test -f $OUT1; then
65         rm -f $OUT2
66         wget -q -O $OUT2 $f
67         if diff $OUT1 $OUT2 >$DIFF; then
68             :
69         else
70             echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
71             code=1
72         fi
73     else
74         echo "Test $testno: Making for the first time"
75         wget -q -O $OUT1 $f
76         code=1
77     fi
78     testno=`expr $testno + 1`
79 done
80
81 sleep 1
82 # Kill programs
83 if test -n "$YTPID"; then
84     kill $YTPID
85 fi
86
87 if test -n "$PP2PID"; then
88     kill $PP2PID
89 fi
90
91 exit $code
92
93 # Local Variables:
94 # mode:shell-script
95 # sh-indentation: 2
96 # sh-basic-offset: 4
97 # End: