]> granicus.if.org Git - postgresql/blobdiff - src/test/regress/pg_regress.sh
copydir() and rmtree() need to use lstat, not stat, to behave as expected
[postgresql] / src / test / regress / pg_regress.sh
index cf45f73ae4fc2e2fbba1123d56eaeefec6053a05..f56b737d0bcb5dd74f787e6ad413a0d82c745007 100644 (file)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $PostgreSQL: pgsql/src/test/regress/pg_regress.sh,v 1.50 2004/11/17 18:06:04 tgl Exp $
+# $PostgreSQL: pgsql/src/test/regress/pg_regress.sh,v 1.65 2006/07/18 00:32:41 tgl Exp $
 
 me=`basename $0`
 : ${TMPDIR=/tmp}
@@ -11,8 +11,11 @@ PostgreSQL regression test driver
 Usage: $me [options...] [extra tests...]
 
 Options:
+  --dbname=DB               use database DB (default \`regression')
   --debug                   turn on debug mode in programs that are run
   --inputdir=DIR            take input files from DIR (default \`.')
+  --load-language=lang      load the named language before running the
+                            tests; can appear multiple times
   --max-connections=N       maximum number of concurrent connections
                             (default is 0 meaning unlimited)
   --multibyte=ENCODING      use ENCODING as the multibyte encoding, and
@@ -21,9 +24,11 @@ Options:
   --schedule=FILE           use test ordering schedule from FILE
                             (may be used multiple times to concatenate)
   --temp-install[=DIR]      create a temporary installation (in DIR)
+  --no-locale               use C locale
 
 Options for \`temp-install' mode:
   --top-builddir=DIR        (relative) path to top level build directory
+  --temp-port=PORT          port number to start temp postmaster on
 
 Options for using an existing installation:
   --host=HOST               use postmaster running on HOST
@@ -80,7 +85,6 @@ fi
 : ${outputdir=.}
 
 libdir='@libdir@'
-pkglibdir='@pkglibdir@'
 bindir='@bindir@'
 datadir='@datadir@'
 host_platform='@host_tuple@'
@@ -96,6 +100,7 @@ fi
 unset mode
 unset schedule
 unset debug
+unset nolocale
 unset top_builddir
 unset temp_install
 unset multibyte
@@ -103,6 +108,8 @@ unset multibyte
 dbname=regression
 hostname=localhost
 maxconnections=0
+temp_port=65432
+load_langs=""
 
 : ${GMAKE='@GMAKE@'}
 
@@ -120,15 +127,26 @@ do
         --version)
                 echo "pg_regress (PostgreSQL @VERSION@)"
                 exit 0;;
+        --dbname=*)
+                dbname=`expr "x$1" : "x--dbname=\(.*\)"`
+                shift;;
         --debug)
                 debug=yes
                 shift;;
         --inputdir=*)
                 inputdir=`expr "x$1" : "x--inputdir=\(.*\)"`
                 shift;;
+        --load-language=*)
+                lang=`expr "x$1" : "x--load-language=\(.*\)"`
+                load_langs="$load_langs $lang"
+                unset lang
+                shift;;
         --multibyte=*)
                 multibyte=`expr "x$1" : "x--multibyte=\(.*\)"`
                 shift;;
+        --no-locale)
+                nolocale=yes
+                shift;;
         --temp-install)
                 temp_install=./tmp_check
                 shift;;
@@ -148,6 +166,9 @@ do
         --top-builddir=*)
                 top_builddir=`expr "x$1" : "x--top-builddir=\(.*\)"`
                 shift;;
+        --temp-port=*)
+                temp_port=`expr "x$1" : "x--temp-port=\(.*\)"`
+                shift;;
         --host=*)
                 PGHOST=`expr "x$1" : "x--host=\(.*\)"`
                 export PGHOST
@@ -192,11 +213,10 @@ esac
 
 
 # ----------
-# When on QNX or BeOS, don't use Unix sockets.
+# On some platforms we can't use Unix sockets.
 # ----------
-
 case $host_platform in
-    *-*-qnx* | *beos*)
+    *-*-cygwin* | *-*-mingw32*)
         unix_sockets=no;;
     *)
         unix_sockets=yes;;
@@ -208,7 +228,7 @@ esac
 # ----------
 
 case $host_platform in
-    *-*-qnx* | *-*-sco3.2v5*)
+    *-*-sco3.2v5*)
         DIFFFLAGS=-b;;
     *)
         DIFFFLAGS=-w;;
@@ -238,18 +258,20 @@ PGDATESTYLE='ISO, MDY'; export PGDATESTYLE
 # with the result of the last shell command before the `exit'.  Hence
 # we have to write `(exit x); exit' below this point.
 
-trap '
-    savestatus=$?
+exit_trap(){ 
+    savestatus=$1
     if [ -n "$postmaster_pid" ]; then
         kill -2 "$postmaster_pid"
         wait "$postmaster_pid"
         unset postmaster_pid
     fi
     rm -f "$TMPFILE" && exit $savestatus
-' 0
+}
 
-trap '
-    savestatus=$?
+trap 'exit_trap $?' 0
+
+sig_trap() {
+    savestatus=$1
     echo; echo "caught signal"
     if [ -n "$postmaster_pid" ]; then
         echo "signalling fast shutdown to postmaster with pid $postmaster_pid"
@@ -258,7 +280,9 @@ trap '
         unset postmaster_pid
     fi
     (exit $savestatus); exit
-' 1 2 13 15
+}
+
+trap 'sig_trap $?' 1 2 13 15
 
 
 
@@ -302,16 +326,7 @@ LOGDIR=$outputdir/log
 if [ x"$temp_install" != x"" ]
 then
     if echo x"$temp_install" | grep -v '^x/' >/dev/null 2>&1; then
-        case $host_platform in
-          *-*-mingw32*)
-                pkglibdir="`pwd -W`/$temp_install/install/$pkglibdir"
-                 temp_install="`pwd`/$temp_install"
-                ;;
-          *)
-                temp_install="`pwd`/$temp_install"
-                pkglibdir=$temp_install/install/$pkglibdir
-                ;;
-        esac
+        temp_install="`pwd`/$temp_install"
     fi
 
     bindir=$temp_install/install/$bindir
