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