3 # $Header: /cvsroot/pgsql/src/test/regress/Attic/run_check.sh,v 1.6 2000/01/09 20:54:36 tgl Exp $
10 echo "Syntax: $0 <hostname> [extra-tests]"
15 # Change to the regression test directory explicitly
20 # Some paths used during the test
23 CHKDIR="$PWD/tmp_check"
28 TIMDIR="$CHKDIR/timestamp"
42 # Get the commandline parameters
49 # Special setting for Windows (no unix domain sockets)
51 if [ "x$hostname" = "xwin" ]
53 HOSTLOC="-h localhost"
59 # Determine if echo -n works
61 if echo '\c' | grep -s c >/dev/null 2>&1
71 # Set timezone and datestyle explicitly
73 PGTZ="PST8PDT"; export PGTZ
74 PGDATESTYLE="Postgres,US"; export PGDATESTYLE
77 # The SQL shell to use during this test
79 FRONTEND="$BINDIR/psql $HOSTLOC -n -e -q"
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.
92 HOSTPAT=`expr "$LINE" : '.*/\(.*\)='`
93 if [ `expr "$hostname" : "$HOSTPAT"` -ne 0 ]
95 SUBSTLIST="$SUBSTLIST $LINE"
101 # Catch SIGINT and SIGTERM to shutdown the postmaster
105 echo "user abort ..."
108 echo "Signalling postmaster with PID $PMPID to shutdown immediately"
118 # Prepare a clean check directory
122 echo "=============== Removing old ./tmp_check directory ... ================"
126 echo "=============== Create ./tmp_check directory ================"
132 # Install this build into ./tmp/check
134 echo "=============== Installing new build into ./tmp_check ================"
135 ${MAKE:-gmake} -C ../.. POSTGRESDIR=$CHKDIR install >$LOGDIR/install.log 2>&1
140 echo "ERROR: Check installation failed - cannot continue"
141 echo "Please examine $LOGDIR/install.log"
142 echo "for the reason."
149 # Change the path so that all binaries from the current
150 # build are first candidates
152 PATH=$CHKDIR/bin:$PATH
157 # Run initdb to initialize a database system in ./tmp_check
159 echo "=============== Initializing check database instance ================"
160 initdb --pglib=$LIBDIR --pgdata=$PGDATA >$LOGDIR/initdb.log 2>&1
165 echo "ERROR: Check initdb failed - cannot continue"
166 echo "Please examine $LOGDIR/initdb.log"
167 echo "for the reason."
174 # Start a postmaster for the check instance and give
175 # him some time to pass the WAL recovery code.
177 echo "=============== Starting regression postmaster ================"
178 postmaster -D $PGDATA -p $PGPORT -o -F >$LOGDIR/postmaster.log 2>&1 &
182 if kill -0 $PMPID >/dev/null 2>&1
184 echo "Regression postmaster is running - PID=$PMPID PGPORT=$PGPORT"
187 echo "ERROR: Regression postmaster did not startup."
188 echo "Please examine $LOGDIR/postmaster.log"
189 echo "for the reason."
196 # Create the regression database
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"
206 unset PGCLIENTENCODING
209 createdb $ENCODINGOPT $HOSTLOC regression
210 if [ $? -ne 0 ]; then
218 # Install the PL/pgSQL language in it
220 echo "=============== Installing PL/pgSQL... ================"
221 createlang $HOSTLOC plpgsql regression
222 if [ $? -ne 0 -a $? -ne 2 ]; then
223 echo createlang failed
230 # Run the regression tests specified in the ./sql/run_check.tests file
232 echo "=============== Running regression queries... ================"
233 echo "" > regression.diffs
234 echo "" > regress.out
236 TESTS=./sql/run_check.tests
240 for name in $extratests ; do
243 ) | while read line ; do
246 # Count line numbers and skip comments and empty lines
249 line=`echo $line | sed -e 's/[ ]*#.*//'`
256 # Extract the type keyword and the name
258 type=`echo $line | awk '{print $1;}'`
259 name=`echo $line | awk '{print $2;}'`
262 parallel) # ----------
263 # This is the beginning of a new group of
264 # tests that should be executed in parallel.
273 # Again count line numbers and skip comments
276 line=`echo $line | sed -e 's/[ ]*#.*//'`
283 # Collect and count the number of tests to
286 type=`echo $line | awk '{print $1;}'`
287 name=`echo $line | awk '{print $2;}'`
289 if [ "$type" = "endparallel" ]
294 if [ "$type" = "parallel" ]
297 echo "$TESTS line $lno: parallel cannot be nested"
301 if [ "$type" != "test" ]
304 echo "$TESTS line $lno: syntax error"
309 if [ ! -z "$parlist" ]
314 parlist="${parlist}$name"
315 parntests=`expr $parntests + 1`
319 # Check that we found a matching 'endparallel'
324 echo "$TESTS at EOF: missing endparallel for line $parlno"
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!
338 gnam=`echo "$pargroup ($parntests tests)" | awk '{printf "%-26.26s", $0;}'`
339 echo "parallel $gnam ..."
344 $FRONTEND regression < sql/${name}.sql \
345 > results/${name}.out 2>&1
346 $ECHO_N " $name" $ECHO_C
353 # Setup status information for the diff check below
360 # This is a test that must be executed serialized
362 pnam=`echo $name | awk '{printf "%-20.20s", $1;}'`
363 $ECHO_N "sequential test $pnam ... " $ECHO_C
365 $FRONTEND regression < sql/${name}.sql \
366 > results/${name}.out 2>&1
369 # Setup status information for the diff check below
376 # And this is space for extensions
379 echo "$TESTS line $lno: syntax error"
386 # One single or a group of parallel tests has been completed.
387 # Check the output against the expected results.
389 # On the fly we create run_check.out and regress.out in the
390 # old format, so checkresults will still find the proper
393 for name in $checklist ; do
394 if [ $checkpname -ne 0 ]
396 pnam=`echo $name | awk '{printf "%-20.20s", $1;}'`
397 $ECHO_N " test $pnam ... " $ECHO_C
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.
405 EXPECTED="expected/${name}.out"
406 for LINE in $SUBSTLIST
408 if [ `expr "$LINE" : "$name/"` -ne 0 ]
410 SUBST=`echo "$LINE" | sed 's/^.*=//'`
411 EXPECTED="expected/${SUBST}.out"
415 if [ `diff -w ${EXPECTED} results/${name}.out | wc -l` -ne 0 ]
417 ( diff -wC3 ${EXPECTED} results/${name}.out ; \
419 echo "----------------------" ; \
421 ) >> regression.diffs
423 echo "$name .. failed" >> regress.out
426 echo "$name .. ok" >> regress.out
429 done | tee run_check.out 2>&1
432 # Finally kill the postmaster we started
434 echo "=============== Terminating regression postmaster ================"