@@ -327,7 +342,13 @@ then
         unset PGHOST
         unset PGHOSTADDR
     fi
-    PGPORT=65432
+
+    # since Makefile isn't very bright, check for out-of-range temp_port
+    if [ "$temp_port" -ge 1024 -a "$temp_port" -le 65535 ] ; then
+       PGPORT=$temp_port
+    else
+       PGPORT=65432
+    fi
     export PGPORT
 
     # Get rid of environment stuff that might cause psql to misbehave
@@ -386,15 +407,9 @@ then
         (exit 2); exit
     fi
 
-    # fix conversion shared objs path
-    conv=$datadir/conversion_create.sql
-    backup=$conv.bak
-    mv $conv $backup
-    sed -e "s@\$libdir@$pkglibdir@g" $backup > $conv
-    rm $backup
-
     message "initializing database system"
-    [ "$debug" = yes ] && initdb_options='--debug'
+    [ "$debug" = yes ] && initdb_options="--debug"
+    [ "$nolocale" = yes ] && initdb_options="$initdb_options --no-locale"
     "$bindir/initdb" -D "$PGDATA" -L "$datadir" --noclean $initdb_options >"$LOGDIR/initdb.log" 2>&1
 
     if [ $? -ne 0 ]
@@ -413,7 +428,11 @@ then
 
     message "starting postmaster"
     [ "$debug" = yes ] && postmaster_options="$postmaster_options -d 5"
-    [ "$unix_sockets" = no ] && postmaster_options="$postmaster_options -i"
+    if [ "$unix_sockets" = no ]; then
+        postmaster_options="$postmaster_options -c listen_addresses=$hostname"
+    else
+        postmaster_options="$postmaster_options -c listen_addresses="
+    fi
     "$bindir/postmaster" -D "$PGDATA" -F $postmaster_options >"$LOGDIR/postmaster.log" 2>&1 &
     postmaster_pid=$!
 
@@ -422,7 +441,7 @@ then
     # wait forever, however.
     i=0
     max=60
-    until "$bindir/psql" -X $psql_options template1 </dev/null 2>/dev/null
+    until "$bindir/psql" -X $psql_options postgres </dev/null 2>/dev/null
     do
         i=`expr $i + 1`
         if [ $i -ge $max ]
@@ -462,13 +481,6 @@ else # not temp-install
             ;;
     esac
 
-    # If Unix sockets are not available, use the local host by default.
-    if [ "$unix_sockets" = no ]; then
-        PGHOST=$hostname
-        export PGHOST
-        unset PGHOSTADDR
-    fi
-
     if [ -n "$PGPORT" ]; then
         port_info="port $PGPORT"
     else
