Git development
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: [PATCH v3 1/3] Add valgrind support in test scripts
Date: Mon, 26 Jan 2009 00:18:50 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.1.00.0901260018340.14855@racer> (raw)
In-Reply-To: <alpine.DEB.1.00.0901260014470.14855@racer>


This patch adds the ability to use valgrind's memcheck tool to
diagnose memory problems in Git while running the test scripts.

It works by creating symlinks to a valgrind script, which have the same
name as our Git binaries, and then putting that directory in front of
the test script's PATH as well as set GIT_EXEC_PATH to that directory.

Git scripts are symlinked from that directory directly.  That way, Git
binaries called by Git scripts are valgrinded, too.

Valgrind can be used by specifying "GIT_TEST_OPTS=--valgrind" in the
make invocation. Any invocation of git that finds any errors under
valgrind will exit with failure code 126. Any valgrind output will go
to the usual stderr channel for tests (i.e., /dev/null, unless -v has
been specified).

If you need to pass options to valgrind -- you might want to run
another tool than memcheck, for example -- you can set the environment
variable GIT_VALGRIND_OPTIONS.

A few default suppressions are included, since libz seems to trigger
quite a few false positives. We'll assume that libz works and that we
can ignore any errors which are reported there.

Note: it is safe to run the valgrind tests in parallel, as the links in
t/valgrind/bin/ are created using proper locking.

Initial patch and all the hard work by Jeff King.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 t/README                |    8 ++++++-
 t/test-lib.sh           |   54 +++++++++++++++++++++++++++++++++++++++++++++-
 t/valgrind/.gitignore   |    1 +
 t/valgrind/default.supp |   21 ++++++++++++++++++
 t/valgrind/valgrind.sh  |   12 ++++++++++
 5 files changed, 93 insertions(+), 3 deletions(-)
 create mode 100644 t/valgrind/.gitignore
 create mode 100644 t/valgrind/default.supp
 create mode 100755 t/valgrind/valgrind.sh

diff --git a/t/README b/t/README
index 8f12d48..811bc0d 100644
--- a/t/README
+++ b/t/README
@@ -39,7 +39,8 @@ this:
     * passed all 3 test(s)
 
 You can pass --verbose (or -v), --debug (or -d), and --immediate
-(or -i) command line argument to the test.
+(or -i) command line argument to the test, or by setting GIT_TEST_OPTS
+appropriately before running "make".
 
 --verbose::
 	This makes the test more verbose.  Specifically, the
@@ -58,6 +59,11 @@ You can pass --verbose (or -v), --debug (or -d), and --immediate
 	This causes additional long-running tests to be run (where
 	available), for more exhaustive testing.
 
+--valgrind::
+	Execute all Git binaries with valgrind and exit with status
+	126 on errors (just like regular tests, this will only stop
+	the test script when running under -i).  Valgrind errors
+	go to stderr, so you might want to pass the -v option, too.
 
 Skipping Tests
 --------------
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 41d5a59..67d7883 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -94,6 +94,8 @@ do
 	--no-python)
 		# noop now...
 		shift ;;
+	--va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
+		valgrind=t; shift ;;
 	*)
 		break ;;
 	esac
