Skip to content

Commit 952af35

Browse files
Thomas Rastgitster
authored andcommitted
tests: parameterize --valgrind option
Running tests under helgrind and DRD recently proved useful in tracking down thread interaction issues. This can unfortunately not be done through GIT_VALGRIND_OPTIONS because any tool other than memcheck would complain about unknown options. Let --valgrind take an optional parameter that describes the valgrind tool to invoke. The default mode is to run memcheck as before. Signed-off-by: Thomas Rast <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fd4fab8 commit 952af35

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

t/README

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,21 @@ appropriately before running "make".
9292
This causes additional long-running tests to be run (where
9393
available), for more exhaustive testing.
9494

95-
--valgrind::
96-
Execute all Git binaries with valgrind and exit with status
97-
126 on errors (just like regular tests, this will only stop
98-
the test script when running under -i).
95+
--valgrind=<tool>::
96+
Execute all Git binaries under valgrind tool <tool> and exit
97+
with status 126 on errors (just like regular tests, this will
98+
only stop the test script when running under -i).
9999

100100
Since it makes no sense to run the tests with --valgrind and
101101
not see any output, this option implies --verbose. For
102102
convenience, it also implies --tee.
103103

104-
Note that valgrind is run with the option --leak-check=no,
104+
<tool> defaults to 'memcheck', just like valgrind itself.
105+
Other particularly useful choices include 'helgrind' and
106+
'drd', but you may use any tool recognized by your valgrind
107+
installation.
108+
109+
Note that memcheck is run with the option --leak-check=no,
105110
as the git process is short-lived and some errors are not
106111
interesting. In order to run a single command under the same
107112
conditions manually, you should set GIT_VALGRIND to point to

t/test-lib.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ do
193193
--no-color)
194194
color=; shift ;;
195195
--va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
196-
valgrind=t; verbose=t; shift ;;
196+
valgrind=memcheck
197+
shift ;;
198+
--valgrind=*)
199+
valgrind=$(expr "z$1" : 'z[^=]*=\(.*\)')
200+
shift ;;
197201
--tee)
198202
shift ;; # was handled already
199203
--root=*)
@@ -204,6 +208,8 @@ do
204208
esac
205209
done
206210

211+
test -n "$valgrind" && verbose=t
212+
207213
if test -n "$color"
208214
then
209215
say_color () {
@@ -530,6 +536,8 @@ then
530536
PATH=$GIT_VALGRIND/bin:$PATH
531537
GIT_EXEC_PATH=$GIT_VALGRIND/bin
532538
export GIT_VALGRIND
539+
GIT_VALGRIND_MODE="$valgrind"
540+
export GIT_VALGRIND_MODE
533541
elif test -n "$GIT_TEST_INSTALLED"
534542
then
535543
GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||

t/valgrind/valgrind.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@
22

33
base=$(basename "$0")
44

5-
TRACK_ORIGINS=
5+
TOOL_OPTIONS='--leak-check=no'
66

7-
VALGRIND_VERSION=$(valgrind --version)
8-
VALGRIND_MAJOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*\([0-9]*\)')
9-
VALGRIND_MINOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*[0-9]*\.\([0-9]*\)')
10-
test 3 -gt "$VALGRIND_MAJOR" ||
11-
test 3 -eq "$VALGRIND_MAJOR" -a 4 -gt "$VALGRIND_MINOR" ||
12-
TRACK_ORIGINS=--track-origins=yes
7+
case "$GIT_VALGRIND_MODE" in
8+
memcheck)
9+
VALGRIND_VERSION=$(valgrind --version)
10+
VALGRIND_MAJOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*\([0-9]*\)')
11+
VALGRIND_MINOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*[0-9]*\.\([0-9]*\)')
12+
test 3 -gt "$VALGRIND_MAJOR" ||
13+
test 3 -eq "$VALGRIND_MAJOR" -a 4 -gt "$VALGRIND_MINOR" ||
14+
TOOL_OPTIONS="$TOOL_OPTIONS --track-origins=yes"
15+
;;
16+
*)
17+
TOOL_OPTIONS="--tool=$GIT_VALGRIND_MODE"
18+
esac
1319

1420
exec valgrind -q --error-exitcode=126 \
15-
--leak-check=no \
16-
--suppressions="$GIT_VALGRIND/default.supp" \
1721
--gen-suppressions=all \
18-
$TRACK_ORIGINS \
22+
--suppressions="$GIT_VALGRIND/default.supp" \
23+
$TOOL_OPTIONS \
1924
--log-fd=4 \
2025
--input-fd=4 \
2126
$GIT_VALGRIND_OPTIONS \

0 commit comments

Comments
 (0)