From: Eric Biggers <ebiggers@google.com>
To: Eryu Guan <guaneryu@gmail.com>
Cc: fstests@vger.kernel.org
Subject: Re: [PATCH] common/rc: add missing 'local' keywords
Date: Fri, 6 Apr 2018 15:17:13 -0700 [thread overview]
Message-ID: <20180406221713.GB40084@google.com> (raw)
In-Reply-To: <20180406085603.GO30836@localhost.localdomain>
Hi Eryu, thanks for the review!
On Fri, Apr 06, 2018 at 04:56:03PM +0800, Eryu Guan wrote:
> On Thu, Apr 05, 2018 at 11:31:29AM -0700, Eric Biggers wrote:
> > A lot of the helper functions in xfstests are unnecessarily declaring
> > variables without the 'local' keyword, which pollutes the global
> > namespace and can collide with variables in tests. Fix this for
> > everything in common/rc that I could find.
> >
> > Signed-off-by: Eric Biggers <ebiggers@google.com>
>
> Thanks a lot for doing this! I need some time to do careful testing, as
> something can be broken implicitly, as the "$err_msg" usage below.
>
Indeed, I ran the 'auto' group tests on ext4 and xfs using gce-xfstests, but
that doesn't cover everything.
> > ---
> > common/rc | 306 ++++++++++++++++++++++++++++--------------------------
> > 1 file changed, 158 insertions(+), 148 deletions(-)
> >
> > diff --git a/common/rc b/common/rc
> > index 6a91850c..39e1db43 100644
> > --- a/common/rc
> > +++ b/common/rc
> > @@ -53,12 +53,8 @@ _require_math()
> > _math()
> > {
> > [ $# -le 0 ] && return
> > - if [ "$BC" ]; then
> > - result=$(LANG=C echo "scale=0; $@" | "$BC" -q 2> /dev/null)
> > - else
> > - _notrun "this test requires 'bc' tool for doing math operations"
> > - fi
> > - echo "$result"
> > + _require_math
>
> I think _require_math belongs to tests that take use of _math, not _math
> itself.
>
Yes, _math is only used by generic/260 and xfs/259 which already do
_require_math, so I'll just remove _require_math from here.
> >
> > _dump_err()
> > {
> > - err_msg="$*"
> > + local err_msg="$*"
> > echo "$err_msg"
> > }
> >
> > _dump_err2()
> > {
> > - err_msg="$*"
> > + local err_msg="$*"
> > >2& echo "$err_msg"
> > }
> >
> > _log_err()
> > {
> > - err_msg="$*"
> > + local err_msg="$*"
>
> It seems the "$err_msg" in above functions need to be global,
> common/report needs it set somewhere. Perhaps we can name it with a
> leading underscore to indicate it's a global variable.
>
Ick. I'll add a leading underscore.
> > @@ -1130,7 +1131,7 @@ _repair_scratch_fs()
> > *)
> > # Let's hope fsck -y suffices...
> > fsck -t $FSTYP -y $SCRATCH_DEV 2>&1
> > - res=$?
> > + local res=$?
> > case $res in
> > 0|1|2)
> > res=0
> > @@ -1317,7 +1318,7 @@ _is_block_dev()
> > exit 1
> > fi
> >
> > - _dev=$1
> > + local _dev=$1
>
> A 'local' variable could drop the leading underscore then.
>
Will do for here and the other places.
Eric
prev parent reply other threads:[~2018-04-06 22:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-05 18:31 [PATCH] common/rc: add missing 'local' keywords Eric Biggers
2018-04-06 8:56 ` Eryu Guan
2018-04-06 22:17 ` Eric Biggers [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180406221713.GB40084@google.com \
--to=ebiggers@google.com \
--cc=fstests@vger.kernel.org \
--cc=guaneryu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox