3 # $Header: /cvsroot/pgsql/src/test/regress/Attic/run_check.sh,v 1.21 2000/07/06 21:33:45 petere 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"
32 PMOPTIONS=${PMOPTIONS:-"-o -F"}
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"
48 LD_LIBRARY_PATH="$LIBDIR"
50 export LD_LIBRARY_PATH
53 # Get the commandline parameters
60 # Special setting for Windows (no unix domain sockets)
62 if [ "x$hostname" = "xwin" -o "x$hostname" = "xi386-pc-qnx" ]
64 HOSTLOC="-h localhost"
74 # Determine if echo -n works
76 if echo '\c' | grep -s c >/dev/null 2>&1
86 # Set backend timezone and datestyle explicitly
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.
93 PGTZ="PST8PDT"; export PGTZ
94 PGDATESTYLE="ISO,US"; export PGDATESTYLE
97 # The SQL shell to use during this test
99 FRONTEND="$BINDIR/psql $HOSTLOC -a -q -X"
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.
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 :-(
113 cat /dev/null > $TMPFILE
116 HOSTPAT=`expr "$LINE" : '.*/\(.*\)='`
117 if [ `expr "$hostname" : "$HOSTPAT"` -ne 0 ]
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
126 SUBSTLIST=`cat $TMPFILE`
130 # Catch SIGINT and SIGTERM to shutdown the postmaster
134 echo "user abort ..."
137 echo "Signalling postmaster with PID $PMPID to shutdown immediately"
143 LD_LIBRARY_PATH="$old_LD_LIBRARY_PATH"
148 # Prepare a clean check directory
152 echo "=============== Removing old ./tmp_check directory ... ================"
156 echo "=============== Create ./tmp_check directory ================"
162 # Install this build into ./tmp/check
164 echo "=============== Installing new build into ./tmp_check ================"
165 ${MAKE:-gmake} -C ../../.. POSTGRESDIR=$CHKDIR prefix=$CHKDIR install >$LOGDIR/install.log 2>&1
170 echo "ERROR: Check installation failed - cannot continue"
171 echo "Please examine $LOGDIR/install.log"
172 echo "for the reason."
179 # Change the path so that all binaries from the current
180 # build are first candidates
182 PATH=$CHKDIR/bin:$PATH
187 # Run initdb to initialize a database system in ./tmp_check
189 echo "=============== Initializing check database instance ================"
190 initdb -D $PGDATA --noclean >$LOGDIR/initdb.log 2>&1
195 echo "ERROR: Check initdb failed - cannot continue"
196 echo "Please examine $LOGDIR/initdb.log"
197 echo "for the reason."
204 # Start a postmaster for the check instance and give
205 # him some time to pass the WAL recovery code.
207 echo "=============== Starting regression postmaster ================"
208 postmaster -D $PGDATA $USETCPIP -p $PGPORT $PMOPTIONS >$LOGDIR/postmaster.log 2>&1 &
212 if kill -0 $PMPID >/dev/null 2>&1
214 echo "Regression postmaster is running - PID=$PMPID PGPORT=$PGPORT"
217 echo "ERROR: Regression postmaster did not startup."
218 echo "Please examine $LOGDIR/postmaster.log"
219 echo "for the reason."
225 # Set frontend timezone and datestyle explicitly
227 PGTZ="PST8PDT"; export PGTZ
228 PGDATESTYLE="Postgres,US"; export PGDATESTYLE
231 # Create the regression database
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"
241 unset PGCLIENTENCODING
244 createdb $ENCODINGOPT $HOSTLOC regression
245 if [ $? -ne 0 ]; then
253 # Install the PL/pgSQL language in it
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
267 # Run the regression tests specified in the ./sql/run_check.tests file
269 echo "=============== Running regression queries... ================"
270 cat /dev/null > regression.diffs
271 cat /dev/null > regress.out
273 if [ "x$hostname" = "xi386-pc-qnx" ]; then
279 TESTS=./sql/run_check.tests
283 for name in $extratests ; do
286 ) | while read line ; do
289 # Count line numbers and skip comments and empty lines
292 line=`echo $line | sed -e 's/[ ]*#.*//'`
299 # Extract the type keyword and the name
301 type=`echo $line | awk '{print $1;}'`
302 name=`echo $line | awk '{print $2;}'`
305 parallel) # ----------
306 # This is the beginning of a new group of
307 # tests that should be executed in parallel.
316 # Again count line numbers and skip comments
319 line=`echo $line | sed -e 's/[ ]*#.*//'`
326 # Collect and count the number of tests to
329 type=`echo $line | awk '{print $1;}'`
330 name=`echo $line | awk '{print $2;}'`
332 if [ "$type" = "endparallel" ]
337 if [ "$type" = "parallel" ]
340 echo "$TESTS line $lno: parallel cannot be nested"
344 if [ "$type" != "test" ]
347 echo "$TESTS line $lno: syntax error"
352 if [ ! -z "$parlist" ]
357 parlist="${parlist}$name"
358 parntests=`expr $parntests + 1`
362 # Check that we found a matching 'endparallel'
367 echo "$TESTS at EOF: missing endparallel for line $parlno"
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!
381 gnam=`echo "$pargroup ($parntests tests)" | awk '{printf "%-26.26s", $0;}'`
382 echo "parallel $gnam ..."
387 $FRONTEND regression < sql/${name}.sql \
388 > results/${name}.out 2>&1
389 $ECHO_N " $name" $ECHO_C
396 # Setup status information for the diff check below
403 # This is a test that must be executed serialized
405 pnam=`echo $name | awk '{printf "%-20.20s", $1;}'`
406 $ECHO_N "sequential test $pnam ... " $ECHO_C
408 $FRONTEND regression < sql/${name}.sql \
409 > results/${name}.out 2>&1
412 # Setup status information for the diff check below
419 # And this is space for extensions
422 echo "$TESTS line $lno: syntax error"
429 # One single or a group of parallel tests has been completed.
430 # Check the output against the expected results.
432 # On the fly we create run_check.out and regress.out in the
433 # old format, so checkresults will still find the proper
436 for name in $checklist ; do
437 if [ $checkpname -ne 0 ]
439 pnam=`echo $name | awk '{printf "%-20.20s", $1;}'`
440 $ECHO_N " test $pnam ... " $ECHO_C
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.
448 EXPECTED="expected/${name}.out"
449 for LINE in $SUBSTLIST
451 if [ `expr "$LINE" : "$name="` -ne 0 ]
453 SUBST=`echo "$LINE" | sed 's/^.*=//'`
454 EXPECTED="expected/${SUBST}.out"
458 if [ `diff ${DIFFOPT} ${EXPECTED} results/${name}.out | wc -l` -ne 0 ]
460 ( diff ${DIFFOPT} -C3 ${EXPECTED} results/${name}.out ; \
462 echo "----------------------" ; \
464 ) >> regression.diffs
466 echo "$name .. failed" >> regress.out
469 echo "$name .. ok" >> regress.out
472 done | tee run_check.out 2>&1
475 # Finally kill the postmaster we started
477 echo "=============== Terminating regression postmaster ================"
480 LD_LIBRARY_PATH="$old_LD_LIBRARY_PATH"