On July 18, 1:06 am Tom Lane <[EMAIL PROTECTED]> wrote:
> "Magnus Hagander" <[EMAIL PROTECTED]> writes:
> >  Per discussion at the conference:
> >  In order to run the regression tests on Windows without msys,
> >  pg_regress needs to be reimplemnted in C.
>
> This has some minor portability issues (macros with ... aren't portable,
> for instance) but I think it's something we need to do.  Barring
> objections I'm going to clean up and apply it.

I've sent Magnus a patch a few days ago (but he seems to be without
internet connection already), maybe it can help you. I just fixed it such
that it worked for my non-standard install path.


I also did a small patch for the Makefile to compile and call pg_regress.

I append both patches (and hence won't send this mail to -hackers)

I also proposed to make pg_regress more modular some time ago:

http://archives.postgresql.org/pgsql-patches/2006-06/msg00212.php

A similar approach should be kept in mind as an enhancement to the C version.


Joachim
diff -ur cvs/pgsql/src/test/regress/GNUmakefile cvs.build/pgsql/src/test/regress/GNUmakefile
--- cvs/pgsql/src/test/regress/GNUmakefile	2006-03-24 08:11:21.000000000 +0100
+++ cvs.build/pgsql/src/test/regress/GNUmakefile	2006-07-15 00:30:33.000000000 +0200
@@ -42,18 +42,26 @@
 
 all: pg_regress
 
-pg_regress: pg_regress.sh GNUmakefile $(top_builddir)/src/Makefile.global
-	sed -e 's,@bindir@,$(bindir),g' \
-	    -e 's,@libdir@,$(libdir),g' \
-	    -e 's,@pkglibdir@,$(pkglibdir),g' \
-	    -e 's,@datadir@,$(datadir),g' \
-	    -e 's/@VERSION@/$(VERSION)/g' \
-	    -e 's/@host_tuple@/$(host_tuple)/g' \
-	    -e 's,@GMAKE@,$(MAKE),g' \
-	    -e 's/@enable_shared@/$(enable_shared)/g' \
-	    -e 's/@GCC@/$(GCC)/g' \
-	  $< >$@
-	chmod a+x $@
+pg_regress: pg_regress.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -o pg_regress pg_regress.o \
+		$(top_builddir)/src/backend/utils/mb/wstrncmp.o \
+		$(top_builddir)/src/backend/regex/regexec.o \
+		$(top_builddir)/src/backend/regex/regcomp.o \
+		$(top_builddir)/src/port/dirmod.o \
+		$(top_builddir)/src/port/pgsleep.o
+
+#pg_regress: pg_regress.sh GNUmakefile $(top_builddir)/src/Makefile.global
+#	sed -e 's,@bindir@,$(bindir),g' \
+#	    -e 's,@libdir@,$(libdir),g' \
+#	    -e 's,@pkglibdir@,$(pkglibdir),g' \
+#	    -e 's,@datadir@,$(datadir),g' \
+#	    -e 's/@VERSION@/$(VERSION)/g' \
+#	    -e 's/@host_tuple@/$(host_tuple)/g' \
+#	    -e 's,@GMAKE@,$(MAKE),g' \
+#	    -e 's/@enable_shared@/$(enable_shared)/g' \
+#	    -e 's/@GCC@/$(GCC)/g' \
+#	  $< >$@
+#	chmod a+x $@
 
 install: pg_regress
 	$(INSTALL_SCRIPT) pg_regress '$(DESTDIR)$(pgxsdir)/$(subdir)/pg_regress'
@@ -67,7 +75,7 @@
 NAME = regress
 SO_MAJOR_VERSION= 0
 SO_MINOR_VERSION= 0
-OBJS = regress.o
+OBJS = regress.o pg_regress.o
 SHLIB_LINK = $(BE_DLLLIBS)
 
 include $(top_srcdir)/src/Makefile.shlib
@@ -141,9 +149,12 @@
 ##
 
 check: all
+	echo bindir: $(bindir)
+	echo datadir: $(datadir)
+	echo libdir: $(libdir)
 	-rm -rf ./testtablespace
 	mkdir ./testtablespace
-	$(SHELL) ./pg_regress --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --schedule=$(srcdir)/parallel_schedule --multibyte=$(MULTIBYTE) --load-language=plpgsql $(MAXCONNOPT) $(NOLOCALE)
+	./pg_regress --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --schedule=$(srcdir)/parallel_schedule --multibyte=$(MULTIBYTE) --load-language=plpgsql --platform=$(host_tuple) --bindir=$(bindir) --datadir=$(datadir) $(NOLOCALE)
 
 installcheck: all
 	-rm -rf ./testtablespace
--- /tmp/pg_regress.c	2006-07-14 22:15:30.000000000 +0200
+++ pg_regress.c	2006-07-15 00:40:52.000000000 +0200
@@ -15,6 +15,9 @@
 #define INVALID_PID -1
 #endif
 
+
+#define DEFAULT_TEMP "./tmp_check"
+
 #define header(t, ...) do { char tmp[128];sprintf(tmp, t, ##__VA_ARGS__);printf("============== %-38s ==============\n",tmp); fflush(stdout); } while (0); 
 #define status(a, ...) do { printf(a, ##__VA_ARGS__); fflush(stdout); if(logfile) fprintf(logfile,a,##__VA_ARGS__); } while (0);
 #define status_end() do { printf("\n"); fflush(stdout); if (logfile) fprintf(logfile,"\n"); } while (0);
@@ -29,6 +32,9 @@
 
 static char *libdir = NULL;
 static char *bindir = "";
+static char *temp_install_bindir = "";
+static char *datadir = "";
+static char *temp_install_datadir = "";
 static char *inputdir = ".";
 static char *outputdir = ".";
 static char *host_platform = NULL;
@@ -175,6 +181,19 @@
 	putenv(newval);
 }
 
+static bool
+regress_exec_cmd(const char *cmd)
+{
+	int status;
+
+	if (debug)
+		printf("executing: %s\n", cmd);
+
+	status = WEXITSTATUS(system(cmd));
+
+	return status == 0;
+}
+
 static void
 initialize_environment(void)
 {
@@ -204,12 +223,23 @@
 	if (temp_install)
 	{
 		/* setup bin and lib dirs for temp install */
-		bindir = malloc(strlen(temp_install) + 32);
-		sprintf(bindir,"%s/install/usr/local/pgsql/bin/", temp_install);
+		temp_install_bindir = malloc(strlen(temp_install)
+									 + strlen("/install/")
+									 + strlen(bindir)
+									 + 1);
+		sprintf(temp_install_bindir, "%s/install/%s", temp_install, bindir);
+
+
+		temp_install_datadir = malloc(strlen(temp_install)
+									  + strlen("/install/")
+									  + strlen(datadir)
+									  + 1);
+		sprintf(temp_install_datadir, "%s/install/%s", temp_install, datadir);
+
+
 		libdir = malloc(strlen(temp_install) + 32);
 		sprintf(libdir,"%s/install/usr/local/pgsql/lib", temp_install);
 
-
 		add_to_path("LD_LIBRARY_PATH", ':', libdir);
 		add_to_path("DYLD_LIBRARY_PATH", ':', libdir);
 #ifdef WIN32
@@ -244,7 +274,8 @@
 	vsprintf(query2, query, args);
 	va_end(args);
 
-	sprintf(psql_cmd, "%spsql -X -c \"%s\" %s", bindir, query2, database);
+	sprintf(psql_cmd, "%s/psql -X -c \"%s\" %s", temp_install_bindir,
+												query2, database);
 
 	p = popen(psql_cmd, "r");
 	if (!p)
@@ -319,8 +350,8 @@
 	sprintf(infile, "%s/sql/%s.sql", inputdir, basefile);
 	sprintf(outfile, "%s/results/%s.out", outputdir, basefile);
 
-	sprintf(psql_cmd, "%spsql -X -a -q -d %s <%s >%s 2>&1",
-		bindir, dbname, infile, outfile);
+	sprintf(psql_cmd, "%s/psql -X -a -q -d %s <%s >%s 2>&1",
+			temp_install_bindir, dbname, infile, outfile);
 
 	return spawn_process(psql_cmd);
 }
@@ -625,7 +656,8 @@
 	fclose(scf);
 	if (temp_install)
 	{
-		sprintf(scbuf, "\"%spg_ctl\" -D \"%s/data\" stop", bindir, temp_install);
+		sprintf(scbuf, "\"%s/pg_ctl\" -D \"%s/data\" stop",
+					   temp_install_bindir, temp_install);
 		system(scbuf);
 	}
 
@@ -712,7 +744,7 @@
 		{"multibyte", required_argument, NULL, 6},
 		{"outputdir", required_argument, NULL, 7},
 		{"schedule", required_argument, NULL, 8},
-		{"temp-install", required_argument, NULL, 9},
+		{"temp-install", optional_argument, NULL, 9},
 		{"no-locale", no_argument, NULL, 10},
 		{"top-builddir", required_argument, NULL, 11},
 		{"temp-port", required_argument, NULL, 12},
@@ -721,6 +753,7 @@
 		{"user", required_argument, NULL, 15},
 		{"platform", required_argument, NULL, 16},
 		{"bindir", required_argument, NULL, 17},
+		{"datadir", required_argument, NULL, 18},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -765,6 +798,9 @@
 				schedule = strdup(optarg);
 				break;
 			case 9:
+				if (!optarg)
+					/* no temp_install path specified */
+					optarg = DEFAULT_TEMP;
 				if (optarg[0] == '/')
 					temp_install = strdup(optarg);
 				else
@@ -804,6 +840,9 @@
 			case 17:
 				bindir = strdup(optarg);
 				break;
+			case 18:
+				datadir = strdup(optarg);
+				break;
 			default:
 				/* getopt_long already emitted a complaint */
 				fprintf(stderr,"\nTry \"%s -h\" for more information.\n",argv[0]);
@@ -846,33 +885,35 @@
 
 		header("creating temporary installation");
 		sprintf(buf,"make -C \"%s\" DESTDIR=\"%s/install\" install with_perl=no with_python=no > \"%s/log/install.log\" 2>&1",
-			top_builddir, temp_install, outputdir);
-		if (WEXITSTATUS(system(buf)) != 0)
+			top_builddir, temp_install, temp_install);
+		if (!regress_exec_cmd(buf))
 		{
-			fprintf(stderr, "installation failed.\nExamine %s/log/install.log for the reason.\n", outputdir);
+			fprintf(stderr, "installation failed.\nExamine %s/log/install.log for the reason.\n", temp_install);
 			exit(2);
 		}
 
 		header("initializing database system");
-		sprintf(buf,"\"%sinitdb\" -D \"%s/data\" -L \"%s/install/usr/local/pgsql/share\" --noclean %s %s > %s/log/initdb.log 2>&1",
-			bindir, temp_install, temp_install, nolocale?"--no-locale":"", debug?"--debug":"", outputdir);
-		if (WEXITSTATUS(system(buf)) != 0)
+		sprintf(buf,"\"%s/initdb\" -D \"%s/data\" -L \"%s\" --noclean %s %s > %s/log/initdb.log 2>&1",
+			temp_install_bindir, temp_install, temp_install_datadir,
+			nolocale?"--no-locale":"", debug?"--debug":"", temp_install);
+		if (!regress_exec_cmd(buf) != 0)
 		{
-			fprintf(stderr,"initdb failed.\nExamine %s/log/initdb.log for the reason.\n", outputdir);
+			fprintf(stderr,"initdb failed.\nExamine %s/log/initdb.log for the reason.\n", temp_install);
 			exit(2);
 		}
 
 		header("starting postmaster");
-		sprintf(buf,"\"%spostmaster\" -D \"%s/data\" -F %s -c listen_addresses=%s >\"%s/log/postmaster.log\" 2>&1",
-			bindir, temp_install, debug?"-d5":"", hostname?hostname:"", outputdir);
+		sprintf(buf,"\"%s/postmaster\" -D \"%s/data\" -F %s -c listen_addresses=%s >\"%s/log/postmaster.log\" 2>&1",
+			temp_install_bindir, temp_install,
+			debug?"-d5":"", hostname?hostname:"", temp_install);
 		if (spawn_process(buf) == INVALID_PID)
 		{
-			fprintf(stderr,"postmaster failed.\nExamine %s/log/postmaster.log for the reason\n", outputdir);
+			fprintf(stderr,"postmaster failed.\nExamine %s/log/postmaster.log for the reason\n", temp_install);
 			exit(2);
 		}
 		
-		sprintf(buf,"\"%spsql\" -X -c \"SELECT 1;\" postgres >%s 2>&1",
-			bindir, DEVNULL);
+		sprintf(buf,"\"%s/psql\" -X -c \"SELECT 1;\" postgres >%s 2>&1",
+			temp_install_bindir, DEVNULL);
 		for (i = 0; i < 60; i++)
 		{
 			int r = system(buf);
---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to