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 <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Jun 23, 2013 at 20:12 UTC 5dfc368f5ec4c448cf3c76908b4c0e77cb4b902a
3 files changed +43 -1
t/README
+5
@@ -126,6 +126,11 @@ appropriately before running "make".
126 the 't/valgrind/' directory and use the commands under
127 't/valgrind/bin/'.
128
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 +
134 --tee::
135 In addition to printing the test output to the terminal,
136 write it to files named 't/test-results/$TEST_NAME.out'.
t/test-lib.sh
+35 -1
@@ -201,6 +201,9 @@ do
201 --valgrind=*)
202 valgrind=$(expr "z$1" : 'z[^=]*=\(.*\)')
203 shift ;;
204 + --valgrind-only=*)
205 + valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
206 + shift ;;
207 --tee)
208 shift ;; # was handled already
209 --root=*)
@@ -211,7 +214,14 @@ do
214 esac
215 done
216
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
225
226 if test -n "$color"
227 then
@@ -371,6 +381,25 @@ maybe_setup_verbose () {
381 last_verbose=$verbose
382 }
383
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 +
403 test_eval_ () {
404 # This is a separate function because some tests use
405 # "return" to end a test_expect_success block early.
@@ -401,10 +430,12 @@ test_run_ () {
430 test_start_ () {
431 test_count=$(($test_count+1))
432 maybe_setup_verbose
433 + maybe_setup_valgrind
434 }
435
436 test_finish_ () {
437 echo >&3 ""
438 + maybe_teardown_valgrind
439 maybe_teardown_verbose
440 }
441
@@ -590,6 +621,9 @@ then
621 export GIT_VALGRIND
622 GIT_VALGRIND_MODE="$valgrind"
623 export GIT_VALGRIND_MODE
624 + GIT_VALGRIND_ENABLED=t
625 + test -n "$valgrind_only" && GIT_VALGRIND_ENABLED=
626 + export GIT_VALGRIND_ENABLED
627 elif test -n "$GIT_TEST_INSTALLED"
628 then
629 GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||
t/valgrind/valgrind.sh
+3
@@ -4,6 +4,9 @@ base=$(basename "$0")
4
5 TOOL_OPTIONS='--leak-check=no'
6
7 +test -z "$GIT_VALGRIND_ENABLED" &&
8 +exec "$GIT_VALGRIND"/../../"$base" "$@"
9 +
10 case "$GIT_VALGRIND_MODE" in
11 memcheck-fast)
12 ;;