@@ -478,15 +490,13 @@ else # not temp-install
     if [ -n "$PGHOST" ]; then
         echo "(using postmaster on $PGHOST, $port_info)"
     else
-        case $host_platform in
-            *-*-mingw32*)
-                echo "(using postmaster on localhost socket, $port_info)"
-                ;;
-            *)
-                echo "(using postmaster on Unix socket, $port_info)"
-                ;;
-        esac
+        if [ "$unix_sockets" = no ]; then
+            echo "(using postmaster on localhost, $port_info)"
+        else
+            echo "(using postmaster on Unix socket, $port_info)"
+        fi
     fi
+
     message "dropping database \"$dbname\""
     "$bindir/dropdb" $psql_options "$dbname"
     # errors can be ignored
@@ -497,7 +507,7 @@ fi
 # Set up SQL shell for the test.
 # ----------
 
-PSQL="$bindir/psql -a -q -X $psql_options"
+psql_test_options="-a -q -X $psql_options"
 
 
 # ----------
@@ -525,9 +535,6 @@ fi
 # Create the regression database
 # We use template0 so that any installation-local cruft in template1
 # will not mess up the tests.
-# Note: the reason for checkpointing just after creating the new DB is so
-# that if we get a backend core dump during the tests, WAL replay won't
-# remove the core file.
 # ----------
 
 message "creating database \"$dbname\""
@@ -538,7 +545,6 @@ if [ $? -ne 0 ]; then
 fi
 
 "$bindir/psql" -q -X $psql_options -c "\
-checkpoint;
 alter database \"$dbname\" set lc_messages to 'C';
 alter database \"$dbname\" set lc_monetary to 'C';
 alter database \"$dbname\" set lc_numeric to 'C';
@@ -550,28 +556,20 @@ fi
 
 
 # ----------
-# Remove regressuser* and regressgroup* user accounts.
-# ----------
-
-message "dropping regression test user accounts"
-"$bindir/psql" -q -X $psql_options -c 'DROP GROUP regressgroup1; DROP GROUP regressgroup2; DROP USER regressuser1, regressuser2, regressuser3, regressuser4;' $dbname 2>/dev/null
-if [ $? -eq 2 ]; then
-    echo "$me: could not drop user accounts"
-    (exit 2); exit
-fi
-
-
-# ----------
-# Install the PL/pgSQL language in it
+# Install any requested PL languages
 # ----------
 
 if [ "$enable_shared" = yes ]; then
-        message "installing PL/pgSQL"
-        "$bindir/createlang" -L "$pkglibdir" $psql_options plpgsql $dbname
-        if [ $? -ne 0 ] && [ $? -ne 2 ]; then
-            echo "$me: createlang failed"
-            (exit 2); exit
+    for lang in xyzzy $load_langs ; do    
+        if [ "$lang" != "xyzzy" ]; then
+            message "installing $lang"
+            "$bindir/createlang" $psql_options $lang $dbname
+            if [ $? -ne 0 ] && [ $? -ne 2 ]; then
+                echo "$me: createlang $lang failed"
+                (exit 2); exit
+            fi
         fi
+    done
 fi
 
 
@@ -625,8 +623,8 @@ do
         # Run a single test
         formatted=`echo $1 | awk '{printf "%-20.20s", $1;}'`
         $ECHO_N "test $formatted ... $ECHO_C"
-        ( $PSQL -d "$dbname" <"$inputdir/sql/$1.sql" >"$outputdir/results/$1.out" 2>&1 )&
-       wait
+        ( "$bindir/psql" $psql_test_options -d "$dbname" <"$inputdir/sql/$1.sql" >"$outputdir/results/$1.out" 2>&1 )&
+        wait
     else
         # Start a parallel group
         $ECHO_N "parallel group ($# tests): $ECHO_C"
@@ -636,7 +634,7 @@ do
         fi
         for name do
             ( 
-              $PSQL -d "$dbname" <"$inputdir/sql/$name.sql" >"$outputdir/results/$name.out" 2>&1
+              "$bindir/psql" $psql_test_options -d "$dbname" <"$inputdir/sql/$name.sql" >"$outputdir/results/$name.out" 2>&1
               $ECHO_N " $name$ECHO_C"
             ) &
             if [ $maxconnections -gt 0 ] ; then