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