Test return error if curl is not found
[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 # Fire up pazpar2
32 rm -f pazpar2.log
33
34 PREFIX=$1
35 if test "x${PREFIX}" = "x"; then
36     echo Missing prefix for run_pazpar2.sh
37     exit 1
38 fi
39 CFG=${PREFIX}.cfg
40 URLS=${PREFIX}_urls
41 VALGRINDLOG=${PREFIX}_valgrind.log
42
43 usevalgrind=false
44 if test -n "$PAZPAR2_USE_VALGRIND"; then
45     usevalgrind=$PAZPAR2_USE_VALGRIND;
46 fi
47 if $usevalgrind; then
48     valgrind --leak-check=full --log-file=$VALGRINDLOG ../src/pazpar2 -X -l pazpar2.log -f ${CFG} >extra_pazpar2.log 2>&1 &
49 else
50     YAZ_LOG=zoom,zoomdetails,debug,log,fatal ../src/pazpar2 -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 ps -p $PP2PID >/dev/null 2>&1; then
63     :
64 else
65     code=1
66     PP2PID=""
67     echo "pazpar2 failed to start"
68 fi
69
70 # We can start test for real
71
72 oIFS="$IFS"
73 IFS='
74 '
75
76 testno=1
77 for f in `cat ${srcdir}/${URLS}`; do
78     if echo $f | grep '^http' >/dev/null; then
79         OUT1=${srcdir}/${PREFIX}_${testno}.res
80         OUT2=${PREFIX}_${testno}.log
81         DIFF=${PREFIX}_${testno}.dif
82         rm -f $OUT2 $DIFF
83         if test -n "${postfile}"; then
84             eval $POST
85         else
86             eval $GET
87         fi
88         if test ! -f $OUT2; then
89             touch $OUT2
90         fi
91         if test -f $OUT1; then
92             if diff $OUT1 $OUT2 >$DIFF; then
93                 :
94             else
95                 echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
96                 echo "URL: $f"
97                 code=1
98             fi
99         else
100             echo "Test $testno: Making for the first time"
101             mv $OUT2 $OUT1
102             code=1
103         fi
104         testno=`expr $testno + 1`
105         postfile=
106     elif echo $f | grep '^[0-9]' >/dev/null; then
107         sleep $f
108     else
109         if test -f $f; then
110             postfile=$f
111         else
112             echo "File $f does not exist"
113             code=1
114         fi
115     fi
116     if ps -p $PP2PID >/dev/null 2>&1; then
117         :
118     else
119         IFS="$oIFS"
120         echo "Test $testno: pazpar2 died"
121         exit 1
122     fi
123 done
124 IFS="$oIFS"
125
126 # Kill programs
127
128 if test -n "$PP2PID"; then
129     kill $PP2PID
130     sleep 2
131 fi
132
133 exit $code
134
135 # Local Variables:
136 # mode:shell-script
137 # sh-indentation: 2
138 # sh-basic-offset: 4
139 # End: