progress.c tests: test some invalid usage

Test what happens when we "stop" without a "start", omit the "stop"
after a "start", or start two concurrent progress bars. This
extends the trace2 tests added in 98a1364740 (trace2: log progress
time and throughput, 2020-05-12).

These tests are not merely testing the helper, but invalid API usage
that can happen if the progress.c API is misused.

The "without stop" test will leak under SANITIZE=leak, since this
buggy use of the API will leak memory. But let's not skip it entirely,
or use the "!SANITIZE_LEAK" prerequisite check as we'd do with tests
that we're skipping due to leaks we haven't fixed yet. Instead
annotate the specific command that should skip leak checking with
custom $LSAN_OPTIONS[1].

1. https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2022-02-03 22:40:14 +01:00 committed by Junio C Hamano
parent 791afae292
commit bbfb1c243d

View File

@ -325,4 +325,54 @@ test_expect_success 'progress generates traces' '
grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event
'
test_expect_success 'progress generates traces: stop / start' '
cat >in <<-\EOF &&
start 0
stop
EOF
GIT_TRACE2_EVENT="$PWD/trace-startstop.event" test-tool progress \
<in 2>stderr &&
test_region progress "Working hard" trace-startstop.event
'
test_expect_success 'progress generates traces: start without stop' '
cat >in <<-\EOF &&
start 0
EOF
GIT_TRACE2_EVENT="$PWD/trace-start.event" \
LSAN_OPTIONS=detect_leaks=0 \
test-tool progress \
<in 2>stderr &&
grep region_enter.*progress trace-start.event &&
! grep region_leave.*progress trace-start.event
'
test_expect_success 'progress generates traces: stop without start' '
cat >in <<-\EOF &&
stop
EOF
GIT_TRACE2_EVENT="$PWD/trace-stop.event" test-tool progress \
<in 2>stderr &&
! grep region_enter.*progress trace-stop.event &&
! grep region_leave.*progress trace-stop.event
'
test_expect_success 'progress generates traces: start with active progress bar (no stops)' '
cat >in <<-\EOF &&
start 0 One
start 0 Two
EOF
GIT_TRACE2_EVENT="$PWD/trace-2start.event" \
LSAN_OPTIONS=detect_leaks=0 \
test-tool progress \
<in 2>stderr &&
grep region_enter.*progress.*One trace-2start.event &&
grep region_enter.*progress.*Two trace-2start.event &&
! grep region_leave trace-2start.event
'
test_done