2 # $Header: /cvsroot/pgsql/src/test/regress/Attic/pg_regress.sh,v 1.11 2000/11/21 17:34:21 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@'
76 enable_shared='@enable_shared@'
95 # Parse command line options
105 echo "pg_regress (PostgreSQL @VERSION@)"
111 inputdir=`expr "x$1" : "x--inputdir=\(.*\)"`
114 multibyte=`expr "x$1" : "x--multibyte=\(.*\)"`
117 temp_install=./tmp_check
120 temp_install=`expr "x$1" : "x--temp-install=\(.*\)"`
123 outputdir=`expr "x$1" : "x--outputdir=\(.*\)"`
126 foo=`expr "x$1" : "x--schedule=\(.*\)"`
127 schedule="$schedule $foo"
130 top_builddir=`expr "x$1" : "x--top-builddir=\(.*\)"`
133 PGHOST=`expr "x$1" : "x--host=\(.*\)"`
136 PGPORT=`expr "x$1" : "x--port=\(.*\)"`
139 PGUSER=`expr "x$1" : "x--user=\(.*\)"`
143 echo "$me: invalid argument $1" 1>&2
146 extra_tests="$extra_tests $1"
153 # When on Windows, QNX or BeOS, don't use Unix sockets.
156 case $host_platform in
157 *-*-cygwin* | *-*-qnx* | *beos*)
165 # Set up diff to ignore horizontal white space differences.
168 case $host_platform in
177 # Set backend timezone and datestyle explicitly
179 # To pass the horology test in its current form, the postmaster must be
180 # started with PGDATESTYLE=ISO, while the frontend must be started with
181 # PGDATESTYLE=Postgres. We set the postmaster values here and change
182 # to the frontend settings after the postmaster has been started.
185 PGTZ='PST8PDT'; export PGTZ
186 PGDATESTYLE='ISO,US'; export PGDATESTYLE
190 # Exit trap to remove temp file and shut down postmaster
193 # Note: There are some stupid shells (even among recent ones) that
194 # ignore the argument to exit (as in `exit 1') if there is an exit
195 # trap. The trap (and thus the shell script) will then always exit
196 # with the result of the last shell command before the `exit'. Hence
197 # we have to write `(exit x); exit' below this point.
201 if [ -n "$postmaster_pid" ]; then
202 kill -2 "$postmaster_pid"
203 wait "$postmaster_pid"
206 rm -f "$TMPFILE" && exit $savestatus
211 echo; echo "caught signal"
212 if [ -n "$postmaster_pid" ]; then
213 echo "signalling fast shutdown to postmaster with pid $postmaster_pid"
214 kill -2 "$postmaster_pid"
215 wait "$postmaster_pid"
218 (exit $savestatus); exit
224 # Scan resultmap file to find which platform-specific expected files to use.
225 # The format of each line of the file is
226 # testname/hostplatformpattern=substitutefile
227 # where the hostplatformpattern is evaluated per the rules of expr(1),
228 # namely, it is a standard regular expression with an implicit ^ at the start.
230 # The tempfile hackery is needed because some shells will run the loop
231 # inside a subshell, whereupon shell variables set therein aren't seen
232 # outside the loop :-(
235 cat /dev/null >$TMPFILE
238 HOSTPAT=`expr "$LINE" : '.*/\(.*\)='`
239 if [ `expr "$host_platform" : "$HOSTPAT"` -ne 0 ]
241 # remove hostnamepattern from line so that there are no shell
242 # wildcards in SUBSTLIST; else later 'for' could expand them!
243 TESTNAME=`expr "$LINE" : '\(.*\)/'`
244 SUBST=`echo "$LINE" | sed 's/^.*=//'`
245 echo "$TESTNAME=$SUBST" >> $TMPFILE
247 done <"$inputdir/resultmap"
248 SUBSTLIST=`cat $TMPFILE`
252 LOGDIR=$outputdir/log
254 if [ x"$temp_install" != x"" ]
256 if echo x"$temp_install" | grep -v '^x/' >/dev/null 2>&1; then
257 temp_install="`pwd`/$temp_install"
260 bindir=$temp_install/$bindir
261 libdir=$temp_install/$libdir
262 datadir=$temp_install/$datadir
263 PGDATA=$temp_install/data
264 if [ "$unix_sockets" = no ]; then
272 # Set up shared library paths, needed by psql and pg_encoding
273 # (if you run multibyte). LD_LIBRARY_PATH covers many platforms,
274 # feel free to account for others as well.
277 if [ -n "$LD_LIBRARY_PATH" ]; then
278 LD_LIBRARY_PATH="$libdir:$LD_LIBRARY_PATH"
280 LD_LIBRARY_PATH=$libdir
282 export LD_LIBRARY_PATH
285 if [ -d "$temp_install" ]; then
286 message "removing existing temp installation"
287 rm -rf "$temp_install"
290 message "creating temporary installation"
291 if [ ! -d "$LOGDIR" ]; then
292 mkdir -p "$LOGDIR" || { (exit 2); exit; }
294 $GMAKE -C "$top_builddir" DESTDIR="$temp_install" install with_perl=no with_python=no >"$LOGDIR/install.log" 2>&1
299 echo "$me: installation failed"
300 echo "Examine $LOGDIR/install.log for the reason."
306 message "initializing database system"
307 [ "$debug" = yes ] && initdb_options='--debug'
308 "$bindir/initdb" -D "$PGDATA" -L "$datadir" --noclean $initdb_options >"$LOGDIR/initdb.log" 2>&1
313 echo "$me: initdb failed"
314 echo "Examine $LOGDIR/initdb.log for the reason."
324 message "starting postmaster"
325 [ "$debug" = yes ] && postmaster_options="$postmaster_options -d 5"
326 [ "$unix_sockets" = no ] && postmaster_options="$postmaster_options -i"
327 "$bindir/postmaster" -D "$PGDATA" -F $postmaster_options >"$LOGDIR/postmaster.log" 2>&1 &
330 if kill -0 $postmaster_pid >/dev/null 2>&1
332 echo "running on port $PGPORT with pid $postmaster_pid"
335 echo "$me: postmaster did not start"
336 echo "Examine $LOGDIR/postmaster.log for the reason."
341 # give postmaster some time to pass WAL recovery
344 else # not temp-install
346 # If Unix sockets are not available, use the local host by default.
347 [ "$unix_sockets" = no ] && ${PGHOST=$hostname}
349 if [ -n "$PGPORT" ]; then
350 port_info="port $PGPORT"
352 port_info="default port"
355 if [ -n "$PGHOST" ]; then
356 echo "(using postmaster on $PGHOST, $port_info)"
358 echo "(using postmaster on Unix socket, $port_info)"
360 message "dropping database \"$dbname\""
361 "$bindir/dropdb" $psql_options "$dbname"
362 # errors can be ignored
367 # Set up SQL shell for the test.
370 PSQL="$bindir/psql -a -q -X $psql_options"
374 # Set frontend timezone and datestyle explicitly
377 PGTZ='PST8PDT'; export PGTZ
378 PGDATESTYLE='Postgres,US'; export PGDATESTYLE
382 # Set up multibyte environment
385 if [ -n "$multibyte" ]; then
386 PGCLIENTENCODING=$multibyte
387 export PGCLIENTENCODING
388 encoding_opt="-E $multibyte"
390 unset PGCLIENTENCODING
395 # Create the regression database
398 message "creating database \"$dbname\""
399 "$bindir/createdb" $encoding_opt $psql_options "$dbname"
400 if [ $? -ne 0 ]; then
401 echo "$me: createdb failed"
407 # Install the PL/pgSQL language in it
410 if [ "$enable_shared" = yes ]; then
411 message "installing PL/pgSQL"
412 "$bindir/createlang" -L "$libdir" $psql_options plpgsql $dbname
413 if [ $? -ne 0 ] && [ $? -ne 2 ]; then
414 echo "$me: createlang failed"
424 message "running regression test queries"
426 if [ ! -d "$outputdir/results" ]; then
427 mkdir -p "$outputdir/results" || { (exit 2); exit; }
429 result_summary_file=$outputdir/regression.out
430 diff_file=$outputdir/regression.diffs
432 cat /dev/null >"$result_summary_file"
433 cat /dev/null >"$diff_file"
437 [ "$enable_shared" != yes ] && echo "ignore: plpgsql"
439 for x in $extra_tests; do
442 ) | sed 's/[ ]*#.*//g' | \
447 [ -z "$line" ] && continue
451 if [ x"$1" = x"ignore:" ]; then
453 ignore_list="$ignore_list $@"
455 elif [ x"$1" != x"test:" ]; then
456 echo "$me:$schedule:$lno: syntax error"
466 if [ $# -eq 1 ]; then
468 formatted=`echo $1 | awk '{printf "%-20.20s", $1;}'`
469 $ECHO_N "test $formatted ... $ECHO_C"
471 $PSQL -d "$dbname" <"$inputdir/sql/$1.sql" >"$outputdir/results/$1.out" 2>&1
473 # Start a parallel group
474 $ECHO_N "parallel group ($# tests): $ECHO_C"
476 ( $PSQL -d $dbname <"$inputdir/sql/$name.sql" >"$outputdir/results/$name.out" 2>&1
477 $ECHO_N " $name$ECHO_C"
486 # (We do not want to run the diffs immediately after each test,
487 # because they would certainly get corrupted if run in parallel
492 if [ $# -ne 1 ]; then
493 formatted=`echo "$name" | awk '{printf "%-20.20s", $1;}'`
494 $ECHO_N " $formatted ... $ECHO_C"
497 # Check list extracted from resultmap to see if we should compare
498 # to a system-specific expected file.
499 # There shouldn't be multiple matches, but take the last if there are.
501 EXPECTED="$inputdir/expected/${name}.out"
502 for LINE in $SUBSTLIST
504 if [ `expr "$LINE" : "$name="` -ne 0 ]
506 SUBST=`echo "$LINE" | sed 's/^.*=//'`
507 EXPECTED="$inputdir/expected/${SUBST}.out"
511 diff $DIFFFLAGS $EXPECTED $outputdir/results/${name}.out >/dev/null 2>&1
516 ( diff $DIFFFLAGS -C3 $EXPECTED $outputdir/results/${name}.out
518 echo "======================================================================"
519 echo ) >> "$diff_file"
520 if echo " $ignore_list " | grep " $name " >/dev/null 2>&1 ; then
521 echo "failed (ignored)"
532 done | tee "$result_summary_file" 2>&1
540 if [ -n "$postmaster_pid" ]; then
541 message "shutting down postmaster"
542 kill -15 "$postmaster_pid"
553 count_total=`cat "$result_summary_file" | grep '\.\.\.' | wc -l | sed 's/ //g'`
554 count_ok=`cat "$result_summary_file" | grep '\.\.\. ok' | wc -l | sed 's/ //g'`
555 count_failed=`cat "$result_summary_file" | grep '\.\.\. FAILED' | wc -l | sed 's/ //g'`
556 count_ignored=`cat "$result_summary_file" | grep '\.\.\. failed (ignored)' | wc -l | sed 's/ //g'`
559 if [ $count_total -eq $count_ok ]; then
560 msg="All $count_total tests passed."
562 elif [ $count_failed -eq 0 ]; then
563 msg="$count_ok of $count_total tests passed, $count_ignored failed test(s) ignored."
565 elif [ $count_ignored -eq 0 ]; then
566 msg="$count_failed of $count_total tests failed."
569 msg="$count_failed of $count_total tests failed, $count_ignored failed test(s) ignored."
573 dashes=`echo " $msg " | sed 's/./=/g'`
579 if [ -s "$diff_file" ]; then
580 echo "The differences that caused some tests to fail can be viewed in the"
581 echo "file \`$diff_file'. A copy of the test summary that you see"
582 echo "above is saved in the file \`$result_summary_file'."
585 rm -f "$diff_file" "$result_summary_file"