Remove timestamp from pazpar2.log.
[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 # terminate pazpar2 if test takes more than this (in seconds)
13 WAIT=120
14
15 kill_pazpar2()
16 {
17     if test -n "$PP2PID"; then
18         kill $PP2PID
19     fi
20     if test -n "$SLEEP_PID"; then
21         kill $SLEEP_PID
22         SLEEP_PID=""
23     fi
24 }
25
26 # look for curl in PATH
27 oIFS=$IFS
28 IFS=:
29 curl=''
30 for p in $PATH; do
31     if test -x $p/curl; then
32         curl=$p/curl
33         break
34     fi
35 done
36 IFS=$oIFS
37
38 if test -z $curl; then
39     echo "curl not found. $PREFIX can not be tested"
40     exit 1
41 fi
42 GET='$curl --silent --output $OUT2 "$f"'
43 POST='$curl --silent --header "Content-Type: text/xml" --data-binary "@$postfile" --output $OUT2  "$f"'
44
45 if [ -z "$SKIP_PAZPAR2" ] ; then
46 # Fire up pazpar2
47     rm -f $PREFIX_pazpar2.log
48 fi
49 PREFIX=$1
50 if test "x${PREFIX}" = "x"; then
51     echo Missing prefix for run_pazpar2.sh
52     exit 1
53 fi
54
55 CFG=${PREFIX}.cfg
56 URLS=${PREFIX}.urls
57 VALGRINDLOG=${PREFIX}_valgrind.log
58
59 if test -n "$PAZPAR2_USE_VALGRIND"; then
60     valgrind --num-callers=30 --show-reachable=yes --leak-check=full --log-file=$VALGRINDLOG ../src/pazpar2 -X -l pazpar2.log -f ${CFG} >extra_pazpar2.log 2>&1 &
61 elif test -n "$SKIP_PAZPAR2"; then 
62     echo "Skipping pazpar2. Must already be running with correct config!!! " 
63 else
64     YAZ_LOG=zoom,zoomdetails,debug,log,fatal ../src/pazpar2 -v loglevel,fatal,warn,log,debug,notime,zoom,zoomdetails -d -X -l ${PREFIX}_pazpar2.log -f ${srcdir}/${CFG} >extra_pazpar2.log 2>&1 &
65 fi
66
67 PP2PID=$!
68
69 if [ -z "$SKIP_PAZPAR2" ] ; then 
70     if ps -p $PP2PID >/dev/null 2>&1; then
71         (sleep $WAIT; kill_pazpar2 >/dev/null) &
72         SLEEP_PID=$!
73         trap kill_pazpar2 INT
74         trap kill_pazpar2 HUP
75         sleep 3
76     else
77         echo "pazpar2 failed to start"
78         exit 1
79     fi
80 fi
81
82 # Set to success by default.. Will be set to non-zero in case of failure
83 code=0
84
85 # We can start test for real
86 testno=1
87 for f in `cat ${srcdir}/${URLS}`; do
88     if echo $f | grep '^http' >/dev/null; then
89         OUT1=${srcdir}/${PREFIX}_${testno}.res
90         OUT2=${PREFIX}_${testno}.log
91         DIFF=${PREFIX}_${testno}.dif
92         rm -f $OUT2 $DIFF
93         if [ -n "$DEBUG" ] ; then 
94             echo "test $testno: $f" 
95         fi
96         if test -n "${postfile}"; then
97             eval $POST
98         else
99             eval $GET
100         fi
101         if test ! -f $OUT2; then
102             touch $OUT2
103         fi
104         if test -f $OUT1; then
105             if diff $OUT1 $OUT2 >$DIFF; then
106                 :
107             else
108                 echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
109                 echo "URL: $f"
110                 code=1
111             fi
112         else
113             echo "Test $testno: Making for the first time"
114             mv $OUT2 $OUT1
115             code=1
116         fi
117         testno=`expr $testno + 1`
118         postfile=
119     elif echo $f | grep '^[0-9]' >/dev/null; then
120         if [ -n "$DEBUG" ] ; then 
121             echo "Sleeping $f"
122         fi
123         sleep $f
124     else
125         if test -f $srcdir/$f; then
126             postfile=$srcdir/$f
127         else
128             echo "File $f does not exist"
129             code=1
130         fi
131     fi
132     if [ -z "$SKIP_PAZPAR2" ] ; then  
133         if ps -p $PP2PID >/dev/null 2>&1; then
134             :
135         else
136             IFS="$oIFS"
137             if test -n "$SLEEP_PID"; then
138                 echo "Test $testno: pazpar2 terminated (timeout, probably)"
139             else
140                 echo "Test $testno: pazpar2 died"
141             fi
142             exit 1
143         fi
144     fi
145 done
146
147 # Kill programs
148
149 if [ -z "$SKIP_PAZPAR2" ] ; then 
150     kill_pazpar2
151     sleep 2
152 fi
153
154 exit $code
155
156 # Local Variables:
157 # mode:shell-script
158 # sh-indentation: 2
159 # sh-basic-offset: 4
160 # End: