Testing: align test no and line no (_urls)
[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 testno=1
73 for f in `cat ${srcdir}/${URLS}`; do
74     if echo $f | grep '^http' >/dev/null; then
75         OUT1=${srcdir}/${PREFIX}_${testno}.res
76         OUT2=${PREFIX}_${testno}.log
77         DIFF=${PREFIX}_${testno}.dif
78         rm -f $OUT2 $DIFF
79         if test -n "${postfile}"; then
80             eval $POST
81         else
82             eval $GET
83         fi
84         if test ! -f $OUT2; then
85             touch $OUT2
86         fi
87         if test -f $OUT1; then
88             if diff $OUT1 $OUT2 >$DIFF; then
89                 :
90             else
91                 echo "Test $testno: Failed. See $OUT1, $OUT2 and $DIFF"
92                 echo "URL: $f"
93                 code=1
94             fi
95         else
96             echo "Test $testno: Making for the first time"
97             mv $OUT2 $OUT1
98             code=1
99         fi
100         testno=`expr $testno + 1`
101         postfile=
102     elif echo $f | grep '^[0-9]' >/dev/null; then
103         sleep $f
104     else
105         if test -f $f; then
106             postfile=$f
107         else
108             echo "File $f does not exist"
109             code=1
110         fi
111     fi
112     if ps -p $PP2PID >/dev/null 2>&1; then
113         :
114     else
115         IFS="$oIFS"
116         echo "Test $testno: pazpar2 died"
117         exit 1
118     fi
119 done
120
121 # Kill programs
122
123 if test -n "$PP2PID"; then
124     kill $PP2PID
125     sleep 2
126 fi
127
128 exit $code
129
130 # Local Variables:
131 # mode:shell-script
132 # sh-indentation: 2
133 # sh-basic-offset: 4
134 # End: