From patchwork Wed Oct 13 22:28:17 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: 12557397 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 6C054C433F5 for ; Wed, 13 Oct 2021 22:28:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52B8161183 for ; Wed, 13 Oct 2021 22:28:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230442AbhJMWah (ORCPT ); Wed, 13 Oct 2021 18:30:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbhJMWaf (ORCPT ); Wed, 13 Oct 2021 18:30:35 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8D1EC061746 for ; Wed, 13 Oct 2021 15:28:30 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id e12so13220870wra.4 for ; Wed, 13 Oct 2021 15:28:30 -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=0hb31jai8oRS/QSuTfr/QIkQZRI0USLV0q1sWmvi5Ew=; b=qxQJkJOKNVo3yBztIetugB0M5GLpXYDJWLJl9YmmIKTxlmu59FDxW3S0H/xPgv3Dkb JE6T3L4eKfHxQmbhtoj+KDr5Na1DpRI4vka+urZ7DWAct5chYH/3es8oo4wkzR+510MD z73elnSPm3Iqonn0r1ZXoqc7oRux2dNLNCmn7A/Jg8ChN2qUuv++mYBayyhN688VF0MI dQ+4Janp3pEawTaHBpDcUJxIt9aWD06XD/lybDrBYoObzkXnGB2QJdzDyvlxLHP3qvOV 4Fg39x4m3lsa47QvEkdbI3UUvYnThrkIjZuoVNACgQYI7qdqJV6zlyiQcHKkZO0Xi5X2 72PQ== 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=0hb31jai8oRS/QSuTfr/QIkQZRI0USLV0q1sWmvi5Ew=; b=Q+BYJz34SJSt6OydWjE+plz9lAQqAw7zX0/JqWLzxqd5fDdkEvFYN9js96LFk14Yzw 1hdqQ0TpPhts6JPueHQBid7FjQ9Q/DVUoHcx54QCEmZeWHKnKwkkaKQYTjPx40kqAftm s6CSIwjR2Y4z1P7j7vF1rZtZRXM+1faO0Ff99vAvpp5WEVXRHxqPbY0p5z8w9qoy4oad o9+t6I4qbQeQt5ovWJjZsOC2qHqcprocTI3cxP6MQqTnHPFj7AZgNaWT8thCSHlGYGHT SFGv1C+LSTh1gHi5NrQaFwSL3db+vg1mFVGJ8Ko6rBXi/3fVr0Ic89c1H9pktCILocmE 5vNA== X-Gm-Message-State: AOAM533tj1ZyoYEXgsGPgnFdt6ZMnfibJMBlKRveCPjaTm31uZivcVgl jV0Wd0E6UQfyJfQrvDW8S8qBBtDbh1CrLw== X-Google-Smtp-Source: ABdhPJxEsOKMqdBcwsbpRHDzPn+Hp8CrVrFRJfeqlPJ+vZd/FVxgQHkkcveyt9SyW7Jc+zl8qpaFdA== X-Received: by 2002:a7b:c383:: with SMTP id s3mr15758233wmj.60.1634164109126; Wed, 13 Oct 2021 15:28:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28:28 -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 , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 01/10] leak tests: fix a memory leaks in "test-progress" helper Date: Thu, 14 Oct 2021 00:28:17 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 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 Wed Oct 13 22:28:18 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: 12557399 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 193A7C433EF for ; Wed, 13 Oct 2021 22:28:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0181161152 for ; Wed, 13 Oct 2021 22:28:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230496AbhJMWah (ORCPT ); Wed, 13 Oct 2021 18:30:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbhJMWag (ORCPT ); Wed, 13 Oct 2021 18:30:36 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31344C061749 for ; Wed, 13 Oct 2021 15:28:31 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id y3so13297579wrl.1 for ; Wed, 13 Oct 2021 15:28:31 -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=TDvMrx5FyoSPasPYzPlyF6XWXWetuKGLYNhXWYxOezs=; b=N4oKvfq7J7N+6S+qvtDW8+hJb8d6YibRhwVHmM3gaGyhcb7zbJ7YNQoycr274Hbi4R qVvM81o6wzk7W6eYwlRSsVRec5l9v1AMSFPoMzt5qy4K5qfsvV4jkcXWuHO8iWI7xAH6 HFWBDpkyDXLaFe1oYUHOqsX8JDta2H1Wmc83MLIqvBiZduHINZHeXwUjd7Ms2/W23LB9 9lHQCdNSjLDgGm49YNwDcjLhQ6knosSW/dEOwwbZYPjt+6luziAPmp6bl4SJNymzxHhq QPdA9QIKwvyT/rgWAV0xNbji0flLy/WnBC8vL1YqeoAQz2zwaMAxgtS8UpQSmlkrcFTW 9O+w== 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=TDvMrx5FyoSPasPYzPlyF6XWXWetuKGLYNhXWYxOezs=; b=QqH5JW5tBlENKMkNszX2dUTpjQJDOYNV8Cu+DzB5wjKf1qS34VXrGQRstT3uYUNKd2 zzRutgoix7fkNmMpICDJF7sZRW7+Mk/SDXrCmxj+bGlYUcOIitSOmz6M/n54MV90fcnH A075r2PC/Vyo6dOceXsDMT6DelauvTY4Q9OtBsLsruXjREqBfyf28/0qgPUCUj5d+iu1 Fh2RLjIV7HHDyLF7Qa2p989TfWVY6adkegvt/J1cTTX0HPPKh6KiGL/10xyWzMTPywNP YWTcROeBdhmougg5Nd/Vt16IzGh5wyjU/0vmV6F00FBUVIzkOVF3NIdksH0SjKt8RqdH H20g== X-Gm-Message-State: AOAM531EoUlhI5TvRYKVhCWA4vuC/1RGp1QJypeAbcechKLDZCGQr31s nqyejR4+BpmR/tlQ0QFugo0Ykya061gTKg== X-Google-Smtp-Source: ABdhPJxMa9GVCarb1FFAu9eX2aYtKDoD1y0JzrriFl5bkQQnwAR7y6r4+GP/IMQNK4vx78aXXwNCng== X-Received: by 2002:a05:6000:1449:: with SMTP id v9mr2077513wrx.433.1634164109992; Wed, 13 Oct 2021 15:28:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28:29 -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 , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 02/10] progress.c test helper: add missing braces Date: Thu, 14 Oct 2021 00:28:18 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 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 Wed Oct 13 22:28:19 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: 12557401 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 7FEA7C433FE for ; Wed, 13 Oct 2021 22:28:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67E9B61130 for ; Wed, 13 Oct 2021 22:28:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231149AbhJMWak (ORCPT ); Wed, 13 Oct 2021 18:30:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230345AbhJMWag (ORCPT ); Wed, 13 Oct 2021 18:30:36 -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 804EAC061570 for ; Wed, 13 Oct 2021 15:28:32 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id i12so13174784wrb.7 for ; Wed, 13 Oct 2021 15:28:32 -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=ddxSj6KP0tvn8TrlGQWIRbJ/b5B8fpAxa050MwZIz28=; b=Rv7+D1s2YRhUaUTLYLFTXlXD1rg44u2UP20/g21VxWEyU8OC6b+aPLhLqWmTBCmjmN ZsqwVbdts7cevf9d4ASp9cT/+rRNgyRRsfEr+SjW45aa9l3KbWF2ECAXPjzSq3eltm41 s52P8m3lB/GlXMoEPCXM30Cv8WUijkFkPnu57d8U3F0NF2LF9Ebm6xT4cam3wxKURLm9 AdCn6IOGMwy2d5Ue5OELH+Hvmh6L8VSdjlCCaQVFiCKa1ptGW0IrljmZU/ZBytmyAjgi sdj1KnM1k3DvZ3j/g/gmgOXMEzOy8JW3E6zINL/WnWgkdK9CCqfu8gHChDj6pThPlkEk wp8w== 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=ddxSj6KP0tvn8TrlGQWIRbJ/b5B8fpAxa050MwZIz28=; b=rTG/PbITkoSeVVqDGVtbgZlrLLXYp7IGKqjUTX39NDtra8P549MQ5NqGCTpxuCES5k bLoLCobVMA5HAqICBySyA3GaeyLrf0isOUHxDpC4guHr4QUbgbC2+mRVoKRHT5YiaDhm VKe96jGLLtLDqSM1buFXtxyeqrIYW+J4ozhtLWLa/HDBuGlueP62uERVS7R/2jIWXcXW vMcP8GlalUlXmTjeYASRvqQRCPT0yNhGrQBCwpJOFT4NSoVAjv6+cb1bB9aR5OSshndG BrET3kGSXKMN3bM8DziusfC/ZJj3uBPJx1Rb5E7oyZKcrMRHXXeloBApOn3HeoaTzcmp 07lw== X-Gm-Message-State: AOAM533MWILvnB72wGv/45hO7cAsrz/X/YivpoO2ypZ1F2fSjEB94/+m NswUBvNr94XiWYlcmphT2brubY4isHSLGA== X-Google-Smtp-Source: ABdhPJyoxpDyYmkPq5HslaP5tIeBveP0yKo5cjlpuq7WSKGCk/5YRD1R5WAJ1JNUwqTA2F03+I3f6Q== X-Received: by 2002:a7b:c0d6:: with SMTP id s22mr1953165wmh.135.1634164110846; Wed, 13 Oct 2021 15:28:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28:30 -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 , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 03/10] progress.c tests: make start/stop verbs on stdin Date: Thu, 14 Oct 2021 00:28:19 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 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 | 37 ++++++++++++++++------- t/t0500-progress-display.sh | 58 +++++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 32 deletions(-) diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c index 50fd3be3dad..45ccbafa9da 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,43 @@ #include "parse-options.h" #include "progress.h" #include "strbuf.h" +#include "string-list.h" int cmd__progress(int argc, const char **argv) { - int total = 0; - const char *title; + const char *const default_title = "Working hard"; + struct string_list list = STRING_LIST_INIT_DUP; + const struct string_list_item *item; 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 == ' ') { + item = string_list_insert(&list, end + 1); + progress = start_progress(item->string, 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 +78,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(&list, 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 Wed Oct 13 22:28:20 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: 12557403 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 491F0C433EF for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31A4B61163 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231162AbhJMWal (ORCPT <rfc822;git@archiver.kernel.org>); Wed, 13 Oct 2021 18:30:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbhJMWah (ORCPT <rfc822;git@vger.kernel.org>); Wed, 13 Oct 2021 18:30:37 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52A38C061570 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:33 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id t2so13195534wrb.8 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:33 -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=obL6wYtLKpKX8U1DvI6zm9EhffbdHUjcFscbxnXSJH8=; b=ltRpX1Hbxj9+nORjRC3BFgMjLF+ekPSODaovS+i623sH96Tn9hb8XQRTGQ1GSiB3SO 3JpNYF/rtnIyNQSG4/P370eywZqXxlaVmpLts4+9U1BGm259wmOLoh+l4fzojnTQjNLS xjHK1bS3Fk24AEOWMK6W+4BQmHoSUjtWTLctDUKfD8JfNZmAlWjcHOBjojFm9tLbMd3i sNdyB2gnMiIY9X5dlnSO5FjElybdVjeWPJg515i88zmqf3ifwdxkD9XxLVQ/zLqSVtq/ v4R5pS8ZcTVtLcnose2Eqs8CES7aup0w21sTCJgTQe7cdtOdbrWitPlFcy57YcaY3Pnd FnGw== 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=obL6wYtLKpKX8U1DvI6zm9EhffbdHUjcFscbxnXSJH8=; b=zraCOUrOwJdUsnpmq68DwaoH4UnNbT70NlTngjf+2vfPqFRZ2AqgKAPxp2Om9wHH4M NQvalc17KB0EsqIWF8qpWJohmTH8Azi2Qlcisqf8wJizD335AIYHVeHLsFJMbDPRFKAC hZe3HCLJcqjYYRQZXjRaLuW6X+27Vkc5M95n0N/nHHIA2mYGKZmcOk1kXxdADgnhgDy+ Ia5uMdZvEQZmKHQNpDYDNaCRKzQlw6oLgeBpB7m7D/mLMfvBnaoMgiBll/t+fiBKOztt K91WhDs2uBMNPRQO+x7KzrsrbwrKI50LzsBWuZLdzQmFn6NL7MoTWeUi1tIjPKspn1Cf V8Aw== X-Gm-Message-State: AOAM531+GJdhBcZKLglDgTelrhRb8YUrR4yeftfbFxsDW9n52uEputf2 idKMG/S+P21Jfwl2FII6YYUi1pMkhDGjEQ== X-Google-Smtp-Source: ABdhPJz5fW3Q/16yIvdrQ+wXS2t+SDfEJXpd45qAcnBliRg1jf4rcyeh0WtyESHed6o+NKnkfEGk/w== X-Received: by 2002:a7b:cc0b:: with SMTP id f11mr15443802wmh.2.1634164111691; Wed, 13 Oct 2021 15:28:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28:31 -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>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> Subject: [PATCH v3 04/10] progress.c tests: test some invalid usage Date: Thu, 14 Oct 2021 00:28:20 +0200 Message-Id: <patch-v3-04.10-efc0ec360cc-20211013T222329Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 In-Reply-To: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> References: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> <cover-v3-00.10-00000000000-20211013T222329Z-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 Wed Oct 13 22:28:21 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: 12557405 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 0430BC433F5 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E25ED61163 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231177AbhJMWal (ORCPT <rfc822;git@archiver.kernel.org>); Wed, 13 Oct 2021 18:30:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbhJMWai (ORCPT <rfc822;git@vger.kernel.org>); Wed, 13 Oct 2021 18:30:38 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 109A3C061570 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:34 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id r18so13221879wrg.6 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:33 -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=KQGoMoKgkJeqht+KmlfrwXr3eIR/SmK9Of58DWNXlBo=; b=Be3lno3tR3rqfwAi/B773JPO8XCynmQf4nr3t+ytcJatroQihis07iKEM+iREBYdrR dIphXZo7KUn0Z5DoWeVZrlBSuEdiCEzoGiUPlTobnzmgTn4nT4DPF+pFB0yJzRt/ycCG qKZU38Iav4BQH7k7eezCUNbCkvIa5WlPeemBWIeXyJq6rhUk8PeFK1lyvdzB4lawVFda cjxLT/spFyZHqrASA5KDHsJKbn6F8CUDeYBpZgqjcs29sSfQSzJPlbZQyqm3iqNNFaNK hRdi0RoOYmD/PiCRsI2D2rdYTq5wEe97g4Jp/JvQ9+J/pCvuQlnvJP6QO5e1osMcqnc8 efrA== 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=KQGoMoKgkJeqht+KmlfrwXr3eIR/SmK9Of58DWNXlBo=; b=BIviiJYg5Wz+HJVTlBEsmSgizn5bLmzRnSWL+SU7C/BngqWIrfKxf0ypvPq8wj1pNU p6g5iDKos5hDiv3+wAgkBqlmrjRfwMMokLZZd2ykGcLJlWfqVOmLvsYWVkzqT0FpKvbh AM8pQMlQOPMR+OI8Abeks5gZQ7wrUGxyXZDyHgVU4FML9Qs4fhAKCJebgrl94/AYQJnZ 8EY8FpUaH9nqT06cm+CXvaP0lX9n+QmyOZ3je0LGBTBIUmEy3K46plV91Xb0a9WiBTMz VMwnd3pjVANuIOoO+TR62W2Pb3ltV7jjnr1+VCyZIOsDP8CpW9vh2MC3TBPF3P7FK8Uu Y3wQ== X-Gm-Message-State: AOAM530vivnT6FEUE52C/J7s5wqoiC0QWwtv6HOL9fS5EsShEID1v5NG IShhBXjezwIWXWPfj+6rmoTfDV++8AO+Lw== X-Google-Smtp-Source: ABdhPJySPRW53hrD/YBosLCgM2Pp9H6nC+Rr+wjBuXQU4ezeY7g+jsP7hvhsxnFQJr3RZNObnizT2A== X-Received: by 2002:a05:600c:4fcd:: with SMTP id o13mr16043148wmq.158.1634164112446; Wed, 13 Oct 2021 15:28:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28:31 -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>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> Subject: [PATCH v3 05/10] progress.c: move signal handler functions lower Date: Thu, 14 Oct 2021 00:28:21 +0200 Message-Id: <patch-v3-05.10-9e36f03de46-20211013T222329Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 In-Reply-To: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> References: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Move the signal handler functions to just before the start_progress_delay() where they'll be referenced, instead of having them at the top of the file. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- progress.c | 92 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/progress.c b/progress.c index 680c6a8bf93..893cb0fe56f 100644 --- a/progress.c +++ b/progress.c @@ -53,50 +53,6 @@ static volatile sig_atomic_t progress_update; */ int progress_testing; uint64_t progress_test_ns = 0; -void progress_test_force_update(void) -{ - progress_update = 1; -} - - -static void progress_interval(int signum) -{ - progress_update = 1; -} - -static void set_progress_signal(void) -{ - struct sigaction sa; - struct itimerval v; - - if (progress_testing) - return; - - progress_update = 0; - - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = progress_interval; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_RESTART; - sigaction(SIGALRM, &sa, NULL); - - v.it_interval.tv_sec = 1; - v.it_interval.tv_usec = 0; - v.it_value = v.it_interval; - setitimer(ITIMER_REAL, &v, NULL); -} - -static void clear_progress_signal(void) -{ - struct itimerval v = {{0,},}; - - if (progress_testing) - return; - - setitimer(ITIMER_REAL, &v, NULL); - signal(SIGALRM, SIG_IGN); - progress_update = 0; -} static int is_foreground_fd(int fd) { @@ -249,6 +205,54 @@ void display_progress(struct progress *progress, uint64_t n) display(progress, n, NULL); } +static void progress_interval(int signum) +{ + progress_update = 1; +} + +/* + * The progress_test_force_update() function is intended for testing + * the progress output, i.e. exclusively for 'test-tool progress'. + */ +void progress_test_force_update(void) +{ + progress_update = 1; +} + +static void set_progress_signal(void) +{ + struct sigaction sa; + struct itimerval v; + + if (progress_testing) + return; + + progress_update = 0; + + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = progress_interval; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; + sigaction(SIGALRM, &sa, NULL); + + v.it_interval.tv_sec = 1; + v.it_interval.tv_usec = 0; + v.it_value = v.it_interval; + setitimer(ITIMER_REAL, &v, NULL); +} + +static void clear_progress_signal(void) +{ + struct itimerval v = {{0,},}; + + if (progress_testing) + return; + + setitimer(ITIMER_REAL, &v, NULL); + signal(SIGALRM, SIG_IGN); + progress_update = 0; +} + static struct progress *start_progress_delay(const char *title, uint64_t total, unsigned delay, unsigned sparse) { From patchwork Wed Oct 13 22:28:22 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: 12557407 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 93F20C433FE for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B6F361163 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231190AbhJMWam (ORCPT <rfc822;git@archiver.kernel.org>); Wed, 13 Oct 2021 18:30:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230511AbhJMWai (ORCPT <rfc822;git@vger.kernel.org>); Wed, 13 Oct 2021 18:30:38 -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 00212C061746 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:34 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id r18so13221977wrg.6 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:34 -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=8gmEs7kPC/IGsDrmgBg3TAQZ842QE67Xqn6dlHHLKCE=; b=Ud7z1eSy3MN/3s4yZPvVoKxXocjYz17Pee5oLM9Yw/fY+x2pur3rlYb03bGzQPcG2E ROzsBPTsjYQE/ZahK7ajLHuJjxBwPWfLObEd6sjq2uT6BZEy89UdgqLhaeC+I+JMVpxI eb3y+N6krJvD4i4ILdvpmphBBLFhAag/Be2zi4J8P/2DSvkl14iEX6BjDxqVnR8ih+gY uhaui7cZijc8ieLv7V4RB852+l28IzfprdVCVLCQEGGblEERXLnC1cPcul2Dcbrfi3Wc e+/Ko1gxzLadXlyODhvM2cO8ZMQk1IPwHowaJp8TJ7RL0aOqbayXJnBNUlKWc0b6TbQl HctA== 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=8gmEs7kPC/IGsDrmgBg3TAQZ842QE67Xqn6dlHHLKCE=; b=TdQ1JTU17cGvkVehB7QPJ7pERIiD0RUFBWK8cmG9VtY/BqRS3fJXwWZ3CdHbu0d3Zq 3zKIzZr9MJV/yR4vBw0GT68TmN7eafdorrKY7RqsSz6lQk1ZM1tig78oMKbfoOQKzyqy 8E/5g3vbRE4gIyBqWFmq9Qh6paVg1SHUXLU522rEEE+OVkgArp5bRPUV581QNvcJSOCc BAnxySnsR5j+rVI4TJFtPZDekGUHHRgqT0+jojjCqGtCxbJN0AbXmDJv5+q4nfraFf37 LK551g3qXVOMLtnyVdnF4v97OKo8NI9bGjZbaNtOs4VIgcwm9Sopld8vcmPvGrMivBkx 9/2g== X-Gm-Message-State: AOAM5318MWSjf1tVx8rpI51z0SoWwZDUVcSSfretPcvB+LfvH3dptcfz yhA5o3Z5M1S1oPaqgEZyoCyP7ps6FRw40g== X-Google-Smtp-Source: ABdhPJw7n83ejR8bD8/Rl6o0/4JHOnLWeRN9QQB0NaWjKDgE7QEAGcfY4KeTn7F5fBKHsSL1gkStwg== X-Received: by 2002:adf:9787:: with SMTP id s7mr2121791wrb.191.1634164113365; Wed, 13 Oct 2021 15:28:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28:32 -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>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> Subject: [PATCH v3 06/10] progress.c: call progress_interval() from progress_test_force_update() Date: Thu, 14 Oct 2021 00:28:22 +0200 Message-Id: <patch-v3-06.10-c7c3843564e-20211013T222329Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 In-Reply-To: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> References: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org Define the progress_test_force_update() function in terms of progress_interval(). For documentation purposes these two functions have the same body, but different names. Let's just define the test function by calling progress_interval() with SIGALRM ourselves. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- progress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progress.c b/progress.c index 893cb0fe56f..7fcc513717a 100644 --- a/progress.c +++ b/progress.c @@ -216,7 +216,7 @@ static void progress_interval(int signum) */ void progress_test_force_update(void) { - progress_update = 1; + progress_interval(SIGALRM); } static void set_progress_signal(void) From patchwork Wed Oct 13 22:28:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12557409 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 D8837C433F5 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBE2A61163 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231240AbhJMWao (ORCPT <rfc822;git@archiver.kernel.org>); Wed, 13 Oct 2021 18:30:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbhJMWaj (ORCPT <rfc822;git@vger.kernel.org>); Wed, 13 Oct 2021 18:30:39 -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 B3BF2C061749 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:35 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id e12so13221387wra.4 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28: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=4AXp/uomUWbfDjEKWU3J2bdlHQbIwqwWakuUfA2NxYU=; b=UuHrLZUO1usqtNZWs3OWMkcFsKTgGAp5QB+DLUYa0z7jdFDieBIE7MKZp3ldMwHYi6 Ud6D+WEWzKjpqOtm4p91fMybJcTxErQQD8qU3m0dMYjd4gBqZQAwSbJtWdHIB7QmRjEC hOFTFiNrnFXSZCod61SULRxAVhjRQehScy7TbUDiLZsEl8JviGpuNGOZIlr7HCcceQUW DzgqJjyqh7mXJTCNRvaUXuanulW82W3qVaiyDYd3YYv9O25+yCQ7S8SA/wlXmIwsqGSS 7cptEcstjHIsNFvgMNIzpKeSYecQdLFATK67QO8culmiubM5B3l+n0gpvtjFi6XjG3Bf wenQ== 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=4AXp/uomUWbfDjEKWU3J2bdlHQbIwqwWakuUfA2NxYU=; b=YejD7KFLnL7X+6cT/FEvsfT1JVWdRexBBV4FzCi72AtD4vuNg7Cf1fzPn/X1Y21ucP YWC4VtFeQehQlJaDCr5lf2fmxjaMPknmkUs9bmaLLLH2YOny6I8rTAM62+bvLf0He+dw r47AB7SXNe8FAhTrdex4O+4J2k4bQIdCiBemWV8qEY0nDw7CrD5cn4OwG8NU5m0+CQAq d4YwjBvv9xhWQXjiAMkaQdIERyIvBgl35ToUJm2X6dVG+eJ88uWLP5bDMLNX8my4VBND b5Xo4ZGM4l4oweOG4Ng69tXhhzIBIR4Z7jtGgQ1nsMZPAtZzdLNE5pFLQFrgD96/siNy Zx0w== X-Gm-Message-State: AOAM530baEBhHyq5xFk47dy2A1iqtDXWea21NMy4ma4iPwzt6C1X9Mpk 088cawLbxsgez1xFcgljD96GmgIDoV+MQQ== X-Google-Smtp-Source: ABdhPJyvj9DTJtDDsB7KV4qoA+RLdV4lQZHJ1um7+oVC2tS2NjeBz2BON7He9x9c1o/IMScZwI5Rjg== X-Received: by 2002:a7b:c4c2:: with SMTP id g2mr2026406wmk.134.1634164114105; Wed, 13 Oct 2021 15:28:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28:33 -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>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> Subject: [PATCH v3 07/10] progress.c: add temporary variable from progress struct Date: Thu, 14 Oct 2021 00:28:23 +0200 Message-Id: <patch-v3-07.10-cd2d27b1626-20211013T222329Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 In-Reply-To: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> References: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> <cover-v3-00.10-00000000000-20211013T222329Z-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 7fcc513717a..b9369e9a264 100644 --- a/progress.c +++ b/progress.c @@ -329,15 +329,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 Wed Oct 13 22:28:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12557411 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 BAC38C433FE for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1F6D61130 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231265AbhJMWap (ORCPT <rfc822;git@archiver.kernel.org>); Wed, 13 Oct 2021 18:30:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231148AbhJMWak (ORCPT <rfc822;git@vger.kernel.org>); Wed, 13 Oct 2021 18:30:40 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69AD9C061753 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:36 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v17so13147739wrv.9 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28: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=1oYIMLm/YDq6Ixuqi2fTr+luLXPqf7kd6iZVq8i76Hs=; b=GoHJ29MmJOpPlvrZyAOOeI8PAzc5Bih7Z9f4cF4i4O6dDaW5tw9aEwH2zULaf4kNJO OwDoxm4cN+xJgfOHU6ppqFhT+NCRty2gn5HngK06NNorzWS6KF/ZvduDPoRIwFbdbK42 pNGeZRKJtUqC9JbJdj6we57B3KK39H4tDe2GU+tHOBslEFxNb3mcVAa8JmyXk3SnoANy stv9GJ/4zUMlDLCDkeOWQOKbuSunjxbFQ+51Q1GQr8ARGn96wAUiEyzCi8pkPb5yCx1+ PXEShpzX/64K6SaXGTrhDanA5z9u4swhPPupIHWaq9gNPQq8+XdZZP1/Az6z/5KoZGEP 2j7A== 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=1oYIMLm/YDq6Ixuqi2fTr+luLXPqf7kd6iZVq8i76Hs=; b=3ydyfe2WxnqySDqdOEqvzyQqC4VsCDei2vbg5f8ovmz20nD44WslU0DeBEf5NYMFkq BkTW+dMCOZOYGbRPFh4jHR0iXNqNNgbxofIGiyWOgVOPEeodpPfiryyuA0FwzPVDRhdr Eg20LTgFwov4XoH4wT9IHx1YI36ER2enjSqBr1Qc6gav8e59Tjd9rbwuB7XFSEeqmZaB NR3ydvukOmfbEWec+y2M2/PBqveXTs5yL5+x47Ir7A4CwCNtHHJsZcudefoRKiql1tfQ BfDGmAR/rtXBjPIMwRRZej3IDp8hhIMZHnGWiCSqpwJ75GIsBwfnK0vcoRoAnE4AMx5A 3Q0w== X-Gm-Message-State: AOAM530i7BZmReS9DPGr4Iw32CmPlpM2QlzUvzAGKuRSLnaRQ38iH6yS Q7VpVooIANWyAQsuLTYvcK+yBWt3o3fCsg== X-Google-Smtp-Source: ABdhPJxcOFWwAIyhl4HdzFSrRg9+dTQh/9LxaWYIvTnCfm9OcVA5nDBjcCW/Jc/Opi1jrh88Wd6LRQ== X-Received: by 2002:a1c:1dcb:: with SMTP id d194mr1947127wmd.156.1634164114816; Wed, 13 Oct 2021 15:28:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28:34 -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>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> Subject: [PATCH v3 08/10] pack-bitmap-write.c: don't return without stop_progress() Date: Thu, 14 Oct 2021 00:28:24 +0200 Message-Id: <patch-v3-08.10-e0a3510dd88-20211013T222329Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 In-Reply-To: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> References: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> <cover-v3-00.10-00000000000-20211013T222329Z-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> Reviewed-by: Emily Shaffer <emilyshaffer@google.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 Wed Oct 13 22:28:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> X-Patchwork-Id: 12557413 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 728D9C433F5 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5EA0761130 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231129AbhJMWaq (ORCPT <rfc822;git@archiver.kernel.org>); Wed, 13 Oct 2021 18:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbhJMWal (ORCPT <rfc822;git@vger.kernel.org>); Wed, 13 Oct 2021 18:30:41 -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 2BA39C061570 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:37 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id e3so13033308wrc.11 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28: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=qg+bhkQ+/nS9/6OzsVYyaYV/554zq1Uhg8a990JfRO4=; b=bL1RxRF6kKcIdLeXUnDqmwShqQrDDTOLpHfpTB+qPOe17evmGVE1eZ67wC65UP/axs BsbTvUPxWY8v5b73NweOijbOR9M/rY/a54xZPuZ9nXfj0DHH7tBxoI9Maw7XIzKASYgJ ORQr2Hcdt/PXmPALhRe65IcXTkyjwTe69Rs4VzzTvYQSm1dvYQMcORKS4xX+UBXj3HRd SOH3gTuZgKJOIbaGVfQrMA9E4b/OXceVfo7+UFL9lzdDBCgmFiWYn5+hohVU3GWIjP25 tFABd6pfKLV9NBiPwi4Q0L/KbWL88+xXxi6PlyF7Cbw7nYJBvQyJTfQNSWZjvZ5EdJWb KH9A== 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=qg+bhkQ+/nS9/6OzsVYyaYV/554zq1Uhg8a990JfRO4=; b=eTjCZBPBbqxkt/CiZzMbGEEjJJJh2XXEm2rlfkdok/VPy4XdpXZoZIc2ZmtvwyGfZW vZBK/XQb79DCraEr9vCL6NyYF90NEoJZsC1Eaq9mP6U6M24WEKOTKJP++yt0X6U62muA 033HmU52vyQYCeZGVumG4xPeAZ4VGayeWYLGZwA91VLQu+9JDlWYES+2t0W9tAu4prd8 sK8dU4OsHOOJ+YoI7KRxwUAke+GldSqkmk8+rS5U2z0RyZcGqBZlk5HHKPaQ7bTE+22W bkzVP87vDptojIlAsZ7CR8d5d53QU9kR+C157b4AHSYoYv34d9aSM0mUaUozOUBgCIwN Gp4w== X-Gm-Message-State: AOAM5334QaOjS9CoyJEHgMKl2P2yYm4spq7UL+8h1gVu6uPK+i2VuFCX 950ot1E5K2AYmAg1/XfPYASkX081X/KFiw== X-Google-Smtp-Source: ABdhPJzrMA0SzUKku5GgMGNdg5ykAdI7W7M/Nj/Gm9ErZvvW9F7iCKgFN60CIPipPxEZoiUlnQjc9g== X-Received: by 2002:a05:6000:18a3:: with SMTP id b3mr2232793wri.178.1634164115552; Wed, 13 Oct 2021 15:28:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28: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>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> Subject: [PATCH v3 09/10] various *.c: use isatty(1|2), not isatty(STDIN_FILENO|STDERR_FILENO) Date: Thu, 14 Oct 2021 00:28:25 +0200 Message-Id: <patch-v3-09.10-2cf14881ecf-20211013T222329Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 In-Reply-To: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> References: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> <cover-v3-00.10-00000000000-20211013T222329Z-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> Reviewed-by: Emily Shaffer <emilyshaffer@google.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 Wed Oct 13 22:28: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: 12557415 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 A9ABFC433FE for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 917BD610F9 for <git@archiver.kernel.org>; Wed, 13 Oct 2021 22:28:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbhJMWar (ORCPT <rfc822;git@archiver.kernel.org>); Wed, 13 Oct 2021 18:30:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231207AbhJMWao (ORCPT <rfc822;git@vger.kernel.org>); Wed, 13 Oct 2021 18:30:44 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA3F8C061766 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28:37 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id i12so13175424wrb.7 for <git@vger.kernel.org>; Wed, 13 Oct 2021 15:28: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=G9ac3knnjEv/RFKA+6kLIUZXWuXXTtqmIJDu9xNXc68=; b=pPGAbXxegU7Lhyy+Y5Zl4LJkLzHg29hRwPCQs1LYUXkrzZSlE0zNolwHQRrh7ld7S+ jzeAFfhvtDzmagnl4RY6khw0XV9xd8ldXI0m44JLwYiiUQo/V4WntEG230P54JWZ0rCQ zIIJ9ZVVaBEMEu4dxHSs3E+dxZiHYkk6a7wGNl5bSKtP433+OX23xy1TjLErlUx92yiR 6zl8KCHjT/dyTt7Dq3soUi/v7ggKdK014ie8jzAu76IYxy7eUcm7ewc1+V4TQFnTsIz6 obvcnGrFUXmBh8iN2NAGzzpvEdtgwje5vcWotQe/PFCEekWohDm+yfgI7DFf71FkjPC0 Hd4A== 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=G9ac3knnjEv/RFKA+6kLIUZXWuXXTtqmIJDu9xNXc68=; b=TqEspKZ81B9BneCTjTnyEAxuWjela0XzQxXgiAYDFnqqEpdkTJ0N/NUy02tZ7qgf1i 10dBb9qaooaBB1rYQxKeBaJLUvWx8OiW1ByiMYM13j8ddJkoUt/m2aaWAEHkxaolFODi JIgOI4JaeehVyNN28xTLWj6vMtLwCfB/iJaCQTuK6EBftGLb8Qidcm9lXmkXJVCuafKf aRG4yDumES5rfaRJDWu166SG6cBm2rOT4JIsFJs40x90gLK2BvCOb6aKJnN+kny3c7dq j85xd+bxJyb7MdTJd47PTWt0qwielnhqKhUUyboYSQ5DBCBilR3//4Fdvd3nKNo7hfhK qjEw== X-Gm-Message-State: AOAM533bhZJ80RA7ZX+HUJSXTGWIzHIweBJ1XdXoCeDmLjQcFvS+3QJB RQIMjnO9wcHIj84ZtY0kwOAUory2WSn8yg== X-Google-Smtp-Source: ABdhPJz5WRUvZy6LCCwu9q6mDm5qNAtgjNPRx9pe5yWBUOmBvcuDMLWH2p+mTI7Pk5He4VMFfy2x/A== X-Received: by 2002:a05:6000:2a3:: with SMTP id l3mr2209236wry.12.1634164116322; Wed, 13 Oct 2021 15:28:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l5sm736683wrq.77.2021.10.13.15.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 15:28: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>, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= <avarab@gmail.com> Subject: [PATCH v3 10/10] progress.c: add & assert a "global_progress" variable Date: Thu, 14 Oct 2021 00:28:26 +0200 Message-Id: <patch-v3-10.10-01d5bbfce76-20211013T222329Z-avarab@gmail.com> X-Mailer: git-send-email 2.33.1.1346.g48288c3c089 In-Reply-To: <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> References: <cover-v2-0.8-00000000000-20210920T225701Z-avarab@gmail.com> <cover-v3-00.10-00000000000-20211013T222329Z-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: <git.vger.kernel.org> X-Mailing-List: git@vger.kernel.org The progress.c code makes a hard assumption that only one progress bar be active at a time (see [1] for a bug where this wasn't the case). Add a BUG() that'll trigger if we ever regress on that promise and have two progress bars active at the same time. There was an alternative test-only approach to doing the same thing[2], but by doing this outside of a GIT_TEST_* mode we'll know we've put a hard stop to this particular API misuse. It will also establish scaffolding to address current fundamental limitations in the progress output: The current output must be "driven" by calls to the likes of display_progress(). Once we have a global current progress object we'll be able to update that object via SIGALRM. See [3] for early code to do that. It's conceivable that this change will hit the BUG() condition in some scenario that we don't currently have tests for, this would be very bad. If that happened we'd die just because we couldn't emit some pretty output. See [4] for a discussion of why our test coverage is lacking; our progress display is hidden behind isatty(2) checks in many cases, so the test suite doesn't cover it unless individual tests are run in "--verbose" mode, we might also have multi-threaded use of the API, so two progress bars stopping and starting would only be visible due to a race condition. Despite that, I think that this change won't introduce such regressions, because: 1. I've read all the code using the progress API (and have modified a large part of it in some WIP code I have). Almost all of it is really simple, the parts that aren't[5] are complex in the display_progress() part, not in starting or stopping the progress bar. 2. The entire test suite passes when instrumented with an ad-hoc Linux-specific mode (it uses gettid()) to die if progress bars are ever started or stopped on anything but the main thread[6]. Extending that to die if display_progress() is called in a thread reveals that we have exactly two users of the progress bar under threaded conditions, "git index-pack" and "git pack-objects". Both uses are straightforward, and they don't start/stop the progress bar when threads are active. 3. I've likewise done an ad-hoc test to force progress bars to be displayed with: perl -pi -e 's[isatty\(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). Between those three points I think it's safe to go ahead with this change. 1. 6f9d5f2fda1 (commit-graph: fix progress of reachable commits, 2020-07-09) 2. https://lore.kernel.org/git/20210620200303.2328957-3-szeder.dev@gmail.com 3. https://lore.kernel.org/git/patch-18.25-e21fc66623f-20210623T155626Z-avarab@gmail.com/ 4. https://lore.kernel.org/git/cover-00.25-00000000000-20210623T155626Z-avarab@gmail.com/ 5. b50c37aa44d (Merge branch 'ab/progress-users-adjust-counters' into next, 2021-09-10) 6. https://lore.kernel.org/git/877dffg37n.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Emily Shaffer <emilyshaffer@google.com> --- progress.c | 18 ++++++++++++++---- t/t0500-progress-display.sh | 11 +++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/progress.c b/progress.c index b9369e9a264..a31500f8b2b 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 @@ -219,11 +220,16 @@ void progress_test_force_update(void) progress_interval(SIGALRM); } -static void set_progress_signal(void) +static void set_progress_signal(struct progress *progress) { struct sigaction sa; struct itimerval v; + if (global_progress) + BUG("'%s' progress still active when trying to start '%s'", + global_progress->title, progress->title); + global_progress = progress; + if (progress_testing) return; @@ -241,10 +247,14 @@ static void set_progress_signal(void) setitimer(ITIMER_REAL, &v, NULL); } -static void clear_progress_signal(void) +static void clear_progress_signal(struct progress *progress) { struct itimerval v = {{0,},}; + if (!global_progress) + BUG("should have active global_progress when cleaning up"); + global_progress = NULL; + if (progress_testing) return; @@ -268,7 +278,7 @@ static struct progress *start_progress_delay(const char *title, uint64_t total, strbuf_init(&progress->counters_sb, 0); progress->title_len = utf8_strwidth(title); progress->split = 0; - set_progress_signal(); + set_progress_signal(progress); trace2_region_enter("progress", title, the_repository); return progress; } @@ -372,7 +382,7 @@ void stop_progress_msg(struct progress **p_progress, const char *msg) display(progress, progress->last_value, buf); free(buf); } - clear_progress_signal(); + clear_progress_signal(progress); strbuf_release(&progress->counters_sb); if (progress->throughput) strbuf_release(&progress->throughput->display); diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh index 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