5a6b3bc958c19d88d9a8df59369e86b7602a92e6
[pazpar2-moved-to-github.git] / test / run_pazpar2.sh
1 #!/bin/sh
2 # $Id: run_pazpar2.sh,v 1.1 2007-09-10 08:18:19 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
27 PREFIX=$1
28 if test "x${PREFIX}" = "x"; then
29     echo Missing prefix for run_pazpar2.sh
30     exit 1
31 fi
32 CFG=${PREFIX}.cfg
33 URLS=${PREFIX}_urls
34
35 if test "$usevalgrind"; then
36     valgrind --log-file=valgrind ../src/pazpar2 -X -l pazpar2.log -f ${CFG} -t ${srcdir}/test_http.xml >extra_pazpar2.log 2>&1 &
37 else
38     ../src/pazpar2 -X -l pazpar2.log -f ${srcdir}/${CFG} -t ${srcdir}/test_http.xml >extra_pazpar2.log 2>&1 &
39 fi
40
41
42 PP2PID=$!
43
44 # Give it a chance to start properly..
45 sleep 3
46
47 # Set to success by default.. Will be set to non-zero in case of failure
48 code=0
49
50 if ps -p $PP2PID >/dev/null 2>&1; then
51     :
52 else
53     code=1
54     PP2PID=""
55     echo "pazpar2 failed to start"
56 fi
57
58 # We can start test for real
59
60 oIFS="$IFS"
61 IFS='
62 '
63
64 testno=1
65 for f in `cat ${srcdir}/${URLS}`; do
66     if echo $f | grep '^http' >/dev/null; then
67         OUT1=${srcdir}/${PREFIX}_${testno}.res
68         OUT2=${PREFIX}_${testno}.log
69         DIFF=${PREFIX}_${testno}.dif
70         if test -f $OUT1; then
71             rm -f $OUT2
72             if test -n "${wget}"; then
73                 ${wget} -q -O $OUT2 $f
74             elif test -n "${lynx}"; then
75                 ${lynx} -dump $f >$OUT2
76             else
77                 break
78             fi
79             if diff $OUT1 $OUT2 >$DIFF; then
80                 :
81             else
82                 echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
83                 code=1
84             fi
85         else
86             echo "Test $testno: Making for the first time"
87             ${wget} -q -O $OUT1 $f
88             code=1
89         fi
90         testno=`expr $testno + 1`
91     else
92         sleep $f
93     fi
94     if ps -p $PP2PID >/dev/null 2>&1; then
95         :
96     else
97         echo "pazpar2 died"
98     fi
99 done
100 IFS="$oIFS"
101
102 sleep 1
103 # Kill programs
104
105 if test -n "$PP2PID"; then
106     kill $PP2PID
107 fi
108
109 exit $code
110
111 # Local Variables:
112 # mode:shell-script
113 # sh-indentation: 2
114 # sh-basic-offset: 4
115 # End: