diff mbox

[ovs-dev] ovn.at: Fix "ovn -- 1 LR with distributed router gateway port" test

Message ID 20170501202130.GC32729@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff May 1, 2017, 8:21 p.m. UTC
On Fri, Apr 21, 2017 at 10:32:57AM +0900, YAMAMOTO Takashi wrote:
> NetBSD implementation of wc command outputs extra whitespaces
> like the following.  Tweak the test to success on such environments.
> 
>     % echo hoge|wc -l|hexdump -C
>     00000000  20 20 20 20 20 20 20 31  0a                       |       1.|
>     00000009
>     %
> 
> The failing test was introduced by
> commit 41a15b71ed1ef35aa612a1128082219fbfc3f327
> (ovn: Introduce distributed gateway port and "chassisredirect" port binding)
> 
> Signed-off-by: YAMAMOTO Takashi <yamamoto@ovn.org>

Thanks a lot for this fix.

This is not the first time we've had trouble with wc, and not the first
project where I've had trouble with wc.  POSIX standardizes the output
format for wc, but neither GNU or BSD honors the standard, and so it's
not even that a particular OS is at fault.

Anyway, how about the following?  I believe that it will fix the problem
you're seeing, and it ought to avoid new problems of the same kind in
the future.  What do you think?

Thanks,

Ben.

--8<--------------------------cut here-------------------------->8--

From: Ben Pfaff <blp@ovn.org>
Date: Mon, 1 May 2017 13:19:43 -0700
Subject: [PATCH] ovs-macros: Add helper to make 'wc' use POSIX compliant
 output format.

Several times, we've had to fix tests that used 'wc' and expected a
particular output format.  POSIX is specific about the output format, but
neither GNU or BSD wc honors it.  This commit makes whatever 'wc' is on
the system use the POSIX output format.

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 tests/ovs-macros.at | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Takashi YAMAMOTO May 2, 2017, 5:48 a.m. UTC | #1
On Tue, May 2, 2017 at 5:21 AM, Ben Pfaff <blp@ovn.org> wrote:

> On Fri, Apr 21, 2017 at 10:32:57AM +0900, YAMAMOTO Takashi wrote:
> > NetBSD implementation of wc command outputs extra whitespaces
> > like the following.  Tweak the test to success on such environments.
> >
> >     % echo hoge|wc -l|hexdump -C
> >     00000000  20 20 20 20 20 20 20 31  0a                       |
>  1.|
> >     00000009
> >     %
> >
> > The failing test was introduced by
> > commit 41a15b71ed1ef35aa612a1128082219fbfc3f327
> > (ovn: Introduce distributed gateway port and "chassisredirect" port
> binding)
> >
> > Signed-off-by: YAMAMOTO Takashi <yamamoto@ovn.org>
>
> Thanks a lot for this fix.
>
> This is not the first time we've had trouble with wc, and not the first
> project where I've had trouble with wc.  POSIX standardizes the output
> format for wc, but neither GNU or BSD honors the standard, and so it's
> not even that a particular OS is at fault.
>
> Anyway, how about the following?  I believe that it will fix the problem
> you're seeing, and it ought to avoid new problems of the same kind in
> the future.  What do you think?
>
> Thanks,
>
> Ben.
>
> --8<--------------------------cut here-------------------------->8--
>
> From: Ben Pfaff <blp@ovn.org>
> Date: Mon, 1 May 2017 13:19:43 -0700
> Subject: [PATCH] ovs-macros: Add helper to make 'wc' use POSIX compliant
>  output format.
>
> Several times, we've had to fix tests that used 'wc' and expected a
> particular output format.  POSIX is specific about the output format, but
> neither GNU or BSD wc honors it.  This commit makes whatever 'wc' is on
> the system use the POSIX output format.
>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
>

good idea.  tested it on netbsd.
Acked-by: YAMAMOTO Takashi <yamamoto@ovn.org>


> ---
>  tests/ovs-macros.at | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at
> index 123c713395e4..37e72d992555 100644
> --- a/tests/ovs-macros.at
> +++ b/tests/ovs-macros.at
> @@ -114,6 +114,16 @@ parent_pid () {
>          ps -o ppid= -p $1
>      fi
>  }
> +
> +# Normalize the output of 'wc' to match POSIX.
> +# POSIX says 'wc' should print "%d %d %d", but GNU prints "%7d %7d %7d".
> +# POSIX says 'wc -l' should print "%d %s", but BSD prints "%8d".
> +#
> +# This fixes all of those (it will screw up filenames that contain
> +# multiple sequential spaces, but that doesn't really matter).
> +wc () {
> +   command wc "$@" | tr -s ' ' ' ' | sed 's/^ *//'
> +}
>  ]
>  m4_divert_pop([PREPARE_TESTS])
>
> --
> 2.10.2
>
>
Ben Pfaff May 2, 2017, 3:09 p.m. UTC | #2
On Tue, May 02, 2017 at 02:48:00PM +0900, Takashi YAMAMOTO wrote:
> On Tue, May 2, 2017 at 5:21 AM, Ben Pfaff <blp@ovn.org> wrote:
> 
> > On Fri, Apr 21, 2017 at 10:32:57AM +0900, YAMAMOTO Takashi wrote:
> > > NetBSD implementation of wc command outputs extra whitespaces
> > > like the following.  Tweak the test to success on such environments.
> > >
> > >     % echo hoge|wc -l|hexdump -C
> > >     00000000  20 20 20 20 20 20 20 31  0a                       |
> >  1.|
> > >     00000009
> > >     %
> > >
> > > The failing test was introduced by
> > > commit 41a15b71ed1ef35aa612a1128082219fbfc3f327
> > > (ovn: Introduce distributed gateway port and "chassisredirect" port
> > binding)
> > >
> > > Signed-off-by: YAMAMOTO Takashi <yamamoto@ovn.org>
> >
> > Thanks a lot for this fix.
> >
> > This is not the first time we've had trouble with wc, and not the first
> > project where I've had trouble with wc.  POSIX standardizes the output
> > format for wc, but neither GNU or BSD honors the standard, and so it's
> > not even that a particular OS is at fault.
> >
> > Anyway, how about the following?  I believe that it will fix the problem
> > you're seeing, and it ought to avoid new problems of the same kind in
> > the future.  What do you think?
> >
> > Thanks,
> >
> > Ben.
> >
> > --8<--------------------------cut here-------------------------->8--
> >
> > From: Ben Pfaff <blp@ovn.org>
> > Date: Mon, 1 May 2017 13:19:43 -0700
> > Subject: [PATCH] ovs-macros: Add helper to make 'wc' use POSIX compliant
> >  output format.
> >
> > Several times, we've had to fix tests that used 'wc' and expected a
> > particular output format.  POSIX is specific about the output format, but
> > neither GNU or BSD wc honors it.  This commit makes whatever 'wc' is on
> > the system use the POSIX output format.
> >
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> >
> 
> good idea.  tested it on netbsd.
> Acked-by: YAMAMOTO Takashi <yamamoto@ovn.org>

Thanks for the review!  I applied this to master.
diff mbox

Patch

diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at
index 123c713395e4..37e72d992555 100644
--- a/tests/ovs-macros.at
+++ b/tests/ovs-macros.at
@@ -114,6 +114,16 @@  parent_pid () {
         ps -o ppid= -p $1
     fi
 }
+
+# Normalize the output of 'wc' to match POSIX.
+# POSIX says 'wc' should print "%d %d %d", but GNU prints "%7d %7d %7d".
+# POSIX says 'wc -l' should print "%d %s", but BSD prints "%8d".
+#
+# This fixes all of those (it will screw up filenames that contain
+# multiple sequential spaces, but that doesn't really matter).
+wc () {
+   command wc "$@" | tr -s ' ' ' ' | sed 's/^ *//'
+}
 ]
 m4_divert_pop([PREPARE_TESTS])