Skip to content

Commit f989180

Browse files
committed
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"
2 parents 0040d6e + 633fe50 commit f989180

File tree

1 file changed

+34
-99
lines changed

1 file changed

+34
-99
lines changed

t/test-lib.sh

Lines changed: 34 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -205,29 +205,17 @@ do
205205
--valgrind-only=*)
206206
valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
207207
shift ;;
208-
--valgrind-parallel=*)
209-
valgrind_parallel=$(expr "z$1" : 'z[^=]*=\(.*\)')
210-
shift ;;
211-
--valgrind-only-stride=*)
212-
valgrind_only_stride=$(expr "z$1" : 'z[^=]*=\(.*\)')
213-
shift ;;
214-
--valgrind-only-offset=*)
215-
valgrind_only_offset=$(expr "z$1" : 'z[^=]*=\(.*\)')
216-
shift ;;
217208
--tee)
218209
shift ;; # was handled already
219210
--root=*)
220211
root=$(expr "z$1" : 'z[^=]*=\(.*\)')
221212
shift ;;
222-
--statusprefix=*)
223-
statusprefix=$(expr "z$1" : 'z[^=]*=\(.*\)')
224-
shift ;;
225213
*)
226214
echo "error: unknown test option '$1'" >&2; exit 1 ;;
227215
esac
228216
done
229217

230-
if test -n "$valgrind_only" || test -n "$valgrind_only_stride"
218+
if test -n "$valgrind_only"
231219
then
232220
test -z "$valgrind" && valgrind=memcheck
233221
test -z "$verbose" && verbose_only="$valgrind_only"
@@ -329,25 +317,25 @@ trap 'die' EXIT
329317

330318
test_ok_ () {
331319
test_success=$(($test_success + 1))
332-
say_color "" "${statusprefix}ok $test_count - $@"
320+
say_color "" "ok $test_count - $@"
333321
}
334322

335323
test_failure_ () {
336324
test_failure=$(($test_failure + 1))
337-
say_color error "${statusprefix}not ok $test_count - $1"
325+
say_color error "not ok $test_count - $1"
338326
shift
339327
echo "$@" | sed -e 's/^/# /'
340328
test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
341329
}
342330

343331
test_known_broken_ok_ () {
344332
test_fixed=$(($test_fixed+1))
345-
say_color error "${statusprefix}ok $test_count - $@ # TODO known breakage vanished"
333+
say_color error "ok $test_count - $@ # TODO known breakage vanished"
346334
}
347335

348336
test_known_broken_failure_ () {
349337
test_broken=$(($test_broken+1))
350-
say_color warn "${statusprefix}not ok $test_count - $@ # TODO known breakage"
338+
say_color warn "not ok $test_count - $@ # TODO known breakage"
351339
}
352340

