b4b9f866950f94d48071118c0a33c2ddf0c7f2b1
[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 usevalgrind=false
35 if test "$usevalgrind"; then
36     valgrind --leak-check=full --log-file=valgrind ../src/pazpar2 -X -l pazpar2.log -f ${CFG} >extra_pazpar2.log 2>&1 &
37 else
38     YAZ_LOG=zoom,zoomdetails,debug,log,fatal ../src/pazpar2 -d -X -l pazpar2.log -f ${srcdir}/${CFG} >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                 if test -n "${postfile}"; then
74                     ${wget} -q -O $OUT2 --header="Content-Type: text/xml" --post-file=$postfile $f
75                 else
76                     ${wget} -q -O $OUT2 $f
77                 fi
78             elif test -n "${lynx}"; then
79                 ${lynx} -dump $f >$OUT2
80             else
81                 break
82             fi
83             if diff $OUT1 $OUT2 >$DIFF; then
84                 :
85             else
86                 echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
87                 echo "URL: $f"
88                 code=1
89             fi
90         else
91             echo "Test $testno: Making for the first time"
92             ${wget} -q -O $OUT1 $f
93             code=1
94         fi
95         testno=`expr $testno + 1`
96         postfile=
97     elif echo $f | grep '^[0-9]' >/dev/null; then
98         sleep $f
99     else
100         if test -f $f; then
101             postfile=$f
102         else
103             echo "File $f does not exist"
104             code=1
105         fi
106     fi
107     if ps -p $PP2PID >/dev/null 2>&1; then
108         :
109     else
110         echo "Test $testno: pazpar2 died"
111         exit 1
112     fi
113 done
114 IFS="$oIFS"
115
116 sleep 1
117 # Kill programs
118
119 if test -n "$PP2PID"; then
120     kill $PP2PID
121 fi
122
123 exit $code
124
125 # Local Variables:
126 # mode:shell-script
127 # sh-indentation: 2
128 # sh-basic-offset: 4
129 # End: