]> granicus.if.org Git - postgresql/blob - src/test/regress/run_check.sh
d057d35264fa2cb9c1eec6249b622063c87439b9
[postgresql] / src / test / regress / run_check.sh
1 #!/bin/sh
2 #
3 # $Header: /cvsroot/pgsql/src/test/regress/Attic/run_check.sh,v 1.21 2000/07/06 21:33:45 petere Exp $
4
5 # ----------
6 # Check call syntax
7 # ----------
8 if [ $# -eq 0 ]
9 then
10     echo "Syntax: $0 <hostname> [extra-tests]"
11     exit 1
12 fi
13
14 # ----------
15 # Change to the regression test directory explicitly
16 # ----------
17 cd `dirname $0`
18
19 # ----------
20 # Some paths used during the test
21 # ----------
22 PWD=`pwd`
23 CHKDIR="$PWD/tmp_check"
24 PGDATA="$CHKDIR/data"
25 LIBDIR="$CHKDIR/lib"
26 BINDIR="$CHKDIR/bin"
27 LOGDIR="$CHKDIR/log"
28 TIMDIR="$CHKDIR/timestamp"
29 PGPORT="65432"
30 PGLIB="$LIBDIR"
31 PMPID=""
32 PMOPTIONS=${PMOPTIONS:-"-o -F"}
33
34 export CHKDIR
35 export PGDATA
36 export PGLIB
37 export LOGDIR
38 export TIMDIR
39 export PGPORT
40
41 # Needed by psql and pg_encoding (if you run multibyte).
42 # I hope this covers all platforms with shared libraries,
43 # otherwise feel free to cover your platform here as well.
44 if [ "$LD_LIBRARY_PATH" ]; then
45         old_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
46         LD_LIBRARY_PATH="$LIBDIR:$LD_LIBARY_PATH"
47 else
48         LD_LIBRARY_PATH="$LIBDIR"
49 fi
50 export LD_LIBRARY_PATH
51
52 # ----------
53 # Get the commandline parameters
54 # ----------
55 hostname=$1
56 shift
57 extratests="$*"
58
59 # ----------
60 # Special setting for Windows (no unix domain sockets)
61 # ----------
62 if [ "x$hostname" = "xwin" -o "x$hostname" = "xi386-pc-qnx" ]
63 then
64     HOSTLOC="-h localhost"
65     USETCPIP="-i"
66 else
67     HOSTLOC=""
68     USETCPIP=""
69 fi
70
71 unset PGHOST
72
73 # ----------
74 # Determine if echo -n works
75 # ----------
76 if echo '\c' | grep -s c >/dev/null 2>&1
77 then
78     ECHO_N="echo -n"
79     ECHO_C=""
80 else
81     ECHO_N="echo"
82     ECHO_C='\c'
83 fi
84
85 # ----------
86 # Set backend timezone and datestyle explicitly
87 #
88 # To pass the horology test in its current form, the postmaster must be
89 # started with PGDATESTYLE=ISO, while the frontend must be started with
90 # PGDATESTYLE=Postgres.  We set the postmaster values here and change
91 # to the frontend settings after the postmaster has been started.
92 # ----------
93 PGTZ="PST8PDT"; export PGTZ
94 PGDATESTYLE="ISO,US"; export PGDATESTYLE
95
96 # ----------
97 # The SQL shell to use during this test
98 # ----------
99 FRONTEND="$BINDIR/psql $HOSTLOC -a -q -X"
100
101 # ----------
102 # Scan resultmap file to find which platform-specific expected files to use.
103 # The format of each line of the file is
104 #               testname/hostnamepattern=substitutefile
105 # where the hostnamepattern is evaluated per the rules of expr(1) --- namely,
106 # it is a standard regular expression with an implicit ^ at the start.
107 #
108 # The tempfile hackery is needed because some shells will run the loop
109 # inside a subshell, whereupon shell variables set therein aren't seen
110 # outside the loop :-(
111 # ----------
112 TMPFILE="matches.$$"
113 cat /dev/null > $TMPFILE
114 while read LINE
115 do
116         HOSTPAT=`expr "$LINE" : '.*/\(.*\)='`
117         if [ `expr "$hostname" : "$HOSTPAT"` -ne 0 ]
118         then
119                 # remove hostnamepattern from line so that there are no shell
120                 # wildcards in SUBSTLIST; else later 'for' could expand them!
121                 TESTNAME=`expr "$LINE" : '\(.*\)/'`
122                 SUBST=`echo "$LINE" | sed 's/^.*=//'`
123                 echo "$TESTNAME=$SUBST" >> $TMPFILE
124         fi
125 done <resultmap
126 SUBSTLIST=`cat $TMPFILE`
127 rm -f $TMPFILE
128
129 # ----------
130 # Catch SIGINT and SIGTERM to shutdown the postmaster
131 # ----------
132 trap '  echo ""
133                 echo ""
134                 echo "user abort ..."
135                 if [ ! -z "$PMPID" ]
136                 then
137                         echo "Signalling postmaster with PID $PMPID to shutdown immediately"
138                         kill -2 $PMPID
139                         wait $PMPID
140                         echo ""
141                 fi
142                 echo ""
143                 LD_LIBRARY_PATH="$old_LD_LIBRARY_PATH"
144                 exit 1
145 ' 2 15
146
147 # ----------
148 # Prepare a clean check directory
149 # ----------
150 if [ -d $CHKDIR ]
151 then
152         echo "=============== Removing old ./tmp_check directory ... ================"
153         rm -rf $CHKDIR
154 fi
155
156 echo "=============== Create ./tmp_check directory           ================"
157 mkdir -p $CHKDIR
158 mkdir -p $LOGDIR
159
160
161 # ----------
162 # Install this build into ./tmp/check
163 # ----------
164 echo "=============== Installing new build into ./tmp_check  ================"
165 ${MAKE:-gmake} -C ../../.. POSTGRESDIR=$CHKDIR prefix=$CHKDIR install >$LOGDIR/install.log 2>&1
166
167 if [ $? -ne 0 ]
168 then
169         echo ""
170         echo "ERROR: Check installation failed - cannot continue"
171         echo "Please examine $LOGDIR/install.log"
172         echo "for the reason."
173         echo ""
174         exit 2
175 fi
176
177
178 # ----------
179 # Change the path so that all binaries from the current
180 # build are first candidates
181 # ----------
182 PATH=$CHKDIR/bin:$PATH
183 export PATH
184
185
186 # ----------
187 # Run initdb to initialize a database system in ./tmp_check
188 # ----------
189 echo "=============== Initializing check database instance   ================"
190 initdb -D $PGDATA --noclean >$LOGDIR/initdb.log 2>&1
191
192 if [ $? -ne 0 ]
193 then
194         echo ""
195         echo "ERROR: Check initdb failed - cannot continue"
196         echo "Please examine $LOGDIR/initdb.log"
197         echo "for the reason."
198         echo ""
199         exit 3
200 fi
201
202
203 # ----------
204 # Start a postmaster for the check instance and give
205 # him some time to pass the WAL recovery code. 
206 #----------
207 echo "=============== Starting regression postmaster         ================"
208 postmaster -D $PGDATA $USETCPIP -p $PGPORT $PMOPTIONS >$LOGDIR/postmaster.log 2>&1 &
209 PMPID=$!
210 sleep 2
211
212 if kill -0 $PMPID >/dev/null 2>&1
213 then
214         echo "Regression postmaster is running - PID=$PMPID PGPORT=$PGPORT"
215 else
216         echo ""
217         echo "ERROR: Regression postmaster did not startup."
218         echo "Please examine $LOGDIR/postmaster.log"
219         echo "for the reason."
220         echo ""
221         exit 4
222 fi
223
224 # ----------
225 # Set frontend timezone and datestyle explicitly
226 # ----------
227 PGTZ="PST8PDT"; export PGTZ
228 PGDATESTYLE="Postgres,US"; export PGDATESTYLE
229
230 # ----------
231 # Create the regression database
232 # ----------
233 echo "=============== Creating regression database...        ================"
234 if [ -n "$MULTIBYTE" ];then
235     mbtests=`echo $MULTIBYTE | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
236     PGCLIENTENCODING="$MULTIBYTE"
237     export PGCLIENTENCODING
238     ENCODINGOPT="-E $MULTIBYTE"
239 else
240     mbtests=""
241     unset PGCLIENTENCODING
242     ENCODINGOPT=""
243 fi
244 createdb $ENCODINGOPT $HOSTLOC regression
245 if [ $? -ne 0 ]; then
246      echo createdb failed
247          kill -15 $PMPID
248      exit 1
249 fi
250
251
252 # ----------
253 # Install the PL/pgSQL language in it
254 # ----------
255 if [ "x$hostname" != "xi386-pc-qnx" ]; then
256 echo "=============== Installing PL/pgSQL...                 ================"
257 createlang -L $LIBDIR $HOSTLOC plpgsql regression
258 if [ $? -ne 0 -a $? -ne 2 ]; then
259      echo createlang failed
260          kill -15 $PMPID
261      exit 1
262 fi
263 fi
264
265
266 # ----------
267 # Run the regression tests specified in the ./sql/run_check.tests file
268 # ----------
269 echo "=============== Running regression queries...          ================"
270 cat /dev/null > regression.diffs
271 cat /dev/null > regress.out
272
273 if [ "x$hostname" = "xi386-pc-qnx" ]; then
274         DIFFOPT="-b"
275 else
276         DIFFOPT="-w"
277 fi
278
279 TESTS=./sql/run_check.tests
280 lno=0
281 (
282         cat $TESTS 
283         for name in $extratests ; do
284                 echo "test $name"
285         done
286 ) | while read line ; do
287
288         # ----------
289         # Count line numbers and skip comments and empty lines
290         # ----------
291         lno=`expr $lno + 1`
292         line=`echo $line | sed -e 's/[  ]*#.*//'`
293         if [ -z "$line" ]
294         then
295                 continue
296         fi
297
298         # ----------
299         # Extract the type keyword and the name
300         # ----------
301         type=`echo $line | awk '{print $1;}'`
302         name=`echo $line | awk '{print $2;}'`
303
304         case $type in
305                 parallel)       # ----------
306                                         # This is the beginning of a new group of
307                                         # tests that should be executed in parallel.
308                                         # ----------
309                                         parlist=
310                                         parlno=$lno
311                                         pargroup=$name
312                                         parntests=0
313                                         parpar=0
314                                         while read line ; do
315                                                 # ----------
316                                                 # Again count line numbers and skip comments
317                                                 # ----------
318                                                 lno=`expr $lno + 1`
319                                                 line=`echo $line | sed -e 's/[  ]*#.*//'`
320                                                 if [ -z "$line" ]
321                                                 then
322                                                         continue
323                                                 fi
324
325                                                 # ----------
326                                                 # Collect and count the number of tests to
327                                                 # execute parallel
328                                                 # ----------
329                                                 type=`echo $line | awk '{print $1;}'`
330                                                 name=`echo $line | awk '{print $2;}'`
331
332                                                 if [ "$type" = "endparallel" ]
333                                                 then
334                                                         parend=1
335                                                         break
336                                                 fi
337                                                 if [ "$type" = "parallel" ]
338                                                 then
339                                                         echo ""
340                                                         echo "$TESTS line $lno: parallel cannot be nested"
341                                                         echo ""
342                                                         exit 5
343                                                 fi
344                                                 if [ "$type" != "test" ]
345                                                 then
346                                                         echo ""
347                                                         echo "$TESTS line $lno: syntax error"
348                                                         echo ""
349                                                         exit 5
350                                                 fi
351
352                                                 if [ ! -z "$parlist" ]
353                                                 then
354                                                         parlist="$parlist "
355                                                 fi
356
357                                                 parlist="${parlist}$name"
358                                                 parntests=`expr $parntests + 1`
359                                         done
360
361                                         # ----------
362                                         # Check that we found a matching 'endparallel'
363                                         # ----------
364                                         if [ $parend -eq 0 ]
365                                         then
366                                                 echo ""
367                                                 echo "$TESTS at EOF: missing endparallel for line $parlno"
368                                                 echo ""
369                                                 exit 5
370                                         fi
371
372                                         # ----------
373                                         # Tell what we're doing and then start them all, using
374                                         # a subshell for each one.  The subshell is just there
375                                         # to print the test name when it finishes, so one can
376                                         # see which tests finish fastest.  We do NOT run the
377                                         # ok/failed comparison tests in the parallel subshells,
378                                         # because we want the diffs (if any) to come out in a
379                                         # predictable order --- and certainly not interleaved!
380                                         # ----------
381                                         gnam=`echo "$pargroup ($parntests tests)" | awk '{printf "%-26.26s", $0;}'`
382                                         echo "parallel $gnam  ..."
383
384                                         for name in $parlist
385                                         do
386                                                 (
387                                                         $FRONTEND regression < sql/${name}.sql                  \
388                                                                 > results/${name}.out 2>&1
389                                                         $ECHO_N " $name" $ECHO_C
390                                                 ) &
391                                         done
392                                         wait
393                                         echo ""
394
395                                         # ----------
396                                         # Setup status information for the diff check below
397                                         # ----------
398                                         checklist="$parlist"
399                                         checkpname=1
400                                         ;;
401
402                 test)           # ----------
403                                         # This is a test that must be executed serialized
404                                         # ----------
405                                         pnam=`echo $name | awk '{printf "%-20.20s", $1;}'`
406                                         $ECHO_N "sequential test $pnam ... " $ECHO_C
407
408                                         $FRONTEND regression < sql/${name}.sql                                  \
409                                                 > results/${name}.out 2>&1
410
411                                         # ----------
412                                         # Setup status information for the diff check below
413                                         # ----------
414                                         checklist="$name"
415                                         checkpname=0
416                                         ;;
417
418                 *)                      # ----------
419                                         # And this is space for extensions
420                                         # ----------
421                                         echo ""
422                                         echo "$TESTS line $lno: syntax error"
423                                         echo ""
424                                         exit 5
425                                         ;;
426         esac
427
428         # ----------
429         # One single or a group of parallel tests has been completed.
430         # Check the output against the expected results.
431         #
432         # On the fly we create run_check.out and regress.out in the
433         # old format, so checkresults will still find the proper
434         # information.
435         # ----------
436         for name in $checklist ; do
437                 if [ $checkpname -ne 0 ]
438                 then
439                         pnam=`echo $name | awk '{printf "%-20.20s", $1;}'`
440                         $ECHO_N "           test $pnam ... " $ECHO_C
441                 fi
442
443                 #
444                 # Check list extracted from resultmap to see if we should compare
445                 # to a system-specific expected file.
446                 # There shouldn't be multiple matches, but take the last if there are.
447                 #
448                 EXPECTED="expected/${name}.out"
449                 for LINE in $SUBSTLIST
450                 do
451                         if [ `expr "$LINE" : "$name="` -ne 0 ]
452                         then
453                                 SUBST=`echo "$LINE" | sed 's/^.*=//'`
454                                 EXPECTED="expected/${SUBST}.out"
455                         fi
456                 done
457
458                 if [ `diff ${DIFFOPT} ${EXPECTED} results/${name}.out | wc -l` -ne 0 ]
459                 then
460                         (       diff ${DIFFOPT} -C3 ${EXPECTED} results/${name}.out     ; \
461                                 echo ""                                                                         ; \
462                                 echo "----------------------"                           ; \
463                                 echo ""                                                                         ; \
464                         ) >> regression.diffs
465                         echo "FAILED"
466                         echo "$name .. failed" >> regress.out
467                 else
468                         echo "ok"
469                         echo "$name .. ok" >> regress.out
470                 fi
471         done
472 done | tee run_check.out 2>&1
473
474 # ----------
475 # Finally kill the postmaster we started
476 # ----------
477 echo "=============== Terminating regression postmaster      ================"
478 kill -15 $PMPID
479
480 LD_LIBRARY_PATH="$old_LD_LIBRARY_PATH"
481
482 exit 0