353341
test_debug () {
@@ -377,9 +365,7 @@ maybe_teardown_verbose () {
377365
last_verbose=t
378366
maybe_setup_verbose () {
379367
test -z "$verbose_only" && return
380-
if match_pattern_list $test_count $verbose_only ||
381-
{ test -n "$valgrind_only_stride" &&
382-
expr $test_count "%" $valgrind_only_stride - $valgrind_only_offset = 0 >/dev/null; }
368+
if match_pattern_list $test_count $verbose_only
383369
then
384370
exec 4>&2 3>&1
385371
# Emit a delimiting blank line when going from
@@ -403,17 +389,13 @@ maybe_teardown_valgrind () {
403389

404390
maybe_setup_valgrind () {
405391
test -z "$GIT_VALGRIND" && return
406-
if test -z "$valgrind_only" && test -z "$valgrind_only_stride"
392+
if test -z "$valgrind_only"
407393
then
408394
GIT_VALGRIND_ENABLED=t
409395
return
410396
fi
411397
GIT_VALGRIND_ENABLED=
412398
if match_pattern_list $test_count $valgrind_only
413-
then
414-
GIT_VALGRIND_ENABLED=t
415-
elif test -n "$valgrind_only_stride" &&
416-
expr $test_count "%" $valgrind_only_stride - $valgrind_only_offset = 0 >/dev/null
417399
then
418400
GIT_VALGRIND_ENABLED=t
419401
fi
@@ -477,8 +459,8 @@ test_skip () {
477459
of_prereq=" of $test_prereq"
478460
fi
479461

480-
say_color skip >&3 "${statusprefix}skipping test: $@"
481-
say_color skip "${statusprefix}ok $test_count # skip $1 (missing $missing_prereq${of_prereq})"
462+
say_color skip >&3 "skipping test: $@"
463+
say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})"
482464
: true
483465
;;
484466
*)
@@ -516,11 +498,11 @@ test_done () {
516498

517499
if test "$test_fixed" != 0
518500
then
519-
say_color error "${statusprefix}# $test_fixed known breakage(s) vanished; please update test(s)"
501+
say_color error "# $test_fixed known breakage(s) vanished; please update test(s)"
520502
fi
521503
if test "$test_broken" != 0
522504
then
523-
say_color warn "${statusprefix}# still have $test_broken known breakage(s)"
505+
say_color warn "# still have $test_broken known breakage(s)"
524506
fi
525507
if test "$test_broken" != 0 || test "$test_fixed" != 0
526508
then
@@ -543,9 +525,9 @@ test_done () {
543525
then
544526
if test $test_remaining -gt 0
545527
then
546-
say_color pass "${statusprefix}# passed all $msg"
528+
say_color pass "# passed all $msg"
547529
fi
548-
say "${statusprefix}1..$test_count$skip_all"
530+
say "1..$test_count$skip_all"
549531
fi
550532

551533
test -d "$remove_trash" &&
@@ -559,18 +541,15 @@ test_done () {
559541
*)
560542
if test $test_external_has_tap -eq 0
561543
then
562-
say_color error "${statusprefix}# failed $test_failure among $msg"
563-
say "${statusprefix}1..$test_count"
544+
say_color error "# failed $test_failure among $msg"
545+
say "1..$test_count"
564546
fi
565547

566548
exit 1 ;;
567549

568550
esac
569551
}
570552

571-
572-
# Set up a directory that we can put in PATH which redirects all git
573-
# calls to 'valgrind git ...'.
574553
if test -n "$valgrind"
575554
then
576555
make_symlink () {
@@ -618,42 +597,33 @@ then
618597
make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
619598
}
620599

621-
# In the case of --valgrind-parallel, we only need to do the
622-
# wrapping once, in the main script. The worker children all
623-
# have $valgrind_only_stride set, so we can skip based on that.
624-
if test -z "$valgrind_only_stride"
625-
then
626-
# override all git executables in TEST_DIRECTORY/..
627-
GIT_VALGRIND=$TEST_DIRECTORY/valgrind
628-
mkdir -p "$GIT_VALGRIND"/bin
629-
for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-*
630-
do
631-
make_valgrind_symlink $file
632-
done
633-
# special-case the mergetools loadables
634-
make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
635-
OLDIFS=$IFS
636-
IFS=:
637-
for path in $PATH
600+
# override all git executables in TEST_DIRECTORY/..
601+
GIT_VALGRIND=$TEST_DIRECTORY/valgrind
602+
mkdir -p "$GIT_VALGRIND"/bin
603+
for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-*
604+
do
605+
make_valgrind_symlink $file
606+
done
607+
# special-case the mergetools loadables
608+
make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
609+
OLDIFS=$IFS
610+
IFS=:
611+
for path in $PATH
612+
do
613+
ls "$path"/git-* 2> /dev/null |
614+
while read file
638615
do
639-
ls "$path"/git-* 2> /dev/null |
640-
while read file
641-
do
642-
make_valgrind_symlink "$file"
643-
done
616+
make_valgrind_symlink "$file"
644617
done
645-
IFS=$OLDIFS
646-
fi
618+
done
619+
IFS=$OLDIFS
647620
PATH=$GIT_VALGRIND/bin:$PATH
648621
GIT_EXEC_PATH=$GIT_VALGRIND/bin
649622
export GIT_VALGRIND
650623
GIT_VALGRIND_MODE="$valgrind"
651624
export GIT_VALGRIND_MODE
652625
GIT_VALGRIND_ENABLED=t
653-
if test -n "$valgrind_only" || test -n "$valgrind_only_stride"
654-
then
655-
GIT_VALGRIND_ENABLED=
656-
fi
626+
test -n "$valgrind_only" && GIT_VALGRIND_ENABLED=
657627
export GIT_VALGRIND_ENABLED
658628
elif test -n "$GIT_TEST_INSTALLED"
659629
then
@@ -730,41 +700,6 @@ then
730700
else
731701
mkdir -p "$TRASH_DIRECTORY"
732702
fi
733-
734-
# Gross hack to spawn N sub-instances of the tests in parallel, and
735-
# summarize the results. Note that if this is enabled, the script
736-
# terminates at the end of this 'if' block.
737-
if test -n "$valgrind_parallel"
738-
then
739-
for i in $(test_seq 1 $valgrind_parallel)
740-
do
741-
root="$TRASH_DIRECTORY/vgparallel-$i"
742-
mkdir "$root"
743-
TEST_OUTPUT_DIRECTORY="$root" \
744-
${SHELL_PATH} "$0" \
745-
--root="$root" --statusprefix="[$i] " \
746-
--valgrind="$valgrind" \
747-
--valgrind-only-stride="$valgrind_parallel" \
748-
--valgrind-only-offset="$i" &
749-
pids="$pids $!"
750-
done
751-
trap "kill $pids" INT TERM HUP
752-
wait $pids
753-
trap - INT TERM HUP
754-
for i in $(test_seq 1 $valgrind_parallel)
755-
do
756-
root="$TRASH_DIRECTORY/vgparallel-$i"
757-
eval "$(cat "$root/test-results/$(basename "$0" .sh)"-*.counts |
758-
sed 's/^\([a-z][a-z]*\) \([0-9][0-9]*\)/inner_\1=\2/')"
759-
test_count=$(expr $test_count + $inner_total)
760-
test_success=$(expr $test_success + $inner_success)
761-
test_fixed=$(expr $test_fixed + $inner_fixed)
762-
test_broken=$(expr $test_broken + $inner_broken)
763-
test_failure=$(expr $test_failure + $inner_failed)
764-
done
765-
test_done
766-
fi
767-
768703
# Use -P to resolve symlinks in our working directory so that the cwd
769704
# in subprocesses like git equals our $PWD (for pathname comparisons).
770705
cd -P "$TRASH_DIRECTORY" || exit 1

0 commit comments

Comments
 (0)