Hello,

18.12.2020 19:02, Tom Lane wrote:
> "osumi.takami...@fujitsu.com" <osumi.takami...@fujitsu.com> writes:
>> I have a question about how to execute valgrind with TAP tests
>> in order to check some patches in the community.
>> My main interest is testing src/test/subscription now but
>> is there any general way to do it ?
> The standard solution is
>
> (1) Build normally (well, with -DUSE_VALGRIND)
> (2) Move the postgres executable aside, say
>     mv src/backend/postgres src/backend/postgres.orig
> (3) Replace the executable with a wrapper script that invokes
>     valgrind on the original executable
> (4) Now you can run "make check" with a valgrind'ed server,
>     as well as things that depend on "make check", such as TAP tests
>
> The script I use for (3) is attached; adjust paths and options to taste.
I use the attached patch for this purpose, that slightly simplifies
things and covers all the other binaries:
git apply .../install-vrunner.patch
CPPFLAGS="-DUSE_VALGRIND -Og" ./configure --enable-tap-tests
--enable-debug --enable-cassert && make && make check
`make check-world` is possible too, with
src/bin/pg_ctl/t/001_start_stop.pl disabled (removed).

Best regards,
Alexander
diff --git a/install-vrunner.sh b/install-vrunner.sh
new file mode 100755
index 00000000000..21881d4c729
--- /dev/null
+++ b/install-vrunner.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+set -e
+
+SRCDIR=$1
+PGPREFIX=$SRCDIR/tmp_install/usr/local/pgsql
+
+cd $PGPREFIX/bin
+cp $SRCDIR/src/tools/valgrind.supp ./
+
+echo ""
+cat << 'EOF' > vrunner
+#!/bin/bash
+set -e
+BD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+SN="$(basename "${BASH_SOURCE[0]}")"
+OBIN="_$SN"
+[[ $LD_PRELOAD = *"valgrind"* ]] && exec $BD/$OBIN "$@"
+
+exec valgrind --quiet  --exit-on-first-error=yes --error-exitcode=1 --leak-check=no --time-stamp=yes \
+ --gen-suppressions=all --suppressions=$BD/valgrind.supp \
+ --trace-children=yes --trace-children-skip="/bin/*,/usr/bin/*" \
+ $BD/$OBIN "$@"
+EOF
+chmod a+x vrunner
+
+for f in *; do
+    if [ "$f" = "vrunner" ] || [ ! -x "$f" ]; then continue; fi
+    mv "$f" "_$f"
+    ln -s vrunner "$f"
+    chmod a+x "$f"
+done
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 884d66920b6..87af7fd9ab8 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -411,6 +411,7 @@ ifeq ($(MAKELEVEL),0)
 	$(MKDIR_P) '$(abs_top_builddir)'/tmp_install/log
 	$(MAKE) -C '$(top_builddir)' DESTDIR='$(abs_top_builddir)'/tmp_install install >'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1
 	$(MAKE) -j1 $(if $(CHECKPREP_TOP),-C $(CHECKPREP_TOP),) checkprep >>'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1
+	'$(abs_top_builddir)'/install-vrunner.sh '$(abs_top_builddir)'
 endif
 endif
 endif
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 7f427e7d60e..e6115881f6b 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -689,12 +689,7 @@ wait_for_postmaster(pgpid_t pm_pid, bool do_checkpoint)
 			pmpid = atol(optlines[LOCK_FILE_LINE_PID - 1]);
 			pmstart = atol(optlines[LOCK_FILE_LINE_START_TIME - 1]);
 			if (pmstart >= start_time - 2 &&
-#ifndef WIN32
-				pmpid == pm_pid
-#else
-			/* Windows can only reject standalone-backend PIDs */
 				pmpid > 0
-#endif
 				)
 			{
 				/*

Reply via email to