From patchwork Mon Oct 25 11:25:00 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: 12581495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72899C433F5 for ; Mon, 25 Oct 2021 11:25:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F66C60551 for ; Mon, 25 Oct 2021 11:25:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233088AbhJYL1f (ORCPT ); Mon, 25 Oct 2021 07:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233081AbhJYL1e (ORCPT ); Mon, 25 Oct 2021 07:27:34 -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 78A1CC061745 for ; Mon, 25 Oct 2021 04:25:12 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id e4so12214618wrc.7 for ; Mon, 25 Oct 2021 04:25:12 -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=djINBR4XCf7WufzYI7BJR1aL8y9PMnYTVmR09XWwbfQ=; b=kDSSAtXxzApfFqE1X1gn6sPvgpLGNbhOMfEIWX7CPMqNrNH4St3G1H1YKusmSmgrf1 rEL4mnB7FcRwPEKKr0g0+nFGkRDuvhPTnYRNg1iAH8KSM7+0XCTPI3IQkur+mMhjrd9m CGpnVZgKVodblCuNPgvD40q9ZWMHMGxy9kJqnRG7ToBpV1sc+aI4a09UUpK4QluYnA0g VJMwaaN5Xsnnp06nKGJteaiaCbiyw/BBjz7mh3kD1dBnCYxy8If0MCZerre6YJR1JjPD Vab+2mh5NXdJ5yKktV/q8mu8TOa8D6mibV6fZXPl4VQhh+v/qIELnkDpqRd0uzOmVwSH eKFg== 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=djINBR4XCf7WufzYI7BJR1aL8y9PMnYTVmR09XWwbfQ=; b=QPGw0ajzNS7DDwatK1f+AdRN7xouW4IEyxbEj4c7TQWUY1IzOSpb0ywhVrH7p0SLcw Sc7Ure0UzUbn0GH7hIyk/xmsYnfmrv+GVCPqi+4htwUcHNYtQDp8eX1zKBcye7vAzrZ0 OzV4TS4mlik6OGNQmS5BEo4DDVVcNyTKe6Y347ZxazsHjR3pn13druztfqdo+mTA5WHd sSB1juMFmXU1WHtxWSeOBLJVdQsRPxQeCktgkImF2zvKNmgQbEckScKtXZf0gBVVH6Ch YB/GnfLgdEOenMnqZnL4Gvl9HFSKVB+fYjkMr/gv2YdatYoNUfaSXmx00/Or0lqV+x7S kGHQ== X-Gm-Message-State: AOAM533G4vHfRL1nMyfAVAL9xToA7HYEaJcFTVPMI95cMnKZFFRp1jHZ id2WeyPvfV/qOsArH5sBJ5qVtAXErwoiNw== X-Google-Smtp-Source: ABdhPJzgOMFX62WmptBVE8K0m+bX177x65KhRurhYdiS7dbUE9aju5qLwyktUDXVwOHGc5XpgUVK3w== X-Received: by 2002:a05:6000:2a4:: with SMTP id l4mr23282720wry.221.1635161110866; Mon, 25 Oct 2021 04:25:10 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l2sm19021993wmi.1.2021.10.25.04.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 04:25:10 -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?= , Emily Shaffer , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v4 1/8] leak tests: fix a memory leaks in "test-progress" helper Date: Mon, 25 Oct 2021 13:25:00 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1510.ge5c82eefb93 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak in the test-progress helper, and mark the corresponding "t0500-progress-display.sh" test as being leak-free under SANITIZE=leak. This fixes a leak added in 2bb74b53a4 (Test the progress display, 2019-09-16). My 48f68715b14 (tr2: stop leaking "thread_name" memory, 2021-08-27) had fixed another memory leak in this test (as it did some trace2 testing). Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-progress.c | 1 + t/t0500-progress-display.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c index 5d05cbe7894..9265e6ab7cf 100644 --- a/t/helper/test-progress.c +++ b/t/helper/test-progress.c @@ -69,6 +69,7 @@ int cmd__progress(int argc, const char **argv) die("invalid input: '%s'\n", line.buf); } stop_progress(&progress); + strbuf_release(&line); return 0; } diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index 22058b503ac..f37cf2eb9c9 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -2,6 +2,7 @@ test_description='progress display' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh show_cr () { From patchwork Mon Oct 25 11:25:01 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: 12581497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B75BC433F5 for ; Mon, 25 Oct 2021 11:25:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7AEB60551 for ; Mon, 25 Oct 2021 11:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233105AbhJYL1i (ORCPT ); Mon, 25 Oct 2021 07:27:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233087AbhJYL1f (ORCPT ); Mon, 25 Oct 2021 07:27:35 -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 455B8C061767 for ; Mon, 25 Oct 2021 04:25:13 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id m22so8895840wrb.0 for ; Mon, 25 Oct 2021 04:25:13 -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=EbsG0EM3mwaRgbSFnkf/58IaUBPc3hPXNcYps+BMyxA=; b=Rz2PboDffKAjfPx9m2yRb851zHghF9HPUdj+Oy7VLG9zRUYlKTvst8wuwn/zVF2lCa X1ZyVvO3f8WC2Ej9YteC/7YL18tMpubIem3YX9X/X2EeFwDd6xfwF3gSczKpWxMcgDwJ VtTu8ldm1hFPYuM/AnBwveivp3Da4DSYAaubFbHlMqe0Y0Rk9QszrWoOpactwpOUSj+r WkiTfYB3ulbOLvsTqQuNcdZgGdHNLqkHPG7RvGobJHDItcaNAB+udmapmTZKkB1tiqWq fVPR16/umHW5NQQVmaw+pTMMuHwVsOgHlQFE3EpM+RZb/9ju+zhRr820FWtiFgUOHZ94 8JWA== 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=EbsG0EM3mwaRgbSFnkf/58IaUBPc3hPXNcYps+BMyxA=; b=QxNyW26SseAwE6W17oBkQ4zM2S6Ag5suayymh8+yqnUhC6y8CLsXwIQvBr/FJ/J9V6 dt85PvUglD/Cd6w/CD14w3LNWGjDd9o6dul5hK/EREJ4a0dE35XEXAvZWYYsGL3mrWbO zQ1MOHGJHVMBUM3KkiZ2yHV3LNEHTt/bJGwo4JL6YM13raPSuRP80yC3eDhdsgzQozfg fpMUWYUO981PuudapuC4R+tu090nRM7jwKHh8ofXAQa7GV2F6PFXCekgg+wvci/3PkDd zLTNNWVbD4GhM6sE+9dp0vaSn9V+6drrBgpVHDnzrQDUSx7GVoy6CisWUPXzkdjdNjVV BtHQ== X-Gm-Message-State: AOAM5337IHX11nMOqcWOhGbMscZKZLhIR35pWiF966jGq66y7OGsmPqk /vBJ8origKQqpBVhIL2gdWX8NO6tCkQnhg== X-Google-Smtp-Source: ABdhPJxwhuLeylFpL6xaPze3Kovpa9RJivy6kXV/79lmJsRJSqOt4/a9GKfqv2/noKBmx/WhMJG/qQ== X-Received: by 2002:a5d:64a1:: with SMTP id m1mr11114893wrp.101.1635161111609; Mon, 25 Oct 2021 04:25:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l2sm19021993wmi.1.2021.10.25.04.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 04:25:11 -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?= , Emily Shaffer , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v4 2/8] progress.c test helper: add missing braces Date: Mon, 25 Oct 2021 13:25:01 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1510.ge5c82eefb93 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org If we have braces on one arm of an if/else all of them should have it, per the CodingGuidelines's "When there are multiple arms to a conditional[...]" advice. This formatting change makes a subsequent commit smaller. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-progress.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c index 9265e6ab7cf..50fd3be3dad 100644 --- a/t/helper/test-progress.c +++ b/t/helper/test-progress.c @@ -63,10 +63,11 @@ 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 { die("invalid input: '%s'\n", line.buf); + } } stop_progress(&progress); strbuf_release(&line); From patchwork Mon Oct 25 11:25:02 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: 12581499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA9FDC433FE for ; Mon, 25 Oct 2021 11:25:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D584560F9D for ; Mon, 25 Oct 2021 11:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233110AbhJYL1i (ORCPT ); Mon, 25 Oct 2021 07:27:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233089AbhJYL1g (ORCPT ); Mon, 25 Oct 2021 07:27:36 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F029DC061745 for ; Mon, 25 Oct 2021 04:25:13 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id e4so12214743wrc.7 for ; Mon, 25 Oct 2021 04:25:13 -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=ExLol0ckdF5sciF5S24HHMxBQPBbMshO7V/WDmjRjgI=; b=Rvs1IhBGOwLpRIIEEe8VSEJ6shGUQHGzsx1dhW8C+HF67q18FjpAjAE+beWjevVvY9 gV6rtyYgBajpY7FjRzKqmQ2ZaXbF2FadIxSumnGZRSpyByNIC0dRpDyzv6U6AoZq4vmy cRVegLoT7YVYhm5i/8OfN/ir4FDhxbMvd0ygrRXVbn3xtC3d9C9Sxl2j0rZZLC/3Nq9/ 4OjGseYgrd5n11OGeFVGS8TWX3fihWt9dI+yGS7L+tInJEgYbhNHHyl2wIZtl5adjzok 53/ut/2d0F3R82Fw8XGSmihIV8dUChhScdzVDcx4+gPLhlXo5Ivpkqi9QAPTEX3uQbPE 7rbA== 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=ExLol0ckdF5sciF5S24HHMxBQPBbMshO7V/WDmjRjgI=; b=CiRbDD6s/9agfZ44xl8mcCzvnK4tahuJR3VqNyJqOFvNkVBz+FbGH83qsecpNU6S+W fUvVAzohEd3P0MSELf+dEK101s/o0NJ8TJPwaKtl8VBBN9Pb/07IfaOCRZ3vG/x3eGtX Axsu/rlq6q02DAHZGPT8cjOjpGZSHXUaXKIForhv3NccIkfrnsilVjLRWhpO3138Edif 6aJxp3oIHRXpMoNIc3iIP0X3+Rv80SGO1TX7JzGCVBiO9oaN2vtDzPnVwpzG5hgh3jxx BxUw/G7vtlWfDmxkDDiudIBA7ngzBx4COcRAu5kfEZOZX39XUMsdafw3Mj3P6ZnqDuQh ITow== X-Gm-Message-State: AOAM5332DWKZnMY2Zp6m00TESswE2KCVqlHZ9dlR4jnPDoWJY6eVSs4X AchpT6Hdgu5o+R10vobt5+t23aQlbPQ+xw== X-Google-Smtp-Source: ABdhPJzRN8ccKtAVQ6Yiu0xVY5YavIIR+1AMGzvINMDeA2u6nWpgyHEFOtgvTKk9JDGXmEhI7Y1i/Q== X-Received: by 2002:a5d:6484:: with SMTP id o4mr22695832wri.337.1635161112307; Mon, 25 Oct 2021 04:25:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l2sm19021993wmi.1.2021.10.25.04.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 04:25:11 -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?= , Emily Shaffer , Taylor Blau , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= Subject: [PATCH v4 3/8] progress.c tests: make start/stop commands on stdin Date: Mon, 25 Oct 2021 13:25:02 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1510.ge5c82eefb93 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 tests. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-progress.c | 46 ++++++++++++++++++++++------- t/t0500-progress-display.sh | 58 +++++++++++++++++++++++-------------- 2 files changed, 72 insertions(+), 32 deletions(-) diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c index 50fd3be3dad..1435c28e950 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), + * Uses the default title of "Working hard" + * if the " <title>" is omitted. * "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. */ @@ -19,34 +23,52 @@ #include "parse-options.h" #include "progress.h" #include "strbuf.h" +#include "string-list.h" + +/* + * We can't use "end + 1" as an argument to start_progress() below, it + * doesn't xstrdup() its "title" argument. We need to hold onto a + * valid "char *" for it until the end. + */ +static char *dup_title(struct string_list *titles, const char *title) +{ + return string_list_insert(titles, title)->string; +} int cmd__progress(int argc, const char **argv) { - int total = 0; - const char *title; + const char *const default_title = "Working hard"; + struct string_list titles = STRING_LIST_INIT_DUP; 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 (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 == ' ') + progress = start_progress(dup_title(&titles, + 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); @@ -65,12 +87,14 @@ int cmd__progress(int argc, const char **argv) display_throughput(progress, byte_count); } else if (!strcmp(line.buf, "update")) { progress_test_force_update(); + } else if (!strcmp(line.buf, "stop")) { + stop_progress(&progress); } else { die("invalid input: '%s'\n", line.buf); } } - stop_progress(&progress); strbuf_release(&line); + string_list_clear(&titles, 0); return 0; } diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index f37cf2eb9c9..27ab4218b01 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -18,6 +18,7 @@ test_expect_success 'simple progress display' ' EOF cat >in <<-\EOF && + start 0 update progress 1 update @@ -26,8 +27,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 @@ -42,11 +44,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 @@ -63,14 +67,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 @@ -89,16 +93,16 @@ Working hard.......2.........3.........4.........5.........6: EOF cat >in <<-\EOF && + start 100000 Working hard.......2.........3.........4.........5.........6 update 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 @@ -117,14 +121,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 @@ -141,14 +145,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 @@ -165,12 +169,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 @@ -186,6 +192,7 @@ test_expect_success 'progress display with throughput' ' EOF cat >in <<-\EOF && + start 0 throughput 102400 1000 update progress 10 @@ -198,8 +205,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 @@ -215,6 +223,7 @@ test_expect_success 'progress display with throughput and total' ' EOF cat >in <<-\EOF && + start 40 throughput 102400 1000 progress 10 throughput 204800 2000 @@ -223,8 +232,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 @@ -240,6 +250,7 @@ test_expect_success 'cover up after throughput shortens' ' EOF cat >in <<-\EOF && + start 0 throughput 409600 1000 update progress 1 @@ -252,8 +263,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 @@ -268,6 +280,7 @@ test_expect_success 'cover up after throughput shortens a lot' ' EOF cat >in <<-\EOF && + start 0 throughput 1 1000 update progress 1 @@ -277,8 +290,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 @@ -286,6 +300,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 @@ -298,10 +313,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 Oct 25 11:25:03 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: 12581501 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 117A6C433F5 for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7C5261039 for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233092AbhJYL1j (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 25 Oct 2021 07:27:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233096AbhJYL1g (ORCPT <rfc822;git@vger.kernel.org>); Mon, 25 Oct 2021 07:27:36 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC9A7C061243 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:14 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 83-20020a1c0456000000b0032cb02544aaso870938wme.5 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:14 -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=ADbg9X0OR2ynfZEOBez2fCy1svIgi27eg5SO/lLPkDA=; b=l2AXJavmQRFMDl95zozd+1/MmzAtrOjzJLXj/3dfkV0EYFw1uLfE6/WXrkSocnUUC5 rCdyJGhZTJp5H4pIZwO/xqsVUgCyfS5O0APBQvEZdaCPj0GlyTXgZ1HYnnQXjJxiXeaR DD9n8Qe9ZR44a/cTahShPmSvZyqtLcbDgDIf9VUuWGNAWX7AjjW7mIhvTRC8p0yOSR9F mWE5Q+uGA3j6MLKQmV83bh4BOjEc/08addaJY4bTrBOv8PWIST94gR+cbe3QdNLqlaoo P3Jggh0gk+3EvgZTelyM3aDxITCF9RBcJqVXk4jG/+Rh7CVU6t7IkTRD8NUMvl68c1m9 2izw== 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=ADbg9X0OR2ynfZEOBez2fCy1svIgi27eg5SO/lLPkDA=; b=qrSylE6uyCrrHEXDpbnIjmmEEQjTy1941fiF1TqKz7lZCmVj7mAqjCy2BpvBZAAOIl P/qhRJkWxo0jdePZ0YksmBBDs7WuPkD/xDSpZtIRmM+Y8W0Y4Al4YiW+aipnDHQofmuD zXNxEKySlhDorDRmF7vK119aPzmccqyp8jDVc5Eyxo+AbPQ2Tkf4atRBnrmCvHqy1Ttm 4w0dmA9E3F0QurVrHG3pM0duwPWkjXd1wbZvMCYIH+HzGMCEacCpHUFqvFPO9n5orXmg qbUr0J+mAtNVXBou2jfJ3BMujaZAF7aLddBRBSirnIj+A03Q3i663CLVgG4SKTPvJzdA 1snA== X-Gm-Message-State: AOAM532Q1GhZGVCoifVJgKKsMOyghTrGxh56V+0m9DWDq+iF+GLdq3E1 /LIG+gqvS5glW4fcPsZsc8T48ytqK8JQxQ== X-Google-Smtp-Source: ABdhPJzwW4QjUzqaJRz/y+5cS86O9GXqWVZFEwW6Gjj8EzaJ715DfiFUAZhZMYe4TKmKMOOybNo+9g== X-Received: by 2002:a05:600c:2314:: with SMTP id 20mr11669583wmo.76.1635161113170; Mon, 25 Oct 2021 04:25:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l2sm19021993wmi.1.2021.10.25.04.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 04:25:12 -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>, Emily Shaffer <emilyshaffer@google.com>, Taylor Blau <me@ttaylorr.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= <avarab@gmail.com> Subject: [PATCH v4 4/8] progress.c tests: test some invalid usage Date: Mon, 25 Oct 2021 13:25:03 +0200 Message-Id: <patch-v4-4.8-474ce31f9d2-20211025T111915Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1510.ge5c82eefb93 In-Reply-To: <cover-v4-0.8-00000000000-20211025T111915Z-avarab@gmail.com> References: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> <cover-v4-0.8-00000000000-20211025T111915Z-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). 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> --- t/t0500-progress-display.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index 27ab4218b01..59e9f226ea4 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -325,4 +325,39 @@ 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_done From patchwork Mon Oct 25 11:25:04 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: 12581505 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78EDBC433EF for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6621D60F46 for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233127AbhJYL1l (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 25 Oct 2021 07:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233103AbhJYL1i (ORCPT <rfc822;git@vger.kernel.org>); Mon, 25 Oct 2021 07:27:38 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90292C061225 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:15 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 62-20020a1c0241000000b0032ca21cffeeso8580110wmc.1 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:15 -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=yuW3dE/4pXNUEbjfNDw2oKQ7LStdBet8HwwI9x2amEM=; b=EuwwGj39P6+HVswuVAD2nG9Efp2pfiiQ023RCeRFAvCO6rx3a9nhyPKgm3mrvll0/Z +amEFjEC7cmqwcAtBTh2tqN6KB6aEh/3eohkszWo5gvz0goKerEV8HXs7HLv6opPfVw+ RIIkRiiPtatU+cQ7phTfL60EeLZSlCujOtglZWgJs/GlIztT9vo6VvJEuTXj5dfzl5+C JDF2G6JXqErr4ZmVatr1VdKMn86FbtNm7qMrl8EJPm/C7ZIn0LfJaoKnF19UiVa/XoOA 5+kwQGO+BIUX+H4+Cu+uhKk/SrY76u5UEfrfSBcYYbczV2WKSbI9dkgzMx4KtvHGKoQc lyvA== 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=yuW3dE/4pXNUEbjfNDw2oKQ7LStdBet8HwwI9x2amEM=; b=Zm5UPRcquhL/nVzv0efqI9zZyDYqJtXsFNF5UFaO+skDul9TI1L+0deczqLAMGZ1Xj n+a2o1mMvII9sih2QJdMxrmbQMuAbmJCtc0S9JN95P0jry7zCENrdzw+kwWMSYbxMEAL wWgzG6y4SrHxcQ4mpbUwNmvv7I5Khzlg3SFoX21SZZwceNC0hWqdo3Sy7L+JMNpsIF+U Vya/MsfB1Mmr4ln1fANC7J1rVgByOu9GzhZsF7zzIq1aQEwOLIn4WNkGT1aiWxcDkc2e yKOtkU32hoR3OBKsQSgwyo1dixCqbQlbDuFYmIFXnbVHSO4dBIIB0wiyuCZ2rxvWT24x VjOw== X-Gm-Message-State: AOAM5305Akr8g0f+LHDskX6IinD1Uam9lqq94VYH46j3YUp5ueOeYCMv N8kGxhGi4lEta8wOg9Vwh8DS2PsYOKH66A== X-Google-Smtp-Source: ABdhPJzxgqWC15FOcchRdBmBEJrwigx04LxXLzEC/pQI1b/JzOmqKGurE6zZkuWbOdJikkKM3nVbEA== X-Received: by 2002:a05:600c:4ec8:: with SMTP id g8mr47692562wmq.153.1635161113910; Mon, 25 Oct 2021 04:25:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l2sm19021993wmi.1.2021.10.25.04.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 04:25:13 -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>, Emily Shaffer <emilyshaffer@google.com>, Taylor Blau <me@ttaylorr.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= <avarab@gmail.com> Subject: [PATCH v4 5/8] progress.c: add temporary variable from progress struct Date: Mon, 25 Oct 2021 13:25:04 +0200 Message-Id: <patch-v4-5.8-ff039742148-20211025T111915Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1510.ge5c82eefb93 In-Reply-To: <cover-v4-0.8-00000000000-20211025T111915Z-avarab@gmail.com> References: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> <cover-v4-0.8-00000000000-20211025T111915Z-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> --- progress.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/progress.c b/progress.c index 680c6a8bf93..76a95cb7322 100644 --- a/progress.c +++ b/progress.c @@ -325,15 +325,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 Oct 25 11:25:05 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: 12581503 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CFD5C433F5 for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29D7560F9D for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233134AbhJYL1n (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 25 Oct 2021 07:27:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233106AbhJYL1i (ORCPT <rfc822;git@vger.kernel.org>); Mon, 25 Oct 2021 07:27:38 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A0F6C061745 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:16 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id a20-20020a1c7f14000000b003231d13ee3cso12719044wmd.3 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:16 -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=Hzrp3g5InBMk/hfmZl1PkVZ3dihy4kchyTa4C99GeBo=; b=F47OoBDBrP9+I7RDlXfZu4iCYLJBI/hjZf4gmHK6fZq5P9Q35jXVG2DA8XTEZABkO2 sGBQt6PWGmVAlk1Sn7UVHPcZ4GCJiWT5Xn7bxbcnGNUOuXWPwSwq/y7pFzLcy9UBrGiH WXO2yFWzsA4R/cLPJnywsHsZtBoAyr1GoHjScboB+wy7FqnoAQg9j5fdRprffbmbZQ8z lKZLsPpB4HTIKQ/1cxOq4Mu8wCOn7gNtM1nKgolNzrL0/x18AS7sQHCh61ZafVv2O65j RNsU/j+amJYdzOF0pRjAkhnVcXgaoF4ldn/qZMsxdg4lGOIyjErpjH5fyyEnoKPwU+4i uV8Q== 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=Hzrp3g5InBMk/hfmZl1PkVZ3dihy4kchyTa4C99GeBo=; b=cVG6GF1V4tY0inl6ZyylOE5SxKDE4JOqlMhPuhXm60F9Hgd3RNtrgvbL1PJNx+tsbR VGK6EwDzn2kzfKLDalfQ4qE3cIE6HIML+XZY71HZbZgAyJWpMkZVexYVTtDujKG3fXC0 fGeSO00EvkwZK8o6Oe+v6dAUH5rSY8WpPmYi7epSn7xVvQSI6nhbYGXNbhV89IBTljdX h/oq2cPrHrM/A8pR80L/QEtIfKulM9Cbg6I3/jbJQrlhxPA9fWJuM78flh+pDGpzPfMW 3L1CnxqpzEEGkRvylfD3vdtnWXspk76M6/6Fnxr7b2Imbi3H2JxUTRqWgpMPRpBWCcDG bulg== X-Gm-Message-State: AOAM532dHz/tLftrVcUr6/+1F9l1MguJ0dQDPDs3Ww3MRLogM6dtsjC+ M0h4AXU4nRtPZO9mxGZifYUceEfW5Gkklg== X-Google-Smtp-Source: ABdhPJx5g+lN+4VbCNKx/iTLwliHEmo+7oz6enKR02Y7pbcjDT3/iJRs2h8bfIG6Y9T0BXkK+7ni4A== X-Received: by 2002:a05:600c:3782:: with SMTP id o2mr5921993wmr.102.1635161114686; Mon, 25 Oct 2021 04:25:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l2sm19021993wmi.1.2021.10.25.04.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 04:25:14 -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>, Emily Shaffer <emilyshaffer@google.com>, Taylor Blau <me@ttaylorr.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= <avarab@gmail.com> Subject: [PATCH v4 6/8] pack-bitmap-write.c: don't return without stop_progress() Date: Mon, 25 Oct 2021 13:25:05 +0200 Message-Id: <patch-v4-6.8-3dfe31decff-20211025T111915Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1510.ge5c82eefb93 In-Reply-To: <cover-v4-0.8-00000000000-20211025T111915Z-avarab@gmail.com> References: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> <cover-v4-0.8-00000000000-20211025T111915Z-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. We could call stop_progress() before we return, but better yet is to defer calling start_progress() until we need it. 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. Suggested-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- pack-bitmap-write.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 9c55c1531e1..cab3eaa2acd 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -575,15 +575,15 @@ void bitmap_writer_select_commits(struct commit **indexed_commits, QSORT(indexed_commits, indexed_commits_nr, date_compare); - if (writer.show_progress) - writer.progress = start_progress("Selecting bitmap commits", 0); - if (indexed_commits_nr < 100) { for (i = 0; i < indexed_commits_nr; ++i) push_bitmapped_commit(indexed_commits[i]); return; } + if (writer.show_progress) + writer.progress = start_progress("Selecting bitmap commits", 0); + for (;;) { struct commit *chosen = NULL; From patchwork Mon Oct 25 11:25:06 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: 12581507 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E626C433EF for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28DF460551 for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233149AbhJYL1r (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 25 Oct 2021 07:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233089AbhJYL1j (ORCPT <rfc822;git@vger.kernel.org>); Mon, 25 Oct 2021 07:27:39 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 034AAC061767 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:17 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id g141so10350514wmg.4 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:16 -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=DwSZhYyrau9nwuLcxzWkCG4Es0SOtFRs2qRa4hKDT3U=; b=VVUktnitUT63JL0LUquQbaY/137rLH9LU2DbjIPNKotwzT662Kmvavb9SOWms7HsNu 1vk4pT/oRz4tgji6BIpbQhGTxfUuqNX8ebYX22Zp9wuPMkAovTpT3P0FtPbaH1tpITeu IgRpCyyotTi8JL6rRCMXLTg/o2web+gDiKSO2RtrM7My/sjWJS4fRWAzzHQGBtAt894O ee2ab1PyuxZvk5Js+CysIR+ayACyBvb6w6S/gLRcbNPMXUbm1s8dZl0m7RaqG71Bqc0/ qCLTCh6xnNnRySgmhVLdG+irBOlaWOxU8IxGivuTHq/iAmOixqO+LBuw0vCPAWVbloSl L/MA== 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=DwSZhYyrau9nwuLcxzWkCG4Es0SOtFRs2qRa4hKDT3U=; b=rvrTUQ2s4tRzQaXVCf70+Vpr/IKzRu2y7u65QRH/gzXQi9HJzs36u9W7laAwolnCjl b3mWsqqdYvl6kwnrg9hYirhpipW2vSpL1h8+AZfJ+JTqU+nCfRVj9sWX3ESs/mMJo3oQ RO5oaQwud0rFLxh0M8C5pxAn+pQro31rVCv9Tbj86NdsdsKA+4BosZeEkD/mITU/uyOp yEzwKWdUYOUa2hYVy6uuBf5UZ6EldMUiL+2DI17+fKNP+mORPtr3g6KGWtFaluIAlj+i HBJwdJAHue6v/rvps/05nypErEzjtGIb4BQdq1jBlz7FyxqJ2TZZq1RRmyvl3ESSJeaJ Ir5Q== X-Gm-Message-State: AOAM5314Q9u5SPP49oiMvfRVxhmpvraoEJKSVQUAchduYWG/4K/WlmhQ D0P6tlXQQUuYMF/RJQMSOi+VsYFo39bagg== X-Google-Smtp-Source: ABdhPJyH7i/1UvZBVU4sf9Im53iIeYdhxK7HlWYZEQYUUFx6ZryQ4qrSufECZAvG3S+zcwnAI9O1yg== X-Received: by 2002:a7b:c0c2:: with SMTP id s2mr19423549wmh.101.1635161115378; Mon, 25 Oct 2021 04:25:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l2sm19021993wmi.1.2021.10.25.04.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 04:25:14 -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>, Emily Shaffer <emilyshaffer@google.com>, Taylor Blau <me@ttaylorr.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= <avarab@gmail.com> Subject: [PATCH v4 7/8] various *.c: use isatty(1|2), not isatty(STDIN_FILENO|STDERR_FILENO) Date: Mon, 25 Oct 2021 13:25:06 +0200 Message-Id: <patch-v4-7.8-8a18eb40fae-20211025T111915Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1510.ge5c82eefb93 In-Reply-To: <cover-v4-0.8-00000000000-20211025T111915Z-avarab@gmail.com> References: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> <cover-v4-0.8-00000000000-20211025T111915Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org We have over 50 uses of "isatty(1)" and "isatty(2)" in the codebase, only these two used the stdlib.h macros to refer to them. Let's change these for consistency, and because a subsequent commit's commit message outlines a recipe to change all of these for ad-hoc testing, not needing to match these with that ad-hoc regex will make things easier to explain. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- builtin/bisect--helper.c | 2 +- builtin/bundle.c | 2 +- compat/mingw.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 28a2e6a5750..1727cb051fb 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -830,7 +830,7 @@ static int bisect_autostart(struct bisect_terms *terms) fprintf_ln(stderr, _("You need to start by \"git bisect " "start\"\n")); - if (!isatty(STDIN_FILENO)) + if (!isatty(1)) return -1; /* diff --git a/builtin/bundle.c b/builtin/bundle.c index 5a85d7cd0fe..df69c651753 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -56,7 +56,7 @@ static int parse_options_cmd_bundle(int argc, static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { int all_progress_implied = 0; - int progress = isatty(STDERR_FILENO); + int progress = isatty(2); struct strvec pack_opts; int version = -1; int ret; diff --git a/compat/mingw.c b/compat/mingw.c index 9e0cd1e097f..0f545c1a7d1 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2374,7 +2374,7 @@ int mingw_raise(int sig) switch (sig) { case SIGALRM: if (timer_fn == SIG_DFL) { - if (isatty(STDERR_FILENO)) + if (isatty(2)) fputs("Alarm clock\n", stderr); exit(128 + SIGALRM); } else if (timer_fn != SIG_IGN) From patchwork Mon Oct 25 11:25:07 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: 12581509 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C69DC433EF for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84CC260551 for <git@archiver.kernel.org>; Mon, 25 Oct 2021 11:25:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233165AbhJYL1s (ORCPT <rfc822;git@archiver.kernel.org>); Mon, 25 Oct 2021 07:27:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233113AbhJYL1k (ORCPT <rfc822;git@vger.kernel.org>); Mon, 25 Oct 2021 07:27:40 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAFECC061745 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:17 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id g141so10350571wmg.4 for <git@vger.kernel.org>; Mon, 25 Oct 2021 04:25:17 -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=fvyCaMkGyKsa/glN12zH0G9IoijkeftbM7jsFbP/N54=; b=Yex47PyZVdWi6VT4qFavUEi2dgQzxcQ+6jX/bOy5cRfmV4CzSaAYhg57Vty+NtNFoa K4onCUi32LrwSkKOj9poWw2EoLqiCnZ+P7GCxbecuTrQ7p2ip+pLbORDr87xGddqq68s /D85/keAXUhhh1r0DrrgaVgkMc7POrfJHRC2BGIY56avVG1hPbiTEXDJC0cU8vV/up40 vkApf7IOEzotAyZDLD8Rx2u/mZTJs9fx3dFLQrRavlLhyVhd/8I12JgwTk3kmspaZMxm ME9s9FhMUoPrw+FSz5eMWnyrBzGI0x3TLX+amSDv3KLBxt8+5Hqdb6ROQoSf12Iv5f/y 2+8g== 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=fvyCaMkGyKsa/glN12zH0G9IoijkeftbM7jsFbP/N54=; b=xod1cWQYYXZwofVIj0k62fjpb0eEBvGBoRCxl11ZfqBRHskqVCw0DvjUH15Dy55AaO +CCVp4IeXUyX+1zr9qVA44t14VcXgOwM3MaL+o18QrJrkCQvbOncO3oK10wS8MZ8igQS KoeTdPWS5Rl8YkP08qY3Knl3715F/wc+i9C7BdWpEPJY0yIMwxoe1ahDUA+CE/Hc/Vla LjDI8qsjQW2LncaP0o6z4Wf8FIji+bfR7dsNUcgCT8BxaVs9GuF6591rURov+CYLvnaJ W7fUYBpFkAbFlg2HykZGvZ3Jz4w6DeOOVHNfhnYHl7pOjZvJmw60NAMoL4uTlGLbp6zG Vi1A== X-Gm-Message-State: AOAM533eQNblyBdmNkT26m/TylY/EZIs+Czv6aHqdPyS/XbyRiSmgt5S ZfX2iWoRJcvOHBtTWwI6SMzcDWD1IukiEw== X-Google-Smtp-Source: ABdhPJzb+89KS7A6Ccynw+Z1fRQPfekjFxrWSBQks5diprX11J7iIRe+IPS4gzKQO2pbhL2rUrw4hA== X-Received: by 2002:a1c:c90f:: with SMTP id f15mr19039735wmb.78.1635161116049; Mon, 25 Oct 2021 04:25:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l2sm19021993wmi.1.2021.10.25.04.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 04:25:15 -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>, Emily Shaffer <emilyshaffer@google.com>, Taylor Blau <me@ttaylorr.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFz?= =?utf-8?b?b24=?= <avarab@gmail.com> Subject: [PATCH v4 8/8] progress.c: add & assert a "global_progress" variable Date: Mon, 25 Oct 2021 13:25:07 +0200 Message-Id: <patch-v4-8.8-06124e8ac5e-20211025T111915Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1510.ge5c82eefb93 In-Reply-To: <cover-v4-0.8-00000000000-20211025T111915Z-avarab@gmail.com> References: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> <cover-v4-0.8-00000000000-20211025T111915Z-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, this will cover cases where we're busy, but either haven't invoked our first display_progress() yet, or the time between display_progress() is too long. 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\(2\)][1]g' $(git grep -l -F 'isatty(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). This doesn't address any currently out-of-tree user of progress.c, i.e. WIP patches, or progress output that's a part of forks of git.git. Those hopefully have test coverage that would expose the BUG(). If they don't they'll either run into it in code that displays more than one progress bar for the lifetime of the progress, or which calls stop_progress() with a non-NULL "progress" without a corresponding start_progress(). Both of those cases are less likely than the general cases of progress.c API misuse. Between those three points above and the discussion of how this could impact out-of-tree users 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> --- progress.c | 18 ++++++++++++++++++ t/t0500-progress-display.sh | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/progress.c b/progress.c index 76a95cb7322..7483aec2e2a 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 @@ -249,6 +250,14 @@ void display_progress(struct progress *progress, uint64_t n) display(progress, n, NULL); } +static void set_global_progress(struct progress *progress) +{ + if (global_progress) + BUG("'%s' progress still active when trying to start '%s'", + global_progress->title, progress->title); + global_progress = progress; +} + static struct progress *start_progress_delay(const char *title, uint64_t total, unsigned delay, unsigned sparse) { @@ -264,6 +273,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_global_progress(progress); set_progress_signal(); trace2_region_enter("progress", title, the_repository); return progress; @@ -340,6 +350,13 @@ void stop_progress(struct progress **p_progress) stop_progress_msg(p_progress, _("done")); } +static void unset_global_progress(void) +{ + if (!global_progress) + BUG("should have active global_progress when cleaning up"); + global_progress = NULL; +} + void stop_progress_msg(struct progress **p_progress, const char *msg) { struct progress *progress; @@ -369,6 +386,7 @@ void stop_progress_msg(struct progress **p_progress, const char *msg) free(buf); } clear_progress_signal(); + unset_global_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 59e9f226ea4..867fdace3f2 100755 --- a/t/t0500-progress-display.sh +++ b/t/t0500-progress-display.sh @@ -298,6 +298,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 "^BUG: .*'\''one'\'' progress still active when trying to start '\''two'\''$" stderr +' + test_expect_success 'progress generates traces' ' cat >in <<-\EOF && start 40