@@ -467,8 +469,56 @@ test_done () {
 # Test the binaries we have just built.  The tests are kept in
 # t/ subdirectory and are run in 'trash directory' subdirectory.
 TEST_DIRECTORY=$(pwd)
-PATH=$TEST_DIRECTORY/..:$PATH
-GIT_EXEC_PATH=$(pwd)/..
+if test -z "$valgrind"
+then
+	PATH=$TEST_DIRECTORY/..:$PATH
+	GIT_EXEC_PATH=$TEST_DIRECTORY/..
+else
+	make_symlink () {
+		test -h "$2" &&
+		test "$1" = "$(readlink "$2")" || {
+			# be super paranoid
+			if mkdir "$2".lock
+			then
+				rm -f "$2" &&
+				ln -s "$1" "$2" &&
+				rm -r "$2".lock
+			else
+				while test -d "$2".lock
+				do
+					say "Waiting for lock on $2."
+					sleep 1
+				done
+			fi
+		}
+	}
+
+	# override all git executables in TEST_DIRECTORY/..
+	GIT_VALGRIND=$TEST_DIRECTORY/valgrind
+	mkdir -p "$GIT_VALGRIND"/bin
+	ls $TEST_DIRECTORY/../git* 2> /dev/null |
+	while read symlink_target
+	do
+		# handle only executables
+		test -x "$symlink_target" || continue
+
+		base=$(basename "$symlink_target")
+		# do not override scripts
+		if test ! -d "$symlink_target" &&
+		    test "#!" != "$(head -c 2 < "$symlink_target")"
+		then
+			symlink_target=../valgrind.sh
+		fi
+		# create the link, or replace it if it is out of date
+		make_symlink "$symlink_target" \
+			"$GIT_VALGRIND/bin/$base" || exit
+	done
+	PATH=$GIT_VALGRIND/bin:$PATH
+	GIT_EXEC_PATH=$GIT_VALGRIND/bin
+	export GIT_VALGRIND
+
+	make_symlink ../../templates "$GIT_VALGRIND"/templates || exit
+fi
 GIT_TEMPLATE_DIR=$(pwd)/../templates/blt
 unset GIT_CONFIG
 GIT_CONFIG_NOSYSTEM=1
diff --git a/t/valgrind/.gitignore b/t/valgrind/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/t/valgrind/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/t/valgrind/default.supp b/t/valgrind/default.supp
new file mode 100644
index 0000000..2482b3b
--- /dev/null
+++ b/t/valgrind/default.supp
@@ -0,0 +1,21 @@
+{
+	ignore-zlib-errors-cond
+	Memcheck:Cond
+	obj:*libz.so*
+}
+
+{
+	ignore-zlib-errors-value4
+	Memcheck:Value4
+	obj:*libz.so*
+}
+
+{
+	writing-data-from-zlib-triggers-errors
+	Memcheck:Param
+	write(buf)
+	obj:/lib/ld-*.so
+	fun:write_in_full
+	fun:write_buffer
+	fun:write_loose_object
+}
diff --git a/t/valgrind/valgrind.sh b/t/valgrind/valgrind.sh
new file mode 100755
index 0000000..24f3a4e
--- /dev/null
+++ b/t/valgrind/valgrind.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+base=$(basename "$0")
+
+exec valgrind -q --error-exitcode=126 \
+	--leak-check=no \
+	--suppressions="$GIT_VALGRIND/default.supp" \
+	--gen-suppressions=all \
+	--log-fd=4 \
+	--input-fd=4 \
+	$GIT_VALGRIND_OPTIONS \
+	"$GIT_VALGRIND"/../../"$base" "$@"
-- 
1.6.1.482.g7d54be

  reply	other threads:[~2009-01-25 23:19 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-19  9:13 What's cooking in git.git (Jan 2009, #04; Mon, 19) Junio C Hamano
2009-01-19 11:54 ` Kjetil Barvik
2009-01-19 13:09   ` Johannes Schindelin
2009-01-19 13:08 ` Johannes Schindelin
2009-01-20  4:44   ` Jeff King
2009-01-20 13:51     ` valgrind patches, was " Johannes Schindelin
2009-01-20 14:19       ` Jeff King
2009-01-20 14:50         ` Johannes Schindelin
2009-01-20 15:04           ` [PATCH 1/2] Add valgrind support in test scripts Johannes Schindelin
2009-01-20 15:05             ` [PATCH 2/2] valgrind: ignore ldso errors Johannes Schindelin
2009-01-21  0:12             ` [PATCH 1/2] Add valgrind support in test scripts Jeff King
2009-01-21  0:41               ` Johannes Schindelin
2009-01-21  1:10               ` [PATCH 1/2 v2] " Johannes Schindelin
2009-01-21  1:11                 ` [INTERDIFF of PATCH " Johannes Schindelin
2009-01-21  8:48                 ` [PATCH " Junio C Hamano
2009-01-21 12:21                   ` Johannes Schindelin
2009-01-21 19:02                 ` Jeff King
2009-01-21 20:49                   ` Johannes Schindelin
2009-01-21 21:53                     ` Jeff King
2009-01-21 22:38                       ` Johannes Schindelin
2009-01-25 23:18                         ` [PATCH 0/3] Valgrind support Johannes Schindelin
2009-01-25 23:18                           ` Johannes Schindelin [this message]
2009-01-25 23:29                             ` [PATCH v3 1/3] Add valgrind support in test scripts Jeff King
2009-01-25 23:35                               ` Johannes Schindelin
2009-01-25 23:42                                 ` Jeff King
2009-01-25 23:19                           ` [PATCH v3 2/3] valgrind: ignore ldso and more libz errors Johannes Schindelin
2009-01-25 23:32                             ` Jeff King
2009-01-26  0:02                               ` Johannes Schindelin
2009-01-26  0:14                                 ` Jeff King
2009-01-25 23:20                           ` [PATCH 3/3] Valgrind support: check for more than just programming errors Johannes Schindelin
2009-01-25 23:42                             ` Jeff King
2009-01-26  0:43                               ` Johannes Schindelin
2009-01-21 22:31                     ` [PATCH] valgrind tests: be super-super paranoid when creating symlinks Johannes Schindelin
2009-01-20 23:24           ` valgrind patches, was Re: What's cooking in git.git (Jan 2009, #04; Mon, 19) Jeff King
2009-01-21  0:10             ` Johannes Schindelin
2009-01-21  0:15               ` Jeff King
2009-01-21  0:28                 ` Johannes Schindelin
2009-01-21  0:37                   ` Jeff King
2009-01-21  1:26                     ` Johannes Schindelin
2009-01-21  1:36                       ` [PATCH 2/2 v2] valgrind: ignore ldso errors Johannes Schindelin
2009-01-21 19:09                         ` Jeff King
2009-01-21 20:51                           ` Johannes Schindelin
2009-01-21 19:07                       ` valgrind patches, was Re: What's cooking in git.git (Jan 2009, #04; Mon, 19) Jeff King
2009-01-21 22:17                         ` Johannes Schindelin
2009-01-21 23:57                           ` Jeff King
2009-01-22  0:42                           ` Junio C Hamano
2009-01-22  0:59                             ` Jeff King
2009-01-22  5:02                               ` Johannes Schindelin
2009-01-22  5:39                                 ` Jeff King
2009-01-27  2:50                           ` Valgrind updates Johannes Schindelin
2009-01-27  3:38                             ` Linus Torvalds
2009-01-27  4:26                               ` Johannes Schindelin
2009-01-27  4:46                                 ` Johannes Schindelin
2009-01-27 13:14                                 ` Mark Brown
2009-01-27 16:54                                   ` Johannes Schindelin
2009-01-27 18:55                                     ` Linus Torvalds
2009-01-27 21:52                                       ` Johannes Schindelin
2009-01-29  1:56                                         ` Linus Torvalds
2009-01-29 14:22                                           ` Johannes Schindelin
2009-01-28 23:06                                       ` Mark Adler
2009-01-28 23:27                                         ` Johannes Schindelin
2009-01-29  0:15                                           ` Mark Adler
2009-01-29 14:14                                             ` Johannes Schindelin
2009-01-29 14:54                                               ` Johannes Schindelin
2009-01-27  4:48                               ` Jeff King
2009-01-27  9:31                                 ` Johannes Schindelin
2009-01-20  4:30 ` What's cooking in git.git (Jan 2009, #04; Mon, 19) Jeff King
2009-01-20  4:40 ` Jeff King
2009-01-20  7:04   ` Junio C Hamano
2009-01-20  7:55   ` Johannes Sixt
2009-01-20 14:18     ` Jeff King
2009-01-20  5:17 ` Boyd Stephen Smith Jr.
2009-01-20  8:57   ` Thomas Rast

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.1.00.0901260018340.14855@racer \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox