From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED 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 C384DC4360F for ; Thu, 4 Apr 2019 12:17:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D9B22171F for ; Thu, 4 Apr 2019 12:17:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729166AbfDDMRD (ORCPT ); Thu, 4 Apr 2019 08:17:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42182 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727039AbfDDMRC (ORCPT ); Thu, 4 Apr 2019 08:17:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3A5381114; Thu, 4 Apr 2019 12:17:02 +0000 (UTC) Received: from localhost (ovpn-200-34.brq.redhat.com [10.40.200.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E537676E12; Thu, 4 Apr 2019 12:17:00 +0000 (UTC) Date: Thu, 4 Apr 2019 14:16:55 +0200 From: Stefano Brivio To: David Ahern Cc: davem@davemloft.net, netdev@vger.kernel.org, David Ahern Subject: Re: [PATCH net-next] selftests: Add debugging options to pmtu.sh Message-ID: <20190404141655.1cc171ad@redhat.com> In-Reply-To: <20190404011824.20921-1-dsahern@kernel.org> References: <20190404011824.20921-1-dsahern@kernel.org> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 04 Apr 2019 12:17:02 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hi David, On Wed, 3 Apr 2019 18:18:24 -0700 David Ahern wrote: > From: David Ahern > > pmtu.sh script runs a number of tests and dumps a summary of pass/fail. > If a test fails, it is near impossible to debug why. For example: > > TEST: ipv6: PMTU exceptions [FAIL] > > There are a lot of commands run behind the scenes for this test. Which > one is failing? > > Add a VERBOSE option to show commands that are run and any output from > those commands. Add a PAUSE_ON_FAIL option to halt the script if a test > fails allowing users to poke around with the setup in the failed state. Thanks for doing this, I have to admit I occasionally had to sprinkle this script with sleep/read/exit in the past. A few comments: > Signed-off-by: David Ahern > --- > tools/testing/selftests/net/pmtu.sh | 215 +++++++++++++++++++++--------------- > 1 file changed, 127 insertions(+), 88 deletions(-) > > diff --git a/tools/testing/selftests/net/pmtu.sh b/tools/testing/selftests/net/pmtu.sh > index 912b2dc50be3..28e8c97b5c9e 100755 > --- a/tools/testing/selftests/net/pmtu.sh > +++ b/tools/testing/selftests/net/pmtu.sh > @@ -116,6 +116,9 @@ > # Kselftest framework requirement - SKIP code is 4. > ksft_skip=4 > > +PAUSE_ON_FAIL=no > +VERBOSE=0 For consistency, I'd also rename 'tracing' below to TRACING and assign it here. > # Some systems don't have a ping6 binary anymore > which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) > > @@ -222,6 +225,26 @@ err_flush() { > err_buf= > } > > +run_cmd() { > + local cmd="$*" > + local out > + local stderr="2>/dev/null" 'local' is not POSIX, and I think it actually breaks (at least) on ksh93 (maybe not a big deal, but I kept everything else POSIX, so I wouldn't break it just for this). Besides, for 'ping' commands, it's stdout that needs to be suppressed (we can just suppress both stdout and stderr if not in verbose mode). > + if [ "$VERBOSE" = "1" ]; then > + printf " COMMAND: $cmd\n" > + stderr= > + fi > + > + out=$(eval $cmd $stderr) I think this needs quoting. Is eval really needed, by the way? > + rc=$? > + if [ "$VERBOSE" = "1" -a -n "$out" ]; then > + echo " $out" > + echo > + fi > + > + return $rc > +} > > [...] > > +while getopts :ptv o Oh, and this is now POSIX and well defined, I didn't know. Thanks for making this readable :) > +do > + case $o in > + p) PAUSE_ON_FAIL=yes;; > + v) VERBOSE=1;; > + t) if which tcpdump > /dev/null 2>&1; then > + tracing=1 > + else > + echo "=== tcpdump not available, tracing disabled" > + fi > + ;; > + *) usage;; > + esac > +done > +shift $(($OPTIND-1)) > + > IFS=" > " > > -tracing=0 > for arg do > - if [ "${arg}" != "${arg#--*}" ]; then > - opt="${arg#--}" > - if [ "${opt}" = "trace" ]; then > - if which tcpdump > /dev/null 2>&1; then > - tracing=1 > - else > - echo "=== tcpdump not available, tracing disabled" > - fi > - else > - usage > - fi > - else > - # Check first that all requested tests are available before > - # running any > - command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; } > - fi > + # Check first that all requested tests are available before > + # running any This fits on a single line now. > + command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; } > done > > trap cleanup EXIT > @@ -1124,6 +1153,11 @@ for t in ${tests}; do > > ( > unset IFS > + > + if [ "$VERBOSE" = "1" ]; then > + printf "\n##########################################################################\n\n" > + fi > + > eval test_${name} > ret=$? > cleanup > @@ -1132,6 +1166,11 @@ for t in ${tests}; do > printf "TEST: %-60s [ OK ]\n" "${t}" > elif [ $ret -eq 1 ]; then > printf "TEST: %-60s [FAIL]\n" "${t}" > + if [ "${PAUSE_ON_FAIL}" = "yes" ]; then > + echo > + echo "Pausing. Hit enter to continue" > + read a > + fi > err_flush > exit 1 > elif [ $ret -eq 2 ]; then -- Stefano