Test server with multiple services
[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} >extra_pazpar2.log 2>&1 &
36 else
37     YAZ_LOG=zoom,zoomdetails,debug,log,fatal ../src/pazpar2 -d -X -l pazpar2.log -f ${srcdir}/${CFG} >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                 echo "URL: $f"
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: