Skip to content

Commit 5dfc368

Browse files
Thomas Rastgitster
authored andcommitted
test-lib: valgrind for only tests matching a pattern
With the new --valgrind-only=<pattern> option, one can enable --valgrind at a per-test granularity, exactly analogous to --verbose-only from the previous commit. The options are wired such that --valgrind implies --verbose (as before), but --valgrind-only=<pattern> implies --verbose-only=<pattern> unless --verbose is also in effect. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff09af3 commit 5dfc368

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

t/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ appropriately before running "make".
126126
the 't/valgrind/' directory and use the commands under
127127
't/valgrind/bin/'.
128128

129+
--valgrind-only=<pattern>::
130+
Like --valgrind, but the effect is limited to tests with
131+
numbers matching <pattern>. The number matched against is
132+
simply the running count of the test within the file.
133+
129134
--tee::
130135
In addition to printing the test output to the terminal,
131136
write it to files named 't/test-results/$TEST_NAME.out'.

t/test-lib.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ do
201201
--valgrind=*)
202202
valgrind=$(expr "z$1" : 'z[^=]*=\(.*\)')
203203
shift ;;
204+
--valgrind-only=*)
205+
valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
206+
shift ;;
204207
--tee)
205208
shift ;; # was handled already
206209
--root=*)
@@ -211,7 +214,14 @@ do
211214
esac
212215
done
213216

214-
test -n "$valgrind" && verbose=t
217+
if test -n "$valgrind_only"
218+
then
219+
test -z "$valgrind" && valgrind=memcheck
220+
test -z "$verbose" && verbose_only="$valgrind_only"
221+
elif test -n "$valgrind"
222+
then
223+
verbose=t
224+
fi
215225

216226
if test -n "$color"
217227
then
@@ -371,6 +381,25 @@ maybe_setup_verbose () {
371381
last_verbose=$verbose
372382
}
373383

384+
maybe_teardown_valgrind () {
385+
test -z "$GIT_VALGRIND" && return
386+
GIT_VALGRIND_ENABLED=
387+
}
388+
389+
maybe_setup_valgrind () {
390+
test -z "$GIT_VALGRIND" && return
391+
if test -z "$valgrind_only"
392+
then
393+
GIT_VALGRIND_ENABLED=t
394+
return
395+
fi
396+
GIT_VALGRIND_ENABLED=
397+
if match_pattern_list $test_count $valgrind_only
398+
then
399+
GIT_VALGRIND_ENABLED=t
400+
fi
401+
}
402+
374403
test_eval_ () {
375404
# This is a separate function because some tests use
376405
# "return" to end a test_expect_success block early.
@@ -401,10 +430,12 @@ test_run_ () {
401430
test_start_ () {
402431
test_count=$(($test_count+1))
403432
maybe_setup_verbose
433+
maybe_setup_valgrind
404434
}
405435

406436
test_finish_ () {
407437
echo >&3 ""
438+
maybe_teardown_valgrind
408439
maybe_teardown_verbose
409440
}
410441

@@ -590,6 +621,9 @@ then
590621
export GIT_VALGRIND
591622
GIT_VALGRIND_MODE="$valgrind"
592623
export GIT_VALGRIND_MODE
624+
GIT_VALGRIND_ENABLED=t
625+
test -n "$valgrind_only" && GIT_VALGRIND_ENABLED=
626+
export GIT_VALGRIND_ENABLED
593627
elif test -n "$GIT_TEST_INSTALLED"
594628
then
595629
GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||

t/valgrind/valgrind.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ base=$(basename "$0")
44

55
TOOL_OPTIONS='--leak-check=no'
66

7+
test -z "$GIT_VALGRIND_ENABLED" &&
8+
exec "$GIT_VALGRIND"/../../"$base" "$@"
9+
710
case "$GIT_VALGRIND_MODE" in
811
memcheck-fast)
912
;;

0 commit comments

Comments
 (0)