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 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>

Ævar Arnfjörð Bjarmason committed Feb 3, 2022 at 22:40 UTC bbfb1c243d5da5dc0427346315d915ba02e8d0dd
1 file changed +50
t/t0500-progress-display.sh
+50
@@ -325,4 +325,54 @@ test_expect_success 'progress generates traces' '
325 grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event
326 '
327
328 +test_expect_success 'progress generates traces: stop / start' '
329 + cat >in <<-\EOF &&
330 + start 0
331 + stop
332 + EOF
333 +
334 + GIT_TRACE2_EVENT="$PWD/trace-startstop.event" test-tool progress \
335 + <in 2>stderr &&
336 + test_region progress "Working hard" trace-startstop.event
337 +'
338 +
339 +test_expect_success 'progress generates traces: start without stop' '
340 + cat >in <<-\EOF &&
341 + start 0
342 + EOF
343 +
344 + GIT_TRACE2_EVENT="$PWD/trace-start.event" \
345 + LSAN_OPTIONS=detect_leaks=0 \
346 + test-tool progress \
347 + <in 2>stderr &&
348 + grep region_enter.*progress trace-start.event &&
349 + ! grep region_leave.*progress trace-start.event
350 +'
351 +
352 +test_expect_success 'progress generates traces: stop without start' '
353 + cat >in <<-\EOF &&
354 + stop
355 + EOF
356 +
357 + GIT_TRACE2_EVENT="$PWD/trace-stop.event" test-tool progress \
358 + <in 2>stderr &&
359 + ! grep region_enter.*progress trace-stop.event &&
360 + ! grep region_leave.*progress trace-stop.event
361 +'
362 +
363 +test_expect_success 'progress generates traces: start with active progress bar (no stops)' '
364 + cat >in <<-\EOF &&
365 + start 0 One
366 + start 0 Two
367 + EOF
368 +
369 + GIT_TRACE2_EVENT="$PWD/trace-2start.event" \
370 + LSAN_OPTIONS=detect_leaks=0 \
371 + test-tool progress \
372 + <in 2>stderr &&
373 + grep region_enter.*progress.*One trace-2start.event &&
374 + grep region_enter.*progress.*Two trace-2start.event &&
375 + ! grep region_leave trace-2start.event
376 +'
377 +
378 test_done