Pazpar2 1.4.4-2 for squeeze
[pazpar2-moved-to-github.git] / test / run_pazpar2.sh
1 #!/bin/sh
2 #
3 # Regression test using pazpar2 against z3950.indexdata.com/marc or gils
4 # Reads Pazpar2 URLs from $1
5 #            Outputs to $1_<no>.log
6 #            Matches against results in $1_<no>.res
7 # Requires curl
8
9 # srcdir might be set by make
10 srcdir=${srcdir:-"."}
11
12 # look for curl in PATH
13 oIFS=$IFS
14 IFS=:
15 curl=''
16 for p in $PATH; do
17     if test -x $p/curl; then
18         curl=$p/curl
19         break
20     fi
21 done
22 IFS=$oIFS
23
24 if test -z $curl; then
25     echo "curl not found. $PREFIX can not be tested"
26     exit 1
27 fi
28 GET='$curl --silent --output $OUT2 "$f"'
29 POST='$curl --silent --header "Content-Type: text/xml" --data-binary "@$postfile" --output $OUT2  "$f"'
30
31 if [ -z "$SKIP_PAZPAR2" ] ; then
32 # Fire up pazpar2
33     rm -f pazpar2.log
34 fi
35 PREFIX=$1
36 if test "x${PREFIX}" = "x"; then
37     echo Missing prefix for run_pazpar2.sh
38     exit 1
39 fi
40
41 CFG=${PREFIX}.cfg
42 URLS=${PREFIX}_urls
43 VALGRINDLOG=${PREFIX}_valgrind.log
44
45 if test -n "$PAZPAR2_USE_VALGRIND"; then
46     valgrind --leak-check=full --log-file=$VALGRINDLOG ../src/pazpar2 -X -l pazpar2.log -f ${CFG} >extra_pazpar2.log 2>&1 &
47 elif test -n "$SKIP_PAZPAR2"; then 
48     echo "Skipping pazpar2. Must already be running with correct config!!! " 
49 else
50     YAZ_LOG=zoom,zoomdetails,debug,log,fatal ../src/pazpar2 -v all -d -X -l pazpar2.log -f ${srcdir}/${CFG} >extra_pazpar2.log 2>&1 &
51 fi
52
53
54 PP2PID=$!
55
56 # Give it a chance to start properly..
57 sleep 3
58
59 # Set to success by default.. Will be set to non-zero in case of failure
60 code=0
61
62 if [ -z "$SKIP_PAZPAR2" ] ; then 
63     if ps -p $PP2PID >/dev/null 2>&1; then
64         :
65     else
66         code=1
67         PP2PID=""
68         echo "pazpar2 failed to start"
69     fi
70 fi
71
72 # We can start test for real
73
74 testno=1
75 for f in `cat ${srcdir}/${URLS}`; do
76     if echo $f | grep '^http' >/dev/null; then
77         OUT1=${srcdir}/${PREFIX}_${testno}.res
78         OUT2=${PREFIX}_${testno}.log
79         DIFF=${PREFIX}_${testno}.dif
80         rm -f $OUT2 $DIFF
81         if [ -n "$DEBUG" ] ; then 
82             echo "test $testno: $f" 
83         fi
84         if test -n "${postfile}"; then
85             eval $POST
86         else
87             eval $GET
88         fi
89         if test ! -f $OUT2; then
90             touch $OUT2
91         fi
92         if test -f $OUT1; then
93             if diff $OUT1 $OUT2 >$DIFF; then
94                 :
95             else
96                 echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
97                 echo "URL: $f"
98                 code=1
99             fi
100         else
101             echo "Test $testno: Making for the first time"
102             mv $OUT2 $OUT1
103             code=1
104         fi
105         testno=`expr $testno + 1`
106         postfile=
107     elif echo $f | grep '^[0-9]' >/dev/null; then
108         if [ -n "$DEBUG" ] ; then 
109             echo "Sleeping $f"
110         fi
111         sleep $f
112     else
113         if test -f $srcdir/$f; then
114             postfile=$srcdir/$f
115         else
116             echo "File $f does not exist"
117             code=1
118         fi
119     fi
120     if [ -z "$SKIP_PAZPAR2" ] ; then  
121         if ps -p $PP2PID >/dev/null 2>&1; then
122             :
123         else
124             IFS="$oIFS"
125             echo "Test $testno: pazpar2 died"
126             exit 1
127         fi
128     fi
129 done
130
131 # Kill programs
132
133 if [ -z "$SKIP_PAZPAR2" ] ; then 
134     if test -n "$PP2PID"; then
135         kill $PP2PID
136         sleep 2
137     fi
138 fi
139
140 exit $code
141
142 # Local Variables:
143 # mode:shell-script
144 # sh-indentation: 2
145 # sh-basic-offset: 4
146 # End: