From patchwork Sun Dec 30 19:16:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10745179 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E90F713AD for ; Sun, 30 Dec 2018 19:16:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB42628AA2 for ; Sun, 30 Dec 2018 19:16:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF67428AB7; Sun, 30 Dec 2018 19:16:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1A1028AA2 for ; Sun, 30 Dec 2018 19:16:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726625AbeL3TQy (ORCPT ); Sun, 30 Dec 2018 14:16:54 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:36930 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbeL3TQy (ORCPT ); Sun, 30 Dec 2018 14:16:54 -0500 Received: by mail-wm1-f67.google.com with SMTP id g67so23233474wmd.2 for ; Sun, 30 Dec 2018 11:16:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2P8f3P+5kgKxaF428sywJpWeG6m7hTg0V/ip9Ral8UY=; b=HGh3D2DcLj402j8Td+xw31nl3NyzcUQBnNcoz6Js+LO8+74E4puDVKxq0FVxzrOM// vlwIlr84Nf6U/0VnobZarbJhYxsr0sZV3FOPp2ZAnoREyKHhGchLNhfmt/TJUlzyx2uL sm5wuyeYkp/ulMCqjC2zqxcriMxPWxfgDw68gVaIEFyaPGKp6ARsJ/TAjzJBWflYOCTg MGder4kH5p78HXHZnbWPHqpPOSDjGgGfdIeI5ue3yyYIGj6Gi3NUJaxmk7yM0DQpExfR hoR/4dEOCcaOuVN2TOjOPjC4/GcEGT/hUofMWdKEfUK+A2J5ca1MlMbN3QxkA2/BrBG9 ERGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2P8f3P+5kgKxaF428sywJpWeG6m7hTg0V/ip9Ral8UY=; b=MAIqaF1iLS4CvTOkUBqHI92G/j7xDFUrAGYLC4wdCvsAflNuB6RKpCPzyFyWigPx6z E/D6CAxuh2tC6+gtU++kh9mxOqW/Aom6ATkp/7ADDi8mSmqWBWXsCJ+gOquYOHqtLd3b fPoB1gKSdl9LEbjJJQ8Zb/jr/s6jt0rWQb/JhuQYy42DQq0ZOAnW69oznR8QRPqaVPr0 Pwdtp1rDcVlKJFaExWSegCE0EUj3uFntpjOgllbME5xVFL1WILp9xCc3lAJzgSK+0NsH NlBfMFVaqL/RXU90c1rJQg6BAuux3ahBum+J8BSa8R59NoWEY9NlDjSQFQ2e5N7wZyCD 04sw== X-Gm-Message-State: AA+aEWbuoEMSIrm5q/9udgDtlUhkm6x/eVVwKy9hHPlY5zVW7pxGSBmf WGCMI9FiV8mBOQMK1WfS7Yoozvgj X-Google-Smtp-Source: AFSGD/XyXe2jNW10uyUZqOYLAi2iqe0dH0pOGpwx7wE1rrfX5QLmtveF/ukd54bY4kacpUe62qtfKw== X-Received: by 2002:a1c:47:: with SMTP id 68mr27824210wma.89.1546197412458; Sun, 30 Dec 2018 11:16:52 -0800 (PST) Received: from localhost.localdomain (84-236-109-65.pool.digikabel.hu. [84.236.109.65]) by smtp.gmail.com with ESMTPSA id h62sm28954226wmf.11.2018.12.30.11.16.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Dec 2018 11:16:51 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Jeff King , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1?= =?utf-8?q?bor?= Subject: [PATCH v3 1/8] test-lib: translate SIGTERM and SIGHUP to an exit Date: Sun, 30 Dec 2018 20:16:22 +0100 Message-Id: <20181230191629.3232-2-szeder.dev@gmail.com> X-Mailer: git-send-email 2.20.1.151.gec613c4b75 In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com> References: <20181209225628.22216-1-szeder.dev@gmail.com> <20181230191629.3232-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Right now if a test script receives SIGTERM or SIGHUP (e.g., because a test was hanging and the user 'kill'-ed it or simply closed the terminal window the test was running in), the shell exits immediately. This can be annoying if the test script did any global setup, like starting apache or git-daemon, as it will not have an opportunity to clean up after itself. A subsequent run of the test won't be able to start its own daemon, and will either fail or skip the tests. Instead, let's trap SIGTERM and SIGHUP as well to make sure we do a clean shutdown, and just chain it to a normal exit (which will trigger any cleanup). This patch follows suit of da706545f7 (t: translate SIGINT to an exit, 2015-03-13), and even stole its commit message as well. Signed-off-by: SZEDER Gábor --- t/test-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 0f1faa24b2..9a3f7930a3 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -476,7 +476,7 @@ die () { GIT_EXIT_OK= trap 'die' EXIT -trap 'exit $?' INT +trap 'exit $?' INT TERM HUP # The user-facing functions are loaded from a separate file so that # test_perf subshells can have them too From patchwork Sun Dec 30 19:16:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10745181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A4736C5 for ; Sun, 30 Dec 2018 19:16:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B8CD28AA2 for ; Sun, 30 Dec 2018 19:16:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FA0B28AB7; Sun, 30 Dec 2018 19:16:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDC9828AA2 for ; Sun, 30 Dec 2018 19:16:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726682AbeL3TQ4 (ORCPT ); Sun, 30 Dec 2018 14:16:56 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37887 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726432AbeL3TQ4 (ORCPT ); Sun, 30 Dec 2018 14:16:56 -0500 Received: by mail-wr1-f68.google.com with SMTP id s12so25102020wrt.4 for ; Sun, 30 Dec 2018 11:16:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fw3JiTxr8pl7NFZa0U6iDv+WqrEjcmmnIKRvHqU7b84=; b=s4VfVHrtJ/aNTFqWceNoce1nUa2MzW8GyimT5OQXLeqj9Lk1zqGqvnfM96trPlDEMt vG06c7LuajX/rQyvgwZwaDFbOGVmOnHlaPtAhAb7U+kxc+VjkYVRv/60RNJxV5BGIi0I FQ4Tp0h+0fsZ3r6QxYQkmTGWL0Ge57Ul59tW9O37Pg91+a6ftPskT9XsHSuc6oiihBSi WkyK251kbq3W+gLSLSWuNOa28vGkF/xWBW+2pVQX9tLY5XJMIsZq1WXS/nQ0sEKVXcor nswZYsWMdEJYKISoF8VQ+Etw06sInhQp8no4G8G9BdN5a1/PYZ7J7+cCRgfGi8DwGb2q qUNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fw3JiTxr8pl7NFZa0U6iDv+WqrEjcmmnIKRvHqU7b84=; b=BvO2E3CiXRdLMKfqAmKpOtDT+2+Lh1jiCuWhoRo5onZsAnO1r1ClRcb9eigrsHJM1C WlAJ8OZs/IHW4d5kyY5ipKXpSypuTc+ciFHI9ondIRjs5/9MaUIVrpYTGvnEbMxaKDol PulINoXIkxvSDgkpm+JtPjj8EC6UmIEmSA3ZaLl7N6GgYJ97eYJbe1XWvOOcSfuQM5km xrYLMAygePLLaEsOB0CMFStFOhK7uB1B0x2ugytipUbG4QBS7FgSlwSaJkJRecqs0YMf EWstRFtiBPHTxzp9+7HJB6kmxHr5X4zEYdehnr/1/Y0S3M8czu9uEE83cECgNVbTjG8r RAvQ== X-Gm-Message-State: AJcUukfc7YRP3sKRh/wEGEo5O+P0DX1fmgO2PosjPhMrOPp5u4+lSmHy 9OD8ynkKm7WTLS5hvVnzXSo= X-Google-Smtp-Source: ALg8bN6ax2QY16J8jC0Y6Meux/82cAYmIllOqECEDXLb4uqn5iW2IpkMmPofqgQ0Z6hNoONjvxwMPw== X-Received: by 2002:adf:c612:: with SMTP id n18mr30204516wrg.174.1546197413610; Sun, 30 Dec 2018 11:16:53 -0800 (PST) Received: from localhost.localdomain (84-236-109-65.pool.digikabel.hu. [84.236.109.65]) by smtp.gmail.com with ESMTPSA id h62sm28954226wmf.11.2018.12.30.11.16.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Dec 2018 11:16:53 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Jeff King , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1?= =?utf-8?q?bor?= Subject: [PATCH v3 2/8] test-lib: parse options in a for loop to keep $@ intact Date: Sun, 30 Dec 2018 20:16:23 +0100 Message-Id: <20181230191629.3232-3-szeder.dev@gmail.com> X-Mailer: git-send-email 2.20.1.151.gec613c4b75 In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com> References: <20181209225628.22216-1-szeder.dev@gmail.com> <20181230191629.3232-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 'test-lib.sh' looks for the presence of certain options like '--tee' and '--verbose-log', so it can execute the test script again to save its standard output and error, and to do so it needs the original command line options the test was invoked with. The next patch is about to move the option parsing loop earlier in 'test-lib.sh', but it is implemented using 'shift' in a while loop, effecively destroying "$@" by the end of the option parsing. Not good. As a preparatory step, turn that option parsing loop into a 'for opt in "$@"' loop to preserve "$@" intact while iterating over the options, and taking extra care to handle the '-r' option's required argument (or the lack thereof). Signed-off-by: SZEDER Gábor --- t/test-lib.sh | 77 ++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 9a3f7930a3..ed7267962f 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -264,58 +264,59 @@ test "x$TERM" != "xdumb" && ( ) && color=t -while test "$#" -ne 0 +store_arg_to= +prev_opt= +for opt do - case "$1" in + if test -n "$store_arg_to" + then + eval $store_arg_to=\$opt + store_arg_to= + prev_opt= + continue + fi + + case "$opt" in -d|--d|--de|--deb|--debu|--debug) - debug=t; shift ;; + debug=t ;; -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) - immediate=t; shift ;; + immediate=t ;; -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) - GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;; + GIT_TEST_LONG=t; export GIT_TEST_LONG ;; -r) - shift; test "$#" -ne 0 || { - echo 'error: -r requires an argument' >&2; - exit 1; - } - run_list=$1; shift ;; + store_arg_to=run_list + ;; --run=*) - run_list=${1#--*=}; shift ;; + run_list=${opt#--*=} ;; -h|--h|--he|--hel|--help) - help=t; shift ;; + help=t ;; -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) - verbose=t; shift ;; + verbose=t ;; --verbose-only=*) - verbose_only=${1#--*=} - shift ;; + verbose_only=${opt#--*=} + ;; -q|--q|--qu|--qui|--quie|--quiet) # Ignore --quiet under a TAP::Harness. Saying how many tests # passed without the ok/not ok details is always an error. - test -z "$HARNESS_ACTIVE" && quiet=t; shift ;; + test -z "$HARNESS_ACTIVE" && quiet=t ;; --with-dashes) - with_dashes=t; shift ;; + with_dashes=t ;; --no-color) - color=; shift ;; + color= ;; --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind) - valgrind=memcheck - shift ;; + valgrind=memcheck ;; --valgrind=*) - valgrind=${1#--*=} - shift ;; + valgrind=${opt#--*=} ;; --valgrind-only=*) - valgrind_only=${1#--*=} - shift ;; + valgrind_only=${opt#--*=} ;; --tee) - shift ;; # was handled already + ;; # was handled already --root=*) - root=${1#--*=} - shift ;; + root=${opt#--*=} ;; --chain-lint) - GIT_TEST_CHAIN_LINT=1 - shift ;; + GIT_TEST_CHAIN_LINT=1 ;; --no-chain-lint) - GIT_TEST_CHAIN_LINT=0 - shift ;; + GIT_TEST_CHAIN_LINT=0 ;; -x) # Some test scripts can't be reliably traced with '-x', # unless the test is run with a Bash version supporting @@ -335,14 +336,20 @@ do else echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD" fi - shift ;; + ;; -V|--verbose-log) - verbose_log=t - shift ;; + verbose_log=t ;; *) - echo "error: unknown test option '$1'" >&2; exit 1 ;; + echo "error: unknown test option '$opt'" >&2; exit 1 ;; esac + + prev_opt=$opt done +if test -n "$store_arg_to" +then + echo "error: $prev_opt requires an argument" >&2 + exit 1 +fi if test -n "$valgrind_only" then From patchwork Sun Dec 30 19:16:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10745183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51BD913AD for ; Sun, 30 Dec 2018 19:17:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4403A28AA2 for ; Sun, 30 Dec 2018 19:17:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38A5628AB7; Sun, 30 Dec 2018 19:17:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D7BC28AA2 for ; Sun, 30 Dec 2018 19:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726727AbeL3TRA (ORCPT ); Sun, 30 Dec 2018 14:17:00 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53000 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726661AbeL3TQ6 (ORCPT ); Sun, 30 Dec 2018 14:16:58 -0500 Received: by mail-wm1-f65.google.com with SMTP id m1so22374754wml.2 for ; Sun, 30 Dec 2018 11:16:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/8/r0oO6eHoGg3cpv4xPGFA40s7qMfU0r7XkY4txoUk=; b=ujMUbaf7c3HV35w5eseVHYl2y9y9auzYTG+ZGt7MfIobxHGYq+o8kBsFbqhH3uaoA2 1EGlMrh8Hem7KTxazNtpkAAw1MXkU3gkqhT8hiuXHxioOmpnaEcOIVdlmRVgaPfgpboC Bl4I0JirvSnoVw81jETRziW9czglXFZKhyG9H5UDMkhvWw7dKuCUS0EIQENdD/oqDB9M pTQKNbtqB6pDEyb4tLqN7aPdKGHIwZ9praeg5lnS9wPf+o4DWPu+oV7iHGnN5urZI1UL Gh0NT+5WQ33VXaRJ7YafZ+5+VfypZZMNb6a5TdO6F9j9NFOjuRn58cjA84HzPqsDmh3F Rz2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/8/r0oO6eHoGg3cpv4xPGFA40s7qMfU0r7XkY4txoUk=; b=CsKEMUJrwv/ythv+FwGBSkN1LAL75s/Nvhiz3si6m+wbO/OIjCBYUkefYYCjmyt3NI KsUnbeDQnCM1WV2A/WXzka6mn4QCgJW3REA+DnHDI0+XNabPIFtYxiNrEqxJE92UZjT+ OEDb3Zm8H3LxBvFZxmongpXEBpoaJJGnyWwaoNVAOg6aavehLGZaA8MBo562pT0aTPu0 Tw4W2b2sYRFzgZH0C60IObnnbS8dHS7HNoeVv1QcQzuEXy9cUtVR2MDsaTyDtIIlgTeQ DI/LLx+AFDC9GweUHcBlztpE7e/eDyWuyUZMAxbQ8qI8GGs1dBFbjKq8hHWVFH+iM5Jy w49Q== X-Gm-Message-State: AA+aEWb5CLU7waJbMhbNpAUfHs4QV4d31jxzFwik4/9FswGJ7bEE7cjC bdvV/ixcoCiRRAtFf9mQwxI= X-Google-Smtp-Source: AFSGD/UDG/japE6LlNpCeXgPW2BnZghgrYmyeLYi27ztBpWzBLR07otFKihNyCsPsExgdTidguGBew== X-Received: by 2002:a1c:a755:: with SMTP id q82mr30577712wme.6.1546197414567; Sun, 30 Dec 2018 11:16:54 -0800 (PST) Received: from localhost.localdomain (84-236-109-65.pool.digikabel.hu. [84.236.109.65]) by smtp.gmail.com with ESMTPSA id h62sm28954226wmf.11.2018.12.30.11.16.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Dec 2018 11:16:53 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Jeff King , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1?= =?utf-8?q?bor?= Subject: [PATCH v3 3/8] test-lib: parse command line options earlier Date: Sun, 30 Dec 2018 20:16:24 +0100 Message-Id: <20181230191629.3232-4-szeder.dev@gmail.com> X-Mailer: git-send-email 2.20.1.151.gec613c4b75 In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com> References: <20181209225628.22216-1-szeder.dev@gmail.com> <20181230191629.3232-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 'test-lib.sh' looks for the presence of certain options like '--tee' and '--verbose-log', so it can execute the test script again to save its standard output and error. It looks for '--valgrind' as well, to set up some Valgrind-specific stuff. These all happen before the actual option parsing loop, and the conditions looking for these options look a bit odd, too. They are not completely correct, either, because in a bogus invocation like './t1234-foo.sh -r --tee' they recognize '--tee', although it should be handled as the required argument of the '-r' option. This patch series will add two more options to look out for early, and, in addition, will have to extract these options' stuck arguments (i.e. '--opt=arg') as well. So let's move the option parsing loop and the couple of related conditions following it earlier in 'test-lib.sh', before the place where the test script is executed again for '--tee' and its friends. Signed-off-by: SZEDER Gábor --- t/test-lib.sh | 228 ++++++++++++++++++++++++++------------------------ 1 file changed, 119 insertions(+), 109 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index ed7267962f..fcc04afdff 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -71,13 +71,125 @@ then exit 1 fi +# Parse options while taking care to leave $@ intact, so we will still +# have all the original command line options when executing the test +# script again for '--tee' and '--verbose-log' below. +store_arg_to= +prev_opt= +for opt +do + if test -n "$store_arg_to" + then + eval $store_arg_to=\$opt + store_arg_to= + prev_opt= + continue + fi + + case "$opt" in + -d|--d|--de|--deb|--debu|--debug) + debug=t ;; + -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) + immediate=t ;; + -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) + GIT_TEST_LONG=t; export GIT_TEST_LONG ;; + -r) + store_arg_to=run_list + ;; + --run=*) + run_list=${opt#--*=} ;; + -h|--h|--he|--hel|--help) + help=t ;; + -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) + verbose=t ;; + --verbose-only=*) + verbose_only=${opt#--*=} + ;; + -q|--q|--qu|--qui|--quie|--quiet) + # Ignore --quiet under a TAP::Harness. Saying how many tests + # passed without the ok/not ok details is always an error. + test -z "$HARNESS_ACTIVE" && quiet=t ;; + --with-dashes) + with_dashes=t ;; + --no-color) + color= ;; + --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind) + valgrind=memcheck + tee=t + ;; + --valgrind=*) + valgrind=${opt#--*=} + tee=t + ;; + --valgrind-only=*) + valgrind_only=${opt#--*=} + tee=t + ;; + --tee) + tee=t ;; + --root=*) + root=${opt#--*=} ;; + --chain-lint) + GIT_TEST_CHAIN_LINT=1 ;; + --no-chain-lint) + GIT_TEST_CHAIN_LINT=0 ;; + -x) + # Some test scripts can't be reliably traced with '-x', + # unless the test is run with a Bash version supporting + # BASH_XTRACEFD (introduced in Bash v4.1). Check whether + # this test is marked as such, and ignore '-x' if it + # isn't executed with a suitable Bash version. + if test -z "$test_untraceable" || { + test -n "$BASH_VERSION" && { + test ${BASH_VERSINFO[0]} -gt 4 || { + test ${BASH_VERSINFO[0]} -eq 4 && + test ${BASH_VERSINFO[1]} -ge 1 + } + } + } + then + trace=t + else + echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD" + fi + ;; + -V|--verbose-log) + verbose_log=t + tee=t + ;; + *) + echo "error: unknown test option '$opt'" >&2; exit 1 ;; + esac + + prev_opt=$opt +done +if test -n "$store_arg_to" +then + echo "error: $prev_opt requires an argument" >&2 + exit 1 +fi + +if test -n "$valgrind_only" +then + test -z "$valgrind" && valgrind=memcheck + test -z "$verbose" && verbose_only="$valgrind_only" +elif test -n "$valgrind" +then + test -z "$verbose_log" && verbose=t +fi + +if test -n "$trace" && test -z "$verbose_log" +then + verbose=t +fi + # if --tee was passed, write the output not only to the terminal, but # additionally to the file test-results/$BASENAME.out, too. -case "$GIT_TEST_TEE_STARTED, $* " in -done,*) - # do not redirect again - ;; -*' --tee '*|*' --va'*|*' -V '*|*' --verbose-log '*) +if test "$GIT_TEST_TEE_STARTED" = "done" +then + : # do not redirect again +elif test -n "$tee" +then mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results" BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)" @@ -94,8 +206,7 @@ done,*) echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE" test "$(cat "$BASE.exit")" = 0 exit - ;; -esac +fi # For repeatability, reset the environment to known value. # TERM is sanitized below, after saving color control sequences. @@ -193,7 +304,7 @@ fi # Add libc MALLOC and MALLOC_PERTURB test # only if we are not executing the test with valgrind -if expr " $GIT_TEST_OPTS " : ".* --valgrind " >/dev/null || +if test -n "$valgrind" || test -n "$TEST_NO_MALLOC_CHECK" then setup_malloc_check () { @@ -264,107 +375,6 @@ test "x$TERM" != "xdumb" && ( ) && color=t -store_arg_to= -prev_opt= -for opt -do - if test -n "$store_arg_to" - then - eval $store_arg_to=\$opt - store_arg_to= - prev_opt= - continue - fi - - case "$opt" in - -d|--d|--de|--deb|--debu|--debug) - debug=t ;; - -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) - immediate=t ;; - -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) - GIT_TEST_LONG=t; export GIT_TEST_LONG ;; - -r) - store_arg_to=run_list - ;; - --run=*) - run_list=${opt#--*=} ;; - -h|--h|--he|--hel|--help) - help=t ;; - -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) - verbose=t ;; - --verbose-only=*) - verbose_only=${opt#--*=} - ;; - -q|--q|--qu|--qui|--quie|--quiet) - # Ignore --quiet under a TAP::Harness. Saying how many tests - # passed without the ok/not ok details is always an error. - test -z "$HARNESS_ACTIVE" && quiet=t ;; - --with-dashes) - with_dashes=t ;; - --no-color) - color= ;; - --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind) - valgrind=memcheck ;; - --valgrind=*) - valgrind=${opt#--*=} ;; - --valgrind-only=*) - valgrind_only=${opt#--*=} ;; - --tee) - ;; # was handled already - --root=*) - root=${opt#--*=} ;; - --chain-lint) - GIT_TEST_CHAIN_LINT=1 ;; - --no-chain-lint) - GIT_TEST_CHAIN_LINT=0 ;; - -x) - # Some test scripts can't be reliably traced with '-x', - # unless the test is run with a Bash version supporting - # BASH_XTRACEFD (introduced in Bash v4.1). Check whether - # this test is marked as such, and ignore '-x' if it - # isn't executed with a suitable Bash version. - if test -z "$test_untraceable" || { - test -n "$BASH_VERSION" && { - test ${BASH_VERSINFO[0]} -gt 4 || { - test ${BASH_VERSINFO[0]} -eq 4 && - test ${BASH_VERSINFO[1]} -ge 1 - } - } - } - then - trace=t - else - echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD" - fi - ;; - -V|--verbose-log) - verbose_log=t ;; - *) - echo "error: unknown test option '$opt'" >&2; exit 1 ;; - esac - - prev_opt=$opt -done -if test -n "$store_arg_to" -then - echo "error: $prev_opt requires an argument" >&2 - exit 1 -fi - -if test -n "$valgrind_only" -then - test -z "$valgrind" && valgrind=memcheck - test -z "$verbose" && verbose_only="$valgrind_only" -elif test -n "$valgrind" -then - test -z "$verbose_log" && verbose=t -fi - -if test -n "$trace" && test -z "$verbose_log" -then - verbose=t -fi - if test -n "$color" then # Save the color control sequences now rather than run tput From patchwork Sun Dec 30 19:16:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10745191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E03613AD for ; Sun, 30 Dec 2018 19:17:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6166928AA2 for ; Sun, 30 Dec 2018 19:17:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 548AE28AD0; Sun, 30 Dec 2018 19:17:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B40EA28AA2 for ; Sun, 30 Dec 2018 19:17:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbeL3TRA (ORCPT ); Sun, 30 Dec 2018 14:17:00 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:53002 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726432AbeL3TQ5 (ORCPT ); Sun, 30 Dec 2018 14:16:57 -0500 Received: by mail-wm1-f66.google.com with SMTP id m1so22374765wml.2 for ; Sun, 30 Dec 2018 11:16:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PTT3+cx2wgGX7JG24QBqYkK5kyTyhNCQHB1sb5ffYhM=; b=SbFvtFTAhpZXSScUR1YNM1Z2a5o0/aMkMHSjBq1Ao5lovXB1fLQG5YvTy04btXdFIl jBfhdU5llLIVHXWvRT3KTdXuEAVEs/DrOuX/PJuVpbeI2qg4Nr1VOpmSj8rs3JTykPdZ VkpDhld36lN1URauoLDgIyXz/gicxewk39/W5PWeZ7dryKeB8iQKfOLABQqWqLwnL4iI 3/4TZTlK8fe/WX+iRhpxw+9eY1kwlN1jC4lBLygrSHSMHmiCMmC5PNxbfTJn20WGvu5n CFJzk2hHaDuXLnzUfX27yvWh167vdIXcYXs8rmoHOSrL9UsQft+rMrg2fZogEiYW3IRZ q1Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PTT3+cx2wgGX7JG24QBqYkK5kyTyhNCQHB1sb5ffYhM=; b=KUJRR/2g/2Pnv0lzSc7gOShSrPAQoVJRwUq779DAo6Ngi3mabt4XVS0WqSHlX50WL7 j1KhO+ZzW668u2br+fZV1FBMJvRynBo1wtgNibp5R2FiDphlfoPYk5nygLiKTKgXie2C pkQoIHDWGwPm+A0yJivhubHdWDG0/3QAlGpwZh37C6mrcpUxnm+KUpbLABdvPmR8hcGk TC1O+XiIoS6msfGSGKPidsURbmLsmGHpSbgwpG6nciEyMQPKHAJQ1OgPzjVv8itA6MEd 1xv5I5qKJqaakWdyM4lhdrrt+/h2lQc9VXH6JWbzbo1SVYNUxaMk7436bKR/hdliM1R2 el8g== X-Gm-Message-State: AJcUukfme0r0l3jO97jeD93ZaaYw1iu7tHIPTJmxwApJlfpUB0MptCd7 oeRdhmRTHk2OpePXieDJ2nY= X-Google-Smtp-Source: AFSGD/V7cX4gyj3qKhXAeWI5aT5cmY+q7tpzGrkWcxKIIUIiRXgYqz4QI8TGBu3GDbJmQbj7Irajeg== X-Received: by 2002:a1c:8b09:: with SMTP id n9mr29252004wmd.38.1546197415730; Sun, 30 Dec 2018 11:16:55 -0800 (PST) Received: from localhost.localdomain (84-236-109-65.pool.digikabel.hu. [84.236.109.65]) by smtp.gmail.com with ESMTPSA id h62sm28954226wmf.11.2018.12.30.11.16.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Dec 2018 11:16:54 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Jeff King , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1?= =?utf-8?q?bor?= Subject: [PATCH v3 4/8] test-lib: consolidate naming of test-results paths Date: Sun, 30 Dec 2018 20:16:25 +0100 Message-Id: <20181230191629.3232-5-szeder.dev@gmail.com> X-Mailer: git-send-email 2.20.1.151.gec613c4b75 In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com> References: <20181209225628.22216-1-szeder.dev@gmail.com> <20181230191629.3232-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are two places where we strip off any leading path components and the '.sh' suffix from the test script's pathname, and there are four places where we construct the name of the 't/test-results' directory or the name of various test-specific files in there. The last patch in this series will add even more. Factor these out into helper variables to avoid repeating ourselves. Signed-off-by: SZEDER Gábor --- t/test-lib.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index fcc04afdff..41457d1dcf 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -183,6 +183,10 @@ then verbose=t fi +TEST_NAME="$(basename "$0" .sh)" +TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results" +TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME" + # if --tee was passed, write the output not only to the terminal, but # additionally to the file test-results/$BASENAME.out, too. if test "$GIT_TEST_TEE_STARTED" = "done" @@ -190,12 +194,11 @@ then : # do not redirect again elif test -n "$tee" then - mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results" - BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)" + mkdir -p "$TEST_RESULTS_DIR" # Make this filename available to the sub-process in case it is using # --verbose-log. - GIT_TEST_TEE_OUTPUT_FILE=$BASE.out + GIT_TEST_TEE_OUTPUT_FILE=$TEST_RESULTS_BASE.out export GIT_TEST_TEE_OUTPUT_FILE # Truncate before calling "tee -a" to get rid of the results @@ -203,8 +206,8 @@ then >"$GIT_TEST_TEE_OUTPUT_FILE" (GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1; - echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE" - test "$(cat "$BASE.exit")" = 0 + echo $? >"$TEST_RESULTS_BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE" + test "$(cat "$TEST_RESULTS_BASE.exit")" = 0 exit fi @@ -835,12 +838,9 @@ test_done () { if test -z "$HARNESS_ACTIVE" then - test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results" - mkdir -p "$test_results_dir" - base=${0##*/} - test_results_path="$test_results_dir/${base%.sh}.counts" + mkdir -p "$TEST_RESULTS_DIR" - cat >"$test_results_path" <<-EOF + cat >"$TEST_RESULTS_BASE.counts" <<-EOF total $test_count success $test_success fixed $test_fixed @@ -1046,7 +1046,7 @@ then fi # Test repository -TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)" +TRASH_DIRECTORY="trash directory.$TEST_NAME" test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" case "$TRASH_DIRECTORY" in /*) ;; # absolute path is good From patchwork Sun Dec 30 19:16:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10745189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3FB313AD for ; Sun, 30 Dec 2018 19:17:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6F7F28AA2 for ; Sun, 30 Dec 2018 19:17:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB0D228AB7; Sun, 30 Dec 2018 19:17:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8570128AA2 for ; Sun, 30 Dec 2018 19:17:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726724AbeL3TRA (ORCPT ); Sun, 30 Dec 2018 14:17:00 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:36212 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbeL3TQ6 (ORCPT ); Sun, 30 Dec 2018 14:16:58 -0500 Received: by mail-wr1-f65.google.com with SMTP id u4so25099185wrp.3 for ; Sun, 30 Dec 2018 11:16:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W22rQ0lb2f4bIjQpoBRCrV/fuKAsCLdkSflV1PQYXwA=; b=AwR4phgW7PU8ZLaQIBRjVu3XVWKsNHy839G/rwJ+tIGSZjYL6HX/7c8BFnUIgFJ3OR rkaCOcccsFmC/kAgHqp7W7E7sL/u/2OsLsDmtIM+t/Hp/ZMRnw06jhVTpZ1UduDahlSK xy4FyWbnFB6CqWHn0Oc0HgUS38m1cdXbG13fYDZsOm9FlcLec2k3B2ugARxKfJEbLHmu jIz2hTSQifeTo8bi2ErIaWj4757xe5TY4o2s6D/4aR5eDq1yqHMWtfeYfLaoELUz2QWc fbWEQrYu8gxrhWjVxs45tY5JPDq5tS2rLq5kiAZc5+HL4ijQKNHYd2L3eiEfyZU3qKR6 pYVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W22rQ0lb2f4bIjQpoBRCrV/fuKAsCLdkSflV1PQYXwA=; b=BUYvRMlIYkAQmM1IuUsRR177JLY5BWvpjKgCENQCVaZG9NF+KESISeZ1xVb6wcY+0D WC7sPEWTBuv1tqTWjw2kBENTtY1O5Nfb0Y7uT7BhKi5ci+2NevwucToYBF6wjzMridCw Yc7H0rmn/bZmeF2kafxG95z3bk40nhhbvubrArQBdOK3rNvwPah9E5kwi9wKikaIoLlq SoL9vj2HExJuj3hE1x0Ir6d6XmX3/6LcfJKHs7S6jPZC8vRFxuLR21Vk273DPUTGXhVy IzOcpfam5RmqO4CUxiVAknL065kflTE0pFe+PdSDSXnQGSyDnRkNvz58FwSCT46W0dg5 M/BA== X-Gm-Message-State: AJcUukf0nkd7x+20/0Iqee0ObJtNbGY8q/kkaXmRTtuLDkpPQbPoVQc2 BGnqMwUTfhvdyc8g0wXMAVs= X-Google-Smtp-Source: ALg8bN40uSVHG9esSoTWSxuc/4b0Pn/MSGuRtf6gwO4uLO/q88cRiiUFQ+2JXrJhbgc8yQrOF2Ce5g== X-Received: by 2002:adf:f052:: with SMTP id t18mr33103039wro.112.1546197416973; Sun, 30 Dec 2018 11:16:56 -0800 (PST) Received: from localhost.localdomain (84-236-109-65.pool.digikabel.hu. [84.236.109.65]) by smtp.gmail.com with ESMTPSA id h62sm28954226wmf.11.2018.12.30.11.16.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Dec 2018 11:16:56 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Jeff King , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1?= =?utf-8?q?bor?= Subject: [PATCH v3 5/8] test-lib: set $TRASH_DIRECTORY earlier Date: Sun, 30 Dec 2018 20:16:26 +0100 Message-Id: <20181230191629.3232-6-szeder.dev@gmail.com> X-Mailer: git-send-email 2.20.1.151.gec613c4b75 In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com> References: <20181209225628.22216-1-szeder.dev@gmail.com> <20181230191629.3232-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A later patch in this series will need to know the path to the trash directory early in 'test-lib.sh', but $TRASH_DIRECTORY is set much later. Furthermore, the path to the trash directory depends on the '--root=' option, which, too, is parsed too late. Move parsing '--root=...' to the early option parsing loop, and set $TRASH_DIRECTORY where the other test-specific path variables are set. Signed-off-by: SZEDER Gábor --- t/test-lib.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 41457d1dcf..2b88ba2de1 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -186,6 +186,12 @@ fi TEST_NAME="$(basename "$0" .sh)" TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results" TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME" +TRASH_DIRECTORY="trash directory.$TEST_NAME" +test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" +case "$TRASH_DIRECTORY" in +/*) ;; # absolute path is good + *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;; +esac # if --tee was passed, write the output not only to the terminal, but # additionally to the file test-results/$BASENAME.out, too. @@ -1046,12 +1052,6 @@ then fi # Test repository -TRASH_DIRECTORY="trash directory.$TEST_NAME" -test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" -case "$TRASH_DIRECTORY" in -/*) ;; # absolute path is good - *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;; -esac rm -fr "$TRASH_DIRECTORY" || { GIT_EXIT_OK=t echo >&5 "FATAL: Cannot prepare test area" From patchwork Sun Dec 30 19:16:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10745185 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77A2613AD for ; Sun, 30 Dec 2018 19:17:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 697AB28AAB for ; Sun, 30 Dec 2018 19:17:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DCB228AB7; Sun, 30 Dec 2018 19:17:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50D3A28AA2 for ; Sun, 30 Dec 2018 19:17:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726738AbeL3TRB (ORCPT ); Sun, 30 Dec 2018 14:17:01 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34932 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726690AbeL3TRA (ORCPT ); Sun, 30 Dec 2018 14:17:00 -0500 Received: by mail-wm1-f66.google.com with SMTP id t200so11273658wmt.0 for ; Sun, 30 Dec 2018 11:16:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4GrnKFR07mS7TdVR05EkIjdQNgfKMJ8yO+J4kh6C6Wg=; b=BJ/hmDxqMD4VS0jmg2Qq/RxMADMUlqRT3m98coFYLIlAgXaDYEEUtyLIKLmKhXmFwk pXLOTXQFsNSJDMsrdnjFTstL/s9JixtyWiN3xh4Vmy4wztANyfQZ/o1mFNYQTwP+4Q2t b1capMsc/mxWEVjS6sdS0O3AXRVgMjV/MdoIIUtsDagRt+ej63vJDlR7R0cVLW8npXRG MbRvkXNExIgXlroUo8AoyDO96WT0ruc9bMItbynFL1gZlO2xLS20h0GVB+9KPvzyZ8u4 7H7kgZIYffiR8ISGOUlCuGwAIdEolBcrmECLZXQE0Zpf5gNQqkQ0WESXDfwZyBATQ3oq MU5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4GrnKFR07mS7TdVR05EkIjdQNgfKMJ8yO+J4kh6C6Wg=; b=lGDl/Lye2cecuNFFQndI07H8yheIAi5Q2budaMH+/rRz/TVXANJzujFeTvt+/WuuIt 9kGcGGtPsTmgwDKHS6VkeH02gBVOx9Sh9bKNtUOpppITHRI0EGgFLKvxjTCCuRh80RvW FhUqGm7DkUEM9M3s4PoU1EWm+Etq0mHR9bkeGdM9RlJv1nzDNODzYBeobMnk++s6kJkA zIyeX5jyXVXkxc1xOsmvGs9ul221vR1jJJU1QA3K0qReSyAivGuKxJp7k2AzhISsecAD mrK6TA4MYVDMaLmt9lGJQ2V5XpsmVu85B/XlT14k7TgBApqU0KgWBg1dDiEsG/1UptzD hvOA== X-Gm-Message-State: AJcUukcQV8MaToRFIHqbv1re/KLAVTTrsLhPwLv75Qzn+WQgdsdu4cLw dJWY8FZTw3L8QAc3R2Uc528= X-Google-Smtp-Source: ALg8bN6gaFQ09kSLx04ri+j0sO4gidfk7ALkqbIpGBYaAUeZc3pNvt6eOFvngANbOOy5iqhTlsEg/Q== X-Received: by 2002:a1c:578e:: with SMTP id l136mr16699328wmb.124.1546197418038; Sun, 30 Dec 2018 11:16:58 -0800 (PST) Received: from localhost.localdomain (84-236-109-65.pool.digikabel.hu. [84.236.109.65]) by smtp.gmail.com with ESMTPSA id h62sm28954226wmf.11.2018.12.30.11.16.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Dec 2018 11:16:57 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Jeff King , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1?= =?utf-8?q?bor?= Subject: [PATCH v3 6/8] test-lib: extract Bash version check for '-x' tracing Date: Sun, 30 Dec 2018 20:16:27 +0100 Message-Id: <20181230191629.3232-7-szeder.dev@gmail.com> X-Mailer: git-send-email 2.20.1.151.gec613c4b75 In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com> References: <20181209225628.22216-1-szeder.dev@gmail.com> <20181230191629.3232-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP One of our test scripts, 't1510-repo-setup.sh' [1], still can't be reliably run with '-x' tracing enabled, unless it's executed with a Bash version supporting BASH_XTRACEFD (since v4.1). We have a lengthy condition to check the version of the shell running the test script, and disable tracing if it's not executed with a suitable Bash version [2]. Move this check out from the option parsing loop, so other options can imply '-x' by setting 'trace=t', without missing this Bash version check. [1] 5827506928 (t1510-repo-setup: mark as untraceable with '-x', 2018-02-24) [2] 5fc98e79fc (t: add means to disable '-x' tracing for individual test scripts, 2018-02-24) Signed-off-by: SZEDER Gábor --- t/test-lib.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 2b88ba2de1..7d77a26d44 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -134,25 +134,7 @@ do --no-chain-lint) GIT_TEST_CHAIN_LINT=0 ;; -x) - # Some test scripts can't be reliably traced with '-x', - # unless the test is run with a Bash version supporting - # BASH_XTRACEFD (introduced in Bash v4.1). Check whether - # this test is marked as such, and ignore '-x' if it - # isn't executed with a suitable Bash version. - if test -z "$test_untraceable" || { - test -n "$BASH_VERSION" && { - test ${BASH_VERSINFO[0]} -gt 4 || { - test ${BASH_VERSINFO[0]} -eq 4 && - test ${BASH_VERSINFO[1]} -ge 1 - } - } - } - then - trace=t - else - echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD" - fi - ;; + trace=t ;; -V|--verbose-log) verbose_log=t tee=t @@ -178,6 +160,24 @@ then test -z "$verbose_log" && verbose=t fi +if test -n "$trace" && test -n "$test_untraceable" +then + # '-x' tracing requested, but this test script can't be reliably + # traced, unless it is run with a Bash version supporting + # BASH_XTRACEFD (introduced in Bash v4.1). + if test -n "$BASH_VERSION" && { + test ${BASH_VERSINFO[0]} -gt 4 || { + test ${BASH_VERSINFO[0]} -eq 4 && + test ${BASH_VERSINFO[1]} -ge 1 + } + } + then + : Executed by a Bash version supporting BASH_XTRACEFD. Good. + else + echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD" + trace= + fi +fi if test -n "$trace" && test -z "$verbose_log" then verbose=t From patchwork Sun Dec 30 19:16:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10745187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E62C6C5 for ; Sun, 30 Dec 2018 19:17:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2038F28AA2 for ; Sun, 30 Dec 2018 19:17:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 144FF28AB7; Sun, 30 Dec 2018 19:17:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6558B28AA2 for ; Sun, 30 Dec 2018 19:17:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726741AbeL3TRC (ORCPT ); Sun, 30 Dec 2018 14:17:02 -0500 Received: from mail-wm1-f54.google.com ([209.85.128.54]:33598 "EHLO mail-wm1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726700AbeL3TRB (ORCPT ); Sun, 30 Dec 2018 14:17:01 -0500 Received: by mail-wm1-f54.google.com with SMTP id r24so28959383wmh.0 for ; Sun, 30 Dec 2018 11:16:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G490hWxRkjmzNPRyAG2aYuokWdaIM5x7F5TgGUSqNHU=; b=mIFhhMtpB/C3zAW5nFeneCUA3EaNcaiQxUIU9lJDnP8w+DyvKmNJSdVHB10bpn8sZp lI9nS2Wxs49bUTH9AX5aur4nEG63AKEpqQlJhmSJNe/4Q5CFcFoWYa3d9uwGRBo0T+KN msqCtUYTp+ajUHu+aBkdMYUiXYSroBIj5udL2/iIpLctiFTXweYDCH+DhO2MBA/tpvj3 xRSAhgSqRYjsUz7T1tMk3O/84D2rtslGnhcdLJWMpjSBA4wTQCnm4UYyS5vPuAXpLrPG KnO/NgkdqiaNlSzI+t3G/xJhDxbvNZzWomDLVpsjIIE25JZ99Bbm8NRw1CjdUh50tdCJ 8WgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G490hWxRkjmzNPRyAG2aYuokWdaIM5x7F5TgGUSqNHU=; b=Db+uALTOFp7WXWcJRCMPOcLSQKB8rQdAFoFPXHnCtDDMonsq5B4y8GSOeEKgM1vNvz 8ZxQa9wC4nNfg69oug3maNIR3k/hKxiYGdh1s7VAAnl0Rgs4h57u/6m++JGfUsonUGiZ 2Zw5agSC3iHA4hkH9VQJ8p3HiEuVnKeqY4ILlDI/1Ilt6HiR+V3dgyFfah+qbvtwjOsp 3os8wti6NAvOMHKQHX/WLnEAvNcVPRCpbStpNVA0YUlaI4/drSqJoBFPkkqmQ3aGnXY3 pWSbfbYxRq3j1zrRqXi3wklYj2flSD/kkRg1WlwMshX4hkxalhdWCffZjbYKWvyQKmop WMfQ== X-Gm-Message-State: AA+aEWahT9/rxv/qAOoxF+3HiO+uo68p5zYhzjKklte2VoeZ/B/1hMYt zPCgv/pPqnB1cAt7FR5MQw0= X-Google-Smtp-Source: ALg8bN49ZcC+B1Ow0dYFQnj7ZINx2AA67f9F9gsWMIHOYBuR+uJgL2nqYoWJoUxCw2dk2wQ9JQOWIg== X-Received: by 2002:a1c:a00f:: with SMTP id j15mr27875034wme.84.1546197419016; Sun, 30 Dec 2018 11:16:59 -0800 (PST) Received: from localhost.localdomain (84-236-109-65.pool.digikabel.hu. [84.236.109.65]) by smtp.gmail.com with ESMTPSA id h62sm28954226wmf.11.2018.12.30.11.16.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Dec 2018 11:16:58 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Jeff King , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1?= =?utf-8?q?bor?= Subject: [PATCH v3 7/8] test-lib-functions: introduce the 'test_set_port' helper function Date: Sun, 30 Dec 2018 20:16:28 +0100 Message-Id: <20181230191629.3232-8-szeder.dev@gmail.com> X-Mailer: git-send-email 2.20.1.151.gec613c4b75 In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com> References: <20181209225628.22216-1-szeder.dev@gmail.com> <20181230191629.3232-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Several test scripts run daemons like 'git-daemon' or Apache, and communicate with them through TCP sockets. To have unique ports where these daemons are accessible, the ports are usually the number of the corresponding test scripts, unless the user overrides them via environment variables, and thus all those tests and test libs contain more or less the same bit of one-liner boilerplate code to find out the port. The last patch in this series will make this a bit more complicated. Factor out finding the port for a daemon into the common helper function 'test_set_port' to avoid repeating ourselves. Take special care of test scripts with "low" numbers: - Test numbers below 1024 would result in a port that's only usable as root, so set their port to '10000 + test-nr' to make sure it doesn't interfere with other tests in the test suite. This makes the hardcoded port number in 't0410-partial-clone.sh' unnecessary, remove it. - The shell's arithmetic evaluation interprets numbers with leading zeros as octal values, which means that test number below 1000 and containing the digits 8 or 9 will trigger an error. Remove all leading zeros from the test numbers to prevent this. Note that the 'git p4' tests are unlike the other tests involving daemons in that: - 'lib-git-p4.sh' doesn't use the test's number for unique port as is, but does a bit of additional arithmetic on top [1]. - The port is not overridable via an environment variable. With this patch even 'git p4' tests will use the test's number as default port, and it will be overridable via the P4DPORT environment variable. [1] Commit fc00233071 (git-p4 tests: refactor and cleanup, 2011-08-22) introduced that "unusual" unique port computation without explaining why it was necessary (as opposed to simply using the test number as is). It seems to be just unnecessary complication, and in any case that commit came way before the "test nr as unique port" got "standardized" for other daemons in commits c44132fcf3 (tests: auto-set git-daemon port, 2014-02-10), 3bb486e439 (tests: auto-set LIB_HTTPD_PORT from test name, 2014-02-10), and bf9d7df950 (t/lib-git-svn.sh: improve svnserve tests with parallel make test, 2017-12-01). Signed-off-by: SZEDER Gábor --- t/lib-git-daemon.sh | 2 +- t/lib-git-p4.sh | 9 +-------- t/lib-git-svn.sh | 2 +- t/lib-httpd.sh | 2 +- t/t0410-partial-clone.sh | 1 - t/t5512-ls-remote.sh | 2 +- t/test-lib-functions.sh | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 41 insertions(+), 13 deletions(-) diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh index f98de95c15..41eb1e3ae8 100644 --- a/t/lib-git-daemon.sh +++ b/t/lib-git-daemon.sh @@ -28,7 +28,7 @@ then test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs" fi -LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}} +test_set_port LIB_GIT_DAEMON_PORT GIT_DAEMON_PID= GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh index c27599474c..b3be3ba011 100644 --- a/t/lib-git-p4.sh +++ b/t/lib-git-p4.sh @@ -53,14 +53,7 @@ time_in_seconds () { (cd / && "$PYTHON_PATH" -c 'import time; print(int(time.time()))') } -# Try to pick a unique port: guess a large number, then hope -# no more than one of each test is running. -# -# This does not handle the case where somebody else is running the -# same tests and has chosen the same ports. -testid=${this_test#t} -git_p4_test_start=9800 -P4DPORT=$((10669 + ($testid - $git_p4_test_start))) +test_set_port P4DPORT P4PORT=localhost:$P4DPORT P4CLIENT=client diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh index a8130f9119..f3b478c307 100644 --- a/t/lib-git-svn.sh +++ b/t/lib-git-svn.sh @@ -13,6 +13,7 @@ fi GIT_DIR=$PWD/.git GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn SVN_TREE=$GIT_SVN_DIR/svn-tree +test_set_port SVNSERVE_PORT svn >/dev/null 2>&1 if test $? -ne 1 @@ -119,7 +120,6 @@ require_svnserve () { } start_svnserve () { - SVNSERVE_PORT=${SVNSERVE_PORT-${this_test#t}} svnserve --listen-port $SVNSERVE_PORT \ --root "$rawsvnrepo" \ --listen-once \ diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index a8729f8232..e465116ef9 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -82,7 +82,7 @@ case $(uname) in esac LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"} -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-${this_test#t}} +test_set_port LIB_HTTPD_PORT TEST_PATH="$TEST_DIRECTORY"/lib-httpd HTTPD_ROOT_PATH="$PWD"/httpd diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh index ba3887f178..0aca8d7588 100755 --- a/t/t0410-partial-clone.sh +++ b/t/t0410-partial-clone.sh @@ -480,7 +480,6 @@ test_expect_success 'gc stops traversal when a missing but promised object is re ! grep "$TREE_HASH" out ' -LIB_HTTPD_PORT=12345 # default port, 410, cannot be used as non-root . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index 32e722db2e..cd9e60632d 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -260,7 +260,7 @@ test_lazy_prereq GIT_DAEMON ' # This test spawns a daemon, so run it only if the user would be OK with # testing with git-daemon. test_expect_success PIPE,JGIT,GIT_DAEMON 'indicate no refs in standards-compliant empty remote' ' - JGIT_DAEMON_PORT=${JGIT_DAEMON_PORT-${this_test#t}} && + test_set_port JGIT_DAEMON_PORT && JGIT_DAEMON_PID= && git init --bare empty.git && >empty.git/git-daemon-export-ok && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 6b3bbf99e4..4459bdda13 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1263,3 +1263,39 @@ test_oid () { fi && eval "printf '%s' \"\${$var}\"" } + +# Choose a port number based on the test script's number and store it in +# the given variable name, unless that variable already contains a number. +test_set_port () { + local var=$1 port + + if test $# -ne 1 || test -z "$var" + then + BUG "test_set_port requires a variable name" + fi + + eval port=\$$var + case "$port" in + "") + # No port is set in the given env var, use the test + # number as port number instead. + # Remove not only the leading 't', but all leading zeros + # as well, so the arithmetic below won't (mis)interpret + # a test number like '0123' as an octal value. + port=${this_test#${this_test%%[1-9]*}} + if test "${port:-0}" -lt 1024 + then + # root-only port, use a larger one instead. + port=$(($port + 10000)) + fi + + eval $var=$port + ;; + *[^0-9]*|0*) + error >&7 "invalid port number: $port" + ;; + *) + # The user has specified the port. + ;; + esac +} From patchwork Sun Dec 30 19:16:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 10745193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C42106C5 for ; Sun, 30 Dec 2018 19:17:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5A2B28AA2 for ; Sun, 30 Dec 2018 19:17:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA0FE28ACD; Sun, 30 Dec 2018 19:17:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D57D928AAB for ; Sun, 30 Dec 2018 19:17:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726743AbeL3TRG (ORCPT ); Sun, 30 Dec 2018 14:17:06 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54221 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726737AbeL3TRD (ORCPT ); Sun, 30 Dec 2018 14:17:03 -0500 Received: by mail-wm1-f67.google.com with SMTP id d15so22356630wmb.3 for ; Sun, 30 Dec 2018 11:17:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b+V1+b2P9jvcYtdne4civ3pW6lO32OiRnILZFWPzQUc=; b=WSwropoHDbRVqtjH+zVXbhebpRX9FqGdl59IHWhbYTKXeTzYvUM7iWnrvQovLCrX0r 3wktPeUQFAZjMVV9duilTguSatRxr93NIvb7L7wL7sRjbIOwV+4TlyR/saNTAla+qSKc jCJuzWtrXJa5Jsfl5HMODrYJYrWPfLxz6DzwnWYNdr+52cuaARBrvyxXUakxVR7+g4DV ZxFeO7hkJGvcPuhkEoYGjVHvdSaTk/+bNW2moFFvUjEguxxT43z8HNtWyPrN/m1+++WF /ZiLzQkAbi8yagDySdFQgUMsK1Sx0oiuwToFm/FlFQVtmKyPaEQfek9GE6iizlXCpdtX gpgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b+V1+b2P9jvcYtdne4civ3pW6lO32OiRnILZFWPzQUc=; b=O7wXb0vuzBru6OkRY+Ion9XTwD0+Iq29JxxQumfphKO0ASm9wH+/cz4GAW1QGMsHet mun61K8z/kOGaq+Z2uhuv4C4nLYpQt6GuJsbOiIuKe8a9CXcNV/lSdFekEuZ07v53grO iBdzaYy3KUciZNYvsv24XRv2OFF3DvvcD2jRBh7ppqyzP0skVdzJO+1tgs42fDMCoGSZ KpV+1ZQPMn7sYJrDW59Um+ecIABYio6dDZye4REXwOxaymy2TPmXFEdwUEYDe2mYQZIS +zuqEB7aP8QOtmVnLowFk+L/GxRxTKZs41xNxk2cBLEBdcqaL5KyshE3uAOA2A5KtKcL HwcQ== X-Gm-Message-State: AJcUukcjiSRW/efjFOzuC9Pj+11ulCBYwrXVSKwabrK5WO2i33qG0MJx KByVStv7elbEifcmwD4BVD4= X-Google-Smtp-Source: ALg8bN6+Ov2yFmbCOxpTKc2JRIE0x8N7HuqsLaVhDJrieB5UZilvDkXxCc5/qiYrB5f/2nFD1Ph6lA== X-Received: by 2002:a1c:2007:: with SMTP id g7mr28454104wmg.79.1546197420091; Sun, 30 Dec 2018 11:17:00 -0800 (PST) Received: from localhost.localdomain (84-236-109-65.pool.digikabel.hu. [84.236.109.65]) by smtp.gmail.com with ESMTPSA id h62sm28954226wmf.11.2018.12.30.11.16.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Dec 2018 11:16:59 -0800 (PST) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: Jeff King , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1?= =?utf-8?q?bor?= Subject: [PATCH v3 8/8] test-lib: add the '--stress' option to run a test repeatedly under load Date: Sun, 30 Dec 2018 20:16:29 +0100 Message-Id: <20181230191629.3232-9-szeder.dev@gmail.com> X-Mailer: git-send-email 2.20.1.151.gec613c4b75 In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com> References: <20181209225628.22216-1-szeder.dev@gmail.com> <20181230191629.3232-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Unfortunately, we have a few flaky tests, whose failures tend to be hard to reproduce. We've found that the best we can do to reproduce such a failure is to run the test script repeatedly while the machine is under load, and wait in the hope that the load creates enough variance in the timing of the test's commands that a failure is evenually triggered. I have a command to do that, and I noticed that two other contributors have rolled their own scripts to do the same, all choosing slightly different approaches. To help reproduce failures in flaky tests, introduce the '--stress' option to run a test script repeatedly in multiple parallel jobs until one of them fails, thereby using the test script itself to increase the load on the machine. The number of parallel jobs is determined by, in order of precedence: the number specified as '--stress=', or the value of the GIT_TEST_STRESS_LOAD environment variable, or twice the number of available processors (as reported by the 'getconf' utility), or 8. Make '--stress' imply '--verbose -x --immediate' to get the most information about rare failures; there is really no point in spending all the extra effort to reproduce such a failure, and then not know which command failed and why. To prevent the several parallel invocations of the same test from interfering with each other: - Include the parallel job's number in the name of the trash directory and the various output files under 't/test-results/' as a '.stress-' suffix. - Add the parallel job's number to the port number specified by the user or to the test number, so even tests involving daemons listening on a TCP socket can be stressed. - Redirect each parallel test run's verbose output to 't/test-results/$TEST_NAME.stress-.out', because dumping the output of several parallel running tests to the terminal would create a big ugly mess. For convenience, print the output of the failed test job at the end, and rename its trash directory to end with the '.stress-failed' suffix, so it's easy to find in a predictable path (OTOH, all absolute paths recorded in the trash directory become invalid; we'll see whether this causes any issues in practice). If, in an unlikely case, more than one jobs were to fail nearly at the same time, then print the output of all failed jobs, and rename the trash directory of only the last one (i.e. with the highest job number), as it is the trash directory of the test whose output will be at the bottom of the user's terminal. Based on Jeff King's 'stress' script. Signed-off-by: SZEDER Gábor --- t/README | 19 ++++++- t/test-lib-functions.sh | 7 ++- t/test-lib.sh | 109 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 130 insertions(+), 5 deletions(-) diff --git a/t/README b/t/README index 28711cc508..11ce7675e3 100644 --- a/t/README +++ b/t/README @@ -186,6 +186,22 @@ appropriately before running "make". this feature by setting the GIT_TEST_CHAIN_LINT environment variable to "1" or "0", respectively. +--stress:: +--stress=:: + Run the test script repeatedly in multiple parallel jobs until + one of them fails. Useful for reproducing rare failures in + flaky tests. The number of parallel jobs is, in order of + precedence: , or the value of the GIT_TEST_STRESS_LOAD + environment variable, or twice the number of available + processors (as shown by the 'getconf' utility), or 8. + Implies `--verbose -x --immediate` to get the most information + about the failure. Note that the verbose output of each test + job is saved to 't/test-results/$TEST_NAME.stress-.out', + and only the output of the failed test job is shown on the + terminal. The names of the trash directories get a + '.stress-' suffix, and the trash directory of the failed + test job is renamed to end with a '.stress-failed' suffix. + You can also set the GIT_TEST_INSTALLED environment variable to the bindir of an existing git installation to test that installation. You still need to have built this git sandbox, from which various @@ -425,7 +441,8 @@ This test harness library does the following things: - Creates an empty test directory with an empty .git/objects database and chdir(2) into it. This directory is 't/trash directory.$test_name_without_dotsh', with t/ subject to change by - the --root option documented above. + the --root option documented above, and a '.stress-' suffix + appended by the --stress option. - Defines standard test helper functions for your scripts to use. These functions are designed to make all scripts behave diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 4459bdda13..92cf8f812c 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1288,8 +1288,6 @@ test_set_port () { # root-only port, use a larger one instead. port=$(($port + 10000)) fi - - eval $var=$port ;; *[^0-9]*|0*) error >&7 "invalid port number: $port" @@ -1298,4 +1296,9 @@ test_set_port () { # The user has specified the port. ;; esac + + # Make sure that parallel '--stress' test jobs get different + # ports. + port=$(($port + ${GIT_TEST_STRESS_JOB_NR:-0})) + eval $var=$port } diff --git a/t/test-lib.sh b/t/test-lib.sh index 7d77a26d44..16f74bd524 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -139,6 +139,19 @@ do verbose_log=t tee=t ;; + --stress) + stress=t ;; + --stress=*) + stress=${opt#--*=} + case "$stress" in + *[^0-9]*|0*|"") + echo "error: --stress= requires the number of jobs to run" >&2 + exit 1 + ;; + *) # Good. + ;; + esac + ;; *) echo "error: unknown test option '$opt'" >&2; exit 1 ;; esac @@ -160,6 +173,13 @@ then test -z "$verbose_log" && verbose=t fi +if test -n "$stress" +then + verbose=t + trace=t + immediate=t +fi + if test -n "$trace" && test -n "$test_untraceable" then # '-x' tracing requested, but this test script can't be reliably @@ -183,16 +203,101 @@ then verbose=t fi +TEST_STRESS_JOB_SFX="${GIT_TEST_STRESS_JOB_NR:+.stress-$GIT_TEST_STRESS_JOB_NR}" TEST_NAME="$(basename "$0" .sh)" TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results" -TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME" -TRASH_DIRECTORY="trash directory.$TEST_NAME" +TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME$TEST_STRESS_JOB_SFX" +TRASH_DIRECTORY="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX" test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" case "$TRASH_DIRECTORY" in /*) ;; # absolute path is good *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;; esac +# If --stress was passed, run this test repeatedly in several parallel loops. +if test "$GIT_TEST_STRESS_STARTED" = "done" +then + : # Don't stress test again. +elif test -n "$stress" +then + if test "$stress" != t + then + job_count=$stress + elif test -n "$GIT_TEST_STRESS_LOAD" + then + job_count="$GIT_TEST_STRESS_LOAD" + elif job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null) && + test -n "$job_count" + then + job_count=$((2 * $job_count)) + else + job_count=8 + fi + + mkdir -p "$TEST_RESULTS_DIR" + stressfail="$TEST_RESULTS_BASE.stress-failed" + rm -f "$stressfail" + + stress_exit=0 + trap ' + kill $job_pids 2>/dev/null + wait + stress_exit=1 + ' TERM INT HUP + + job_pids= + job_nr=0 + while test $job_nr -lt "$job_count" + do + ( + GIT_TEST_STRESS_STARTED=done + GIT_TEST_STRESS_JOB_NR=$job_nr + export GIT_TEST_STRESS_STARTED GIT_TEST_STRESS_JOB_NR + + trap ' + kill $test_pid 2>/dev/null + wait + exit 1 + ' TERM INT + + cnt=0 + while ! test -e "$stressfail" + do + $TEST_SHELL_PATH "$0" "$@" >"$TEST_RESULTS_BASE.stress-$job_nr.out" 2>&1 & + test_pid=$! + + if wait $test_pid + then + printf "OK %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt + else + echo $GIT_TEST_STRESS_JOB_NR >>"$stressfail" + printf "FAIL %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt + fi + cnt=$(($cnt + 1)) + done + ) & + job_pids="$job_pids $!" + job_nr=$(($job_nr + 1)) + done + + wait + + if test -f "$stressfail" + then + echo "Log(s) of failed test run(s):" + for failed_job_nr in $(sort -n "$stressfail") + do + echo "Contents of '$TEST_RESULTS_BASE.stress-$failed_job_nr.out':" + cat "$TEST_RESULTS_BASE.stress-$failed_job_nr.out" + done + rm -rf "$TRASH_DIRECTORY.stress-failed" + # Move the last one. + mv "$TRASH_DIRECTORY.stress-$failed_job_nr" "$TRASH_DIRECTORY.stress-failed" + fi + + exit $stress_exit +fi + # if --tee was passed, write the output not only to the terminal, but # additionally to the file test-results/$BASENAME.out, too. if test "$GIT_TEST_TEE_STARTED" = "done"