Skip to content

Commit d3ea582

Browse files
committed
Merge branch 'tr/valgrind'
Let us use not just memgrind but other *grind debuggers. * tr/valgrind: tests: notice valgrind error in test_must_fail tests --valgrind: provide a mode without --track-origins tests: parameterize --valgrind option t/README: --valgrind already implies -v
2 parents 5ab3e4c + eeb6913 commit d3ea582

File tree

4 files changed

+44
-17
lines changed

4 files changed

+44
-17
lines changed

t/README

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,26 @@ 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). Valgrind errors
99-
go to stderr, so you might want to pass the -v option, too.
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).
10099

101100
Since it makes no sense to run the tests with --valgrind and
102101
not see any output, this option implies --verbose. For
103102
convenience, it also implies --tee.
104103

105-
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+
As a special case, <tool> can be 'memcheck-fast', which uses
110+
memcheck but disables --track-origins. Use this if you are
111+
running tests in bulk, to see if there are _any_ memory
112+
issues.
113+
114+
Note that memcheck is run with the option --leak-check=no,
106115
as the git process is short-lived and some errors are not
107116
interesting. In order to run a single command under the same
108117
conditions manually, you should set GIT_VALGRIND to point to

t/test-lib-functions.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ test_must_fail () {
540540
elif test $exit_code = 127; then
541541
echo >&2 "test_must_fail: command not found: $*"
542542
return 1
543+
elif test $exit_code = 126; then
544+
echo >&2 "test_must_fail: valgrind error: $*"
545+
return 1
543546
fi
544547
return 0
545548
}

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: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
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-fast)
9+
;;
10+
memcheck)
11+
VALGRIND_VERSION=$(valgrind --version)
12+
VALGRIND_MAJOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*\([0-9]*\)')
13+
VALGRIND_MINOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*[0-9]*\.\([0-9]*\)')
14+
test 3 -gt "$VALGRIND_MAJOR" ||
15+
test 3 -eq "$VALGRIND_MAJOR" -a 4 -gt "$VALGRIND_MINOR" ||
16+
TOOL_OPTIONS="$TOOL_OPTIONS --track-origins=yes"
17+
;;
18+
*)
19+
TOOL_OPTIONS="--tool=$GIT_VALGRIND_MODE"
20+
esac
1321

1422
exec valgrind -q --error-exitcode=126 \
15-
--leak-check=no \
16-
--suppressions="$GIT_VALGRIND/default.supp" \
1723
--gen-suppressions=all \
18-
$TRACK_ORIGINS \
24+
--suppressions="$GIT_VALGRIND/default.supp" \
25+
$TOOL_OPTIONS \
1926
--log-fd=4 \
2027
--input-fd=4 \
2128
$GIT_VALGRIND_OPTIONS \

0 commit comments

Comments
 (0)