On Sat, Jul 25, 2015 at 4:14 PM, Noah Misch <n...@leadboat.com> wrote:
> On Fri, Jul 24, 2015 at 08:27:42PM +0300, Heikki Linnakangas wrote:
>> On 06/25/2015 07:40 AM, Michael Paquier wrote:
>> >Attached is v7, rebased on 0b157a0.
>>
>> Thanks! I fiddled with this a bit more, to centralize more of the
>> platform-dependent stuff to RewindTest.pm. Also, Windows doesn't have "cat"
>> and "touch" if you haven't installed MinGW, so I replaced those calls with
>> built-in perl code.
>
> My main priority for this patch is to not reintroduce CVE-2014-0067.  The
> patch is operating in a security minefield:

Thanks!

>> --- a/src/bin/pg_ctl/t/001_start_stop.pl
>> +++ b/src/bin/pg_ctl/t/001_start_stop.pl
>> @@ -15,13 +15,9 @@ command_exit_is([ 'pg_ctl', 'start', '-D', 
>> "$tempdir/nonexistent" ],
>>
>>  command_ok([ 'pg_ctl', 'initdb', '-D', "$tempdir/data" ], 'pg_ctl initdb');
>>  command_ok(
>> -     [   "$ENV{top_builddir}/src/test/regress/pg_regress", '--config-auth',
>> +     [ $ENV{PG_REGRESS}, '--config-auth',
>>               "$tempdir/data" ],
>>       'configure authentication');
>> -open CONF, ">>$tempdir/data/postgresql.conf";
>> -print CONF "listen_addresses = ''\n";
>> -print CONF "unix_socket_directories = '$tempdir_short'\n";
>> -close CONF;
>>  command_ok([ 'pg_ctl', 'start', '-D', "$tempdir/data", '-w' ],
>>       'pg_ctl start -w');
>
> Since this series of tests doesn't use standard_initdb, the deleted lines
> remain necessary.

Added with a switch on $config{osname}.

>> @@ -303,7 +297,6 @@ sub run_pg_rewind
>>       }
>>       else
>>       {
>> -
>>               # Cannot come here normally
>
> Unrelated change.

Removed.

>>  sub standard_initdb
>>  {
>>       my $pgdata = shift;
>>       system_or_bail('initdb', '-D', "$pgdata", '-A' , 'trust', '-N');
>> -     system_or_bail("$ENV{top_builddir}/src/test/regress/pg_regress",
>> -             '--config-auth', $pgdata);
>> +     system_or_bail($ENV{PG_REGRESS}, '--config-auth', $pgdata);
>> +
>> +     my $tempdir_short = tempdir_short;
>> +
>> +     open CONF, ">>$pgdata/postgresql.conf";
>> +     print CONF "\n# Added by TestLib.pm)\n";
>> +     if ($Config{osname} eq "MSWin32")
>> +     {
>> +             print CONF "listen_addresses = '127.0.0.1'\n";
>> +     }
>> +     else
>> +     {
>> +             print CONF "unix_socket_directories = '$tempdir_short'\n";
>
> This second branch needs listen_addresses=''; it doesn't help to secure the
> socket directory if the server still listens on localhost.

Yep. Agreed.

>> +sub configure_hba_for_replication
>> +{
>> +     my $pgdata = shift;
>> +
>> +     open HBA, ">>$pgdata/pg_hba.conf";
>> +     print HBA "\n# Allow replication (set up by TestLib.pm)\n";
>> +     if ($Config{osname} ne "MSWin32")
>> +     {
>> +             print HBA "local replication all trust\n";
>> +     }
>> +     else
>> +     {
>> +             print HBA "host replication all 127.0.0.1/32 sspi 
>> include_realm=1 map=regress\n";
>> +             print HBA "host replication all ::1/128 sspi include_realm=1 
>> map=regress\n";
>
> The second line will make the server fail to start on non-IPv6 systems.  You
> shouldn't need it if the clients always connect to 127.0.0.1, not "localhost".

Done.

>> +             configure_for_replication("$tempdir/pgdata");
>
> That function name appears nowhere else.

This looks like dead code to me. Hence removed.

>> +sub tapcheck
>> +{
>> +     InstallTemp();
>> +
>> +     my @args = ( "prove", "--verbose", "t/*.pl");
>> +
>> +     $ENV{PATH} = "$tmp_installdir/bin;$ENV{PATH}";
>> +     $ENV{PERL5LIB} = "$topdir/src/test/perl;$ENV{PERL5LIB}";
>> +     $ENV{PG_REGRESS} = "$topdir/$Config/pg_regress/pg_regress";
>> +
>> +     # Find out all the existing TAP tests by simply looking for t/
>> +     # in the tree.
>
> This target shall not run the SSL suite, for the same reason check-world shall
> not run it.  We could offer a distinct vcregress.pl target for TAP suites
> excluded from check-world.

OK, for the sake of duplicating what GNU does, let's simply ignore it then.

Also I added an equivalent of --enable-tap-tests for this MSVC stuff,
removed afterwards by Heikki. Do we want it or not?

An updated patch is attached.
-- 
Michael
From 51d6d553742753a3389fcb67778662cb24274508 Mon Sep 17 00:00:00 2001
From: Michael Paquier <mich...@otacoo.com>
Date: Sat, 25 Jul 2015 22:50:49 +0900
Subject: [PATCH] Make TAP tests work on Windows.

On Windows, use listen_address=127.0.0.1 to allow connections. We were
already using "pg_regress --config-auth" to set up HBA appropriately.
The standard_initdb helper function now sets up the server's
unix_socket_directories or listen_addresses in the config file, so that
they don't need to be specified in the pg_ctl command line anymore. That
way, the pg_ctl invocations in test programs don't need to differ between
Windows and Unix.

Add another helper function to configure the server's pg_hba.conf to
allow replication connections. The configuration is done similarly to
pg_regress --config-auth: trust on domain sockets on Unix, and SSPI
authentication on Windows.

Replace calls to "cat" and "touch" programs with built-in perl code.

Add "vcregress tapcheck" command for launching the tests on Windows.

Michael Paquier
---
 doc/src/sgml/install-windows.sgml            |   8 ++
 src/Makefile.global.in                       |   2 +-
 src/bin/pg_basebackup/t/010_pg_basebackup.pl | 138 ++++++++++++++-------------
 src/bin/pg_ctl/t/001_start_stop.pl           |  14 ++-
 src/bin/pg_ctl/t/002_status.pl               |   4 -
 src/bin/pg_rewind/RewindTest.pm              |  25 ++---
 src/test/perl/TestLib.pm                     |  79 ++++++++++++---
 src/tools/msvc/clean.bat                     |   7 ++
 src/tools/msvc/vcregress.pl                  |  42 +++++++-
 9 files changed, 217 insertions(+), 102 deletions(-)

diff --git a/doc/src/sgml/install-windows.sgml b/doc/src/sgml/install-windows.sgml
index d154b44..306fb1f 100644
--- a/doc/src/sgml/install-windows.sgml
+++ b/doc/src/sgml/install-windows.sgml
@@ -439,6 +439,7 @@ $ENV{CONFIG}="Debug";
 <userinput>vcregress modulescheck</userinput>
 <userinput>vcregress ecpgcheck</userinput>
 <userinput>vcregress isolationcheck</userinput>
+<userinput>vcregress tapcheck</userinput>
 <userinput>vcregress upgradecheck</userinput>
 </screen>
 
@@ -451,6 +452,13 @@ $ENV{CONFIG}="Debug";
    For more information about the regression tests, see
    <xref linkend="regress">.
   </para>
+
+  <para>
+   The TAP test suite that can be run with <parameter>tapcheck</> has
+   a dependency with the <application>Perl</> module
+   <ulink url="http://search.cpan.org/~toddr/IPC-Run-0.94/";>IPC::Run</>.
+   It can be downloaded from CPAN, and it needs to be placed in PERL5LIB.
+  </para>
  </sect2>
 
  <sect2>
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index e2f7211..59c9eed 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -339,7 +339,7 @@ endef
 
 define prove_check
 rm -rf $(srcdir)/tmp_check/log
-cd $(srcdir) && TESTDIR='$(CURDIR)' $(with_temp_install) PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl
+cd $(srcdir) && TESTDIR='$(CURDIR)' PG_REGRESS='$(top_builddir)/src/test/regress/pg_regress' $(with_temp_install) PGPORT='6$(DEF_PGPORT)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl
 endef
 
 else
diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl
index e47c3a0..40b6b76 100644
--- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl
+++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl
@@ -1,6 +1,7 @@
 use strict;
 use warnings;
 use Cwd;
+use Config;
 use TestLib;
 use Test::More tests => 35;
 
@@ -25,11 +26,7 @@ if (open BADCHARS, ">>$tempdir/pgdata/FOO\xe0\xe0\xe0BAR")
 	close BADCHARS;
 }
 
-open HBA, ">>$tempdir/pgdata/pg_hba.conf";
-print HBA "local replication all trust\n";
-print HBA "host replication all 127.0.0.1/32 trust\n";
-print HBA "host replication all ::1/128 trust\n";
-close HBA;
+configure_hba_for_replication "$tempdir/pgdata";
 system_or_bail 'pg_ctl', '-D', "$tempdir/pgdata", 'reload';
 
 command_fails(
@@ -57,61 +54,7 @@ command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup", '-Ft' ],
 	'tar format');
 ok(-f "$tempdir/tarbackup/base.tar", 'backup tar was created');
 
-my $superlongname = "superlongname_" . ("x" x 100);
-
-system_or_bail 'touch', "$tempdir/pgdata/$superlongname";
-command_fails([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l1", '-Ft' ],
-	'pg_basebackup tar with long name fails');
-unlink "$tempdir/pgdata/$superlongname";
-
-# Create a temporary directory in the system location and symlink it
-# to our physical temp location.  That way we can use shorter names
-# for the tablespace directories, which hopefully won't run afoul of
-# the 99 character length limit.
-my $shorter_tempdir = tempdir_short . "/tempdir";
-symlink "$tempdir", $shorter_tempdir;
-
-mkdir "$tempdir/tblspc1";
-psql 'postgres',
-  "CREATE TABLESPACE tblspc1 LOCATION '$shorter_tempdir/tblspc1';";
-psql 'postgres', "CREATE TABLE test1 (a int) TABLESPACE tblspc1;";
-command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup2", '-Ft' ],
-	'tar format with tablespaces');
-ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created');
-my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar";
-is(scalar(@tblspc_tars), 1, 'one tablespace tar was created');
-
-command_fails(
-	[ 'pg_basebackup', '-D', "$tempdir/backup1", '-Fp' ],
-	'plain format with tablespaces fails without tablespace mapping');
-
-command_ok(
-	[   'pg_basebackup', '-D', "$tempdir/backup1", '-Fp',
-		"-T$shorter_tempdir/tblspc1=$tempdir/tbackup/tblspc1" ],
-	'plain format with tablespaces succeeds with tablespace mapping');
-ok(-d "$tempdir/tbackup/tblspc1", 'tablespace was relocated');
-opendir(my $dh, "$tempdir/pgdata/pg_tblspc") or die;
-ok( (   grep {
-			-l "$tempdir/backup1/pg_tblspc/$_"
-			  and readlink "$tempdir/backup1/pg_tblspc/$_" eq
-			  "$tempdir/tbackup/tblspc1"
-		  } readdir($dh)),
-	"tablespace symlink was updated");
-closedir $dh;
-
-mkdir "$tempdir/tbl=spc2";
-psql 'postgres', "DROP TABLE test1;";
-psql 'postgres', "DROP TABLESPACE tblspc1;";
-psql 'postgres',
-  "CREATE TABLESPACE tblspc2 LOCATION '$shorter_tempdir/tbl=spc2';";
-command_ok(
-	[   'pg_basebackup', '-D', "$tempdir/backup3", '-Fp',
-		"-T$shorter_tempdir/tbl\\=spc2=$tempdir/tbackup/tbl\\=spc2" ],
-	'mapping tablespace with = sign in path');
-ok(-d "$tempdir/tbackup/tbl=spc2", 'tablespace with = sign was relocated');
-
-psql 'postgres', "DROP TABLESPACE tblspc2;";
-
+# Test incorrect arguments
 command_fails(
 	[ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-T=/foo" ],
 	'-T with empty old directory fails');
@@ -132,9 +75,72 @@ command_fails(
 	[ 'pg_basebackup', '-D', "$tempdir/backup_foo", '-Fp', "-Tfoo" ],
 	'-T with invalid format fails');
 
-mkdir "$tempdir/$superlongname";
-psql 'postgres',
-  "CREATE TABLESPACE tblspc3 LOCATION '$tempdir/$superlongname';";
-command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l3", '-Ft' ],
-	'pg_basebackup tar with long symlink target');
-psql 'postgres', "DROP TABLESPACE tblspc3;";
+# Tar format doesn't support filenames longer than 100 bytes.
+my $superlongname = "superlongname_" . ("x" x 100);
+my $superlongpath = "$tempdir/pgdata/$superlongname";
+
+open FILE, ">$superlongpath" or die "unable to create file $superlongpath";
+close FILE;
+command_fails([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l1", '-Ft' ],
+	'pg_basebackup tar with long name fails');
+unlink "$tempdir/pgdata/$superlongname";
+
+# The following tests test symlinks. Windows doesn't have symlinks, so
+# skip on Windows.
+SKIP: {
+    skip "symlinks not supported on Windows", 10 if ($Config{osname} eq "MSWin32");
+
+	# Create a temporary directory in the system location and symlink it
+	# to our physical temp location.  That way we can use shorter names
+	# for the tablespace directories, which hopefully won't run afoul of
+	# the 99 character length limit.
+	my $shorter_tempdir = tempdir_short . "/tempdir";
+	symlink "$tempdir", $shorter_tempdir;
+
+	mkdir "$tempdir/tblspc1";
+	psql 'postgres',
+	"CREATE TABLESPACE tblspc1 LOCATION '$shorter_tempdir/tblspc1';";
+	psql 'postgres', "CREATE TABLE test1 (a int) TABLESPACE tblspc1;";
+	command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup2", '-Ft' ],
+			   'tar format with tablespaces');
+	ok(-f "$tempdir/tarbackup2/base.tar", 'backup tar was created');
+	my @tblspc_tars = glob "$tempdir/tarbackup2/[0-9]*.tar";
+	is(scalar(@tblspc_tars), 1, 'one tablespace tar was created');
+
+	command_fails(
+		[ 'pg_basebackup', '-D', "$tempdir/backup1", '-Fp' ],
+		'plain format with tablespaces fails without tablespace mapping');
+
+	command_ok(
+		[   'pg_basebackup', '-D', "$tempdir/backup1", '-Fp',
+			"-T$shorter_tempdir/tblspc1=$tempdir/tbackup/tblspc1" ],
+		'plain format with tablespaces succeeds with tablespace mapping');
+	ok(-d "$tempdir/tbackup/tblspc1", 'tablespace was relocated');
+	opendir(my $dh, "$tempdir/pgdata/pg_tblspc") or die;
+	ok( (   grep {
+		-l "$tempdir/backup1/pg_tblspc/$_"
+			and readlink "$tempdir/backup1/pg_tblspc/$_" eq
+			"$tempdir/tbackup/tblspc1"
+			} readdir($dh)),
+		"tablespace symlink was updated");
+	closedir $dh;
+
+	mkdir "$tempdir/tbl=spc2";
+	psql 'postgres', "DROP TABLE test1;";
+	psql 'postgres', "DROP TABLESPACE tblspc1;";
+	psql 'postgres',
+	"CREATE TABLESPACE tblspc2 LOCATION '$shorter_tempdir/tbl=spc2';";
+	command_ok(
+		[   'pg_basebackup', '-D', "$tempdir/backup3", '-Fp',
+			"-T$shorter_tempdir/tbl\\=spc2=$tempdir/tbackup/tbl\\=spc2" ],
+		'mapping tablespace with = sign in path');
+	ok(-d "$tempdir/tbackup/tbl=spc2", 'tablespace with = sign was relocated');
+	psql 'postgres', "DROP TABLESPACE tblspc2;";
+
+	mkdir "$tempdir/$superlongname";
+	psql 'postgres',
+	"CREATE TABLESPACE tblspc3 LOCATION '$tempdir/$superlongname';";
+	command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup_l3", '-Ft' ],
+			   'pg_basebackup tar with long symlink target');
+	psql 'postgres', "DROP TABLESPACE tblspc3;";
+}
diff --git a/src/bin/pg_ctl/t/001_start_stop.pl b/src/bin/pg_ctl/t/001_start_stop.pl
index bcceb57..015e4d8 100644
--- a/src/bin/pg_ctl/t/001_start_stop.pl
+++ b/src/bin/pg_ctl/t/001_start_stop.pl
@@ -1,5 +1,6 @@
 use strict;
 use warnings;
+use Config;
 use TestLib;
 use Test::More tests => 17;
 
@@ -15,12 +16,19 @@ command_exit_is([ 'pg_ctl', 'start', '-D', "$tempdir/nonexistent" ],
 
 command_ok([ 'pg_ctl', 'initdb', '-D', "$tempdir/data" ], 'pg_ctl initdb');
 command_ok(
-	[   "$ENV{top_builddir}/src/test/regress/pg_regress", '--config-auth',
+	[ $ENV{PG_REGRESS}, '--config-auth',
 		"$tempdir/data" ],
 	'configure authentication');
 open CONF, ">>$tempdir/data/postgresql.conf";
-print CONF "listen_addresses = ''\n";
-print CONF "unix_socket_directories = '$tempdir_short'\n";
+if ($Config{osname} ne "MSWin32")
+{
+	print CONF "listen_addresses = ''\n";
+	print CONF "unix_socket_directories = '$tempdir_short'\n";
+}
+else
+{
+	print CONF "listen_addresses = '127.0.0.1'\n";
+}
 close CONF;
 command_ok([ 'pg_ctl', 'start', '-D', "$tempdir/data", '-w' ],
 	'pg_ctl start -w');
diff --git a/src/bin/pg_ctl/t/002_status.pl b/src/bin/pg_ctl/t/002_status.pl
index ec0a2a7..31f7c72 100644
--- a/src/bin/pg_ctl/t/002_status.pl
+++ b/src/bin/pg_ctl/t/002_status.pl
@@ -10,10 +10,6 @@ command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/nonexistent" ],
 	4, 'pg_ctl status with nonexistent directory');
 
 standard_initdb "$tempdir/data";
-open CONF, ">>$tempdir/data/postgresql.conf";
-print CONF "listen_addresses = ''\n";
-print CONF "unix_socket_directories = '$tempdir_short'\n";
-close CONF;
 
 command_exit_is([ 'pg_ctl', 'status', '-D', "$tempdir/data" ],
 	3, 'pg_ctl status with server not running');
diff --git a/src/bin/pg_rewind/RewindTest.pm b/src/bin/pg_rewind/RewindTest.pm
index db5e90b..098c342 100644
--- a/src/bin/pg_rewind/RewindTest.pm
+++ b/src/bin/pg_rewind/RewindTest.pm
@@ -195,19 +195,14 @@ max_connections = 10
 ));
 
 	# Accept replication connections on master
-	append_to_file(
-		"$test_master_datadir/pg_hba.conf", qq(
-local replication all trust
-));
+	configure_hba_for_replication $test_master_datadir;
 
-	system_or_bail('pg_ctl' , '-w',
-				   '-D' , $test_master_datadir,
-				   "-o", "-k $tempdir_short --listen-addresses='' -p $port_master",
-				   'start');
+	system_or_bail('pg_ctl', '-w',
+				   '-D', $test_master_datadir,
+				   '-o', "-p $port_master", 'start');
 
 	#### Now run the test-specific parts to initialize the master before setting
 	# up standby
-	$ENV{PGHOST} = $tempdir_short;
 }
 
 sub create_standby
@@ -228,8 +223,7 @@ recovery_target_timeline='latest'
 
 	# Start standby
 	system_or_bail('pg_ctl', '-w', '-D', $test_standby_datadir,
-				   '-o', "-k $tempdir_short --listen-addresses='' -p $port_standby",
-				   'start');
+				   '-o', "-p $port_standby", 'start');
 
 	# Wait until the standby has caught up with the primary, by polling
 	# pg_stat_replication.
@@ -265,7 +259,7 @@ sub run_pg_rewind
 	my $test_mode = shift;
 
 	# Stop the master and be ready to perform the rewind
-	system_or_bail('pg_ctl', '-D', $test_master_datadir, 'stop', '-m', 'fast');
+	system_or_bail('pg_ctl', '-D', $test_master_datadir, '-m', 'fast', 'stop');
 
 	# At this point, the rewind processing is ready to run.
 	# We now have a very simple scenario with a few diverged WAL record.
@@ -283,8 +277,8 @@ sub run_pg_rewind
 	{
 		# Do rewind using a local pgdata as source
 		# Stop the master and be ready to perform the rewind
-		system_or_bail('pg_ctl', '-D', $test_standby_datadir, 'stop',
-					   '-m', 'fast');
+		system_or_bail('pg_ctl', '-D', $test_standby_datadir,
+					   '-m', 'fast', 'stop');
 		command_ok(['pg_rewind',
 					"--debug",
 					"--source-pgdata=$test_standby_datadir",
@@ -323,8 +317,7 @@ recovery_target_timeline='latest'
 
 	# Restart the master to check that rewind went correctly
 	system_or_bail('pg_ctl', '-w', '-D', $test_master_datadir,
-				   '-o', "-k $tempdir_short --listen-addresses='' -p $port_master",
-				   'start');
+				   '-o', "-p $port_master", 'start');
 
 	#### Now run the test-specific parts to check the result
 }
diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm
index 0193d57..39bce44 100644
--- a/src/test/perl/TestLib.pm
+++ b/src/test/perl/TestLib.pm
@@ -3,11 +3,13 @@ package TestLib;
 use strict;
 use warnings;
 
+use Config;
 use Exporter 'import';
 our @EXPORT = qw(
   tempdir
   tempdir_short
   standard_initdb
+  configure_hba_for_replication
   start_test_server
   restart_test_server
   psql
@@ -112,29 +114,78 @@ sub tempdir_short
 	return File::Temp::tempdir(CLEANUP => 1);
 }
 
+# Initialize a new cluster for testing.
+#
+# The PGHOST environment variable is set to connect to the new cluster.
+#
+# Authentication is set up so that only the current OS user can access the
+# cluster. On Unix, we use Unix domain socket connections, with the socket in
+# a directory that's only accessible to the current user to ensure that.
+# On Windows, we use SSPI authentication to ensure the same (by pg_regress
+# --config-auth).
 sub standard_initdb
 {
 	my $pgdata = shift;
 	system_or_bail('initdb', '-D', "$pgdata", '-A' , 'trust', '-N');
-	system_or_bail("$ENV{top_builddir}/src/test/regress/pg_regress",
-		'--config-auth', $pgdata);
+	system_or_bail($ENV{PG_REGRESS}, '--config-auth', $pgdata);
+
+	my $tempdir_short = tempdir_short;
+
+	open CONF, ">>$pgdata/postgresql.conf";
+	print CONF "\n# Added by TestLib.pm)\n";
+	if ($Config{osname} eq "MSWin32")
+	{
+		print CONF "listen_addresses = '127.0.0.1'\n";
+	}
+	else
+	{
+		print CONF "unix_socket_directories = '$tempdir_short'\n";
+		print CONF "listen_addresses = ''\n";
+	}
+	close CONF;
+
+	$ENV{PGHOST}         = ($Config{osname} eq "MSWin32") ? "127.0.0.1" : $tempdir_short;
+}
+
+# Set up the cluster to allow replication connections, in the same way that
+# standard_initdb does for normal connections.
+sub configure_hba_for_replication
+{
+	my $pgdata = shift;
+
+	open HBA, ">>$pgdata/pg_hba.conf";
+	print HBA "\n# Allow replication (set up by TestLib.pm)\n";
+	if ($Config{osname} ne "MSWin32")
+	{
+		print HBA "local replication all trust\n";
+	}
+	else
+	{
+		print HBA "host replication all 127.0.0.1/32 sspi include_realm=1 map=regress\n";
+	}
+	close HBA;
 }
 
 my ($test_server_datadir, $test_server_logfile);
 
+
+# Initialize a new cluster for testing, and start it.
+#
+# The first argument is a temporary directory to create the cluster in.
+# If the second argument is true, the cluster configured to accept
+# replication connections.
 sub start_test_server
 {
 	my ($tempdir) = @_;
 	my $ret;
 
-	my $tempdir_short = tempdir_short;
-
 	print("### Starting test server in $tempdir\n");
 	standard_initdb "$tempdir/pgdata";
-	$ret = system_log('pg_ctl', '-D', "$tempdir/pgdata", '-w', '-l',
-	  "$tempdir/logfile", '-o',
-"--fsync=off -k \"$tempdir_short\" --listen-addresses='' --log-statement=all",
-					'start');
+
+	$ret = system_log('pg_ctl', '-D', "$tempdir/pgdata", '-w',
+	  '-l', "$tempdir/logfile", '-o', "--fsync=off --log-statement=all",
+	  'start');
+
 	if ($ret != 0)
 	{
 		print "# pg_ctl failed; logfile:\n";
@@ -142,7 +193,6 @@ sub start_test_server
 		BAIL_OUT("pg_ctl failed");
 	}
 
-	$ENV{PGHOST}         = $tempdir_short;
 	$test_server_datadir = "$tempdir/pgdata";
 	$test_server_logfile = "$tempdir/logfile";
 }
@@ -216,7 +266,9 @@ sub command_exit_is
 	print("# Running: " . join(" ", @{$cmd}) ."\n");
 	my $h = start $cmd;
 	$h->finish();
-	is($h->result(0), $expected, $test_name);
+	my $result = ($Config{osname} eq "MSWin32") ?
+		($h->full_results)[0] : $h->result(0);
+	is($result, $expected, $test_name);
 }
 
 sub program_help_ok
@@ -269,7 +321,12 @@ sub issues_sql_like
 	truncate $test_server_logfile, 0;
 	my $result = run_log($cmd);
 	ok($result, "@$cmd exit code 0");
-	my $log = `cat '$test_server_logfile'`;
+
+	# read the server log file into variable
+	open SERVERLOG, '<', $test_server_logfile or die "Could not open server log file $test_server_logfile: $!";
+	my $log = do { local $/; <SERVERLOG> };
+	close SERVERLOG;
+
 	like($log, $expected_sql, "$test_name: SQL found in server log");
 }
 
diff --git a/src/tools/msvc/clean.bat b/src/tools/msvc/clean.bat
index fbe3cc6..e3da6aa 100755
--- a/src/tools/msvc/clean.bat
+++ b/src/tools/msvc/clean.bat
@@ -88,6 +88,13 @@ if exist src\test\regress\regress.dll del /q src\test\regress\regress.dll
 if exist src\test\regress\refint.dll del /q src\test\regress\refint.dll
 if exist src\test\regress\autoinc.dll del /q src\test\regress\autoinc.dll
 
+if exist src\bin\initdb\tmp_check rd /s /q src\bin\initdb\tmp_check
+if exist src\bin\pg_basebackup\tmp_check rd /s /q src\bin\pg_basebackup\tmp_check
+if exist src\bin\pg_config\tmp_check rd /s /q src\bin\pg_config\tmp_check
+if exist src\bin\pg_ctl\tmp_check rd /s /q src\bin\pg_ctl\tmp_check
+if exist src\bin\pg_rewind\tmp_check rd /s /q src\bin\pg_rewind\tmp_check
+if exist src\bin\scripts\tmp_check rd /s /q src\bin\scripts\tmp_check
+
 REM Clean up datafiles built with contrib
 REM cd contrib
 REM for /r %%f in (*.sql) do if exist %%f.in del %%f
diff --git a/src/tools/msvc/vcregress.pl b/src/tools/msvc/vcregress.pl
index 6196383..7daa564 100644
--- a/src/tools/msvc/vcregress.pl
+++ b/src/tools/msvc/vcregress.pl
@@ -7,7 +7,9 @@ use strict;
 our $config;
 
 use Cwd;
+use File::Basename;
 use File::Copy;
+use File::Find ();
 
 use Install qw(Install);
 
@@ -32,7 +34,7 @@ if (-e "src/tools/msvc/buildenv.pl")
 
 my $what = shift || "";
 if ($what =~
-/^(check|installcheck|plcheck|contribcheck|modulescheck|ecpgcheck|isolationcheck|upgradecheck)$/i
+/^(check|installcheck|plcheck|contribcheck|modulescheck|ecpgcheck|isolationcheck|upgradecheck|tapcheck)$/i
   )
 {
 	$what = uc $what;
@@ -79,6 +81,7 @@ my %command = (
 	CONTRIBCHECK   => \&contribcheck,
 	MODULESCHECK   => \&modulescheck,
 	ISOLATIONCHECK => \&isolationcheck,
+	TAPCHECK       => \&tapcheck,
 	UPGRADECHECK   => \&upgradecheck,);
 
 my $proc = $command{$what};
@@ -172,6 +175,43 @@ sub isolationcheck
 	exit $status if $status;
 }
 
+sub tapcheck
+{
+	InstallTemp();
+
+	my @args = ( "prove", "--verbose", "t/*.pl");
+
+	$ENV{PATH} = "$tmp_installdir/bin;$ENV{PATH}";
+	$ENV{PERL5LIB} = "$topdir/src/test/perl;$ENV{PERL5LIB}";
+	$ENV{PG_REGRESS} = "$topdir/$Config/pg_regress/pg_regress";
+
+	# Find out all the existing TAP tests by simply looking for t/
+	# in the tree.
+	my $tap_dirs = [];
+	my @top_dir = ($topdir);
+	File::Find::find(
+		{   wanted => sub {
+				/^t\z/s
+				  && push(@$tap_dirs, $File::Find::name);
+			  }
+		},
+		@top_dir);
+
+	# Process each test
+	foreach my $test_path (@$tap_dirs)
+	{
+		next if ($test_path =~ /\/ssl\//);
+
+		my $dir = dirname($test_path);
+		chdir $dir;
+		# Reset those values, they may have been changed by another test.
+		$ENV{TESTDIR} = "$dir";
+		system(@args);
+		my $status = $? >> 8;
+		exit $status if $status;
+	}
+}
+
 sub plcheck
 {
 	chdir $startdir;
-- 
2.4.6

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to