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