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