Use curl or wget for URL tests
[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 if test -x /usr/bin/curl; then
14     GET='/usr/bin/curl -s -o $OUT2 "$f"'
15     POST='/usr/bin/curl -s -H "Content-Type: text/xml" --data-binary "@$postfile" -o $OUT2  "$f"'
16 elif test -x /usr/bin/wget; then
17     GET='/usr/bin/wget -q -O $OUT2 $f'
18     POST='/usr/bin/wget -q -O $OUT2 --header="Content-Type: text/xml" --post-file=$postfile $f'
19 elif test -x /usr/bin/lynx; then
20     GET='/usr/bin/lynx -dump "$f" >$OUT2'
21     POST=''
22 fi
23
24 # Fire up pazpar2
25 rm -f pazpar2.log
26
27
28 PREFIX=$1
29 if test "x${PREFIX}" = "x"; then
30     echo Missing prefix for run_pazpar2.sh
31     exit 1
32 fi
33 CFG=${PREFIX}.cfg
34 URLS=${PREFIX}_urls
35 VALGRINDLOG=${PREFIX}_valgrind.log
36
37 usevalgrind=false
38 if $usevalgrind; then
39     valgrind --leak-check=full --log-file=$VALGRINDLOG ../src/pazpar2 -X -l pazpar2.log -f ${CFG} >extra_pazpar2.log 2>&1 &
40 else
41     YAZ_LOG=zoom,zoomdetails,debug,log,fatal ../src/pazpar2 -d -X -l pazpar2.log -f ${srcdir}/${CFG} >extra_pazpar2.log 2>&1 &
42 fi
43
44
45 PP2PID=$!
46
47 # Give it a chance to start properly..
48 sleep 3
49
50 # Set to success by default.. Will be set to non-zero in case of failure
51 code=0
52
53 if ps -p $PP2PID >/dev/null 2>&1; then
54     :
55 else
56     code=1
57     PP2PID=""
58     echo "pazpar2 failed to start"
59 fi
60
61 # We can start test for real
62
63 oIFS="$IFS"
64 IFS='
65 '
66
67 testno=1
68 for f in `cat ${srcdir}/${URLS}`; do
69     if echo $f | grep '^http' >/dev/null; then
70         OUT1=${srcdir}/${PREFIX}_${testno}.res
71         OUT2=${PREFIX}_${testno}.log
72         DIFF=${PREFIX}_${testno}.dif
73         rm -f $OUT2 $DIFF
74         if test -n "${postfile}"; then
75             eval $POST
76         else
77             eval $GET
78         fi
79         if test -f $OUT1; then
80             if test -f $OUT2; then
81                 if diff $OUT1 $OUT2 >$DIFF; then
82                     :
83                 else
84                     # wget returns 0-size file on HTTP error, curl dont.
85                     if test -s $OUT1; then
86                         echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
87                         echo "URL: $f"
88                         code=1
89                     fi
90                 fi
91             else
92                 echo "Test $test: can not be performed"
93             fi
94         else
95             echo "Test $testno: Making for the first time"
96             mv $OUT2 $OUT1
97             code=1
98         fi
99         testno=`expr $testno + 1`
100         postfile=
101     elif echo $f | grep '^[0-9]' >/dev/null; then
102         sleep $f
103     else
104         if test -f $f; then
105             postfile=$f
106         else
107             echo "File $f does not exist"
108             code=1
109         fi
110     fi
111     if ps -p $PP2PID >/dev/null 2>&1; then
112         :
113     else
114         echo "Test $testno: pazpar2 died"
115         exit 1
116     fi
117 done
118 IFS="$oIFS"
119
120 sleep 1
121 # Kill programs
122
123 if test -n "$PP2PID"; then
124     kill $PP2PID
125 fi
126
127 exit $code
128
129 # Local Variables:
130 # mode:shell-script
131 # sh-indentation: 2
132 # sh-basic-offset: 4
133 # End: