Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxgsV-0006qX-9C for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Dec 2021 02:52:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mxgsU-0007aL-1q for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Dec 2021 02:52:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxgsS-0007aB-1K for pgsql-hackers@lists.postgresql.org; Thu, 16 Dec 2021 02:52:17 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxgsM-0005y0-Dz for pgsql-hackers@lists.postgresql.org; Thu, 16 Dec 2021 02:52:15 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 62E0F32009DB; Wed, 15 Dec 2021 21:52:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 15 Dec 2021 21:52:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=xUhmvgmiAeKUYgaiYS2ayZiK8+F abZ/hKsHUGkvzS80=; b=nwYA0vdrIGVjmdqlGI0a1mt4NkKMkKtncOdpdW8hsGv 0zJIWkoQ5M0dVS3/rV+XZ79eTksffy5r4yJ6DR81A5PUe0KytIANoZiXf5tpfzP/ luZTMZC/c+SzvehduxXRBEzOoW/+JJYzX4XEJS+1xIFkg5QG5Ts1pexbLy9W9sPv 3MKfDHcBkO8WFKY5TMILysbmix+LfB+E2jUr708I4fLdoaiAkpGqNwBuXpia4o/W G8ivQMN4Pk2vNGmv0VnlAMgm0Laq7x6NdCk0/59wHh00ZMM0Th71ZvoWnc6ctxZs QNh2rJsNK0laB4OaZGm4Ic3M1a1xbbEmrhAvVhTl/1g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=xUhmvg miAeKUYgaiYS2ayZiK8+FabZ/hKsHUGkvzS80=; b=G9oWqFc59p3Xd1DNIJnCOI 8zX8HEDmJNGu8/Yff8VhhaaMpH+Te/CHVoBW5v5kfz0xI5UdcNg3zorJDlCr+Q98 7UEYQiY0cL3lCEX0lHaqI8USE6hIJtWYyAbxp09s5Ze+wnWTc5yRp37fnExfOupg +jSkdxUxqTmsEB2eeMQXixI3BGbl4p3Er2nxm3F4VlcE+xZChnoVJgEkpymJK3WT EY1YaRDV4EDUqkXtEkVgPc/K3pjb83IxayxDc9p0S08wGle/S++h5a33dK8x5IoX RrLB16PzlQaKrN75eyIGK7LExj9M97wkuJ3GGWTOBAkCg6MBJhG/Opkl1dth1xew == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrleefgdegkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepvdegudeuhfdtueeltedtveejheeh ieevueeigeelteegleejleeiueeiheegvefhnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Dec 2021 21:52:03 -0500 (EST) Date: Thu, 16 Dec 2021 11:51:55 +0900 From: Michael Paquier To: Andres Freund Cc: Tom Lane , Andrew Dunstan , Postgres hackers Subject: Re: Rewriting the test of pg_upgrade as a TAP test - take three - remastered set Message-ID: References: <3715954.1633208613@sss.pgh.pa.us> <0f70fc0f-c51a-7a58-7e12-c702352eb076@dunslane.net> <3735235.1633232078@sss.pgh.pa.us> <20211214020824.azjrighbeucby5yc@alap3.anarazel.de> <20211214061449.ynrygtcddn3ujunn@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7x7Ylkv9O/YZ9xLG" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --7x7Ylkv9O/YZ9xLG Content-Type: multipart/mixed; boundary="n9enehHYNtT8vR9U" Content-Disposition: inline --n9enehHYNtT8vR9U Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Dec 15, 2021 at 10:47:24AM +0900, Michael Paquier wrote: > Missed that, thanks! I'll think about all that a bit more before > sending a long-overdue rebased version. Okay, here is finally a rebase of this patch, where I have fixed a couple of existing issues, and I have extended the patch to the point where the support range is what I expect should be. In short: - Added support for MSVC for the TAP test. I have considered making upgradecheck silent, but after thinking about it I have just filtered pg_upgrade from bincheck, and simplified upgradecheck to launch the new test. It is simple to switch from one approach to another. This shaves some code in vcregress.pl. - Fixed a set of issues with various chdir commands in the previous patches. The command of pg_regress has been tweaked so as all results are part of src/bin/pg_upgrade/. Any logs generated by pg_upgrade stay in this location, same way as HEAD. - Adapted to the new modules of src/test/perl/. - Support for cross-upgrades now uses upgrade_adapt.sql (I have sent a patch for the buildfarm client about that yesterday actually), same way as test.sh on HEAD. Like HEAD, attempting to use the cross-version HEAD causes diffs between the old and the new dumps. But there is nothing new here. This could be improved more but the attached does already a lot.=20 - Like the previous versions, this supports two modes when setting up the to-be-upgraded cluster: setup things from an old dump or use pg_regress. The buildfarm does the former for upgrades down to 9.2. The core code does the latter. I may have missed one thing or two, but I think that's pretty much what we should be looking for to do the switch to TAP in terms of coverage. -- Michael --n9enehHYNtT8vR9U Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0001-Switch-tests-of-pg_upgrade-to-use-TAP.patch" Content-Transfer-Encoding: quoted-printable =46rom 47fcfac534f947595a880eacdbcfe4f8bd6af516 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Thu, 16 Dec 2021 11:50:54 +0900 Subject: [PATCH v4] Switch tests of pg_upgrade to use TAP --- src/bin/pg_upgrade/.gitignore | 5 + src/bin/pg_upgrade/Makefile | 23 +- src/bin/pg_upgrade/TESTING | 33 ++- src/bin/pg_upgrade/t/001_basic.pl | 9 + src/bin/pg_upgrade/t/002_pg_upgrade.pl | 275 ++++++++++++++++++++++ src/bin/pg_upgrade/test.sh | 279 ----------------------- src/test/perl/PostgreSQL/Test/Cluster.pm | 25 ++ src/tools/msvc/vcregress.pl | 91 +------- 8 files changed, 355 insertions(+), 385 deletions(-) create mode 100644 src/bin/pg_upgrade/t/001_basic.pl create mode 100644 src/bin/pg_upgrade/t/002_pg_upgrade.pl delete mode 100644 src/bin/pg_upgrade/test.sh diff --git a/src/bin/pg_upgrade/.gitignore b/src/bin/pg_upgrade/.gitignore index 2d3bfeaa50..3b64522ab6 100644 --- a/src/bin/pg_upgrade/.gitignore +++ b/src/bin/pg_upgrade/.gitignore @@ -7,3 +7,8 @@ /loadable_libraries.txt /log/ /tmp_check/ + +# Generated by pg_regress +/sql/ +/expected/ +/results/ diff --git a/src/bin/pg_upgrade/Makefile b/src/bin/pg_upgrade/Makefile index 44d06be5a6..35b6c123a5 100644 --- a/src/bin/pg_upgrade/Makefile +++ b/src/bin/pg_upgrade/Makefile @@ -28,6 +28,12 @@ OBJS =3D \ override CPPFLAGS :=3D -DDLSUFFIX=3D\"$(DLSUFFIX)\" -I$(srcdir) -I$(libpq_= srcdir) $(CPPFLAGS) LDFLAGS_INTERNAL +=3D -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_p= gport) =20 +# required for 002_pg_upgrade.pl +REGRESS_SHLIB=3D$(abs_top_builddir)/src/test/regress/regress$(DLSUFFIX) +export REGRESS_SHLIB +REGRESS_OUTPUTDIR=3D$(abs_top_builddir)/src/bin/pg_upgrade +export REGRESS_OUTPUTDIR + all: pg_upgrade =20 pg_upgrade: $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils @@ -49,17 +55,8 @@ clean distclean maintainer-clean: pg_upgrade_dump_globals.sql \ pg_upgrade_dump_*.custom pg_upgrade_*.log =20 -# When $(MAKE) is present, make automatically infers that this is a -# recursive make. which is not actually what we want here, as that -# e.g. prevents output synchronization from working (as make thinks -# that the subsidiary make knows how to deal with that itself, but -# we're invoking a shell script that doesn't know). Referencing -# $(MAKE) indirectly avoids that behaviour. -# See https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.htm= l#MAKE-Variable -NOTSUBMAKEMAKE=3D$(MAKE) +check: + $(prove_check) =20 -check: test.sh all temp-install - MAKE=3D$(NOTSUBMAKEMAKE) $(with_temp_install) bindir=3D$(abs_top_builddir= )/tmp_install/$(bindir) EXTRA_REGRESS_OPTS=3D"$(EXTRA_REGRESS_OPTS)" $(SHEL= L) $< - -# installcheck is not supported because there's no meaningful way to test -# pg_upgrade against a single already-running server +installcheck: + $(prove_installcheck) diff --git a/src/bin/pg_upgrade/TESTING b/src/bin/pg_upgrade/TESTING index e69874b42d..acf769386a 100644 --- a/src/bin/pg_upgrade/TESTING +++ b/src/bin/pg_upgrade/TESTING @@ -2,21 +2,30 @@ THE SHORT VERSION ----------------- =20 On non-Windows machines, you can execute the testing process -described below by running +described below by running the following command in this directory: make check -in this directory. This will run the shell script test.sh, performing -an upgrade from the version in this source tree to a new instance of -the same version. =20 -To test an upgrade from a different version, you must have a built -source tree for the old version as well as this version, and you -must have done "make install" for both versions. Then do: +This will run the TAP tests to run pg_upgrade, performing an upgrade +from the version in this source tree to a new instance of the same +version. + +To test an upgrade from a different version, there are two options +available: + +1) You have a built source tree for the old version as well as this +version's binaries. Then set up the following variables before +launching the test: =20 export oldsrc=3D...somewhere/postgresql (old version's source tree) -export oldbindir=3D...otherversion/bin (old version's installed bin dir) -export bindir=3D...thisversion/bin (this version's installed bin dir) -export libdir=3D...thisversion/lib (this version's installed lib dir) -sh test.sh +export oldinstall=3D...otherversion/ (old version's install base path) + +2) You have a dump that can be used to set up the old version, as well +as this version's binaries. Then set up the following variables: +export olddump=3D...somewhere/dump.sql (old version's dump) +export oldinstall=3D...otherversion/ (old version's install base path) + +Finally, the tests can be done by running + make check =20 In this case, you will have to manually eyeball the resulting dump diff for version-specific differences, as explained below. @@ -87,3 +96,5 @@ steps: =20 7) Diff the regression database dump file with the regression dump file loaded into the old server. + +The generated dump may be reusable with "olddump", as defined above. diff --git a/src/bin/pg_upgrade/t/001_basic.pl b/src/bin/pg_upgrade/t/001_b= asic.pl new file mode 100644 index 0000000000..75b0f98b08 --- /dev/null +++ b/src/bin/pg_upgrade/t/001_basic.pl @@ -0,0 +1,9 @@ +use strict; +use warnings; + +use PostgreSQL::Test::Utils; +use Test::More tests =3D> 8; + +program_help_ok('pg_upgrade'); +program_version_ok('pg_upgrade'); +program_options_handling_ok('pg_upgrade'); diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl b/src/bin/pg_upgrade/t/= 002_pg_upgrade.pl new file mode 100644 index 0000000000..721741d0f8 --- /dev/null +++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl @@ -0,0 +1,275 @@ +# Set of tests for pg_upgrade, including cross-version checks. +use strict; +use warnings; + +use Cwd qw(abs_path getcwd); +use File::Basename qw(dirname); + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More tests =3D> 4; + +# Generate a database with a name made of a range of ASCII characters. +sub generate_db +{ + my ($node, $from_char, $to_char) =3D @_; + + my $dbname =3D ''; + for my $i ($from_char .. $to_char) + { + next if $i =3D=3D 7 || $i =3D=3D 10 || $i =3D=3D 13; # skip BEL, LF, = and CR + $dbname =3D $dbname . sprintf('%c', $i); + } + $node->run_log([ 'createdb', '--port', $node->port, $dbname ]); +} + +# From now on, the test of pg_upgrade consists in setting up an instance. +# This is the source instance used for the upgrade. Then a new and fresh +# instance is created, and is used as the target instance for the +# upgrade. Before running an upgrade a logical dump of the old instance +# is taken, and a second logical dump of the new instance is taken after +# the upgrade. The upgrade test passes if there are no differences after +# running pg_upgrade. + +# Testing upgrades with an older instance of PostgreSQL requires +# setting up two environment variables, among the following: +# - "oldsrc", to point to the code source of the older version. +# This is required to set up the old instance with pg_upgrade. +# - "olddump", to point to a dump file that will be used to set +# up the old instance to upgrade from. +# - "oldinstall", to point to the installation path of the older +# version. + +# "oldsrc" and "olddump" cannot be used together. Setting up +# "olddump" and "oldinstall" will use the dump pointed to to +# set up the old instance. If "oldsrc" is used instead of "olddump", +# the full set of regression tests of the old instance is run +# instead. + +if (defined($ENV{oldsrc}) && defined($ENV{olddump})) +{ + die "oldsrc and olddump are both defined"; +} +elsif (defined($ENV{oldsrc})) +{ + if ( (defined($ENV{oldsrc}) && !defined($ENV{oldinstall})) + || (!defined($ENV{oldsrc}) && defined($ENV{oldinstall}))) + { + # Not all variables are defined, so leave and die if test is + # done with an older installation. + die "oldsrc or oldinstall is undefined"; + } +} +elsif (defined($ENV{olddump})) +{ + if ( (defined($ENV{olddump}) && !defined($ENV{oldinstall})) + || (!defined($ENV{olddump}) && defined($ENV{oldinstall}))) + { + # Not all variables are defined, so leave and die if test is + # done with an older installation. + die "olddump or oldinstall is undefined"; + } +} + +if ((defined($ENV{oldsrc}) || defined($ENV{olddump})) && $windows_os) +{ + # This configuration is not supported on Windows, as regress.so + # location diverges across the compilation methods used on this + # platform. + die "No support for older version tests on Windows"; +} + +# Default is the location of this source code for both nodes used with +# the upgrade. +my $newsrc =3D abs_path("../../.."); +my $oldsrc =3D $ENV{oldsrc} || $newsrc; +$oldsrc =3D abs_path($oldsrc); + +# Temporary location for the dumps taken +my $tempdir =3D PostgreSQL::Test::Utils::tempdir; + +# Initialize node to upgrade +my $oldnode =3D PostgreSQL::Test::Cluster->new('old_node', + install_path =3D> $ENV{oldinstall}); + +$oldnode->init(extra =3D> [ '--locale', 'C', '--encoding', 'LATIN1' ]); +$oldnode->start; + +# Set up the data of the old instance with pg_regress or an old dump. +if (defined($ENV{olddump})) +{ + # Use the dump specified. + my $olddumpfile =3D $ENV{olddump}; + die "no dump file found!" unless -e $olddumpfile; + + # Load the dump, and we are done here. + $oldnode->command_ok( + [ + 'psql', '-X', '-f', $olddumpfile, + '--port', $oldnode->port, 'regression' + ]); +} +else +{ + # Default is to just use pg_regress to setup the old instance + # Creating databases with names covering most ASCII bytes + generate_db($oldnode, 1, 45); + generate_db($oldnode, 46, 90); + generate_db($oldnode, 91, 127); + + # Run core regression tests on the old instance. + $oldnode->run_log([ "createdb", '--port', $oldnode->port, 'regression' ]); + + # Grab any regression options that may be passed down by caller. + my $extra_opts_val =3D $ENV{EXTRA_REGRESS_OPT} || ""; + my @extra_opts =3D split(/\s+/, $extra_opts_val); + + # --dlpath is needed to be able to find the location of regress.so and + # any libraries the regression tests required. This needs to point to + # in the old instance when using it. In the default case, fallback to + # what the caller provided for REGRESS_SHLIB. + my $dlpath; + if (defined($ENV{oldinstall})) + { + $dlpath =3D "$oldsrc/src/test/regress"; + } + else + { + $dlpath =3D dirname($ENV{REGRESS_SHLIB}); + } + $dlpath =3D PostgreSQL::Test::Utils::perl2host($dlpath); + + # --outputdir points to the path where to place the output files, which + # had better be this directory. + my $outputdir =3D + PostgreSQL::Test::Utils::perl2host($ENV{REGRESS_OUTPUTDIR}); + + # --inputdir needs to point to the location of the input files, from the + # cluster to-be-upgraded. + my $inputdir =3D + PostgreSQL::Test::Utils::perl2host("$oldsrc/src/test/regress"); + + my @regress_command =3D [ + $ENV{PG_REGRESS}, '--make-testtablespace-dir', + '--schedule', "$oldsrc/src/test/regress/parallel_schedule", + '--bindir', $oldnode->config_data('--bindir'), + '--dlpath', $dlpath, + '--port', $oldnode->port, + '--outputdir', $outputdir, + '--inputdir', $inputdir, + '--use-existing' + ]; + @regress_command =3D (@regress_command, @extra_opts); + + $oldnode->command_ok(@regress_command, + 'regression test run on old instance'); +} + +# Before dumping, get rid of objects not existing or not supported in later +# versions. This depends on the version of the old server used, and matters +# only if different versions are used for the dump. +if (defined($ENV{oldinstall})) +{ + # Note that upgrade_adapt.sql from the new version is used, to + # cope with an upgrade to this version. + $oldnode->run_log( + [ + 'psql', '-X', '-f', + PostgreSQL::Test::Utils::perl2host( + "$newsrc/src/bin/pg_upgrade/upgrade_adapt.sql"), + '--port', + $oldnode->port, + 'regression' + ]); +} + +# Initialize a new node for the upgrade. This is done early so as it is +# possible to know with which node's PATH the initial dump needs to be +# taken. +my $newnode =3D PostgreSQL::Test::Cluster->new('new_node'); +$newnode->init(extra =3D> [ '--locale=3DC', '--encoding=3DLATIN1' ]); +my $newbindir =3D $newnode->config_data('--bindir'); +my $oldbindir =3D $oldnode->config_data('--bindir'); + +# Take a dump before performing the upgrade as a base comparison. Note +# that we need to use pg_dumpall from the new node here. +$newnode->command_ok( + [ + 'pg_dumpall', '--no-sync', + '-d', $oldnode->connstr('postgres'), + '-f', "$tempdir/dump1.sql" + ], + 'dump before running pg_upgrade'); + +# After dumping, update references to the old source tree's regress.so +# to point to the new tree. +if (defined($ENV{oldinstall})) +{ + # First, fetch all the references to libraries that are not part + # of the default path $libdir. + my $output =3D $oldnode->safe_psql('regression', + "SELECT DISTINCT probin::text FROM pg_proc WHERE probin NOT LIKE '\$libd= ir%';" + ); + chomp($output); + my @libpaths =3D split("\n", $output); + + my $dump_data =3D slurp_file("$tempdir/dump1.sql"); + + my $newregresssrc =3D "$newsrc/src/test/regress"; + foreach (@libpaths) + { + my $libpath =3D $_; + $libpath =3D dirname($libpath); + $dump_data =3D~ s/$libpath/$newregresssrc/g; + } + + open my $fh, ">", "$tempdir/dump1.sql" or die "could not open dump file"; + print $fh $dump_data; + close $fh; + + # This replaces any references to the old tree's regress.so + # the new tree's regress.so. Any references that do *not* + # match $libdir are switched so as this request does not + # depend on the path of the old source tree. This is useful + # when using an old dump. Do the operation on all the database + # that allow connections so as this includes the regression + # database and anything the user has set up. + $output =3D $oldnode->safe_psql('postgres', + "SELECT datname FROM pg_database WHERE datallowconn;"); + chomp($output); + my @datnames =3D split("\n", $output); + foreach (@datnames) + { + my $datname =3D $_; + $oldnode->safe_psql( + $datname, "UPDATE pg_proc SET probin =3D + regexp_replace(probin, '.*/', '$newregresssrc/') + WHERE probin NOT LIKE '\$libdir/%'"); + } +} + +# Update the instance. +$oldnode->stop; + +# Time for the real run. +$newnode->command_ok( + [ + 'pg_upgrade', '-d', $oldnode->data_dir, '-D', + $newnode->data_dir, '-b', $oldbindir, '-B', + $newbindir, '-p', $oldnode->port, '-P', + $newnode->port + ], + 'run of pg_upgrade for new instance'); +$newnode->start; + +# Take a second dump on the upgraded instance. +$newnode->run_log( + [ + 'pg_dumpall', '--no-sync', + '-d', $newnode->connstr('postgres'), + '-f', "$tempdir/dump2.sql" + ]); + +# Compare the two dumps, there should be no differences. +command_ok([ 'diff', '-q', "$tempdir/dump1.sql", "$tempdir/dump2.sql" ], + 'old and new dump match after pg_upgrade'); diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh deleted file mode 100644 index 32d186d897..0000000000 --- a/src/bin/pg_upgrade/test.sh +++ /dev/null @@ -1,279 +0,0 @@ -#!/bin/sh - -# src/bin/pg_upgrade/test.sh -# -# Test driver for pg_upgrade. Initializes a new database cluster, -# runs the regression tests (to put in some data), runs pg_dumpall, -# runs pg_upgrade, runs pg_dumpall again, compares the dumps. -# -# Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group -# Portions Copyright (c) 1994, Regents of the University of California - -set -e - -: ${MAKE=3Dmake} - -# Guard against parallel make issues (see comments in pg_regress.c) -unset MAKEFLAGS -unset MAKELEVEL - -# Run a given "initdb" binary and overlay the regression testing -# authentication configuration. -standard_initdb() { - # To increase coverage of non-standard segment size and group access - # without increasing test runtime, run these tests with a custom setting. - # Also, specify "-A trust" explicitly to suppress initdb's warning. - # --allow-group-access and --wal-segsize have been added in v11. - "$1" -N --wal-segsize 1 --allow-group-access -A trust - if [ -n "$TEMP_CONFIG" -a -r "$TEMP_CONFIG" ] - then - cat "$TEMP_CONFIG" >> "$PGDATA/postgresql.conf" - fi - ../../test/regress/pg_regress --config-auth "$PGDATA" -} - -# What flavor of host are we on? -# Treat MINGW* (msys1) and MSYS* (msys2) the same. -testhost=3D`uname -s | sed 's/^MSYS/MINGW/'` - -# Establish how the server will listen for connections -case $testhost in - MINGW*) - LISTEN_ADDRESSES=3D"localhost" - PG_REGRESS_SOCKET_DIR=3D"" - PGHOST=3Dlocalhost - ;; - *) - LISTEN_ADDRESSES=3D"" - # Select a socket directory. The algorithm is from the "configure" - # script; the outcome mimics pg_regress.c:make_temp_sockdir(). - if [ x"$PG_REGRESS_SOCKET_DIR" =3D x ]; then - set +e - dir=3D`(umask 077 && - mktemp -d /tmp/pg_upgrade_check-XXXXXX) 2>/dev/null` - if [ ! -d "$dir" ]; then - dir=3D/tmp/pg_upgrade_check-$$-$RANDOM - (umask 077 && mkdir "$dir") - if [ ! -d "$dir" ]; then - echo "could not create socket temporary directory in \"/tmp\"" - exit 1 - fi - fi - set -e - PG_REGRESS_SOCKET_DIR=3D$dir - trap 'rm -rf "$PG_REGRESS_SOCKET_DIR"' 0 - trap 'exit 3' 1 2 13 15 - fi - PGHOST=3D$PG_REGRESS_SOCKET_DIR - ;; -esac - -POSTMASTER_OPTS=3D"-F -c listen_addresses=3D\"$LISTEN_ADDRESSES\" -k \"$PG= _REGRESS_SOCKET_DIR\"" -export PGHOST - -# don't rely on $PWD here, as old shells don't set it -temp_root=3D`pwd`/tmp_check -rm -rf "$temp_root" -mkdir "$temp_root" - -: ${oldbindir=3D$bindir} - -: ${oldsrc=3D../../..} -oldsrc=3D`cd "$oldsrc" && pwd` -newsrc=3D`cd ../../.. && pwd` - -# We need to make pg_regress use psql from the desired installation -# (likely a temporary one), because otherwise the installcheck run -# below would try to use psql from the proper installation directory -# of the target version, which might be outdated or not exist. But -# don't override anything else that's already in EXTRA_REGRESS_OPTS. -EXTRA_REGRESS_OPTS=3D"$EXTRA_REGRESS_OPTS --bindir=3D'$oldbindir'" -export EXTRA_REGRESS_OPTS - -# While in normal cases this will already be set up, adding bindir to -# path allows test.sh to be invoked with different versions as -# described in ./TESTING -PATH=3D$bindir:$PATH -export PATH - -BASE_PGDATA=3D"$temp_root/data" -PGDATA=3D"${BASE_PGDATA}.old" -export PGDATA - -# Send installcheck outputs to a private directory. This avoids conflict = when -# check-world runs pg_upgrade check concurrently with src/test/regress che= ck. -# To retrieve interesting files after a run, use pattern tmp_check/*/*.dif= fs. -outputdir=3D"$temp_root/regress" -EXTRA_REGRESS_OPTS=3D"$EXTRA_REGRESS_OPTS --outputdir=3D$outputdir" -export EXTRA_REGRESS_OPTS -mkdir "$outputdir" - -# pg_regress --make-tablespacedir would take care of that in 14~, but this= is -# still required for older versions where this option is not supported. -if [ "$newsrc" !=3D "$oldsrc" ]; then - mkdir "$outputdir"/testtablespace - mkdir "$outputdir"/sql - mkdir "$outputdir"/expected -fi - -logdir=3D`pwd`/log -rm -rf "$logdir" -mkdir "$logdir" - -# Clear out any environment vars that might cause libpq to connect to -# the wrong postmaster (cf pg_regress.c) -# -# Some shells, such as NetBSD's, return non-zero from unset if the variable -# is already unset. Since we are operating under 'set -e', this causes the -# script to fail. To guard against this, set them all to an empty string f= irst. -PGDATABASE=3D""; unset PGDATABASE -PGUSER=3D""; unset PGUSER -PGSERVICE=3D""; unset PGSERVICE -PGSSLMODE=3D""; unset PGSSLMODE -PGREQUIRESSL=3D""; unset PGREQUIRESSL -PGCONNECT_TIMEOUT=3D""; unset PGCONNECT_TIMEOUT -PGHOSTADDR=3D""; unset PGHOSTADDR - -# Select a non-conflicting port number, similarly to pg_regress.c -PG_VERSION_NUM=3D`grep '#define PG_VERSION_NUM' "$newsrc"/src/include/pg_c= onfig.h | awk '{print $3}'` -PGPORT=3D`expr $PG_VERSION_NUM % 16384 + 49152` -export PGPORT - -i=3D0 -while psql -X postgres /dev/null -do - i=3D`expr $i + 1` - if [ $i -eq 16 ] - then - echo port $PGPORT apparently in use - exit 1 - fi - PGPORT=3D`expr $PGPORT + 1` - export PGPORT -done - -# buildfarm may try to override port via EXTRA_REGRESS_OPTS ... -EXTRA_REGRESS_OPTS=3D"$EXTRA_REGRESS_OPTS --port=3D$PGPORT" -export EXTRA_REGRESS_OPTS - -standard_initdb "$oldbindir"/initdb -"$oldbindir"/pg_ctl start -l "$logdir/postmaster1.log" -o "$POSTMASTER_OPT= S" -w - -# Create databases with names covering the ASCII bytes other than NUL, BEL, -# LF, or CR. BEL would ring the terminal bell in the course of this test,= and -# it is not otherwise a special case. PostgreSQL doesn't support the rest. -dbname1=3D`awk 'BEGIN { for (i=3D 1; i < 46; i++) - if (i !=3D 7 && i !=3D 10 && i !=3D 13) printf "%c", i }' "$temp_root"/dump= 1.sql - fi -else - make_installcheck_status=3D$? -fi -"$oldbindir"/pg_ctl -m fast stop -if [ -n "$createdb_status" ]; then - exit 1 -fi -if [ -n "$make_installcheck_status" ]; then - exit 1 -fi -if [ -n "$psql_fix_sql_status" ]; then - exit 1 -fi -if [ -n "$pg_dumpall1_status" ]; then - echo "pg_dumpall of pre-upgrade database cluster failed" - exit 1 -fi - -PGDATA=3D"$BASE_PGDATA" - -standard_initdb 'initdb' - -pg_upgrade $PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "$PGDATA" -b "$oldbindir= " -p "$PGPORT" -P "$PGPORT" - -# make sure all directories and files have group permissions, on Unix hosts -# Windows hosts don't support Unix-y permissions. -case $testhost in - MINGW*|CYGWIN*) ;; - *) if [ `find "$PGDATA" -type f ! -perm 640 | wc -l` -ne 0 ]; then - echo "files in PGDATA with permission !=3D 640"; - exit 1; - fi ;; -esac - -case $testhost in - MINGW*|CYGWIN*) ;; - *) if [ `find "$PGDATA" -type d ! -perm 750 | wc -l` -ne 0 ]; then - echo "directories in PGDATA with permission !=3D 750"; - exit 1; - fi ;; -esac - -pg_ctl start -l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w - -pg_dumpall $extra_dump_options --no-sync \ - -f "$temp_root"/dump2.sql || pg_dumpall2_status=3D$? -pg_ctl -m fast stop - -if [ -n "$pg_dumpall2_status" ]; then - echo "pg_dumpall of post-upgrade database cluster failed" - exit 1 -fi - -case $testhost in - MINGW*) MSYS2_ARG_CONV_EXCL=3D/c cmd /c delete_old_cluster.bat ;; - *) sh ./delete_old_cluster.sh ;; -esac - -if diff "$temp_root"/dump1.sql "$temp_root"/dump2.sql >/dev/null; then - echo PASSED - exit 0 -else - echo "Files $temp_root/dump1.sql and $temp_root/dump2.sql differ" - echo "dumps were not identical" - exit 1 -fi diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/Postg= reSQL/Test/Cluster.pm index c061e850fb..2bf2fcb69d 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -327,6 +327,31 @@ sub install_path =20 =3Dpod =20 +=3Ditem $node->config_data($option) + +Grab some data from pg_config, with $option being the switched +used. + +=3Dcut + +sub config_data +{ + my ($self, $option) =3D @_; + local %ENV =3D $self->_get_env(); + + my ($stdout, $stderr); + my $result =3D + IPC::Run::run [ $self->installed_command('pg_config'), $option ], + '>', \$stdout, '2>', \$stderr + or die "could not execute pg_config"; + chomp($stdout); + $stdout =3D~ s/\r$//; + + return $stdout; +} + +=3Dpod + =3Ditem $node->info() =20 Return a string containing human-readable diagnostic information (paths, e= tc) diff --git a/src/tools/msvc/vcregress.pl b/src/tools/msvc/vcregress.pl index dc5b2df7d7..d62a15883e 100644 --- a/src/tools/msvc/vcregress.pl +++ b/src/tools/msvc/vcregress.pl @@ -287,6 +287,10 @@ sub bincheck foreach my $dir (@bin_dirs) { next unless -d "$dir/t"; + # Do not consider pg_upgrade, as it is handled by + # upgradecheck. + next if ($dir =3D~ "/pg_upgrade/"); + my $status =3D tap_check($dir); $mstat ||=3D $status; } @@ -591,89 +595,12 @@ sub generate_db =20 sub upgradecheck { - my $status; - my $cwd =3D getcwd(); + InstallTemp(); + # Tweak environment for the upgrade tests + $ENV{REGRESS_OUTPUTDIR} =3D "$topdir/src/bin/pg_upgrade"; =20 - # Much of this comes from the pg_upgrade test.sh script, - # but it only covers the --install case, and not the case - # where the old and new source or bin dirs are different. - # i.e. only this version to this version check. That's - # what pg_upgrade's "make check" does. - - $ENV{PGHOST} =3D 'localhost'; - $ENV{PGPORT} ||=3D 50432; - my $tmp_root =3D "$topdir/src/bin/pg_upgrade/tmp_check"; - rmtree($tmp_root); - mkdir $tmp_root || die $!; - my $upg_tmp_install =3D "$tmp_root/install"; # unshared temp install - print "Setting up temp install\n\n"; - Install($upg_tmp_install, "all", $config); - - # Install does a chdir, so change back after that - chdir $cwd; - my ($bindir, $libdir, $oldsrc, $newsrc) =3D - ("$upg_tmp_install/bin", "$upg_tmp_install/lib", $topdir, $topdir); - $ENV{PATH} =3D "$bindir;$ENV{PATH}"; - my $data =3D "$tmp_root/data"; - $ENV{PGDATA} =3D "$data.old"; - my $outputdir =3D "$tmp_root/regress"; - my @EXTRA_REGRESS_OPTS =3D ("--outputdir=3D$outputdir"); - mkdir "$outputdir" || die $!; - - my $logdir =3D "$topdir/src/bin/pg_upgrade/log"; - rmtree($logdir); - mkdir $logdir || die $!; - print "\nRunning initdb on old cluster\n\n"; - standard_initdb() or exit 1; - print "\nStarting old cluster\n\n"; - my @args =3D ('pg_ctl', 'start', '-l', "$logdir/postmaster1.log"); - system(@args) =3D=3D 0 or exit 1; - - print "\nCreating databases with names covering most ASCII bytes\n\n"; - generate_db("\\\"\\", 1, 45, "\\\\\"\\\\\\"); - generate_db('', 46, 90, ''); - generate_db('', 91, 127, ''); - - print "\nSetting up data for upgrading\n\n"; - installcheck_internal('parallel', @EXTRA_REGRESS_OPTS); - - # now we can chdir into the source dir - chdir "$topdir/src/bin/pg_upgrade"; - print "\nDumping old cluster\n\n"; - @args =3D ('pg_dumpall', '-f', "$tmp_root/dump1.sql"); - system(@args) =3D=3D 0 or exit 1; - print "\nStopping old cluster\n\n"; - system("pg_ctl stop") =3D=3D 0 or exit 1; - $ENV{PGDATA} =3D "$data"; - print "\nSetting up new cluster\n\n"; - standard_initdb() or exit 1; - print "\nRunning pg_upgrade\n\n"; - @args =3D ('pg_upgrade', '-d', "$data.old", '-D', $data, '-b', $bindir); - system(@args) =3D=3D 0 or exit 1; - print "\nStarting new cluster\n\n"; - @args =3D ('pg_ctl', '-l', "$logdir/postmaster2.log", 'start'); - system(@args) =3D=3D 0 or exit 1; - print "\nDumping new cluster\n\n"; - @args =3D ('pg_dumpall', '-f', "$tmp_root/dump2.sql"); - system(@args) =3D=3D 0 or exit 1; - print "\nStopping new cluster\n\n"; - system("pg_ctl stop") =3D=3D 0 or exit 1; - print "\nDeleting old cluster\n\n"; - system(".\\delete_old_cluster.bat") =3D=3D 0 or exit 1; - print "\nComparing old and new cluster dumps\n\n"; - - @args =3D ('diff', '-q', "$tmp_root/dump1.sql", "$tmp_root/dump2.sql"); - system(@args); - $status =3D $?; - if (!$status) - { - print "PASSED\n"; - } - else - { - print "dumps not identical!\n"; - exit(1); - } + my $mstat =3D tap_check("$topdir/src/bin/pg_upgrade"); + exit $mstat if $mstat; return; } =20 --=20 2.34.1 --n9enehHYNtT8vR9U-- --7x7Ylkv9O/YZ9xLG Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmG6qcsACgkQnvQgOdby QH3elw/+LBjWOOS29jYZflC/0OqM4WJGWQa9QcN7RR64CxaGHTo5ShfJ/abz3z/s g4fwm+eJbsJ16OMuQ/40Upx7L02jE5CkQ90zhqfJTUiZxWPMmyXBvMI8jEJ5CQ7k gljh2xLwBAO8EkFw2Hrh0jLUJxyIAyo/F36T//8PSHvziFvRQk349KN5vGPNOc8T jPn2U3oic479NhACUbKX29s8LZQ5jD98XXJG+srwJsUz1A4u0CyIvfeg9ZsdYCtR QjO/8HPSGnT6N00YvWwhXLqvElkdFNzVTNOtgEIssasLQ5n7nqAK+1/W6xD5pMNm /ZUeScJQWEI3dRI4TD8EPhmqHaxLfAV240ijLnqbYSsUbheEWd9R3kU8xGxob/xq 071x6/ZDl3TaPavR4rUgv0pXg+q1qJ4M7uX6mN6xCKYmzRfQivEfpv9wYMq4FkPB JyfAFzdERILJiBfcFJrdcDdc1lMQX91l5gA68IK8jx1ffSIyfHsP8H15gqmm78O6 D75Jb/AfqzgEqv1gGyrbKZ+bbfg/HpPW8NWYCTuzRBYM9PI+VnNLoo9vqMkcN6bH LaatqJJfQ/3d9XRZYjrts0w694G29XZvrj0InqC1gLQedCGH2rWxHT76qj3W0DN1 d//DQwCQxMVTz2SdiE/oNhnhxfDQnvJRD78HFBUNkYCDX3QBD1Q= =eN93 -----END PGP SIGNATURE----- --7x7Ylkv9O/YZ9xLG--