Merge branch 'tr/valgrind-test-fix'

* tr/valgrind-test-fix:
  Revert "test-lib: allow prefixing a custom string before "ok N" etc."
  Revert "test-lib: support running tests under valgrind in parallel"
This commit is contained in:
Junio C Hamano
2013-10-30 12:10:52 -07:00

View File

@ -205,29 +205,17 @@ do
--valgrind-only=*) --valgrind-only=*)
valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)') valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
shift ;; 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) --tee)
shift ;; # was handled already shift ;; # was handled already
--root=*) --root=*)
root=$(expr "z$1" : 'z[^=]*=\(.*\)') root=$(expr "z$1" : 'z[^=]*=\(.*\)')
shift ;; shift ;;
--statusprefix=*)
statusprefix=$(expr "z$1" : 'z[^=]*=\(.*\)')
shift ;;
*) *)
echo "error: unknown test option '$1'" >&2; exit 1 ;; echo "error: unknown test option '$1'" >&2; exit 1 ;;
esac esac
done done
if test -n "$valgrind_only" || test -n "$valgrind_only_stride" if test -n "$valgrind_only"
then then
test -z "$valgrind" && valgrind=memcheck test -z "$valgrind" && valgrind=memcheck
test -z "$verbose" && verbose_only="$valgrind_only" test -z "$verbose" && verbose_only="$valgrind_only"
@ -329,12 +317,12 @@ trap 'die' EXIT
test_ok_ () { test_ok_ () {
test_success=$(($test_success + 1)) test_success=$(($test_success + 1))
say_color "" "${statusprefix}ok $test_count - $@" say_color "" "ok $test_count - $@"
} }
test_failure_ () { test_failure_ () {
test_failure=$(($test_failure + 1)) test_failure=$(($test_failure + 1))
say_color error "${statusprefix}not ok $test_count - $1" say_color error "not ok $test_count - $1"
shift shift
echo "$@" | sed -e 's/^/# /' echo "$@" | sed -e 's/^/# /'
test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; } test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
@ -342,12 +330,12 @@ test_failure_ () {
test_known_broken_ok_ () { test_known_broken_ok_ () {
test_fixed=$(($test_fixed+1)) test_fixed=$(($test_fixed+1))
say_color error "${statusprefix}ok $test_count - $@ # TODO known breakage vanished" say_color error "ok $test_count - $@ # TODO known breakage vanished"
} }
test_known_broken_failure_ () { test_known_broken_failure_ () {
test_broken=$(($test_broken+1)) test_broken=$(($test_broken+1))
say_color warn "${statusprefix}not ok $test_count - $@ # TODO known breakage" say_color warn "not ok $test_count - $@ # TODO known breakage"
} }
test_debug () { test_debug () {
@ -377,9 +365,7 @@ maybe_teardown_verbose () {
last_verbose=t last_verbose=t
maybe_setup_verbose () { maybe_setup_verbose () {
test -z "$verbose_only" && return test -z "$verbose_only" && return
if match_pattern_list $test_count $verbose_only || 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 then
exec 4>&2 3>&1 exec 4>&2 3>&1
# Emit a delimiting blank line when going from # Emit a delimiting blank line when going from
@ -403,17 +389,13 @@ maybe_teardown_valgrind () {
maybe_setup_valgrind () { maybe_setup_valgrind () {
test -z "$GIT_VALGRIND" && return test -z "$GIT_VALGRIND" && return
if test -z "$valgrind_only" && test -z "$valgrind_only_stride" if test -z "$valgrind_only"
then then
GIT_VALGRIND_ENABLED=t GIT_VALGRIND_ENABLED=t
return return
fi fi
GIT_VALGRIND_ENABLED= GIT_VALGRIND_ENABLED=
if match_pattern_list $test_count $valgrind_only 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 then
GIT_VALGRIND_ENABLED=t GIT_VALGRIND_ENABLED=t
fi fi
@ -477,8 +459,8 @@ test_skip () {
of_prereq=" of $test_prereq" of_prereq=" of $test_prereq"
fi fi
say_color skip >&3 "${statusprefix}skipping test: $@" say_color skip >&3 "skipping test: $@"
say_color skip "${statusprefix}ok $test_count # skip $1 (missing $missing_prereq${of_prereq})" say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})"
: true : true
;; ;;
*) *)
@ -516,11 +498,11 @@ test_done () {
if test "$test_fixed" != 0 if test "$test_fixed" != 0
then then
say_color error "${statusprefix}# $test_fixed known breakage(s) vanished; please update test(s)" say_color error "# $test_fixed known breakage(s) vanished; please update test(s)"
fi fi
if test "$test_broken" != 0 if test "$test_broken" != 0
then then
say_color warn "${statusprefix}# still have $test_broken known breakage(s)" say_color warn "# still have $test_broken known breakage(s)"
fi fi
if test "$test_broken" != 0 || test "$test_fixed" != 0 if test "$test_broken" != 0 || test "$test_fixed" != 0
then then
@ -543,9 +525,9 @@ test_done () {
then then
if test $test_remaining -gt 0 if test $test_remaining -gt 0
then then
say_color pass "${statusprefix}# passed all $msg" say_color pass "# passed all $msg"
fi fi
say "${statusprefix}1..$test_count$skip_all" say "1..$test_count$skip_all"
fi fi
test -d "$remove_trash" && test -d "$remove_trash" &&
@ -559,8 +541,8 @@ test_done () {
*) *)
if test $test_external_has_tap -eq 0 if test $test_external_has_tap -eq 0
then then
say_color error "${statusprefix}# failed $test_failure among $msg" say_color error "# failed $test_failure among $msg"
say "${statusprefix}1..$test_count" say "1..$test_count"
fi fi
exit 1 ;; exit 1 ;;
@ -568,9 +550,6 @@ test_done () {
esac esac
} }
# Set up a directory that we can put in PATH which redirects all git
# calls to 'valgrind git ...'.
if test -n "$valgrind" if test -n "$valgrind"
then then
make_symlink () { make_symlink () {
@ -618,42 +597,33 @@ then
make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
} }
# In the case of --valgrind-parallel, we only need to do the # override all git executables in TEST_DIRECTORY/..
# wrapping once, in the main script. The worker children all GIT_VALGRIND=$TEST_DIRECTORY/valgrind
# have $valgrind_only_stride set, so we can skip based on that. mkdir -p "$GIT_VALGRIND"/bin
if test -z "$valgrind_only_stride" for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-*
then do
# override all git executables in TEST_DIRECTORY/.. make_valgrind_symlink $file
GIT_VALGRIND=$TEST_DIRECTORY/valgrind done
mkdir -p "$GIT_VALGRIND"/bin # special-case the mergetools loadables
for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-* make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
OLDIFS=$IFS
IFS=:
for path in $PATH
do
ls "$path"/git-* 2> /dev/null |
while read file
do do
make_valgrind_symlink $file make_valgrind_symlink "$file"
done done
# special-case the mergetools loadables done
make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools" IFS=$OLDIFS
OLDIFS=$IFS
IFS=:
for path in $PATH
do
ls "$path"/git-* 2> /dev/null |
while read file
do
make_valgrind_symlink "$file"
done
done
IFS=$OLDIFS
fi
PATH=$GIT_VALGRIND/bin:$PATH PATH=$GIT_VALGRIND/bin:$PATH
GIT_EXEC_PATH=$GIT_VALGRIND/bin GIT_EXEC_PATH=$GIT_VALGRIND/bin
export GIT_VALGRIND export GIT_VALGRIND
GIT_VALGRIND_MODE="$valgrind" GIT_VALGRIND_MODE="$valgrind"
export GIT_VALGRIND_MODE export GIT_VALGRIND_MODE
GIT_VALGRIND_ENABLED=t GIT_VALGRIND_ENABLED=t
if test -n "$valgrind_only" || test -n "$valgrind_only_stride" test -n "$valgrind_only" && GIT_VALGRIND_ENABLED=
then
GIT_VALGRIND_ENABLED=
fi
export GIT_VALGRIND_ENABLED export GIT_VALGRIND_ENABLED
elif test -n "$GIT_TEST_INSTALLED" elif test -n "$GIT_TEST_INSTALLED"
then then
@ -730,41 +700,6 @@ then
else else
mkdir -p "$TRASH_DIRECTORY" mkdir -p "$TRASH_DIRECTORY"
fi fi
# Gross hack to spawn N sub-instances of the tests in parallel, and
# summarize the results. Note that if this is enabled, the script
# terminates at the end of this 'if' block.
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_failure=$(expr $test_failure + $inner_failed)
done
test_done
fi
# Use -P to resolve symlinks in our working directory so that the cwd # Use -P to resolve symlinks in our working directory so that the cwd
# in subprocesses like git equals our $PWD (for pathname comparisons). # in subprocesses like git equals our $PWD (for pathname comparisons).
cd -P "$TRASH_DIRECTORY" || exit 1 cd -P "$TRASH_DIRECTORY" || exit 1