From patchwork Wed Dec 16 07:39:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 11976827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74763C4361B for ; Wed, 16 Dec 2020 07:40:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 240A223A23 for ; Wed, 16 Dec 2020 07:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725812AbgLPHkl (ORCPT ); Wed, 16 Dec 2020 02:40:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725804AbgLPHkl (ORCPT ); Wed, 16 Dec 2020 02:40:41 -0500 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 028D1C0613D6 for ; Tue, 15 Dec 2020 23:40:01 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id 2so21702613ilg.9 for ; Tue, 15 Dec 2020 23:40:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5C3lZKlppggXSNIm7DEmhhLgTVg9hv4L8VP00FesaEg=; b=AqT+rMBXyhY7QODAdvr9ss0M60cnuYkw2RDEsDTQdMY9tPW6mdP+gE+3O8N9OE5vnA pC6HhqUw2QH9c4YcJcF5p1gEfpvWGofy/CUh32jgKDdTghgTKpZs78IkEt9PHdxcpNMt GUvlr/8RQnTwyZIlqgneY/EWA/T7kDVbZfZ6GUmuWq0yTL6YzXBs2xkHKm9dr5Cgnl3S YuGgQNcOuXhQ7BUU79nUkcjbr5EkGZLV0J8lP59XdNXw9UglOxF3C5a9lAdlEOePc81w KYMg5qzjxUiKOgRjQIgcMHjVii4cjly+mtUWZhDPBUJd3XDV4CwpXphjPrqeL4ipKNhW G2pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=5C3lZKlppggXSNIm7DEmhhLgTVg9hv4L8VP00FesaEg=; b=Q45rM3xjc6kX39BzypvXJSYUqA6jKYrBu3Nbh57tx7/ATNkbqUHWTThiXNK3iBa0ng VKWVQLKHgqSlBfQg3rZNHUp8RgbZL+C0jeZxAtfu7GNUbRVCSRzxoUiYpY8pg+zFobfV uhD17nhMzfgYs6UfkuTeNL+xe6s9PkNFOIHLr6901hfctJX6GZauuBhPzZE1SBnI5ULd czZ2cbCj5eSD/352jKx0Qqy39qfN+PtZk94AEKdidMqT5hbsoJq2au9JTBUAeiwaPfsu pstyMrFwc+WuU9Pe++5oqmcSG8Wi8QN4u9gdvNXKFa0WZbV3RGd1z5RE2JWX7fc156km g7aw== X-Gm-Message-State: AOAM533kaQVv8QeciAIZ8QqKfBbv0YYba1rnpfcUFlZwYaYpuyFePFBF pB4SwMXrcwa6EGaY4aVyPwRP3OAFVxk= X-Google-Smtp-Source: ABdhPJxo1w0HygXzU9gvWgPwiWunuSrbsw/3cYFEzQvDKvVtyzSrujHadz4PcpQJz58F57KobaLgCQ== X-Received: by 2002:a92:bac3:: with SMTP id t64mr41501107ill.193.1608104399860; Tue, 15 Dec 2020 23:39:59 -0800 (PST) Received: from localhost.localdomain (user-12l2dpj.cable.mindspring.com. [69.81.55.51]) by smtp.gmail.com with ESMTPSA id p17sm657669ils.45.2020.12.15.23.39.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Dec 2020 23:39:58 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Sangeeta , Philippe Blain , Kaartic Sivaraam , Christian Couder , Lars Schneider , Johannes Schindelin , Eric Sunshine Subject: [PATCH] t/perf: fix test_export() failure with BSD `sed` Date: Wed, 16 Dec 2020 02:39:07 -0500 Message-Id: <20201216073907.62591-1-sunshine@sunshineco.com> X-Mailer: git-send-email 2.30.0.rc0.297.gbcca948854 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org test_perf() runs each test in its own subshell which makes it difficult to persist variables between tests. test_export() addresses this shortcoming by grabbing the values of specified variables after a test runs but before the subshell exits, and writes those values to a file which is loaded into the environment of subsequent tests. To grab the values to be persisted, test_export() pipes the output of the shell's builtin `set` command through `sed` which plucks them out using a regular expression along the lines of `s/^(var1|var2)/.../p`. Unfortunately, though, this use of alternation is not portable. For instance, BSD-lineage `sed` (including macOS `sed`) does not support it in the default "basic regular expression" mode (BRE). It may be possible to enable "extended regular expression" mode (ERE) in some cases with `sed -E`, however, `-E` is neither portable nor part of POSIX. Fortunately, alternation is unnecessary in this case and can easily be avoided, so replace it with a series of simple expressions such as `s/^var1/.../p;s/^var2/.../p`. While at it, tighten the expressions so they match the variable names exactly rather than matching prefixes (i.e. use `s/^var1=/.../p`). If the requirements of test_export() become more complex in the future, then an alternative would be to replace `sed` with `perl` which supports alternation on all platforms, however, the simple elimination of alternation via multiple `sed` expressions suffices for the present. Reported-by: Sangeeta Diagnosed-by: Philippe Blain Signed-off-by: Eric Sunshine --- t/perf/perf-lib.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh index 821581a885..22d727cef8 100644 --- a/t/perf/perf-lib.sh +++ b/t/perf/perf-lib.sh @@ -148,13 +148,18 @@ test_run_perf_ () { . '"$TEST_DIRECTORY"/test-lib-functions.sh' test_export () { [ $# != 0 ] || return 0 - test_export_="$test_export_\\|$1" + test_export_="$test_export_ $1" shift test_export "$@" } '"$1"' ret=$? -set | sed -n "s'"/'/'\\\\''/g"';s/^\\($test_export_\\)/export '"'&'"'/p" >test_vars +needles= +for v in $test_export_ +do + needles="$needles;s/^$v=/export $v=/p" +done +set | sed -n "s'"/'/'\\\\''/g"'$needles" >test_vars exit $ret' >&3 2>&4 eval_ret=$? From patchwork Sun Dec 20 21:27:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 11984217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54502C433E0 for ; Mon, 21 Dec 2020 05:10:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 19E0C22CA1 for ; Mon, 21 Dec 2020 05:10:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727079AbgLUFKd (ORCPT ); Mon, 21 Dec 2020 00:10:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725872AbgLUFKc (ORCPT ); Mon, 21 Dec 2020 00:10:32 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 834DEC0613D3 for ; Sun, 20 Dec 2020 21:10:03 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id z21so5657801pgj.4 for ; Sun, 20 Dec 2020 21:10:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ehU8XnrL0L62/aJROAL8CR76AuZ7UcEFZvkuwPcrqGs=; b=THAkGRXfz3tZhawNPFWVIo806bj8xFblvx9lDhc+QP6ZHpoqPZjQ84su/GthzF3z2L gDr61dbDYJ+oEvKgKIuRT2RwHuRlwxWQE+JDE0F711jqKi5BZ5/FKvslWF4XVD9X6+TB T9Dlo62Jyqzx2p/R93LzLEDGaEaLzC/deAaFrAYqZ9oZFN3cCGUwNVHLJdY2H9pcYf68 NUC7uf0pqWkMNgDPNulyBJdawEmzF02BNLapKnRkcHOO4WjSIXwmakLCdPEymBoCJn+I xZVlnmTmK+RfAOko15tcm40oOhnrHJfv35qzWj5b8+H40ZIc88PzeU2gHihF07Wyeth5 jOyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ehU8XnrL0L62/aJROAL8CR76AuZ7UcEFZvkuwPcrqGs=; b=uC6NeIxLzFsvyJVCFSrE76QHXKYkbJCpZPzEJbsmMdGNdIZn8xP0ZSdN/jFWvIXpHy 3acttAbxzkRFzykS5wMS2cxQvPTDWJxmxO+x+hMD940rUfnwbbF8JWqoQs48O32s8C6o n0H9xhLILGQXUp8bKExN4ngMaqw2owy2wFszwrT/xWgACGtcYIqBJDkZu7oZi/67eeDb m6l6kTCaEKGfOUTgeok3yp/n0DQ8hIIuAXOsaQKOU4ZbZuzS4722UoDvgrGjJhqJyeFR kD5xUYfHcbPQAubopcXNyw/u2QwjY8xW4QWmyjDjX9lYCctMQVnfzTjm9iL/aWmHcup+ tBVQ== X-Gm-Message-State: AOAM533xhnw1NVvVUzztQASJMx9PJrL3zAEajGJy/PkUWmibbHgta2H3 nLSrjAnxMzrem83fiQrEdUedq8LZGvtCHQ== X-Google-Smtp-Source: ABdhPJxfcafX+CHL9zybVev8dH2keTdE3yhGiWESEWpm1XjThg2xzvJ4w5K0+uEv5aDzCts2HLzr0Q== X-Received: by 2002:a05:6e02:4ae:: with SMTP id e14mr13541972ils.132.1608499704869; Sun, 20 Dec 2020 13:28:24 -0800 (PST) Received: from localhost.localdomain (user-12l2dpj.cable.mindspring.com. [69.81.55.51]) by smtp.gmail.com with ESMTPSA id g2sm11872575ilh.41.2020.12.20.13.28.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Dec 2020 13:28:24 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Sangeeta , Philippe Blain , Junio C Hamano , Jeff King , Eric Sunshine Subject: [PATCH 2/1] t/perf: avoid unnecessary test_export() recursion Date: Sun, 20 Dec 2020 16:27:40 -0500 Message-Id: <20201220212740.44273-1-sunshine@sunshineco.com> X-Mailer: git-send-email 2.30.0.rc1.243.g5298b911bd In-Reply-To: <20201216073907.62591-1-sunshine@sunshineco.com> References: <20201216073907.62591-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org test_export() has been self-recursive since its inception even though a simple for-loop would have served just as well to append its arguments to the `test_export_` variable separated by the pipe character "|". Recently `test_export_` was changed instead to a space-separated list of tokens to be exported, an operation which can be accomplished via a single simple assignment, with no need for looping or recursion. Therefore, simplify the implementation. While at it, take advantage of the fact that variable names to be exported are shell identifiers, thus won't be composed of special characters or whitespace, thus simple a `$*` can be used rather than magical `"$@"`. Signed-off-by: Eric Sunshine --- This is a follow-up to [1] as discussed in [2]. It applies cleanly atop 'es/perf-export-fix' and 'master'. [1]: https://lore.kernel.org/git/20201216073907.62591-1-sunshine@sunshineco.com/ [2]: https://lore.kernel.org/git/CAPig+cR+4Wh4Sgk6UhUML4SHqaQsvYmw_77ih+oec2YmqQJCCg@mail.gmail.com/ t/perf/perf-lib.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh index 22d727cef8..e385c6896f 100644 --- a/t/perf/perf-lib.sh +++ b/t/perf/perf-lib.sh @@ -147,10 +147,7 @@ test_run_perf_ () { "$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c ' . '"$TEST_DIRECTORY"/test-lib-functions.sh' test_export () { - [ $# != 0 ] || return 0 - test_export_="$test_export_ $1" - shift - test_export "$@" + test_export_="$test_export_ $*" } '"$1"' ret=$?