2 # $Header: /cvsroot/pgsql/src/test/regress/Attic/pg_regress.sh,v 1.2 2000/10/01 22:23:14 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_triple@'
85 hostname=`hostname` || hostname=localhost
89 # Parse command line options
99 echo "pg_regress (PostgreSQL @VERSION@)"
105 inputdir=`expr "x$1" : "x--inputdir=\(.*\)"`
108 multibyte=`expr "x$1" : "x--multibyte=\(.*\)"`
111 temp_install=./tmp_check
114 temp_install=`expr "x$1" : "x--temp-install=\(.*\)"`
117 outputdir=`expr "x$1" : "x--outputdir=\(.*\)"`
120 foo=`expr "x$1" : "x--schedule=\(.*\)"`
121 schedule="$schedule $foo"
124 top_builddir=`expr "x$1" : "x--top-builddir=\(.*\)"`
127 PGHOST=`expr "x$1" : "x--host=\(.*\)"`
130 PGPORT=`expr "x$1" : "x--port=\(.*\)"`
133 PGUSER=`expr "x$1" : "x--user=\(.*\)"`
137 echo "$me: invalid argument $1" 1>&2
140 extra_tests="$extra_tests $1"
147 # When on Windows or QNX, don't use Unix sockets.
150 case $host_platform in
151 *-*-cygwin* | *-*-qnx*)
157 [ "$unix_sockets" = no ] && psql_options="$psql_options -h $PGHOST"
161 # Set up diff to ignore horizontal white space differences.
164 case $host_platform in
173 # Set backend timezone and datestyle explicitly
175 # To pass the horology test in its current form, the postmaster must be
176 # started with PGDATESTYLE=ISO, while the frontend must be started with
177 # PGDATESTYLE=Postgres. We set the postmaster values here and change
178 # to the frontend settings after the postmaster has been started.
181 PGTZ='PST8PDT'; export PGTZ
182 PGDATESTYLE='ISO,US'; export PGDATESTYLE
186 # Exit trap to remove temp file and shut down postmaster
189 # Note: There are some stupid shells (even among recent ones) that
190 # ignore the argument to exit (as in `exit 1') if there is an exit
191 # trap. The trap (and thus the shell script) will then always exit
192 # with the result of the last shell command before the `exit'. Hence
193 # we have to write `(exit x); exit' below this point.
197 if [ -n "$postmaster_pid" ]; then
198 kill -2 "$postmaster_pid"
199 wait "$postmaster_pid"
202 rm -f "$TMPFILE" && exit $savestatus
207 echo; echo "caught signal"
208 if [ -n "$postmaster_pid" ]; then
209 echo "signalling fast shutdown to postmaster with pid $postmaster_pid"
210 kill -2 "$postmaster_pid"
211 wait "$postmaster_pid"
214 (exit $savestatus); exit
220 # Scan resultmap file to find which platform-specific expected files to use.
221 # The format of each line of the file is
222 # testname/hostplatformpattern=substitutefile
223 # where the hostplatformpattern is evaluated per the rules of expr(1),
224 # namely, it is a standard regular expression with an implicit ^ at the start.
226 # The tempfile hackery is needed because some shells will run the loop
227 # inside a subshell, whereupon shell variables set therein aren't seen
228 # outside the loop :-(
231 cat /dev/null >$TMPFILE
234 HOSTPAT=`expr "$LINE" : '.*/\(.*\)='`
235 if [ `expr "$host_platform" : "$HOSTPAT"` -ne 0 ]
237 # remove hostnamepattern from line so that there are no shell
238 # wildcards in SUBSTLIST; else later 'for' could expand them!
239 TESTNAME=`expr "$LINE" : '\(.*\)/'`
240 SUBST=`echo "$LINE" | sed 's/^.*=//'`
241 echo "$TESTNAME=$SUBST" >> $TMPFILE
243 done <"$inputdir/resultmap"
244 SUBSTLIST=`cat $TMPFILE`
248 LOGDIR=$outputdir/log
250 if [ x"$temp_install" != x"" ]
252 if echo x"$temp_install" | grep -v '^x/' >/dev/null 2>&1; then
253 temp_install="`pwd`/$temp_install"
256 bindir=$temp_install/$bindir
257 libdir=$temp_install/$libdir
258 datadir=$temp_install/$datadir
259 PGDATA=$temp_install/data
264 # Set up shared library paths, needed by psql and pg_encoding
265 # (if you run multibyte). LD_LIBRARY_PATH covers many platforms,
266 # feel free to account for others as well.
269 if [ -n "$LD_LIBRARY_PATH" ]; then
270 LD_LIBRARY_PATH="$libdir:$LD_LIBRARY_PATH"
272 LD_LIBRARY_PATH=$libdir
274 export LD_LIBRARY_PATH
277 if [ -d "$temp_install" ]; then
278 message "removing existing temp installation"
279 rm -rf "$temp_install"
282 message "creating temporary installation"
283 mkdir -p "$LOGDIR" || { (exit 2); exit; }
284 ${MAKE:-gmake} -C "$top_builddir" DESTDIR="$temp_install" install >"$LOGDIR/install.log" 2>&1
289 echo "$me: installation failed"
290 echo "Examine $LOGDIR/install.log for the reason."
296 message "initializing database system"
297 [ "$debug" = yes ] && initdb_options='--debug'
298 "$bindir/initdb" -D "$PGDATA" -L "$datadir" --noclean $initdb_options >"$LOGDIR/initdb.log" 2>&1
303 echo "$me: initdb failed"
304 echo "Examine $LOGDIR/initdb.log for the reason."
314 message "starting postmaster"
315 [ "$debug" = yes ] && postmaster_options="$postmaster_options -d 5"
316 [ "$unix_sockets" = no ] && postmaster_options="$postmaster_options -i"
317 "$bindir/postmaster" -D "$PGDATA" -p "$PGPORT" -F $postmaster_options >"$LOGDIR/postmaster.log" 2>&1 &
320 if kill -0 $postmaster_pid >/dev/null 2>&1
322 echo "running on port $PGPORT with pid $postmaster_pid"
325 echo "$me: postmaster did not start"
326 echo "Examine $LOGDIR/postmaster.log for the reason."
331 # give postmaster some time to pass WAL recovery
334 else # not temp-install
336 if [ -n "$PGHOST" ]; then
337 echo "(using postmaster on $PGHOST at port $PGPORT)"
339 echo "(using postmaster on Unix socket with port $PGPORT)"
341 message "dropping database \"$dbname\""
342 "$bindir/dropdb" -p "$PGPORT" $psql_options "$dbname" >/dev/null 2>&1
343 # errors can be ignored
348 # Set up SQL shell for the test.
351 PSQL="$bindir/psql -a -q -X $psql_options -p $PGPORT"
355 # Set frontend timezone and datestyle explicitly
358 PGTZ='PST8PDT'; export PGTZ
359 PGDATESTYLE='Postgres,US'; export PGDATESTYLE
363 # Set up multibyte environment
366 if [ -n "$multibyte" ]; then
367 PGCLIENTENCODING=$multibyte
368 export PGCLIENTENCODING
369 encoding_opt="-E $multibyte"
371 unset PGCLIENTENCODING
376 # Create the regression database
379 message "creating database \"$dbname\""
380 "$bindir/createdb" -p "$PGPORT" $encoding_opt $psql_options "$dbname"
381 if [ $? -ne 0 ]; then
382 echo "$me: createdb failed"
388 # Install the PL/pgSQL language in it
391 case $host_platform in
394 message "installing PL/pgSQL"
395 "$bindir/createlang" -p "$PGPORT" -L "$libdir" $psql_options plpgsql $dbname
396 if [ $? -ne 0 ] && [ $? -ne 2 ]; then
397 echo "$me: createlang failed"
408 message "running regression test queries"
410 mkdir -p "$outputdir/results" || { (exit 2); exit; }
411 result_summary_file=$outputdir/regression.out
412 diff_file=$outputdir/regression.diffs
414 cat /dev/null >"$result_summary_file"
415 cat /dev/null >"$diff_file"
420 for x in $extra_tests; do
423 ) | sed 's/[ ]*#.*//g' | \
428 [ -z "$line" ] && continue
432 if [ x"$1" = x"ignore:" ]; then
434 ignore_list="$ignore_list $@"
436 elif [ x"$1" != x"test:" ]; then
437 echo "$me:$schedule:$lno: syntax error"
447 if [ $# -eq 1 ]; then
449 formatted=`echo $1 | awk '{printf "%-20.20s", $1;}'`
450 $ECHO_N "test $formatted ... " $ECHO_C
452 $PSQL -d "$dbname" <"$inputdir/sql/$1.sql" >"$outputdir/results/$1.out" 2>&1
454 # Start a parallel group
455 $ECHO_N "parallel group ($# tests): " $ECHO_C
457 ( $PSQL -d $dbname <"$inputdir/sql/$name.sql" >"$outputdir/results/$name.out" 2>&1
458 $ECHO_N " $name" $ECHO_C
467 # (We do not want to run the diffs immediately after each test,
468 # because they would certainly get corrupted if run in parallel
473 if [ $# -ne 1 ]; then
474 formatted=`echo "$name" | awk '{printf "%-20.20s", $1;}'`
475 $ECHO_N " $formatted ... " $ECHO_C
478 # Check list extracted from resultmap to see if we should compare
479 # to a system-specific expected file.
480 # There shouldn't be multiple matches, but take the last if there are.
482 EXPECTED="$inputdir/expected/${name}.out"
483 for LINE in $SUBSTLIST
485 if [ `expr "$LINE" : "$name="` -ne 0 ]
487 SUBST=`echo "$LINE" | sed 's/^.*=//'`
488 EXPECTED="$inputdir/expected/${SUBST}.out"
492 diff $DIFFFLAGS $EXPECTED $outputdir/results/${name}.out >/dev/null 2>&1
497 ( diff $DIFFFLAGS -C3 $EXPECTED $outputdir/results/${name}.out
499 echo "======================================================================"
500 echo ) >> "$diff_file"
501 if echo " $ignore_list " | grep " $name " >/dev/null 2>&1 ; then
502 echo "failed (ignored)"
513 done | tee "$result_summary_file" 2>&1
521 if [ -n "$postmaster_pid" ]; then
522 message "shutting down postmaster"
523 kill -15 "$postmaster_pid"
534 count_total=`cat "$result_summary_file" | grep '\.\.\.' | wc -l | sed 's/ //g'`
535 count_ok=`cat "$result_summary_file" | grep '\.\.\. ok' | wc -l | sed 's/ //g'`
536 count_failed=`cat "$result_summary_file" | grep '\.\.\. FAILED' | wc -l | sed 's/ //g'`
537 count_ignored=`cat "$result_summary_file" | grep '\.\.\. failed (ignored)' | wc -l | sed 's/ //g'`
540 if [ $count_total -eq $count_ok ]; then
541 msg="All $count_total tests passed."
543 elif [ $count_failed -eq 0 ]; then
544 msg="$count_ok of $count_total tests passed, $count_ignored failed test(s) ignored."
546 elif [ $count_ignored -eq 0 ]; then
547 msg="$count_failed of $count_total tests failed."
550 msg="$count_failed of $count_total tests failed, $count_ignored failed test(s) ignored."
554 dashes=`echo " $msg " | sed 's/./=/g'`
560 if [ -s "$diff_file" ]; then
561 echo "The differences that caused some tests to fail can be viewed in the"
562 echo "file \`$diff_file'. A copy of the test summary that you see"
563 echo "above is saved in the file \`$result_summary_file'."
566 rm -f "$diff_file" "$result_summary_file"