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

Ben Pfaff blp at ovn.org
Mon May 1 20:21:30 UTC 2017


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 at 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 at 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 at 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



More information about the dev mailing list