2 # $Header: /cvsroot/pgsql/src/test/regress/Attic/pg_regress.sh,v 1.5 2000/10/03 19:37:39 petere Exp $
6 TMPFILE=$TMPDIR/pg_regress.$$
9 PostgreSQL regression test driver
11 Usage: $me [options...] [extra tests...]
14 --debug turn on debug mode in programs that are run
15 --inputdir=DIR take input files from DIR (default \`.')
16 --multibyte=ENCODING use ENCODING as the multibyte encoding, and
17 also run a test by the same name
18 --outputdir=DIR place output files in DIR (default \`.')
19 --schedule=FILE use test ordering schedule from FILE
20 (may be used multiple times to concatenate)
21 --temp-install[=DIR] create a temporary installation (in DIR)
23 Options for \`temp-install' mode:
24 --top-builddir=DIR (relative) path to top level build directory
26 Options for using an existing installation:
27 --host=HOST use postmaster running on HOST
28 --port=PORT use postmaster running at PORT
29 --user=USER connect as USER
31 The exit status is 0 if all tests passed, 1 if some tests failed, and 2
32 if the tests could not be run for some reason.
34 Report bugs to <pgsql-bugs@postgresql.org>."
38 _dashes='==============' # 14
40 _msg=`echo "$1$_spaces" | cut -c 1-38`
41 echo "$_dashes $_msg $_dashes"
46 # Unset locale settings
49 unset LC_COLLATE LC_CTYPE LC_MONETARY LC_MESSAGES LC_NUMERIC LC_TIME LC_ALL LANG LANGUAGE
53 # Check for echo -n vs echo \c
56 if echo '\c' | grep c >/dev/null 2>&1; then
66 # Initialize default settings
75 host_platform='@host_tuple@'
88 hostname=`hostname` || hostname=localhost
92 # Parse command line options
102 echo "pg_regress (PostgreSQL @VERSION@)"
108 inputdir=`expr "x$1" : "x--inputdir=\(.*\)"`
111 multibyte=`expr "x$1" : "x--multibyte=\(.*\)"`
114 temp_install=./tmp_check
117 temp_install=`expr "x$1" : "x--temp-install=\(.*\)"`
120 outputdir=`expr "x$1" : "x--outputdir=\(.*\)"`
123 foo=`expr "x$1" : "x--schedule=\(.*\)"`
124 schedule="$schedule $foo"
127 top_builddir=`expr "x$1" : "x--top-builddir=\(.*\)"`
130 PGHOST=`expr "x$1" : "x--host=\(.*\)"`
133 PGPORT=`expr "x$1" : "x--port=\(.*\)"`
136 PGUSER=`expr "x$1" : "x--user=\(.*\)"`
140 echo "$me: invalid argument $1" 1>&2
143 extra_tests="$extra_tests $1"
150 # When on Windows or QNX, don't use Unix sockets.
153 case $host_platform in
154 *-*-cygwin* | *-*-qnx*)
162 # Set up diff to ignore horizontal white space differences.
165 case $host_platform in
174 # Set backend timezone and datestyle explicitly
176 # To pass the horology test in its current form, the postmaster must be
177 # started with PGDATESTYLE=ISO, while the frontend must be started with
178 # PGDATESTYLE=Postgres. We set the postmaster values here and change
179 # to the frontend settings after the postmaster has been started.
182 PGTZ='PST8PDT'; export PGTZ
183 PGDATESTYLE='ISO,US'; export PGDATESTYLE
187 # Exit trap to remove temp file and shut down postmaster
190 # Note: There are some stupid shells (even among recent ones) that
191 # ignore the argument to exit (as in `exit 1') if there is an exit
192 # trap. The trap (and thus the shell script) will then always exit
193 # with the result of the last shell command before the `exit'. Hence
194 # we have to write `(exit x); exit' below this point.
198 if [ -n "$postmaster_pid" ]; then
199 kill -2 "$postmaster_pid"
200 wait "$postmaster_pid"
203 rm -f "$TMPFILE" && exit $savestatus
208 echo; echo "caught signal"
209 if [ -n "$postmaster_pid" ]; then
210 echo "signalling fast shutdown to postmaster with pid $postmaster_pid"
211 kill -2 "$postmaster_pid"
212 wait "$postmaster_pid"
215 (exit $savestatus); exit
221 # Scan resultmap file to find which platform-specific expected files to use.
222 # The format of each line of the file is
223 # testname/hostplatformpattern=substitutefile
224 # where the hostplatformpattern is evaluated per the rules of expr(1),
225 # namely, it is a standard regular expression with an implicit ^ at the start.
227 # The tempfile hackery is needed because some shells will run the loop
228 # inside a subshell, whereupon shell variables set therein aren't seen
229 # outside the loop :-(
232 cat /dev/null >$TMPFILE
235 HOSTPAT=`expr "$LINE" : '.*/\(.*\)='`
236 if [ `expr "$host_platform" : "$HOSTPAT"` -ne 0 ]
238 # remove hostnamepattern from line so that there are no shell
239 # wildcards in SUBSTLIST; else later 'for' could expand them!
240 TESTNAME=`expr "$LINE" : '\(.*\)/'`
241 SUBST=`echo "$LINE" | sed 's/^.*=//'`
242 echo "$TESTNAME=$SUBST" >> $TMPFILE
244 done <"$inputdir/resultmap"
245 SUBSTLIST=`cat $TMPFILE`
249 LOGDIR=$outputdir/log
251 if [ x"$temp_install" != x"" ]
253 if echo x"$temp_install" | grep -v '^x/' >/dev/null 2>&1; then
254 temp_install="`pwd`/$temp_install"
257 bindir=$temp_install/$bindir
258 libdir=$temp_install/$libdir
259 datadir=$temp_install/$datadir
260 PGDATA=$temp_install/data
261 if [ "$unix_sockets" = no ]; then
269 # Set up shared library paths, needed by psql and pg_encoding
270 # (if you run multibyte). LD_LIBRARY_PATH covers many platforms,
271 # feel free to account for others as well.
274 if [ -n "$LD_LIBRARY_PATH" ]; then
275 LD_LIBRARY_PATH="$libdir:$LD_LIBRARY_PATH"
277 LD_LIBRARY_PATH=$libdir
279 export LD_LIBRARY_PATH
282 if [ -d "$temp_install" ]; then
283 message "removing existing temp installation"
284 rm -rf "$temp_install"
287 message "creating temporary installation"
288 mkdir -p "$LOGDIR" || { (exit 2); exit; }
289 ${MAKE:-gmake} -C "$top_builddir" DESTDIR="$temp_install" install >"$LOGDIR/install.log" 2>&1
294 echo "$me: installation failed"
295 echo "Examine $LOGDIR/install.log for the reason."
301 message "initializing database system"
302 [ "$debug" = yes ] && initdb_options='--debug'
303 "$bindir/initdb" -D "$PGDATA" -L "$datadir" --noclean $initdb_options >"$LOGDIR/initdb.log" 2>&1
308 echo "$me: initdb failed"
309 echo "Examine $LOGDIR/initdb.log for the reason."
319 message "starting postmaster"
320 [ "$debug" = yes ] && postmaster_options="$postmaster_options -d 5"
321 [ "$unix_sockets" = no ] && postmaster_options="$postmaster_options -i"
322 "$bindir/postmaster" -D "$PGDATA" -F $postmaster_options >"$LOGDIR/postmaster.log" 2>&1 &
325 if kill -0 $postmaster_pid >/dev/null 2>&1
327 echo "running on port $PGPORT with pid $postmaster_pid"
330 echo "$me: postmaster did not start"
331 echo "Examine $LOGDIR/postmaster.log for the reason."
336 # give postmaster some time to pass WAL recovery
339 else # not temp-install
341 # If Unix sockets are not available, use the local host by default.
342 [ "$unix_sockets" = no ] && ${PGHOST=$hostname}
344 if [ -n "$PGPORT" ]; then
345 port_info="port $PGPORT"
347 port_info="default port"
350 if [ -n "$PGHOST" ]; then
351 echo "(using postmaster on $PGHOST, $port_info)"
353 echo "(using postmaster on Unix socket, $port_info)"
355 message "dropping database \"$dbname\""
356 "$bindir/dropdb" $psql_options "$dbname" >/dev/null 2>&1
357 # errors can be ignored
362 # Set up SQL shell for the test.
365 PSQL="$bindir/psql -a -q -X $psql_options"
369 # Set frontend timezone and datestyle explicitly
372 PGTZ='PST8PDT'; export PGTZ
373 PGDATESTYLE='Postgres,US'; export PGDATESTYLE
377 # Set up multibyte environment
380 if [ -n "$multibyte" ]; then
381 PGCLIENTENCODING=$multibyte
382 export PGCLIENTENCODING
383 encoding_opt="-E $multibyte"
385 unset PGCLIENTENCODING
390 # Create the regression database
393 message "creating database \"$dbname\""
394 "$bindir/createdb" $encoding_opt $psql_options "$dbname"
395 if [ $? -ne 0 ]; then
396 echo "$me: createdb failed"
402 # Install the PL/pgSQL language in it
405 case $host_platform in
408 message "installing PL/pgSQL"
409 "$bindir/createlang" -L "$libdir" $psql_options plpgsql $dbname
410 if [ $? -ne 0 ] && [ $? -ne 2 ]; then
411 echo "$me: createlang failed"
422 message "running regression test queries"
424 mkdir -p "$outputdir/results" || { (exit 2); exit; }
425 result_summary_file=$outputdir/regression.out
426 diff_file=$outputdir/regression.diffs
428 cat /dev/null >"$result_summary_file"
429 cat /dev/null >"$diff_file"
434 for x in $extra_tests; do
437 ) | sed 's/[ ]*#.*//g' | \
442 [ -z "$line" ] && continue
446 if [ x"$1" = x"ignore:" ]; then
448 ignore_list="$ignore_list $@"
450 elif [ x"$1" != x"test:" ]; then
451 echo "$me:$schedule:$lno: syntax error"
461 if [ $# -eq 1 ]; then
463 formatted=`echo $1 | awk '{printf "%-20.20s", $1;}'`
464 $ECHO_N "test $formatted ... $ECHO_C"
466 $PSQL -d "$dbname" <"$inputdir/sql/$1.sql" >"$outputdir/results/$1.out" 2>&1
468 # Start a parallel group
469 $ECHO_N "parallel group ($# tests): " $ECHO_C
471 ( $PSQL -d $dbname <"$inputdir/sql/$name.sql" >"$outputdir/results/$name.out" 2>&1
472 $ECHO_N " $name $ECHO_C"
481 # (We do not want to run the diffs immediately after each test,
482 # because they would certainly get corrupted if run in parallel
487 if [ $# -ne 1 ]; then
488 formatted=`echo "$name" | awk '{printf "%-20.20s", $1;}'`
489 $ECHO_N " $formatted ... $ECHO_C"
492 # Check list extracted from resultmap to see if we should compare
493 # to a system-specific expected file.
494 # There shouldn't be multiple matches, but take the last if there are.
496 EXPECTED="$inputdir/expected/${name}.out"
497 for LINE in $SUBSTLIST
499 if [ `expr "$LINE" : "$name="` -ne 0 ]
501 SUBST=`echo "$LINE" | sed 's/^.*=//'`
502 EXPECTED="$inputdir/expected/${SUBST}.out"
506 diff $DIFFFLAGS $EXPECTED $outputdir/results/${name}.out >/dev/null 2>&1
511 ( diff $DIFFFLAGS -C3 $EXPECTED $outputdir/results/${name}.out
513 echo "======================================================================"
514 echo ) >> "$diff_file"
515 if echo " $ignore_list " | grep " $name " >/dev/null 2>&1 ; then
516 echo "failed (ignored)"
527 done | tee "$result_summary_file" 2>&1
535 if [ -n "$postmaster_pid" ]; then
536 message "shutting down postmaster"
537 kill -15 "$postmaster_pid"
548 count_total=`cat "$result_summary_file" | grep '\.\.\.' | wc -l | sed 's/ //g'`
549 count_ok=`cat "$result_summary_file" | grep '\.\.\. ok' | wc -l | sed 's/ //g'`
550 count_failed=`cat "$result_summary_file" | grep '\.\.\. FAILED' | wc -l | sed 's/ //g'`
551 count_ignored=`cat "$result_summary_file" | grep '\.\.\. failed (ignored)' | wc -l | sed 's/ //g'`
554 if [ $count_total -eq $count_ok ]; then
555 msg="All $count_total tests passed."
557 elif [ $count_failed -eq 0 ]; then
558 msg="$count_ok of $count_total tests passed, $count_ignored failed test(s) ignored."
560 elif [ $count_ignored -eq 0 ]; then
561 msg="$count_failed of $count_total tests failed."
564 msg="$count_failed of $count_total tests failed, $count_ignored failed test(s) ignored."
568 dashes=`echo " $msg " | sed 's/./=/g'`
574 if [ -s "$diff_file" ]; then
575 echo "The differences that caused some tests to fail can be viewed in the"
576 echo "file \`$diff_file'. A copy of the test summary that you see"
577 echo "above is saved in the file \`$result_summary_file'."
580 rm -f "$diff_file" "$result_summary_file"