]> git.ipfire.org Git - thirdparty/git.git/commitdiff
progress.c tests: test some invalid usage
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 3 Feb 2022 21:40:14 +0000 (22:40 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 3 Feb 2022 23:39:55 +0000 (15:39 -0800)
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 98a13647408 (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>
t/t0500-progress-display.sh

index 27ab4218b0142f8c53204dd3386ce8c35870584e..1eb3a8306ba15b3e782b940f605afa8ec551ec8c 100755 (executable)
@@ -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