From patchwork Tue Nov 2 12:27:23 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: 12598691 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 C9785C433EF for ; Tue, 2 Nov 2021 12:27:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF6F560EDF for ; Tue, 2 Nov 2021 12:27:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230518AbhKBMaM (ORCPT ); Tue, 2 Nov 2021 08:30:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbhKBMaK (ORCPT ); Tue, 2 Nov 2021 08:30:10 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1D6AC061714 for ; Tue, 2 Nov 2021 05:27:35 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id a20-20020a1c7f14000000b003231d13ee3cso1748270wmd.3 for ; Tue, 02 Nov 2021 05:27:35 -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=ufHwRkxGYi92p2eh9JHC4nqjBONEttk0ji459/spTtw=; b=JA7Sd51CYlMgFhtqqHfSkhdVHW9TAT80B9IGQLNMgVVI+qoQyxyBz5LHq1e3xhw5ag 9u4JzFVaYCJOlwWA5eqpaBHdAeIkA9+YdVOpizNM6up15Lg1YWoNJwtQOMsIqI+VDNJc aSMyllzEc0jBeO1w2GigvBSPz8pqXKjXi2LklQrXCx2rUzH/oyck1F9qvk5wYv9+7nSu O+XG/Oi3i6VvU9MrkwCwHAHRmfxyMcurj1tJEFckpaMO6PCzdeGcwmF9N1zLYTRCvVoh egsoOFCdd6OFZ8WQH9SlaxhzSCpC5yv9OrFpIwSoIiI4+IAazV9k9AcrbQ7pxG+ESivc oYSA== 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=ufHwRkxGYi92p2eh9JHC4nqjBONEttk0ji459/spTtw=; b=i0E3wenSvE2nLREtzpxRUM9I/luX1LRc0+iJjWxsZTqkcx41Gm10KJQGcDGmn98efs xxUV+cFCbt6ZscgpLZPG5Fe5XABmBzdFlU5vsbgo+u5472+AgVmEvM1PU8OjJpogwYqo nLR5RiCddYMcfKqgqOjM6XhORgiWmdPZ3bOyYlFehFPZ8x/qEQ/N/LGXKrhclwt6CUys b/gztx4Bw1o+aDVradzgBt8PHcdkcV63ZQRj1CjfWjxHNPlLcSt1oR8Oo28qRDTvV6Sx 02rU60FU9ycQI6MRNsL2mOKsWsvLDM+yHWjTDmFbWMA/K6gjzSx9l42QrLAb47kJ4eXu Cf/Q== X-Gm-Message-State: AOAM533GJy3g2kUKXZ/ZbLP56cG9pbMTKmx5yR+xYkQGinP8K+GcgFZi eC+6GUDTo42CmBIT8y5ybY+A6mU95jDw2Q== X-Google-Smtp-Source: ABdhPJy5rAjlM/df1cyCpbiWl3iMDJYZSV8WhUFZk3zsM4aW9THi2LeQ+SZPD+HBTMYDLp+GeClEeg== X-Received: by 2002:a7b:cd03:: with SMTP id f3mr6645764wmj.89.1635856054034; Tue, 02 Nov 2021 05:27:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q84sm3332236wme.3.2021.11.02.05.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 05:27:33 -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 , Johannes Sixt , Carlo Arenas , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v6 1/8] leak tests: fix a memory leaks in "test-progress" helper Date: Tue, 2 Nov 2021 13:27:23 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 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 Tue Nov 2 12:27:24 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: 12598693 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 EB996C433F5 for ; Tue, 2 Nov 2021 12:27:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D105460EDF for ; Tue, 2 Nov 2021 12:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230347AbhKBMaN (ORCPT ); Tue, 2 Nov 2021 08:30:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230326AbhKBMaL (ORCPT ); Tue, 2 Nov 2021 08:30:11 -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 7185CC061714 for ; Tue, 2 Nov 2021 05:27:36 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id d5so17721759wrc.1 for ; Tue, 02 Nov 2021 05:27:36 -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=yP5oZ1uEs/zhtyoEzsg1Zu6WWMEFmtkM+3Xn2nQk3Uo=; b=Bt2P83R0oeYGDs0L3iIbkSouR5PiKDLJWpwULSOA/swJZ9yWjbfr3W6RmE7eO2CUd3 +4+EOE7AmlLJF6vFqQ7/sRspv1U7BfpWqBRld0GMlj5fp6n1DUdJAfan/iNm62Prf/d4 3ty6MV507Mi49ncSzvMWbYAPS5imymauNzleiR38EwiZJM6yu9WJ4HFTIwCcaZPNnP66 pjFoqRGejaEvWOfTD4gZuquEyWFUSRt9CKbhmF0pScHMcutcCTUcdAWxtbs1ngpkYSaZ c34sDmKIA17zIIm32nsXg9ivz7nZZ7HKVGY71N0UpgE/YITUAN4/rkbVceOfmzmPJBYn IbCw== 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=yP5oZ1uEs/zhtyoEzsg1Zu6WWMEFmtkM+3Xn2nQk3Uo=; b=bAvr/T8Oc3idQNl7lLS5QStWotLJuqRk+yxqa2CMou82hOlVKMx4rY8lD6TjkfHyBK zPizZ3UF4nLPxanOGqT1qyPN13Sxqbz0RhNU3pTf8okrDVRI0FkqAo3rYVsCf2OogoW7 jKfhN32LkkfIuEAGe5ayajhAhIJunKvVvXXgMz7VokHKOofPhE6ySFfQmHk31vERsXY/ LIxuxC3lSYPxKJ02JpY/rq2AADvrRhd7/ymxwTngIKgfJof6AD2dmagjH+RHdMsgta3I ZXV33FifKDmyqXNe3fMZrYVH90TYajnHPrtCcOC8nkAnWZlR6k8xhhCfDPXKgDfVyALv 9s0g== X-Gm-Message-State: AOAM5336kn25ZRF9f3L1lMv5MPaF6M+4L/FhrAkS8968NYg2RGoAWtA0 Uk+vR7fwxjesQB0MdyIuebsIJ9+C0o+9eQ== X-Google-Smtp-Source: ABdhPJxNA7r+1g141XN7gtspNFU9A4QKYrO/CH75lKjIy3/Aqer1bkwARP+Stnabg4Id+zckBXWzLg== X-Received: by 2002:adf:ba87:: with SMTP id p7mr46250517wrg.282.1635856054813; Tue, 02 Nov 2021 05:27:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q84sm3332236wme.3.2021.11.02.05.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 05:27:34 -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 , Johannes Sixt , Carlo Arenas , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v6 2/8] progress.c test helper: add missing braces Date: Tue, 2 Nov 2021 13:27:24 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 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 Tue Nov 2 12:27:25 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: 12598695 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 AD51CC433EF for ; Tue, 2 Nov 2021 12:27:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97B7F6109D for ; Tue, 2 Nov 2021 12:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231232AbhKBMaO (ORCPT ); Tue, 2 Nov 2021 08:30:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbhKBMaM (ORCPT ); Tue, 2 Nov 2021 08:30:12 -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 561E8C061764 for ; Tue, 2 Nov 2021 05:27:37 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id t30so8189960wra.10 for ; Tue, 02 Nov 2021 05:27:37 -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=DoQQQWG40nCbzLeYEIQr3jxIiP3Ql09y1EeOaoRNU7E=; b=YVO5sK/oyeIXxblPsx3+e5GuZ8Ev9Sm7x3EaJ59/LSKGT6raedTEQE7AZ3YN8biq/F v0tfwkAX6BPQw0R8wgwxc5NWbWx105TDpyFjtzt8X+CcG8XsUP6sMGXdA9Fq+Jvdp120 QitS55iJSuDcpKwcbtNzR0l3n/4oqq1wm1GBQXRjdABnvRTmiUHUNZoli2KIYcqkRr6J io5WzFB3scJBMa/hMm0zKnUJrrH46sRZvZuDdvSdhB71TxlEicyGe9NmpPK9vXyYjhi/ c9Not4qEs/ndLbPbw8rI4tqNEy/C+UYlCKfa5XMbec6xFt54QzSWboJUXpRcgS3dJBK/ 4t3g== 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=DoQQQWG40nCbzLeYEIQr3jxIiP3Ql09y1EeOaoRNU7E=; b=uQkaaTIGIEW1D0FpR0Lx7uKUoCULA2w1H+SCPWp4RSyYG+88swiDOa14XjyZ/BFzw4 3fdN2g3fZvyGiMCnyA5F0M7wfvNlZydtYNLg5lc5j4XJiIdwp5rmtSwj6DLeSJhCw5gd qYzuTyjfZsQuqOB/8clnJQaHtg9Qyp5qIaAN8+iQcb1uSZKFkcnS7v1FOVqcP65VCoRb MMEfL9PSH+QFkZNjvys4HzxjDAREpay+tthIM7bMM6CVU8fA558tLXj/fpaafHtuYg0s hwvmZiMmO/BPVNGutARgM74VwmpJlp9+gKQe3Flqr1fjl3Bhkn/wLzsQRLLYL+/9+Wdw 3/7Q== X-Gm-Message-State: AOAM531d1ZEwiseBI7QL1YFuvqcLX3OcF2ux4qf3fnsanibcUYnn/+Td auM4YZPbTWOcyNcppcLpgnr0h67qOID5Tg== X-Google-Smtp-Source: ABdhPJykTK9rvCAjJZIyGiLdNvL7qSV2WGi+QF93KPOd3T9xygSAwBxtueeqsgjiaEgv/+LIoktirQ== X-Received: by 2002:a5d:6dae:: with SMTP id u14mr46292065wrs.46.1635856055660; Tue, 02 Nov 2021 05:27:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q84sm3332236wme.3.2021.11.02.05.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 05:27:35 -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 , Johannes Sixt , Carlo Arenas , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v6 3/8] progress.c tests: make start/stop commands on stdin Date: Tue, 2 Nov 2021 13:27:25 +0100 Message-Id: X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 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 Tue Nov 2 12:27: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: 12598697 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 5DB82C433EF for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:27:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49B9660F24 for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:27:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231267AbhKBMaP (ORCPT <rfc822;git@archiver.kernel.org>); Tue, 2 Nov 2021 08:30:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230321AbhKBMaN (ORCPT <rfc822;git@vger.kernel.org>); Tue, 2 Nov 2021 08:30:13 -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 4BFAFC061766 for <git@vger.kernel.org>; Tue, 2 Nov 2021 05:27:38 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id t30so8190032wra.10 for <git@vger.kernel.org>; Tue, 02 Nov 2021 05:27:38 -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=wivfjiON1dMNNN7ZvnB/kfbCmpVJdKNvBcImrkNxhig=; b=KsopsXAXMPdE5wxVy8uLRdJTkLp6AOr4wY5rip/ua8wlzyx0TpAE1SiWvqi+WrTu7b rzXn9sdD5cnt1812egd1ID3xpp4E9DT8r7ZY6zoov8aixc97FilpdMtaGowtQmbnzfnN BGV8jX9sAOu6YgDk+TLwMljD6y/RBhy9W9UbPyiWm4F2OO/QNaBZTTLnc9503eghKmgC wo+frpJqHNA8lgjgsfNIEC45aCqofR/hGfyH8I9/9hkbFGtwMk+XNEXlwedsxOtQN7S3 hAqf3QaHVcVtzK6CaZ7c17R02vFnjLeNCNWeadLycw/CM54/YK8rxOF4ERjpAuhR6DD5 5Kzw== 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=wivfjiON1dMNNN7ZvnB/kfbCmpVJdKNvBcImrkNxhig=; b=2L0D9MdKS6KwsICBUou5Z6ZE9kmCUec1jrCluLG+Ii1BPAVpyFarEvcgx2cxTE6kDG mqu6Ehm+s9I1DxKpR+aOnlJzf0naTMlhaQSKROcTP2lrBGX/Ms8UXdoznyaKu5HfMBbx +2rv1dhUyFQEuqeD9CZJR17C5zzqwNOntvhnJF4d01xNe8qODPVRv749LSvtGydwNiS7 giC1rGjCgNghiaflYukuvvNJXBY8ka2IO3QLyYj9o3ERlQVF5oYg9Mi51gBsTtNMgWEW kASofMuUk0pD33k+h89AjO/Cjg+ilD3AvKWFh6IG0drORrQBP+D4uami90dUYWJoU+tO b0MA== X-Gm-Message-State: AOAM533t1qE/HtnvgsVtRuM8bSWPtVLx4ZGerfET/kw49uf0cgnnXSRb gzal9aKvEETuwStYXZcK0nWjOMueWmAyWw== X-Google-Smtp-Source: ABdhPJwC+PSou88Srh0p8pNYy7M/TYcjK+s9dGnC9hOTdUWMi4bBO2m5y0gj0PamYvUxEkSFoXQ7wA== X-Received: by 2002:adf:a1d4:: with SMTP id v20mr4603080wrv.190.1635856056619; Tue, 02 Nov 2021 05:27:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q84sm3332236wme.3.2021.11.02.05.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 05:27:35 -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>, Johannes Sixt <j6t@kdbg.org>, Carlo Arenas <carenas@gmail.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v6 4/8] progress.c tests: test some invalid usage Date: Tue, 2 Nov 2021 13:27:26 +0100 Message-Id: <patch-v6-4.8-7557975a122-20211102T122507Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: <cover-v6-0.8-00000000000-20211102T122507Z-avarab@gmail.com> References: <cover-v5-0.8-00000000000-20211101T190630Z-avarab@gmail.com> <cover-v6-0.8-00000000000-20211102T122507Z-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 Tue Nov 2 12:27: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: 12598699 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 97B4CC4332F for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:27:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8363860F5A for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:27:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231219AbhKBMaR (ORCPT <rfc822;git@archiver.kernel.org>); Tue, 2 Nov 2021 08:30:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbhKBMaO (ORCPT <rfc822;git@vger.kernel.org>); Tue, 2 Nov 2021 08:30:14 -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 46780C0613F5 for <git@vger.kernel.org>; Tue, 2 Nov 2021 05:27:39 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id c71-20020a1c9a4a000000b0032cdcc8cbafso1946377wme.3 for <git@vger.kernel.org>; Tue, 02 Nov 2021 05:27:39 -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=xzlJzQtD48Z6qakgyJN9Jyj7/OVEDeqjq2OC7yZmO2s=; b=DgqA0R+yGuTpynBsCzlaneTvsSxlRwLQynukmcrynik/736qq59BWwoa8jIyfzFrYT eS1szLL6YA39BM8g7Q+RLw94RqGssDN/OGXRL1ca2eP6C7q4qc1WGgz5PARsx6t8ePC+ 3n+Iu9P8Seu2yvOI7BjL9t7TWjO8IsTkDk8lOHBtZfz1nP664U6dRkBRn8J8ZGEk5s5P SIPWuXZuAUbaeL8BlnhPga7SkcNbwfNFnyGocJIye/0BAE2yGOZfHKCajcXdcXmagTmM eCZHXNeLowxZfSwb0J4NGBXnjTenLFVgGpsvFPpOYEJlQFQmL7FndHSuBnbN8O9HFkwN zGBw== 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=xzlJzQtD48Z6qakgyJN9Jyj7/OVEDeqjq2OC7yZmO2s=; b=a3uYimVkZZXGLNWiKqC8UY5KgCqEaeg8C9KRMEqcj5DvnUeSyvl35OtkFgWMSthkGY GbqcEm/oNvzi+gprOlaR9ksqh7P1D+b03GN6gMNcUdEnToaw9LHI4uB5Ug3wlPQYtK7j /UHU0LmdoVwKPtM8NKW9yoqNZ325X6VBXMGq6oEDE5Lxvzv1uHVFKCffaDWLirvjx966 YcoOJJRlR0KHNcyPR+vJTEoPdRfOcMAOUMWJyIKJAuE2Yn7AnCTcXqVSz7pduJ0dDIzy n+Y8iEY4dbWOquB8iPqCvLq9plSTvFXS86v0XUwxMffk0+7fgiwmtWrrQIxkXXwvbZnd N3tw== X-Gm-Message-State: AOAM530JjB4yEd5pEvT4JSqEPnfrTv02f7GShscIsiQ1A3kaXwtmVLYs tclT+ct+CMsRtrMoXsxfCRw/zZdYmcZGUg== X-Google-Smtp-Source: ABdhPJwdt5gvDjVNGaJ6n7D5C33/9AO973RfYeF7EawdD9pk7sBalrYT+jQ9CdKBcv2MwWv2Ne8FDg== X-Received: by 2002:a05:600c:a45:: with SMTP id c5mr6589698wmq.79.1635856057514; Tue, 02 Nov 2021 05:27:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q84sm3332236wme.3.2021.11.02.05.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 05:27:36 -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>, Johannes Sixt <j6t@kdbg.org>, Carlo Arenas <carenas@gmail.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v6 5/8] progress.c: add temporary variable from progress struct Date: Tue, 2 Nov 2021 13:27:27 +0100 Message-Id: <patch-v6-5.8-61c8da31aeb-20211102T122507Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: <cover-v6-0.8-00000000000-20211102T122507Z-avarab@gmail.com> References: <cover-v5-0.8-00000000000-20211101T190630Z-avarab@gmail.com> <cover-v6-0.8-00000000000-20211102T122507Z-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 Tue Nov 2 12:27: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: 12598701 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 B6A9AC433F5 for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:27:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A623060EDF for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231303AbhKBMaS (ORCPT <rfc822;git@archiver.kernel.org>); Tue, 2 Nov 2021 08:30:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231138AbhKBMaP (ORCPT <rfc822;git@vger.kernel.org>); Tue, 2 Nov 2021 08:30:15 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46DA0C061766 for <git@vger.kernel.org>; Tue, 2 Nov 2021 05:27:40 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id z11-20020a1c7e0b000000b0030db7b70b6bso1769195wmc.1 for <git@vger.kernel.org>; Tue, 02 Nov 2021 05:27: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=r/jMWJfUEO0PCU/P85MG9HQhuFL4Ay91kAEpF6M/Lyk=; b=h+LjEajZWr43bEAJ0NzaZqGfQHaop3tEUWQnh67zomXRUsFqOAmB2flWBEQ3zKU/oV yHJpi5lTF9KEIwf0ysNoJ/ZequGf/Ey+eFkO3LoG26LdV5iZzIly7MQJhzJSOSVyEBrQ LaY7GLDdr7pzAjeVxTTUJmuVm1Bodw+e1E391fOfJSQv/eq7tbgVLYtyRAXAM8jY8o14 ByRwN51E3xI7jJ6MAMmJ/caJKCecLKdR1yerHFp1tpFZsUD+cTh1SBuT/OSaiVDACcIp Nu+egvO/dwiD6WbB8hbM77wARyms57tTMiVEBnCbgorq/6miwkIfJHoGpk7NalS7Vr/9 qqPQ== 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=r/jMWJfUEO0PCU/P85MG9HQhuFL4Ay91kAEpF6M/Lyk=; b=5279UVcvpX5/nKfYhmY75pMJSXsY39aR0tYDiR0hfcAj1rF5s5MZMVmm0V9txN4h23 YA8EjvmlHDloHlfkjgEnKt7+LxRwqEPskXoc/2qbPl617z86V8bNGe+XETWpPDWatnSp sPxUedX7IAA7GNA+FZN3tJ8SeSFsgGEN3t4QyW38bEUi5X1UPCjb2lJoZKkxudXy/9lI oYe1PWQkECgZpQWHVXOu9Ju/RrNfyWLt+x9jqUQuUuqdl1XxrA/LChUk0YCn2fIV8kDF pjXW0FVb05p0Emlzc03wUjEKF8c32X2RiorJLZlw6iO7roTQl1pue3UW7Dhj8Vt5GSMl HMGQ== X-Gm-Message-State: AOAM5316wxCdXLZ8B9QvOFR29Z4PTFCOUt74JGG3WxRuMYpMWt1xyb8m jgGfXnMJnJSNJ948O0fn+Jo34luIbCh0+Q== X-Google-Smtp-Source: ABdhPJz/94YPuOaDcpkARk9UXhvzojxOMR7GIqFMYL0hcnMdCMZVDJtsuJ4iPb/KY3zg8lslWHfgIQ== X-Received: by 2002:a1c:f31a:: with SMTP id q26mr6624957wmq.148.1635856058577; Tue, 02 Nov 2021 05:27:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q84sm3332236wme.3.2021.11.02.05.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 05:27:37 -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>, Johannes Sixt <j6t@kdbg.org>, Carlo Arenas <carenas@gmail.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v6 6/8] pack-bitmap-write.c: don't return without stop_progress() Date: Tue, 2 Nov 2021 13:27:28 +0100 Message-Id: <patch-v6-6.8-f6a76b80e91-20211102T122507Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: <cover-v6-0.8-00000000000-20211102T122507Z-avarab@gmail.com> References: <cover-v5-0.8-00000000000-20211101T190630Z-avarab@gmail.com> <cover-v6-0.8-00000000000-20211102T122507Z-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 Tue Nov 2 12:27: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: 12598703 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 4B4D8C433F5 for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:27:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32CD460F24 for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbhKBMa3 (ORCPT <rfc822;git@archiver.kernel.org>); Tue, 2 Nov 2021 08:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbhKBMaQ (ORCPT <rfc822;git@vger.kernel.org>); Tue, 2 Nov 2021 08:30:16 -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 2DD3BC06120A for <git@vger.kernel.org>; Tue, 2 Nov 2021 05:27:41 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id d27so15059101wrb.6 for <git@vger.kernel.org>; Tue, 02 Nov 2021 05:27: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=Rnv5pB5SWWZ9ugmJbSK7qYIu1BxBbdO31Y3eDKu2/hA=; b=nvwt86CZA5j9kPk713oRk+oCL2cdiMRutWDHq+kUC7FjXXqo+UcfQFYdQDmOyLca3J H/JSa5ruEyaG28mvWCUQ0ii3Fh3hOq4xfsYD0jFNLJG3PcYUBRTBposajZO35bAdDfeN 4l5Ry+sDq32ekyTZcrmb9Bh8EZbgguWeh/sg8BaBhjqWRuCd6DD6DEHS4tNdoFmqVEHE JjZ1m/gHHwbEebzKBdg5TyOEoU2AsF4+gaaT5CQDOOaVWOdHMMbLFX1z3wpJw4+C4Jh5 kH/obe7OHwkIpAqlDHl7EOkEqDx+y4RCETY3EwTZ5x9yFQLcDgSpIHLrjihHplShbwQW bs6g== 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=Rnv5pB5SWWZ9ugmJbSK7qYIu1BxBbdO31Y3eDKu2/hA=; b=1wWqLKydtnMACfEHKlsgBS89jBz+T6WRTFeFnk+AzJwuoleEyk9BRQuP4Z88tAEtUl zPWCSoJf+Dkpewo/dgkqdrwkAtF/sfbBcIWQlsGewrCm/rJgLjDUtZaCmwtsCXMoGUrk J5Fxswg5YW6FBnlrUmHz8H3zjHcEfLfX5yhl+Eane5jYBCMv/qX5geWMnUWtKX6Gi8mi czQnzrt3GCSGkzVGbr1jSXbFGwug1oI9xodb5jEWgFUiQn1qNcDpb+W8sSL8dnHO+m30 sC4/LPfTWxIFw7AeJew1Tanor0fsKAAlrrWz3wpCPNkW+eRQ6h7jyWfojuRFBuzW5QeG TOHw== X-Gm-Message-State: AOAM532fDzV8DkfPvjK3azIrnXjO6uEODAqrcCaswPLOCeV4mNd/JjiN LQTBlXKjwViC5nd7Tyo0OPoTPcepfkgKLw== X-Google-Smtp-Source: ABdhPJz44FVM1Mo12QuBbspGvPXbsJ8utpBG2xcpuYlgwGKYilvcF89dRbrxJeba2Mlcaqh3x2dWJw== X-Received: by 2002:a05:6000:2a4:: with SMTP id l4mr20305318wry.238.1635856059410; Tue, 02 Nov 2021 05:27:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q84sm3332236wme.3.2021.11.02.05.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 05:27: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>, Emily Shaffer <emilyshaffer@google.com>, Taylor Blau <me@ttaylorr.com>, Johannes Sixt <j6t@kdbg.org>, Carlo Arenas <carenas@gmail.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v6 7/8] various *.c: use isatty(0|2), not isatty(STDIN_FILENO|STDERR_FILENO) Date: Tue, 2 Nov 2021 13:27:29 +0100 Message-Id: <patch-v6-7.8-1a2eadf28d0-20211102T122507Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: <cover-v6-0.8-00000000000-20211102T122507Z-avarab@gmail.com> References: <cover-v5-0.8-00000000000-20211101T190630Z-avarab@gmail.com> <cover-v6-0.8-00000000000-20211102T122507Z-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, and around 10 "isatty(0)", but these used the {STDIN_FILENO,STD{OUT,ERR}_FILENO} macros in "stdlib.h" 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..21360a4e70b 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(0)) 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 Tue Nov 2 12:27:30 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: 12598705 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 18B54C433F5 for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:28:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0353260C51 for <git@archiver.kernel.org>; Tue, 2 Nov 2021 12:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231194AbhKBMab (ORCPT <rfc822;git@archiver.kernel.org>); Tue, 2 Nov 2021 08:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230321AbhKBMaR (ORCPT <rfc822;git@vger.kernel.org>); Tue, 2 Nov 2021 08:30:17 -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 5BD67C0613F5 for <git@vger.kernel.org>; Tue, 2 Nov 2021 05:27:42 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id z11-20020a1c7e0b000000b0030db7b70b6bso1769277wmc.1 for <git@vger.kernel.org>; Tue, 02 Nov 2021 05:27: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=s0et02o0GKm6Ox9HByfxeLAz3rXAsfI3+dwDFZjnI+8=; b=aUF/c9ZSSV7vdxDZhcezE+Rd+JR3ZW1jhEQfpTUUTAJoDEOKMFVY8dCEFuSEjGiFMm JZTIdOGUqjE8EFYBqKCPVXxNvtFxUykXsrif911Ef4u3FA8BN9x7oJ7fhF/Xtsdury9j FBjNqcupVkvsWHEQkLRuJHi5xVPf52GX2L19FlKlMkH+St9sVIEGE77n707gu7RrIF90 z4wWZ0/rNkTuUiq8RZAOHuZ8+B/b1860lYrbHgf5uMk9nzKNZ9aM2DkHha9Slru4Vb4p dtSecCNxjtvWs/oFqgCbxytz06CnK39vMkRzAvBryi2h3pXQnh0Hs9a8YUhg4UZJzVBR 9UWg== 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=s0et02o0GKm6Ox9HByfxeLAz3rXAsfI3+dwDFZjnI+8=; b=MgmS91lXFaDwkSMgu8QeiIwTgIE6XbeR9ygSBIUQQb10I914k+P2ZVmWswxK3gpEiA +v4pUpwh1PZTS4GhATzbZM4MhxU1OVTMwKY+uXWVlEe0eB4e+qkuNVm+A+NBDr0EStEp doaqadbUPnCLcyxJ7mAVGQkw7+hDHQaV5ODp6ObBcDGu8J1R8lLrVUfsb653t1qZEdtM mwwQSOeosDWG/z78VcxBFiRrqjDgSp6Rz5V+frGw400GbLz5/x8Cdm07MI6a2L/e04XB fE4dOIO1mCqVyqQgvWKI3Om5bRDxN8h/IHdIVzVstkouoTJ1sWqzumdHWw/MM9VfzSGv zkKQ== X-Gm-Message-State: AOAM532cHA6DpIIlmfSoisWY4iaMTKmDq0wA/PIpR/3EK73zA/GXA6HV YVSDcPVzbZ+P6ODaPmE+Z4GlGCS9zIhMvw== X-Google-Smtp-Source: ABdhPJwYNyrZo57UooxfA8cD05EnKPjZbJLPvKFwTJCZTOIjMop6GDx2AtV1kb+LtvoIxW4bGJm11w== X-Received: by 2002:a1c:f219:: with SMTP id s25mr6829682wmc.31.1635856060544; Tue, 02 Nov 2021 05:27:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q84sm3332236wme.3.2021.11.02.05.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Nov 2021 05:27: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>, Emily Shaffer <emilyshaffer@google.com>, Taylor Blau <me@ttaylorr.com>, Johannes Sixt <j6t@kdbg.org>, Carlo Arenas <carenas@gmail.com>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= <avarab@gmail.com> Subject: [PATCH v6 8/8] progress.c: add & assert a "global_progress" variable Date: Tue, 2 Nov 2021 13:27:30 +0100 Message-Id: <patch-v6-8.8-bff919994b5-20211102T122507Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1570.g069344fdd45 In-Reply-To: <cover-v6-0.8-00000000000-20211102T122507Z-avarab@gmail.com> References: <cover-v5-0.8-00000000000-20211101T190630Z-avarab@gmail.com> <cover-v6-0.8-00000000000-20211102T122507Z-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. The linked code in [3] is WIP and not signal-safe since among other things it calls sprintf() from within a signal handler, see e.g. "man 7 signal-safety". But on some platforms a real implementation of it would be able to write() out a prepared-formatted progress update from within a signal handler. That would be sufficient to e.g. show that we're "stalled", or to display something like a simple pre-formatted "spinner". 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