From: Thomas Rast <trast@inf.ethz.ch>
To: <git@vger.kernel.org>
Subject: [RFC PATCH 6/6] test-lib: support running tests under valgrind in parallel
Date: Thu, 16 May 2013 22:50:17 +0200 [thread overview]
Message-ID: <1d22b4b7885ff6b27c0837608aeaacd20e36ed94.1368736093.git.trast@inf.ethz.ch> (raw)
In-Reply-To: <cover.1368736093.git.trast@inf.ethz.ch>
With the new --valgrind-parallel=<n> option, we support running the
tests in a single test script under valgrind in parallel using 'n'
processes.
This really follows the dumbest approach possible, as follows:
* We spawn the test script 'n' times, using a throw-away
TEST_OUTPUT_DIRECTORY. Each of the instances is given options that
ensures that it only runs every n-th test under valgrind, but
together they cover the entire range.
* We add up the numbers from the individual tests, and provide the
usual output.
This is really a gross hack at this point, and should be improved. In
particular we should keep the actual outputs somewhere more easily
discoverable, and summarize them to the user.
Nevertheless, this is already workable and gives a speedup of more
than 2 on a dual-core (hyperthreaded) machine, using n=4. This is
expected since the overhead of valgrind is so big (on the order of 20x
under good conditions, and a large startup overhead at every git
invocation) that redundantly running the non-valgrind tests in between
is not that expensive.
Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
---
t/test-lib.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 55 insertions(+), 5 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 55fa749..b4e81bc 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -204,6 +204,15 @@ do
--valgrind-only=*)
valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
shift ;;
+ --valgrind-parallel=*)
+ valgrind_parallel=$(expr "z$1" : 'z[^=]*=\(.*\)')
+ shift ;;
+ --valgrind-only-stride=*)
+ valgrind_only_stride=$(expr "z$1" : 'z[^=]*=\(.*\)')
+ shift ;;
+ --valgrind-only-offset=*)
+ valgrind_only_offset=$(expr "z$1" : 'z[^=]*=\(.*\)')
+ shift ;;
--tee)
shift ;; # was handled already
--root=*)
@@ -217,7 +226,7 @@ do
esac
done
-if test -n "$valgrind_only"
+if test -n "$valgrind_only" || test -n "$valgrind_only_stride"
then
test -z "$valgrind" && valgrind=memcheck
test -z "$verbose" && verbose_only="$valgrind_only"
@@ -359,8 +368,10 @@ match_pattern_list () {
}
toggle_verbose () {
- test -z "$verbose_only" && return
- if match_pattern_list $test_count $verbose_only
+ test -z "$verbose_only" && test -z "$valgrind_only_stride" && return
+ if match_pattern_list $test_count $verbose_only ||
+ { test -n "$valgrind_only_stride" &&
+ expr $test_count "%" $valgrind_only_stride - $valgrind_only_offset = 0 >/dev/null; }
then
exec 4>&2 3>&1
else
@@ -370,7 +381,7 @@ toggle_verbose () {
toggle_valgrind () {
test -z "$GIT_VALGRIND" && return
- if test -z "$valgrind_only"
+ if test -z "$valgrind_only" && test -z "$valgrind_only_stride"
then
GIT_VALGRIND_ENABLED=t
return
@@ -379,6 +390,10 @@ toggle_valgrind () {
if match_pattern_list $test_count $valgrind_only
then
GIT_VALGRIND_ENABLED=t
+ elif test -n "$valgrind_only_stride" &&
+ expr $test_count "%" $valgrind_only_stride - $valgrind_only_offset = 0 >/dev/null
+ then
+ GIT_VALGRIND_ENABLED=t
fi
}
@@ -600,7 +615,10 @@ then
GIT_VALGRIND_MODE="$valgrind"
export GIT_VALGRIND_MODE
GIT_VALGRIND_ENABLED=t
- test -n "$valgrind_only" && GIT_VALGRIND_ENABLED=
+ if test -n "$valgrind_only" || test -n "$valgrind_only_stride"
+ then
+ GIT_VALGRIND_ENABLED=
+ fi
export GIT_VALGRIND_ENABLED
elif test -n "$GIT_TEST_INSTALLED"
then
@@ -686,6 +704,38 @@ then
else
mkdir -p "$TRASH_DIRECTORY"
fi
+
+if test -n "$valgrind_parallel"
+then
+ for i in $(test_seq 1 $valgrind_parallel)
+ do
+ root="$TRASH_DIRECTORY/vgparallel-$i"
+ mkdir "$root"
+ TEST_OUTPUT_DIRECTORY="$root" \
+ ${SHELL_PATH} "$0" \
+ --root="$root" --statusprefix="[$i] " \
+ --valgrind="$valgrind" \
+ --valgrind-only-stride="$valgrind_parallel" \
+ --valgrind-only-offset="$i" &
+ pids="$pids $!"
+ done
+ trap "kill $pids" INT TERM HUP
+ wait $pids
+ trap - INT TERM HUP
+ for i in $(test_seq 1 $valgrind_parallel)
+ do
+ root="$TRASH_DIRECTORY/vgparallel-$i"
+ eval "$(cat "$root/test-results/$(basename "$0" .sh)"-*.counts |
+ sed 's/^\([a-z][a-z]*\) \([0-9][0-9]*\)/inner_\1=\2/')"
+ test_count=$(expr $test_count + $inner_total)
+ test_success=$(expr $test_success + $inner_success)
+ test_fixed=$(expr $test_fixed + $inner_fixed)
+ test_broken=$(expr $test_broken + $inner_broken)
+ test_failed=$(expr $test_failed + $inner_failed)
+ done
+ test_done
+fi
+
# Use -P to resolve symlinks in our working directory so that the cwd
# in subprocesses like git equals our $PWD (for pathname comparisons).
cd -P "$TRASH_DIRECTORY" || exit 1
--
1.8.3.rc2.393.g8636c0b
next prev parent reply other threads:[~2013-05-16 20:50 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-16 20:50 [PATCH 0/6] --valgrind improvements Thomas Rast
2013-05-16 20:50 ` [PATCH 1/6] test-lib: enable MALLOC_* for the actual tests Thomas Rast
2013-05-16 21:28 ` Elia Pinto
2013-05-16 22:43 ` Junio C Hamano
2013-05-16 20:50 ` [PATCH 2/6] test-lib: refactor $GIT_SKIP_TESTS matching Thomas Rast
2013-05-17 5:48 ` Johannes Sixt
2013-05-17 8:04 ` Thomas Rast
2013-05-17 16:48 ` Junio C Hamano
2013-05-17 17:02 ` Thomas Rast
2013-05-17 17:22 ` Junio C Hamano
2013-05-17 21:29 ` Johannes Sixt
2013-05-16 20:50 ` [PATCH 3/6] test-lib: verbose mode for only tests matching a pattern Thomas Rast
2013-05-29 5:00 ` Jeff King
2013-05-29 5:07 ` Jeff King
2013-05-29 17:53 ` Junio C Hamano
2013-05-16 20:50 ` [PATCH 4/6] test-lib: valgrind " Thomas Rast
2013-05-16 20:50 ` [PATCH 5/6] test-lib: allow prefixing a custom string before "ok N" etc Thomas Rast
2013-05-16 22:53 ` Phil Hord
2013-05-17 8:00 ` Thomas Rast
2013-05-17 13:00 ` Phil Hord
2013-05-16 20:50 ` Thomas Rast [this message]
2013-05-29 4:53 ` [PATCH 0/6] --valgrind improvements Jeff King
2013-06-17 9:18 ` [PATCH v2 " Thomas Rast
2013-06-17 9:18 ` [PATCH v2 1/6] test-lib: enable MALLOC_* for the actual tests Thomas Rast
2013-06-17 9:18 ` [PATCH v2 2/6] test-lib: refactor $GIT_SKIP_TESTS matching Thomas Rast
2013-06-18 7:03 ` Johannes Sixt
2013-06-18 8:23 ` Thomas Rast
2013-06-17 9:18 ` [PATCH v2 3/6] test-lib: verbose mode for only tests matching a pattern Thomas Rast
2013-06-18 5:37 ` Jeff King
2013-06-18 8:45 ` Thomas Rast
2013-06-17 9:18 ` [PATCH v2 4/6] test-lib: valgrind " Thomas Rast
2013-06-17 9:18 ` [PATCH v2 5/6] test-lib: allow prefixing a custom string before "ok N" etc Thomas Rast
2013-06-17 9:18 ` [PATCH v2 6/6] test-lib: support running tests under valgrind in parallel Thomas Rast
2013-06-18 5:46 ` [PATCH v2 0/6] --valgrind improvements Jeff King
2013-06-18 12:25 ` [PATCH v3 0/8] " Thomas Rast
2013-06-18 12:25 ` [PATCH v3 1/8] test-lib: enable MALLOC_* for the actual tests Thomas Rast
2013-06-18 12:25 ` [PATCH v3 2/8] test-lib: refactor $GIT_SKIP_TESTS matching Thomas Rast
2013-06-18 12:25 ` [PATCH v3 3/8] test-lib: rearrange start/end of test_expect_* and test_skip Thomas Rast
2013-06-18 18:21 ` Junio C Hamano
2013-06-18 12:26 ` [PATCH v3 4/8] test-lib: self-test that --verbose works Thomas Rast
2013-06-18 12:26 ` [PATCH v3 5/8] test-lib: verbose mode for only tests matching a pattern Thomas Rast
2013-06-18 12:26 ` [PATCH v3 6/8] test-lib: valgrind " Thomas Rast
2013-06-18 12:26 ` [PATCH v3 7/8] test-lib: allow prefixing a custom string before "ok N" etc Thomas Rast
2013-06-18 12:26 ` [PATCH v3 8/8] test-lib: support running tests under valgrind in parallel 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=1d22b4b7885ff6b27c0837608aeaacd20e36ed94.1368736093.git.trast@inf.ethz.ch \
--to=trast@inf.ethz.ch \
--cc=git@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).