Win32 regression test fixes:

For win32 in general, this makes it possible to run the regression tests
as an admin user by using the same restricted token method that's used
by pg_ctl and initdb.

For vc++, it adds building of pg_regress.exe, adds a resultmap, and
fixes how it runs the install.

Magnus Hagander
This commit is contained in:
Bruce Momjian 2007-02-08 15:28:58 +00:00
parent 51be14e928
commit 6fea31b693
5 changed files with 96 additions and 15 deletions

View File

@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.29 2007/02/07 00:52:35 petere Exp $
* $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.30 2007/02/08 15:28:58 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -67,7 +67,9 @@ static char *bindir = PGBINDIR;
static char *libdir = LIBDIR;
static char *datadir = PGSHAREDIR;
static char *host_platform = HOST_TUPLE;
#ifndef WIN32_ONLY_COMPILER
static char *makeprog = MAKEPROG;
#endif
#ifndef WIN32 /* not used in WIN32 case */
static char *shellprog = SHELLPROG;
@ -133,6 +135,10 @@ psql_command(const char *database, const char *query,...)
the supplied arguments. */
__attribute__((format(printf, 2, 3)));
#ifdef WIN32
typedef BOOL(WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE);
#endif
/*
* allow core files if possible.
*/
@ -854,16 +860,74 @@ spawn_process(const char *cmdline)
return pid;
#else
char *cmdline2;
BOOL b;
STARTUPINFO si;
PROCESS_INFORMATION pi;
HANDLE origToken;
HANDLE restrictedToken;
SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
SID_AND_ATTRIBUTES dropSids[2];
__CreateRestrictedToken _CreateRestrictedToken = NULL;
HANDLE Advapi32Handle;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
Advapi32Handle = LoadLibrary("ADVAPI32.DLL");
if (Advapi32Handle != NULL)
{
_CreateRestrictedToken = (__CreateRestrictedToken) GetProcAddress(Advapi32Handle, "CreateRestrictedToken");
}
if (_CreateRestrictedToken == NULL)
{
if (Advapi32Handle != NULL)
FreeLibrary(Advapi32Handle);
fprintf(stderr, "ERROR: Unable to create restricted tokens on this platform\n");
exit_nicely(2);
}
/* Open the current token to use as base for the restricted one */
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken))
{
fprintf(stderr, "Failed to open process token: %lu\n", GetLastError());
exit_nicely(2);
}
/* Allocate list of SIDs to remove */
ZeroMemory(&dropSids, sizeof(dropSids));
if (!AllocateAndInitializeSid(&NtAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &dropSids[0].Sid) ||
!AllocateAndInitializeSid(&NtAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, 0, &dropSids[1].Sid))
{
fprintf(stderr, "Failed to allocate SIDs: %lu\n", GetLastError());
exit_nicely(2);
}
b = _CreateRestrictedToken(origToken,
DISABLE_MAX_PRIVILEGE,
sizeof(dropSids)/sizeof(dropSids[0]),
dropSids,
0, NULL,
0, NULL,
&restrictedToken);
FreeSid(dropSids[1].Sid);
FreeSid(dropSids[0].Sid);
CloseHandle(origToken);
FreeLibrary(Advapi32Handle);
if (!b)
{
fprintf(stderr, "Failed to create restricted token: %lu\n", GetLastError());
exit_nicely(2);
}
cmdline2 = malloc(strlen(cmdline) + 8);
sprintf(cmdline2, "cmd /c %s", cmdline);
if (!CreateProcess(NULL, cmdline2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
if (!CreateProcessAsUser(restrictedToken, NULL, cmdline2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
fprintf(stderr, _("could not start process for \"%s\": %lu\n"),
cmdline2, GetLastError());
@ -1689,9 +1753,15 @@ main(int argc, char *argv[])
make_directory(buf);
/* "make install" */
#ifndef WIN32_ONLY_COMPILER
snprintf(buf, sizeof(buf),
SYSTEMQUOTE "\"%s\" -C \"%s\" DESTDIR=\"%s/install\" install with_perl=no with_python=no > \"%s/log/install.log\" 2>&1" SYSTEMQUOTE,
makeprog, top_builddir, temp_install, outputdir);
#else
snprintf(buf, sizeof(buf),
SYSTEMQUOTE "perl \"%s/src/tools/msvc/install.pl\" \"%s/install\" >\"%s/log/install.log\" 2>&1" SYSTEMQUOTE,
top_builddir, temp_install, outputdir);
#endif
if (system(buf))
{
fprintf(stderr, _("\n%s: installation failed\nExamine %s/log/install.log for the reason.\nCommand was: %s\n"), progname, outputdir, buf);

View File

@ -1,8 +1,11 @@
float4/i.86-pc-mingw32=float4-exp-three-digits
float4/i.86-pc-win32vc=float4-exp-three-digits
float8/i.86-.*-freebsd=float8-small-is-zero
float8/i.86-.*-openbsd=float8-small-is-zero
float8/i.86-.*-netbsd=float8-small-is-zero
float8/m68k-.*-netbsd=float8-small-is-zero
float8/i.86-pc-mingw32=float8-exp-three-digits-win32
float8/i.86-pc-win32vc=float8-exp-three-digits-win32
float8/i.86-pc-cygwin=float8-small-is-zero
int8/i.86-pc-mingw32=int8-exp-three-digits
int8/i.86-pc-win32vc=int8-exp-three-digits

View File

@ -87,7 +87,7 @@ sub GenerateFiles {
print O "#define HAVE_LIBZ 1\n" if ($self->{options}->{zlib});
print O "#define USE_SSL 1\n" if ($self->{options}->{openssl});
print O "#define ENABLE_NLS 1\n" if ($self->{options}->{nls});
print O "#define LOCALEDIR \"/usr/local/pgsql/share/locale\"\n" if ($self->{options}->{nls});
print O "#define LOCALEDIR \"/share/locale\"\n" if ($self->{options}->{nls});
if ($self->{options}->{xml}) {
print O "#define HAVE_LIBXML2\n";
print O "#define USE_LIBXML\n";
@ -201,17 +201,17 @@ EOF
print "Generating pg_config_paths.h...\n";
open(O,'>', 'src\port\pg_config_paths.h') || confess "Could not open pg_config_paths.h";
print O <<EOF;
#define PGBINDIR "/usr/local/pgsql/bin"
#define PGSHAREDIR "/usr/local/pgsql/share"
#define SYSCONFDIR "/usr/local/pgsql/etc"
#define INCLUDEDIR "/usr/local/pgsql/include"
#define PKGINCLUDEDIR "/usr/local/pgsql/include"
#define INCLUDEDIRSERVER "/usr/local/pgsql/include/server"
#define LIBDIR "/usr/local/pgsql/lib"
#define PKGLIBDIR "/usr/local/pgsql/lib"
#define LOCALEDIR "/usr/local/pgsql/share/locale"
#define DOCDIR "/usr/local/pgsql/doc"
#define MANDIR "/usr/local/pgsql/man"
#define PGBINDIR "/bin"
#define PGSHAREDIR "/share"
#define SYSCONFDIR "/etc"
#define INCLUDEDIR "/include"
#define PKGINCLUDEDIR "/include"
#define INCLUDEDIRSERVER "/include/server"
#define LIBDIR "/lib"
#define PKGLIBDIR "/lib"
#define LOCALEDIR "/share/locale"
#define DOCDIR "/doc"
#define MANDIR "/man"
EOF
close(O);
}

View File

@ -69,6 +69,7 @@ sub CopySetOfFiles {
open($D, "dir /b /s $spec |") || croak "Could not list $spec\n";
while (<$D>) {
chomp;
next if /regress/; # Skip temporary install in regression subdir
my $tgt = $target . basename($_);
print ".";
copy($_, $tgt) || croak "Could not copy $_: $!\n";

View File

@ -265,11 +265,18 @@ foreach my $prg (split /\s+/,$1) {
}
# Regression DLLs
# Regression DLL and EXE
my $regress = $solution->AddProject('regress','dll','misc');
$regress->AddFile('src\test\regress\regress.c');
$regress->AddReference($postgres);
my $pgregress = $solution->AddProject('pg_regress','exe','misc');
$pgregress->AddFile('src\test\regress\pg_regress.c');
$pgregress->AddIncludeDir('src\port');
$pgregress->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
$pgregress->AddDefine('FRONTEND');
$pgregress->AddReference($libpgport);
$solution->Save();
#####################