From patchwork Mon Sep 20 23:09:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12506795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE6E9C4167D for ; Tue, 21 Sep 2021 02:21:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAD2961353 for ; Tue, 21 Sep 2021 02:21:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347970AbhIUCWo (ORCPT ); Mon, 20 Sep 2021 22:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236928AbhIUBvx (ORCPT ); Mon, 20 Sep 2021 21:51:53 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3230AC0386C2 for ; Mon, 20 Sep 2021 16:09:40 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id d21so33928039wra.12 for ; Mon, 20 Sep 2021 16:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7QeCV+mwRrYOX23QQEV6f+F70feUrK2Y4eZUQsru0yc=; b=EMNYHu5EBW2/O4IVWxP+n/GAqFpkQ3FWteW27jB3Yr7P9cQq5zBRj2Ty2FIoWibJHv maoxmqy7wP2276gK2Q0QoyYlOGNpMZVy9yUHROzDMF4gF5Vy8RZplvuyYMBmXaX64Nq/ CDmi7Uf7vMWvGYcpR8RcligPg3znpycdekEXFQKCUOfPp0jYYBmeotemZIl90QDrLJBK 1A+qLwHufLVRQjH5XN9DxXqAwY5+dzMFnpRfdEpibYUzYDxaTgLhuENc4tUnmsxM27D3 I6aCGt2H0CiOGWY3J6sLQWauI0Luzkci1zFq8yO/4CEU3okRnxWdPp/LOOl02HQmIfwj hu5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7QeCV+mwRrYOX23QQEV6f+F70feUrK2Y4eZUQsru0yc=; b=x2cZjlMmKD2r07vCAT2J6VXLnMnFFjjBYrtgVrybP7af212/H5muiWQYqqsEGMAJv5 k1dsesXL9GM1gywKLDXTQQiMxuLxxc7IQK1XeQOcWF1SFePXOuVlcerAPqne8dWaY406 QbMTPt1i6l7Hrzo//IyVnA8hPWMFebnoG47SZLJ7n4FM4LCr/PMwcMTXr+bx9ZWW1IKc RH6CrjDQYtaCWRvyiIqBXMc/35hC2xOofxdR21dzcCtnAzqj1iNyMtRwq90ZWV10hzfb jHr421WsaqLAN+1UrJF9q9/kV3ih6N+/sOEHkHqy+n/0+ZJBYu9g9SmETcobNlCS8AFj RyOw== X-Gm-Message-State: AOAM531mYBuml6o+do6sctTrfqcHEVTMCsNeoqgXY0OId0JXQWym7D+H DeqbAEeSTBntIzsAWVD6p09ExfEyFqPnJA== X-Google-Smtp-Source: ABdhPJy/mt5rt1DSOl5Xhx2HtGYXbS3FvzaGPD6eB4IY/2j/fc7EXhjTqsuBudsQ+HcnuFAB7Y118Q== X-Received: by 2002:a05:600c:20c:: with SMTP id 12mr1369229wmi.90.1632179378532; Mon, 20 Sep 2021 16:09:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm10409154wru.30.2021.09.20.16.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 16:09:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?SZEDER_G=C3=A1bor?= , =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v2 1/8] progress.c tests: make start/stop verbs on stdin Date: Tue, 21 Sep 2021 01:09:22 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the usage of the "test-tool progress" introduced in 2bb74b53a49 (Test the progress display, 2019-09-16) to take command like "start" and "stop" on stdin, instead of running them implicitly. This makes for tests that are easier to read, since the recipe will mirror the API usage, and allows for easily testing invalid usage that would yield (or should yield) a BUG(), e.g. providing two "start" calls in a row. A subsequent commit will add such stress tests. Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Emily Shaffer --- t/helper/test-progress.c | 43 +++++++++++++++++++-------- t/t0500-progress-display.sh | 59 +++++++++++++++++++++++-------------- 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c index 5d05cbe7894..685c0a7c49a 100644 --- a/t/helper/test-progress.c +++ b/t/helper/test-progress.c @@ -3,6 +3,9 @@ * * Reads instructions from standard input, one instruction per line: * + * "start[ [ ]]" - Call start_progress(title, total), + * when "start" use a title of + * "Working hard" with a total of 0. * "progress <items>" - Call display_progress() with the given item count * as parameter. * "throughput <bytes> <millis> - Call display_throughput() with the given @@ -10,6 +13,7 @@ * specify the time elapsed since the * start_progress() call. * "update" - Set the 'progress_update' flag. + * "stop" - Call stop_progress(). * * See 't0500-progress-display.sh' for examples. */ @@ -22,31 +26,41 @@ int cmd__progress(int argc, const char **argv) { - int total = 0; - const char *title; + const char *default_title = "Working hard"; + char *detached_title = NULL; struct strbuf line = STRBUF_INIT; - struct progress *progress; + struct progress *progress = NULL; const char *usage[] = { - "test-tool progress [--total=<n>] <progress-title>", + "test-tool progress <stdin", NULL }; struct option options[] = { - OPT_INTEGER(0, "total", &total, "total number of items"), OPT_END(), }; argc = parse_options(argc, argv, NULL, options, usage, 0); - if (argc != 1) - die("need a title for the progress output"); - title = argv[0]; + if (argc) + usage_with_options(usage, options); progress_testing = 1; - progress = start_progress(title, total); while (strbuf_getline(&line, stdin) != EOF) { char *end; - if (skip_prefix(line.buf, "progress ", (const char **) &end)) { + if (!strcmp(line.buf, "start")) { + progress = start_progress(default_title, 0); + } else if (skip_prefix(line.buf, "start ", (const char **) &end)) { + uint64_t total = strtoull(end, &end, 10); + if (*end == '\0') { + progress = start_progress(default_title, total); + } else if (*end == ' ') { + free(detached_title); + detached_title = strbuf_detach(&line, NULL); + progress = start_progress(end + 1, total); + } else { + die("invalid input: '%s'\n", line.buf); + } + } else if (skip_prefix(line.buf, "progress ", (const char **) &end)) { uint64_t item_count = strtoull(end, &end, 10); if (*end != '\0') die("invalid input: '%s'\n", line.buf); @@ -63,12 +77,15 @@ int cmd__progress(int argc, const char **argv) die("invalid input: '%s'\n", line.buf); progress_test_ns = test_ms * 1000 * 1000; display_throughput(progress, byte_count); - } else if (!strcmp(line.buf, "update")) + } else if (!strcmp(line.buf, "update")) { progress_test_force_update(); - else + } else if (!strcmp(line.buf, "stop")) { + stop_progress(&progress); + } else { die("invalid input: '%s'\n", line.buf); + } } - stop_progress(&progress); + free(detached_title); return 0; } diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index 22058b503ac..ca96ac1fa55 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -17,6 +17,7 @@ test_expect_success 'simple progress display' ' EOF cat >in <<-\EOF && + start 0 update progress 1 update @@ -25,8 +26,9 @@ test_expect_success 'simple progress display' ' progress 4 update progress 5 + stop EOF - test-tool progress "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -41,11 +43,13 @@ test_expect_success 'progress display with total' ' EOF cat >in <<-\EOF && + start 3 progress 1 progress 2 progress 3 + stop EOF - test-tool progress --total=3 "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -62,14 +66,14 @@ Working hard.......2.........3.........4.........5.........6: EOF cat >in <<-\EOF && + start 100000 Working hard.......2.........3.........4.........5.........6 progress 100 progress 1000 progress 10000 progress 100000 + stop EOF - test-tool progress --total=100000 \ - "Working hard.......2.........3.........4.........5.........6" \ - <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -88,16 +92,15 @@ Working hard.......2.........3.........4.........5.........6: EOF cat >in <<-\EOF && - update + start 100000 Working hard.......2.........3.........4.........5.........6 progress 1 update progress 2 progress 10000 progress 100000 + stop EOF - test-tool progress --total=100000 \ - "Working hard.......2.........3.........4.........5.........6" \ - <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -116,14 +119,14 @@ Working hard.......2.........3.........4.........5.........6: EOF cat >in <<-\EOF && + start 100000 Working hard.......2.........3.........4.........5.........6 progress 25000 progress 50000 progress 75000 progress 100000 + stop EOF - test-tool progress --total=100000 \ - "Working hard.......2.........3.........4.........5.........6" \ - <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -140,14 +143,14 @@ Working hard.......2.........3.........4.........5.........6.........7.........: EOF cat >in <<-\EOF && + start 100000 Working hard.......2.........3.........4.........5.........6.........7......... progress 25000 progress 50000 progress 75000 progress 100000 + stop EOF - test-tool progress --total=100000 \ - "Working hard.......2.........3.........4.........5.........6.........7........." \ - <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -164,12 +167,14 @@ test_expect_success 'progress shortens - crazy caller' ' EOF cat >in <<-\EOF && + start 1000 progress 100 progress 200 progress 1 progress 1000 + stop EOF - test-tool progress --total=1000 "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -185,6 +190,7 @@ test_expect_success 'progress display with throughput' ' EOF cat >in <<-\EOF && + start throughput 102400 1000 update progress 10 @@ -197,8 +203,9 @@ test_expect_success 'progress display with throughput' ' throughput 409600 4000 update progress 40 + stop EOF - test-tool progress "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -214,6 +221,7 @@ test_expect_success 'progress display with throughput and total' ' EOF cat >in <<-\EOF && + start 40 throughput 102400 1000 progress 10 throughput 204800 2000 @@ -222,8 +230,9 @@ test_expect_success 'progress display with throughput and total' ' progress 30 throughput 409600 4000 progress 40 + stop EOF - test-tool progress --total=40 "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -239,6 +248,7 @@ test_expect_success 'cover up after throughput shortens' ' EOF cat >in <<-\EOF && + start throughput 409600 1000 update progress 1 @@ -251,8 +261,9 @@ test_expect_success 'cover up after throughput shortens' ' throughput 1638400 4000 update progress 4 + stop EOF - test-tool progress "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -267,6 +278,7 @@ test_expect_success 'cover up after throughput shortens a lot' ' EOF cat >in <<-\EOF && + start throughput 1 1000 update progress 1 @@ -276,8 +288,9 @@ test_expect_success 'cover up after throughput shortens a lot' ' throughput 3145728 3000 update progress 3 + stop EOF - test-tool progress "Working hard" <in 2>stderr && + test-tool progress <in 2>stderr && show_cr <stderr >out && test_cmp expect out @@ -285,6 +298,7 @@ test_expect_success 'cover up after throughput shortens a lot' ' test_expect_success 'progress generates traces' ' cat >in <<-\EOF && + start 40 throughput 102400 1000 update progress 10 @@ -297,10 +311,11 @@ test_expect_success 'progress generates traces' ' throughput 409600 4000 update progress 40 + stop EOF - GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool progress --total=40 \ - "Working hard" <in 2>stderr && + GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool progress \ + <in 2>stderr && # t0212/parse_events.perl intentionally omits regions and data. test_region progress "Working hard" trace.event && From patchwork Mon Sep 20 23:09:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12506797 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA3F2C4167B for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:21:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D57336134F for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:21:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347990AbhIUCWq (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 20 Sep 2021 22:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236929AbhIUBvx (ORCPT <rfc822;git@vger.kernel.org>); Mon, 20 Sep 2021 21:51:53 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1778C0386C3 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:40 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id t8so33999428wrq.4 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jl93F6D2mfoyFx0Y28aThKOlb8mtcUJajLA2zpkbph8=; b=XJKnm6hhaXoO+CUcaDngOA7Rj8m7SKbPwK16sBi2OJQyPtXlQ1mPOjH0+opFgbsz4X e85AppEhl1ThutbvlzHqKDNtvKNXW9e+AZCzF4HXMkuVaMpN5tmUh6CPRwMZ/7CBdBYk FJBLIuAS0hEmnpnBjgyHzj3oRy2a3AODNyhMKLTho35NOOHrkBnqevAXnpaOsmqEhUei 0P+VINogvOsQbeoM1OzZw4HTTMtKJPRhRE2Rwu/3H4B8siI6nwIVk/1HqhbobDa92zMU BqglWgupBGlpSKfJuHFQBQgBN3qpsjjyOeZSG+2BX4ILyxAJZ8JDHsRAWxeUldln0q8n avDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jl93F6D2mfoyFx0Y28aThKOlb8mtcUJajLA2zpkbph8=; b=P0zRXNToszAK/GTBWOwo0fOA2toCCswN5oSzKGdzgMDevICQhcC6zlZW8y8v8ut2me PNYSWuqOldnq20k3hIxtXW7j/yEgRSUW6fwtmUPXbb1XffBFlVQCnmBxHhY8f4fWL9rD gGiAb3OK/7ZRdsC64XYkAM7Lp4VBG+/4FW7smrYIxFo6cId1dB0DhR7UKDYXnafk8fvw ht7x7nSBahNOP9zjPuEKCbzfa4mK9DgGrlwpgj1oGNi4an+RQbFnaiBcpCalnCglANCr LkYhKhe8q0jDuiSiCgLkM/Gi+aK7GR5irNl9ny7prMD2QvjNDO/y4IYWYUdykxypbx8x wIQA== X-Gm-Message-State: AOAM530VL/guO2Nh3+Pk1qvYYFyc3keE2N24PAXxeEtEglSOHrAkM2IJ 5Sb1W8syVS4pKbYBxBSjIKsoR0XdnniD2g== X-Google-Smtp-Source: ABdhPJxAU36dPqjI3ve2bIbMa2H6RG10sEVY+x8qA1kucJz1ryqfjEEVlLkg6Rtm7Z/+nOyun5PK6A== X-Received: by 2002:a1c:7ed3:: with SMTP id z202mr1347025wmc.152.1632179379328; Mon, 20 Sep 2021 16:09:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm10409154wru.30.2021.09.20.16.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 16:09:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v2 2/8] progress.c tests: test some invalid usage Date: Tue, 21 Sep 2021 01:09:23 +0200 Message-Id: <patch-v2-2.8-7b1220b641e-20210920T225701Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d In-Reply-To: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> References: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Test what happens when we "stop" without a "start", omit the "stop" after a "start", or try to start two concurrent progress bars. This extends the trace2 tests added in 98a13647408 (trace2: log progress time and throughput, 2020-05-12). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> --- t/t0500-progress-display.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index ca96ac1fa55..ffa819ca1db 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -323,4 +323,37 @@ 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 + 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 + EOF + + GIT_TRACE2_EVENT="$(pwd)/trace-start.event" 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_done From patchwork Mon Sep 20 23:09:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12506801 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02C9BC4167E for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0D7A61355 for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:21:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348033AbhIUCWs (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 20 Sep 2021 22:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236931AbhIUBvy (ORCPT <rfc822;git@vger.kernel.org>); Mon, 20 Sep 2021 21:51:54 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FFE6C0386C4 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:41 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id u18so32248661wrg.5 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QAW3l7E2VC5xfPBAYoUUmqk4sQJhfNBZ2Uvg11ooxjE=; b=bDAzdp9BmQmck2FJzIzxn5QFTAfWByIU2gDoQw5WwnrsUi2iup1ewHsscSgpwC88Lz mzLTn69HnJOE+Cq4xca4y66wffHeo1ACIxcUKVUxwXcOyGNP63bkRhF0XRmOFk3Kaw+I lD+o/SeSPE+29B6RZqclWg+0Zixk0M7Qs413glmvk/bJ6/odjMhCVYwcHoOGn8ldms4S dnnZdXDk339bSVxgso/7j3BppM/JZZIVHleEM6TmUUiejvB1TTPuXtt+wUzwj/him85L yp6rXR5sDiqDq7PjAXMGzC2ZlNRaC2FquCAmp5Av7YxyEcyWEuV9o6M8vlwsVxnLB7aP tLHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QAW3l7E2VC5xfPBAYoUUmqk4sQJhfNBZ2Uvg11ooxjE=; b=MwMI6pqqE06lTp0LH8B+QMlsxiki/XmGLPzVdwKd7h4zdFipDEMfqSsL457iXX9NNw 6S2lMzLtFNwApsDWJpT44L5NW//9U/pLq+dQAdXwjx4xCV6DX0Jgt7Y4rXeutAoFeYZQ MDnzfmIO+R6kmex+o5EkzgVWHi1UPJJRTP/hNEGqeJqX5B5VQvFZVnJjdAVMHqjTZPuC nECIZEC/w01JWljq2Wd/iavcGFjgcFu6LNqOwXPxM6Jv7WW0l+nEhu7YjqMoeGCiFxHf 5Kyx3sUbaiTx8j/TmTx7oIGkz56/Xl2z+KuaLHQe/bgpavx6hamn6flvPpojv7uKQg28 7jKg== X-Gm-Message-State: AOAM533oPGkKwNY+60UpcVGGcrhHJJMMhlgHmSTsuFhWF6j9qyk93w2Z jvqlx5ervXQCR1k2apu+pp+ZWwal63W+yA== X-Google-Smtp-Source: ABdhPJxK1f8oT0qiP2hPpAYymLr9b0Lzfc8e99MEWbP3hjWbW/Jr7DqUGvZC4QAjdntFMIl1pbMHDw== X-Received: by 2002:a05:600c:1c9e:: with SMTP id k30mr1381412wms.74.1632179379990; Mon, 20 Sep 2021 16:09:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm10409154wru.30.2021.09.20.16.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 16:09:39 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v2 3/8] progress.c: move signal handler functions lower Date: Tue, 21 Sep 2021 01:09:24 +0200 Message-Id: <patch-v2-3.8-f1b8bf1dbde-20210920T225701Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d In-Reply-To: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> References: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Move the signal handler functions to just before the start_progress_delay() where they'll be referenced, instead of having them at the top of the file. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- progress.c | 92 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/progress.c b/progress.c index 680c6a8bf93..893cb0fe56f 100644 --- a/progress.c +++ b/progress.c @@ -53,50 +53,6 @@ static volatile sig_atomic_t progress_update; */ int progress_testing; uint64_t progress_test_ns = 0; -void progress_test_force_update(void) -{ - progress_update = 1; -} - - -static void progress_interval(int signum) -{ - progress_update = 1; -} - -static void set_progress_signal(void) -{ - struct sigaction sa; - struct itimerval v; - - if (progress_testing) - return; - - progress_update = 0; - - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = progress_interval; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; - sigaction(SIGALRM, &sa, NULL); - - v.it_interval.tv_sec = 1; - v.it_interval.tv_usec = 0; - v.it_value = v.it_interval; - setitimer(ITIMER_REAL, &v, NULL); -} - -static void clear_progress_signal(void) -{ - struct itimerval v = {{0,},}; - - if (progress_testing) - return; - - setitimer(ITIMER_REAL, &v, NULL); - signal(SIGALRM, SIG_IGN); - progress_update = 0; -} static int is_foreground_fd(int fd) { @@ -249,6 +205,54 @@ void display_progress(struct progress *progress, uint64_t n) display(progress, n, NULL); } +static void progress_interval(int signum) +{ + progress_update = 1; +} + +/* + * The progress_test_force_update() function is intended for testing + * the progress output, i.e. exclusively for 'test-tool progress'. + */ +void progress_test_force_update(void) +{ + progress_update = 1; +} + +static void set_progress_signal(void) +{ + struct sigaction sa; + struct itimerval v; + + if (progress_testing) + return; + + progress_update = 0; + + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = progress_interval; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; + sigaction(SIGALRM, &sa, NULL); + + v.it_interval.tv_sec = 1; + v.it_interval.tv_usec = 0; + v.it_value = v.it_interval; + setitimer(ITIMER_REAL, &v, NULL); +} + +static void clear_progress_signal(void) +{ + struct itimerval v = {{0,},}; + + if (progress_testing) + return; + + setitimer(ITIMER_REAL, &v, NULL); + signal(SIGALRM, SIG_IGN); + progress_update = 0; +} + static struct progress *start_progress_delay(const char *title, uint64_t total, unsigned delay, unsigned sparse) { From patchwork Mon Sep 20 23:09:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12506799 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08B94C41535 for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE55E61245 for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:21:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348073AbhIUCWu (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 20 Sep 2021 22:22:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236934AbhIUBvy (ORCPT <rfc822;git@vger.kernel.org>); Mon, 20 Sep 2021 21:51:54 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53B30C0386C5 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:42 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id d6so33823832wrc.11 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=naZsfccnHocyUpE9k5UBiFNcCExxwcQZUqhxEIadO0o=; b=mqQPeshkCYnxrbgRSJ9bgLlq01pQqyy+PNd5RTBC5iC8zl8QrXyCVdKtWZ4z/C8x45 FSfUMaNXkYrbINofCfRIDWxQsl1OCEUgDlY7hsICh+vMtm9kpaX55ywhw4RA17veGNjS UK/Nmqhtv12UovcZFORGj0tF4ab4p70X7jkPFUujoJ3oF0AMbYEcJSJAxru7LVmqyhhZ OV67aUKAOTvnEIbQq5gD3Cfq4VWpAYGFBgyTsueQUSCTC/BTUU0lY8TmjifoBP/eULcU uXsebY4POFe/CFfuqJojKHx1fWEjxBNit5mB+h35Bt48B0FNT2HGJkj6MTfQMG48ZeIO gNTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=naZsfccnHocyUpE9k5UBiFNcCExxwcQZUqhxEIadO0o=; b=GlwOe3zXFBrW8Bdf3eUvbaOViZ8lVG6Dol+9O5zIuQG4ck0uU+xjN3r+1eaHBkpBUQ 6eFy7DyGl9SrbpQK0dEfXt9VeuVKH0OTnDk7TOHg3ThhYn4j4PSblSeAmSJ9YzThRmzO +mQ8zticRDpSdONR1jDfnjAOox52x2Q5H07cT6AhAwqu9Q4t1sO/d3+Ms5CPOX8f9I6g RgXpU+9SH8e10GDvB/nYiAcE4VLdqxT96rU+UGHiTffNlOY+WLKIJ1UDT5xnbXTuo+HH hGx8eV27mlzM1QTa5dh5FxBH7BmWo1kxs44Wg+nUX/aIrVjdCT7xuHOwUTHXJU0ZoMaD K+3g== X-Gm-Message-State: AOAM533TzvsrpIbyeY3WwD8oCloctCGT2fGIQhaxIBByGJek/piT4wol VMiGdYSApdFVGVYhzG1WlzC23XfhLAZhpg== X-Google-Smtp-Source: ABdhPJycTVrFnd0paHrbbmjB4SN18fS2eHNwCJeUMQC6Qvg1ERJMtCWR5NwIVCKgXK3scI1kiQaTUg== X-Received: by 2002:adf:ce84:: with SMTP id r4mr31675183wrn.107.1632179380750; Mon, 20 Sep 2021 16:09:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm10409154wru.30.2021.09.20.16.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 16:09:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v2 4/8] progress.c: call progress_interval() from progress_test_force_update() Date: Tue, 21 Sep 2021 01:09:25 +0200 Message-Id: <patch-v2-4.8-74057b0046a-20210920T225701Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d In-Reply-To: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> References: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Define the progress_test_force_update() function in terms of progress_interval(). For documentation purposes these two functions have the same body, but different names. Let's just define the test function by calling progress_interval() with SIGALRM ourselves. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progress.c b/progress.c index 893cb0fe56f..7fcc513717a 100644 --- a/progress.c +++ b/progress.c @@ -216,7 +216,7 @@ static void progress_interval(int signum) */ void progress_test_force_update(void) { - progress_update = 1; + progress_interval(SIGALRM); } static void set_progress_signal(void) From patchwork Mon Sep 20 23:09:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12506807 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DF04C28B2E for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04B756124C for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348094AbhIUCWw (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 20 Sep 2021 22:22:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236944AbhIUBvz (ORCPT <rfc822;git@vger.kernel.org>); Mon, 20 Sep 2021 21:51:55 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1290AC0386C6 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:43 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id q26so33952967wrc.7 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nWArdbesqrtoFzdFuzsNBHMZqO+dxCaMAkuhy7POVic=; b=hz7qvYPH2a6brtPTkRBtKFbppw9nE8WFizAyTMzWmaJ6vKqfFGv8uhICOzWh/UmHmB GmfOLVe7+601Jy0r019xLM/igF6l1IKOES30BH36A7XNkwDT8ZNvmUum0JNMQuWoQY1p GNp5rsM8hCWxKBkyXhrjjFO9ODJPD3FMFJvlCfbSzJfsZCCtjGvkarpNZKqo6psa2Dms GEKljogjtvKIDF1JWV1mxMxB5VIxlgxz1gSZ7ZegAFiXJtEJb4KnRa8lBDzktUepV5Er 6G0EoSj4kqe0Gfp+Z3g3/TlAnvDb9DhcMyBoleJbGZy6Ndv/hwMY15yEmJm/S1gbUclR jX5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nWArdbesqrtoFzdFuzsNBHMZqO+dxCaMAkuhy7POVic=; b=WlpJ/OUtwsYNy7P14GHGLJ2/jvdMpDIAsr+CC5Xya9ILZjmS7m60c2jSMaMdcYFV8N 8VudixjXUEZ89JbOwuG02uT262p528UHdruFxiwThvLunAAw82oXtyZ9jJS6cRDAsKzL c6HtbwIWe2c93oudTNOUlTWPrFnOwEXsCNkWdQwCoc417GC8B+5QVlBmyT8ZggjS9cKm Evl74d+0LJF8i5pKoYqgV3EhE1FOzg3+qw7UHATGQgvJxtrgVwuia9Ie5EndsnjoEhpV f7Su7hAK0pwuoZMaciJfimaUa42oUYCvGsY7JIOfyShM2bplFceZAs8zIczrqKLijlen Rquw== X-Gm-Message-State: AOAM532HV2dhdEhAwGW9fuLacgQHD5MhIwWQBZQYSbY6DkE9YpMJJLC8 JQck6jQoxKepTVuYLpkh9DdFcsisSUMhQA== X-Google-Smtp-Source: ABdhPJyCoI4WXxuGMqtuF+dM6Jy5hS6qpbKCg6i5/eTGZkOIOrb+OpOwfWesyHeoV0CHPDS2wxebKQ== X-Received: by 2002:a05:600c:3b89:: with SMTP id n9mr1392118wms.186.1632179381458; Mon, 20 Sep 2021 16:09:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm10409154wru.30.2021.09.20.16.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 16:09:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v2 5/8] progress.c: stop eagerly fflush(stderr) when not a terminal Date: Tue, 21 Sep 2021 01:09:26 +0200 Message-Id: <patch-v2-5.8-250e50667c2-20210920T225701Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d In-Reply-To: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> References: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org It's the clear intention of the combination of 137a0d0ef56 (Flush progress message buffer in display()., 2007-11-19) and 85cb8906f0e (progress: no progress in background, 2015-04-13) to call fflush(stderr) when we have a stderr in the foreground, but we ended up always calling fflush(stderr) seemingly by omission. Let's not. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> --- progress.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/progress.c b/progress.c index 7fcc513717a..1fade5808de 100644 --- a/progress.c +++ b/progress.c @@ -91,7 +91,8 @@ static void display(struct progress *progress, uint64_t n, const char *done) } if (show_update) { - if (is_foreground_fd(fileno(stderr)) || done) { + int stderr_is_foreground_fd = is_foreground_fd(fileno(stderr)); + if (stderr_is_foreground_fd || done) { const char *eol = done ? done : "\r"; size_t clear_len = counters_sb->len < last_count_len ? last_count_len - counters_sb->len + 1 : @@ -115,7 +116,8 @@ static void display(struct progress *progress, uint64_t n, const char *done) fprintf(stderr, "%s: %s%*s", progress->title, counters_sb->buf, (int) clear_len, eol); } - fflush(stderr); + if (stderr_is_foreground_fd) + fflush(stderr); } progress_update = 0; } From patchwork Mon Sep 20 23:09:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12506803 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3357FC4727C for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1938D6124C for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348115AbhIUCWy (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 20 Sep 2021 22:22:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236940AbhIUBvz (ORCPT <rfc822;git@vger.kernel.org>); Mon, 20 Sep 2021 21:51:55 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D55DDC0386C7 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:43 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id w29so33983740wra.8 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FVXQq1j43TFhFUc+YP1fgFv6CFKstbnD0H9uw1sPm9E=; b=OK7l5anXvxsBeTKuSv8Ave5vLKiTmzZJCAkrJrrlZvdtgxPdIVnUlSJJw9Ixtmz6TK 7g5r8cYtWNzuIn91NLxtkUOncLMp3B2xIg68+GRvWXPzOckdNTssmb/YagnEmMcaQCmx A8qVIMQ0ABqHSLWDMGhkbZuJ225CquqG95qOnPI2SNeISzPh+6qOj1xf6VFoiu/sypdN Zjhy84uutcjx8OXST0RcIcWt0dQtDCXU6HhnUYYk+cRIB76dBtMNKSLWTx7JZ/F1X81b W7+447S0fjBW418xeQGslTqNx4mCfvtIOWMAbT8M0lWmKcuwEbASbjCBUuXAZFoUQyQZ kyTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FVXQq1j43TFhFUc+YP1fgFv6CFKstbnD0H9uw1sPm9E=; b=Pax5UMvOjPrezeQUIbUp2Ge0lEilnmcYwuyYe02ygtcVwpfXDpgXKuIEI6TXwpXDXO moPNxUGm8N1UprJiUHe0bEOqTMyASx39hip305T0eJ4RtTEb/Dtd/ZNb4rSM7WglPIeM 0+gTMgEZ6bC+MjANr/w8oOcGGWMpAI6jDilsjVEE0brNvLaMrqEMtQbbTYuBgZeGHGwH iGMv0zygl6X6EpmKcitFLJqt7tSGWYv6qXXcJDkdstBZ2xN88Z8q9EvTpVe5chXi0hk1 sm2mpa6XzSmD6p8yrXPhgqWDbgI3WDfGoG6K3eAcuhHwWem883ITSCUIGAe+lTyGpedy zuoQ== X-Gm-Message-State: AOAM530fzH5uwg7kZ8ogs0Ca/JQfmVkPRLh/yGjS94u3h6ZR/rSMf3ez r/B5ubUslOvghnECvdo8AL7RF1e5hAopwA== X-Google-Smtp-Source: ABdhPJziKmaOt8xz1wN3OIIRx54MdpIh/1c4yg4h6jhiweB/7bkFBhQ/X4/2HYISmCpmWHKFvYDuEw== X-Received: by 2002:a1c:ed10:: with SMTP id l16mr1415514wmh.8.1632179382217; Mon, 20 Sep 2021 16:09:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm10409154wru.30.2021.09.20.16.09.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 16:09:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v2 6/8] progress.c: add temporary variable from progress struct Date: Tue, 21 Sep 2021 01:09:27 +0200 Message-Id: <patch-v2-6.8-d4e9ff1de73-20210920T225701Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d In-Reply-To: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> References: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Add a temporary "progress" variable for the dereferenced p_progress pointer to a "struct progress *". Before 98a13647408 (trace2: log progress time and throughput, 2020-05-12) we didn't dereference "p_progress" in this function, now that we do it's easier to read the code if we work with a "progress" struct pointer like everywhere else, instead of a pointer to a pointer. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> --- progress.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/progress.c b/progress.c index 1fade5808de..1ab7d19deb8 100644 --- a/progress.c +++ b/progress.c @@ -331,15 +331,16 @@ void stop_progress(struct progress **p_progress) finish_if_sparse(*p_progress); if (*p_progress) { + struct progress *progress = *p_progress; trace2_data_intmax("progress", the_repository, "total_objects", (*p_progress)->total); if ((*p_progress)->throughput) trace2_data_intmax("progress", the_repository, "total_bytes", - (*p_progress)->throughput->curr_total); + progress->throughput->curr_total); - trace2_region_leave("progress", (*p_progress)->title, the_repository); + trace2_region_leave("progress", progress->title, the_repository); } stop_progress_msg(p_progress, _("done")); From patchwork Mon Sep 20 23:09:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12506805 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E0ACC28B57 for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 245AA61268 for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348131AbhIUCWz (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 20 Sep 2021 22:22:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236948AbhIUBvz (ORCPT <rfc822;git@vger.kernel.org>); Mon, 20 Sep 2021 21:51:55 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B6BBC0386C8 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:44 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id t7so728898wrw.13 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=naZ0LHBIRKwmSuHqHqHXtxUtYulOiw0Z/A0mhATm+hE=; b=ZuitZG0XpiZAPc841Qg+5t5VyKLmq13DhSnzoKJiJWY0ZETJC/g77z5dyEfITyFiMm HFnRBR6i7nZECHaS+ZkqTmRDyZJNh2NngkUOfnINAqhxXNSoUX32wJnmRC8fGoWIs/h3 i2OCV7gfOptOKwi5xuxO89yWHhk7ua6WBpLT2aPT0l0Nut2gp0mCCoOja4boLqRBYgtI +jwgmFPUWb8LDCOLYhqjHNA5oYldJtxfckwA3K9yXzj2mVAPd5RUil5avhTLaiv1DOTH nzmxidoxfR45/yridjrGVgzczdXcr7Uwj/bfy9d8lIS/Z7UX4iH7OYq47mHoxYxX+f7z Ll/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=naZ0LHBIRKwmSuHqHqHXtxUtYulOiw0Z/A0mhATm+hE=; b=fFVGKeHlp/4GaIX2JMTO8W1PU3H1i1NGB5kDRhhZjOMjCZtuQyP8k92PuGwTGWqLMl qKiyBPztJKNX3XLhgs6+SBtJny38Qp8VnWIW9CQYu6OmF+VNbARUVZ4WVrunZ3d+lJfV B8sfe9XBV5vV/tja80cZEvkDKQtA7hMcbMlGJg7f6oZjeSqqPXEN9ZoHZRg/uUZHj5sx HUwVgEJWyzSs5g17ThqScs7HR9E5iKkvICM8M0LDQ/ditfNhCp5NiSDkw3vHRS4mQOT5 02o4fiTRuc0x12Jpq9usoS4PgICIUZV5gI7M7kjVorGqJDnyBeh5xehiVpJCkpCmOqtJ m5Gg== X-Gm-Message-State: AOAM530ia6E3kFbqnTDVDdi1h5Rr/Etf9P9yatmyo1HKPBLJtTq11YPq U6ie9Ye1ym8sCV+WIxotWzl1U0VEf6lHCQ== X-Google-Smtp-Source: ABdhPJwaqJlwnmzTKW3l/5Ij9NLcPBTELQA76TA7SeDNEkCWYHiQlNKinFYsgUkbOKZNEFkY/axxkw== X-Received: by 2002:a5d:54cf:: with SMTP id x15mr32120281wrv.27.1632179382936; Mon, 20 Sep 2021 16:09:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm10409154wru.30.2021.09.20.16.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 16:09:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v2 7/8] pack-bitmap-write.c: add a missing stop_progress() Date: Tue, 21 Sep 2021 01:09:28 +0200 Message-Id: <patch-v2-7.8-a3f133ca7ad-20210920T225701Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d In-Reply-To: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> References: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Fix a bug that's been here since 7cc8f971085 (pack-objects: implement bitmap writing, 2013-12-21), we did not call stop_progress() if we reached the early exit in this function. This will matter in a subsequent commit where we BUG(...) out if this happens, and matters now e.g. because we don't have a corresponding "region_end" for the progress trace2 event. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> --- pack-bitmap-write.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 88d9e696a54..6e110e41ea4 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -550,6 +550,7 @@ void bitmap_writer_select_commits(struct commit **indexed_commits, if (indexed_commits_nr < 100) { for (i = 0; i < indexed_commits_nr; ++i) push_bitmapped_commit(indexed_commits[i]); + stop_progress(&writer.progress); return; } From patchwork Mon Sep 20 23:09:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12506809 Return-Path: <git-owner@kernel.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C2EFC28CAB for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 368336135A for <git@archiver.kernel.org>; Tue, 21 Sep 2021 02:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348155AbhIUCW5 (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 20 Sep 2021 22:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236951AbhIUBvz (ORCPT <rfc822;git@vger.kernel.org>); Mon, 20 Sep 2021 21:51:55 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7745BC0386C9 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:45 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id q11so33982592wrr.9 for <git@vger.kernel.org>; Mon, 20 Sep 2021 16:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5d2I3N/f87AORrgrORJFxXfRXq5GxsOnBkOVkMCC3CM=; b=RYcVr/mpHYW40/6ioRVPNR6UG65zx1f0yda/gAmBREYVGR/xaYOZgb/5E2UPLz2hgH rHk4PwhKdru9Jmm1OwXIUYgR2H6I405fhJvZPSOlMkNO8CyJUZJ0YH61EyQnZYKOIaBQ xpKNZ/kBPbYcKystlyH5qky9YEyJWW8J8CjuzE8ykStlFuLoPssAWdlhknMBsb8DhoMK nEpNsJKF58ZTUwKa1e8ZscQK0vA+EUoiD5yyUqK2fGiVmSqRObZfWxJyb2dCzFnozuRH Xd2xkWJ8wnVenJXx6sLYNFabOyBUv8zO5rFdXuKquPr5toAJX9iVW8M0LBNvpplsSoro 7XNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5d2I3N/f87AORrgrORJFxXfRXq5GxsOnBkOVkMCC3CM=; b=e+i1cZYZ/xlrUUQ2R5obFmWQzPph64U3m83Xn83uRpHMvc7MpkBAou86CEsHoPN9FH 7t1nMNFBJXirFOYY2f3mNyo/Yg9AV/jms6/MUkOOjB9GqwYSV6yjXsiThmHSrEXAE1+9 UsCFX5P1O0UwDmW+Gi8AkRDAHTzYoXc/O4M6AxgfCFwPxk63cEz8SaHgEFH3ttUbrn19 WspA/k9huBp4sD4snVwNqW0dvsGV0VPd+7EtqmqNnYLyVM/bdBcAypRjKTG7mxnqdzS8 CdTSBax8ciFwo/AiscPehHPnVY48G6XUmOuX800btsAE5gwRnU2PVjdMu1wqaegkVXEC fLOg== X-Gm-Message-State: AOAM530ofjkeZY5gxH7z8IZfB3R7gnkfOVTurP1UAby3X3gmA69jtntY 9vz9eJVV3vbGriOS64DParXz0PQE/p1HzA== X-Google-Smtp-Source: ABdhPJzPTAT0nxLs1WjH755xTCe0NCINA0sM38xgSh3pa7s3QR5a9U20v91TTZDT6kjjNsstqD10UA== X-Received: by 2002:adf:e481:: with SMTP id i1mr30997670wrm.353.1632179383828; Mon, 20 Sep 2021 16:09:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c8sm10409154wru.30.2021.09.20.16.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 16:09:43 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, =?utf-8?q?SZEDER_G=C3=A1bor?= <szeder.dev@gmail.com>, =?utf-8?q?Ren=C3=A9_S?= =?utf-8?q?charfe?= <l.s.r@web.de>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v2 8/8] progress.c: add & assert a "global_progress" variable Date: Tue, 21 Sep 2021 01:09:29 +0200 Message-Id: <patch-v2-8.8-1bd285eba0d-20210920T225701Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d In-Reply-To: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> References: <cover-0.8-0000000000-20210722T125012Z-avarab@gmail.com> <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org The progress.c code makes a hard assumption that only one progress bar be active at a time (see [1] for a bug where this wasn't the case). Add a BUG() that'll trigger if we ever regress on that promise and have two progress bars active at the same time. There was an alternative test-only approach to doing the same thing[2], but by doing this outside of a GIT_TEST_* mode we'll know we've put a hard stop to this particular API misuse. It will also establish scaffolding to address current fundamental limitations in the progress output: The current output must be "driven" by calls to the likes of display_progress(). Once we have a global current progress object we'll be able to update that object via SIGALRM. See [3] for early code to do that. It's conceivable that this change will hit the BUG() condition in some scenario that we don't currently have tests for, this would be very bad. If that happened we'd die just because we couldn't emit some pretty output. See [4] for a discussion of why our test coverage is lacking; our progress display is hidden behind isatty(2) checks in many cases, so the test suite doesn't cover it unless individual tests are run in "--verbose" mode, we might also have multi-threaded use of the API, so two progress bars stopping and starting would only be visible due to a race condition. Despite that, I think that this change won't introduce such regressions, because: 1. I've read all the code using the progress API (and have modified a large part of it in some WIP code I have). Almost all of it is really simple, the parts that aren't[5] are complex in the display_progress() part, not in starting or stopping the progress bar. 2. The entire test suite passes when instrumented with an ad-hoc Linux-specific mode (it uses gettid()) to die if progress bars are ever started or stopped on anything but the main thread[6]. Extending that to die if display_progress() is called in a thread reveals that we have exactly two users of the progress bar under threaded conditions, "git index-pack" and "git pack-objects". Both uses are straightforward, and they don't start/stop the progress bar when threads are active. 3. I've likewise done an ad-hoc test to force progress bars to be displayed with: perl -pi -e 's[isatty\((?:STDERR_FILENO|2)\)][1]g' $(git grep -l 'isatty\((STDERR_FILENO|2)\)') I.e. to replace all checks (not just for progress) of checking whether STDERR is connected to a TTY, and then monkeypatching is_foreground_fd() in progress.c to always "return 1". Running the tests with those applied, interactively and under -V reveals via: $ grep -e set_progress_signal -e clear_progress_signal test-results/*out That nothing our tests cover hits the BUG conditions added here, except the expected "BUG: start two concurrent progress bars" test being added here. That isn't entirely true since we won't be getting 100% coverage due to cascading failures from tests that expected no progress output on stderr. To make sure I covered 100% I also tried making the display() function in progress.c a NOOP on top of that (it's the calls to start_progress_delay() and stop_progress()) that matter. That doesn't hit the BUG() either. Some tests fail in that mode due to a combination of the overzealous isatty(2) munging noted above, and the tests that are testing that the progress output itself is present (but for testing I'd made display() a NOOP). Between those three points I think it's safe to go ahead with this change. 1. 6f9d5f2fda1 (commit-graph: fix progress of reachable commits, 2020-07-09) 2. https://lore.kernel.org/git/20210620200303.2328957-3-szeder.dev@gmail.com 3. https://lore.kernel.org/git/patch-18.25-e21fc66623f-20210623T155626Z-avarab@gmail.com/ 4. https://lore.kernel.org/git/cover-00.25-00000000000-20210623T155626Z-avarab@gmail.com/ 5. b50c37aa44d (Merge branch 'ab/progress-users-adjust-counters' into next, 2021-09-10) 6. https://lore.kernel.org/git/877dffg37n.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> --- progress.c | 17 +++++++++++++---- t/t0500-progress-display.sh | 11 +++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/progress.c b/progress.c index 1ab7d19deb8..14a023f4b43 100644 --- a/progress.c +++ b/progress.c @@ -46,6 +46,7 @@ struct progress { }; static volatile sig_atomic_t progress_update; +static struct progress *global_progress; /* * These are only intended for testing the progress output, i.e. exclusively @@ -221,11 +222,15 @@ void progress_test_force_update(void) progress_interval(SIGALRM); } -static void set_progress_signal(void) +static void set_progress_signal(struct progress *progress) { struct sigaction sa; struct itimerval v; + if (global_progress) + BUG("should have no global_progress in set_progress_signal()"); + global_progress = progress; + if (progress_testing) return; @@ -243,10 +248,14 @@ static void set_progress_signal(void) setitimer(ITIMER_REAL, &v, NULL); } -static void clear_progress_signal(void) +static void clear_progress_signal(struct progress *progress) { struct itimerval v = {{0,},}; + if (!global_progress) + BUG("should have a global_progress in clear_progress_signal()"); + global_progress = NULL; + if (progress_testing) return; @@ -270,7 +279,7 @@ static struct progress *start_progress_delay(const char *title, uint64_t total, strbuf_init(&progress->counters_sb, 0); progress->title_len = utf8_strwidth(title); progress->split = 0; - set_progress_signal(); + set_progress_signal(progress); trace2_region_enter("progress", title, the_repository); return progress; } @@ -374,7 +383,7 @@ void stop_progress_msg(struct progress **p_progress, const char *msg) display(progress, progress->last_value, buf); free(buf); } - clear_progress_signal(); + clear_progress_signal(progress); strbuf_release(&progress->counters_sb); if (progress->throughput) strbuf_release(&progress->throughput->display); diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index ffa819ca1db..124d33c96b3 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -296,6 +296,17 @@ test_expect_success 'cover up after throughput shortens a lot' ' test_cmp expect out ' +test_expect_success 'BUG: start two concurrent progress bars' ' + cat >in <<-\EOF && + start 0 one + start 0 two + EOF + + test_must_fail test-tool progress \ + <in 2>stderr && + grep -E "^BUG: .*: should have no global_progress in set_progress_signal\(\)$" stderr +' + test_expect_success 'progress generates traces' ' cat >in <<-\EOF && start 40