68f80e27de22d69227a03426d95df864a5e054bb
[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 VALGRINDLOG=${PREFIX}_valgrind.log
34
35 usevalgrind=false
36 if $usevalgrind; then
37     valgrind --leak-check=full --log-file=$VALGRINDLOG ../src/pazpar2 -X -l pazpar2.log -f ${CFG} >extra_pazpar2.log 2>&1 &
38 else
39     YAZ_LOG=zoom,zoomdetails,debug,log,fatal ../src/pazpar2 -d -X -l pazpar2.log -f ${srcdir}/${CFG} >extra_pazpar2.log 2>&1 &
40 fi
41
42
43 PP2PID=$!
44
45 # Give it a chance to start properly..
46 sleep 3
47
48 # Set to success by default.. Will be set to non-zero in case of failure
49 code=0
50
51 if ps -p $PP2PID >/dev/null 2>&1; then
52     :
53 else
54     code=1
55     PP2PID=""
56     echo "pazpar2 failed to start"
57 fi
58
59 # We can start test for real
60
61 oIFS="$IFS"
62 IFS='
63 '
64
65 testno=1
66 for f in `cat ${srcdir}/${URLS}`; do
67     if echo $f | grep '^http' >/dev/null; then
68         OUT1=${srcdir}/${PREFIX}_${testno}.res
69         OUT2=${PREFIX}_${testno}.log
70         DIFF=${PREFIX}_${testno}.dif
71         rm -f $OUT2 $DIFF
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
84         if test -f $OUT1; then
85             if diff $OUT1 $OUT2 >$DIFF; then
86                 :
87             else
88                 echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
89                 echo "URL: $f"
90                 code=1
91             fi
92         else
93             echo "Test $testno: Making for the first time"
94             mv $OUT2 $OUT1
95             code=1
96         fi
97         testno=`expr $testno + 1`
98         postfile=
99     elif echo $f | grep '^[0-9]' >/dev/null; then
100         sleep $f
101     else
102         if test -f $f; then
103             postfile=$f
104         else
105             echo "File $f does not exist"
106             code=1
107         fi
108     fi
109     if ps -p $PP2PID >/dev/null 2>&1; then
110         :
111     else
112         echo "Test $testno: pazpar2 died"
113         exit 1
114     fi
115 done
116 IFS="$oIFS"
117
118 sleep 1
119 # Kill programs
120
121 if test -n "$PP2PID"; then
122     kill $PP2PID
123 fi
124
125 exit $code
126
127 # Local Variables:
128 # mode:shell-script
129 # sh-indentation: 2
130 # sh-basic-offset: 4
131 # End: