diff mbox

[ovs-dev,1/5] tests: Define trim_zeros in only one place.

Message ID 1469603005-5992-2-git-send-email-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff July 27, 2016, 7:03 a.m. UTC
Defining trim_zeros in a common place allows us to skip defining it in
every test that needs it.

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 tests/ovn.at | 61 +++++++++++-------------------------------------------------
 1 file changed, 11 insertions(+), 50 deletions(-)

Comments

Ryan Moats July 29, 2016, 2:56 a.m. UTC | #1
"dev" <dev-bounces@openvswitch.org> wrote on 07/27/2016 02:03:21 AM:

> From: Ben Pfaff <blp@ovn.org>
> To: dev@openvswitch.org
> Cc: Ben Pfaff <blp@ovn.org>
> Date: 07/27/2016 02:03 AM
> Subject: [ovs-dev] [PATCH 1/5] tests: Define trim_zeros in only one
place.
> Sent by: "dev" <dev-bounces@openvswitch.org>
>
> Defining trim_zeros in a common place allows us to skip defining it in
> every test that needs it.
>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
> ---

cleaning up code is always a good thing and tests pass for me
after applying it, so ...

Acked-by: Ryan Moats <rmoats@us.ibm.com>
Flaviof July 29, 2016, 3:47 a.m. UTC | #2
On Wed, Jul 27, 2016 at 2:03 AM, Ben Pfaff <blp@ovn.org> wrote:

> Defining trim_zeros in a common place allows us to skip defining it in
> every test that needs it.
>
> Signed-off-by: Ben Pfaff <blp@ovn.org>
>

Acked-by: Flavio Fernandes <flavio@flaviof.com>



> ---
>  tests/ovn.at | 61
> +++++++++++-------------------------------------------------
>  1 file changed, 11 insertions(+), 50 deletions(-)
>
> diff --git a/tests/ovn.at b/tests/ovn.at
> index 86efcf5..0fe2527 100644
> --- a/tests/ovn.at
> +++ b/tests/ovn.at
> @@ -1,3 +1,14 @@
> +# trim_zeros()
> +#
> +# Removes pairs of trailing zeros from lines of text.  Useful for
> +# fairly comparing Ethernet packets that might have been padded out to
> +# a minimum (e.g. 64-byte) length.
> +m4_divert_text([PREPARE_TESTS],
> +  [trim_zeros() {
> +     sed 's/\(00\)\{1,\}$//' "$@"
> +   }
> +])
> +
>  AT_BANNER([OVN components])
>
>  AT_SETUP([ovn -- lexer])
> @@ -737,9 +748,6 @@ vif_to_hv() {
>  # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
>  # more) list the VIFs on which the packet should be received.  INPORT and
> the
>  # OUTPORTs are specified as logical switch port numbers, e.g. 11 for
> vif11.
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>  for i in 1 2 3; do
>      for j in 1 2 3; do
>          : > $i$j.expected
> @@ -1038,9 +1046,6 @@ vif_to_hv() {
>  # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
>  # more) list the VIFs on which the packet should be received.  INPORT and
> the
>  # OUTPORTs are specified as logical switch port numbers, e.g. 11 for
> vif11.
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>  for i in 1 2; do
>      for j in 1 2 3 4 5; do
>          : > $i$j.expected
> @@ -1223,9 +1228,6 @@ sleep 1
>  # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
>  # more) list the VIFs on which the packet should be received.  INPORT and
> the
>  # OUTPORTs are specified as logical switch port numbers, e.g. 1 for vif1.
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>  for i in 1 2 3; do
>      : > $i.expected
>  done
> @@ -1384,9 +1386,6 @@ sleep 1
>  # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
>  # more) list the VIFs on which the packet should be received.  INPORT and
> the
>  # OUTPORTs are specified as lport numbers, e.g. 1 for vif1.
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>  for i in 1 2 3; do
>      : > $i.expected
>  done
> @@ -1593,9 +1592,6 @@ sleep 1
>  # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
>  # more) list the VIFs on which the packet should be received.  INPORT and
> the
>  # OUTPORTs are specified as logical switch port numbers, e.g. 123 for
> vif123.
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>  for i in 1 2 3; do
>      for j in 1 2 3; do
>          for k in 1 2 3; do
> @@ -1951,10 +1947,6 @@ vif_to_hv() {
>      echo hv${1%?}
>  }
>
> -
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>  for i in 1 2 3; do
>      for j in 1 2 3; do
>          : > $i$j.expected
> @@ -2372,9 +2364,6 @@ sleep 1
>  ip_to_hex() {
>      printf "%02x%02x%02x%02x" "$@"
>  }
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>
>  # Packet to send.
>  src_mac="f00000010203"
> @@ -2474,9 +2463,6 @@ sleep 1
>  ip_to_hex() {
>      printf "%02x%02x%02x%02x" "$@"
>  }
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>
>  # Packet to send.
>  src_mac="f00000010203"
> @@ -2610,9 +2596,6 @@ sleep 1
>  ip_to_hex() {
>      printf "%02x%02x%02x%02x" "$@"
>  }
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>
>  # Packet to send.
>  src_mac="f00000010203"
> @@ -2768,9 +2751,6 @@ sleep 1
>  ip_to_hex() {
>      printf "%02x%02x%02x%02x" "$@"
>  }
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>
>  # Send ip packets between foo1 and alice1
>  src_mac="f00000010203"
> @@ -2865,9 +2845,6 @@ AT_CHECK([ovs-vsctl add-port br-int localvif1 -- set
> Interface localvif1 externa
>
>  # Wait for packet to be received.
>  OVS_WAIT_UNTIL([test `wc -c < "hv/snoopvif-tx.pcap"` -ge 50])
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>  $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv/snoopvif-tx.pcap |
> trim_zeros > packets
>
>  expected="fffffffffffff0000000000108060001080006040001f00000000001c0a80102000000000000c0a80102"
>  echo $expected > expout
> @@ -2996,9 +2973,6 @@ sleep 1
>  ip_to_hex() {
>      printf "%02x%02x%02x%02x" "$@"
>  }
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>
>  # Send ip packets between foo1 and alice1
>  src_mac="f00000010203"
> @@ -3138,10 +3112,6 @@ sleep 2
>
>  as hv1 ovs-vsctl show
>
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
> -
>  # This shell function sends a DHCP request packet
>  # test_dhcp INPORT SRC_MAC DHCP_TYPE OFFER_IP ...
>  test_dhcp() {
> @@ -3443,9 +3413,6 @@ sleep 2
>  ip_to_hex() {
>      printf "%02x%02x%02x%02x" "$@"
>  }
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>
>  # Send ip packets between foo1 and alice1
>  src_mac="f00000010203"
> @@ -3590,9 +3557,6 @@ sleep 1
>  ip_to_hex() {
>      printf "%02x%02x%02x%02x" "$@"
>  }
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>  for i in 1 2; do
>      : > vif$i.expected
>  done
> @@ -3756,9 +3720,6 @@ sleep 1
>  vif_to_hv() {
>      echo hv1${1%?}
>  }
> -trim_zeros() {
> -    sed 's/\(00\)\{1,\}$//'
> -}
>  for i in 1 2; do
>      : > $i.expected
>  done
> --
> 2.1.3
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
Ben Pfaff July 29, 2016, 4:43 a.m. UTC | #3
On Thu, Jul 28, 2016 at 09:56:09PM -0500, Ryan Moats wrote:
> "dev" <dev-bounces@openvswitch.org> wrote on 07/27/2016 02:03:21 AM:
> 
> > From: Ben Pfaff <blp@ovn.org>
> > To: dev@openvswitch.org
> > Cc: Ben Pfaff <blp@ovn.org>
> > Date: 07/27/2016 02:03 AM
> > Subject: [ovs-dev] [PATCH 1/5] tests: Define trim_zeros in only one
> place.
> > Sent by: "dev" <dev-bounces@openvswitch.org>
> >
> > Defining trim_zeros in a common place allows us to skip defining it in
> > every test that needs it.
> >
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> > ---
> 
> cleaning up code is always a good thing and tests pass for me
> after applying it, so ...
> 
> Acked-by: Ryan Moats <rmoats@us.ibm.com>

Thanks, applied.
diff mbox

Patch

diff --git a/tests/ovn.at b/tests/ovn.at
index 86efcf5..0fe2527 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -1,3 +1,14 @@ 
+# trim_zeros()
+#
+# Removes pairs of trailing zeros from lines of text.  Useful for
+# fairly comparing Ethernet packets that might have been padded out to
+# a minimum (e.g. 64-byte) length.
+m4_divert_text([PREPARE_TESTS],
+  [trim_zeros() {
+     sed 's/\(00\)\{1,\}$//' "$@"
+   }
+])
+
 AT_BANNER([OVN components])
 
 AT_SETUP([ovn -- lexer])
@@ -737,9 +748,6 @@  vif_to_hv() {
 # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
 # more) list the VIFs on which the packet should be received.  INPORT and the
 # OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11.
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 for i in 1 2 3; do
     for j in 1 2 3; do
         : > $i$j.expected
@@ -1038,9 +1046,6 @@  vif_to_hv() {
 # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
 # more) list the VIFs on which the packet should be received.  INPORT and the
 # OUTPORTs are specified as logical switch port numbers, e.g. 11 for vif11.
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 for i in 1 2; do
     for j in 1 2 3 4 5; do
         : > $i$j.expected
@@ -1223,9 +1228,6 @@  sleep 1
 # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
 # more) list the VIFs on which the packet should be received.  INPORT and the
 # OUTPORTs are specified as logical switch port numbers, e.g. 1 for vif1.
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 for i in 1 2 3; do
     : > $i.expected
 done
@@ -1384,9 +1386,6 @@  sleep 1
 # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
 # more) list the VIFs on which the packet should be received.  INPORT and the
 # OUTPORTs are specified as lport numbers, e.g. 1 for vif1.
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 for i in 1 2 3; do
     : > $i.expected
 done
@@ -1593,9 +1592,6 @@  sleep 1
 # digits) and Ethernet type ETHTYPE (4 hex digits).  The OUTPORTs (zero or
 # more) list the VIFs on which the packet should be received.  INPORT and the
 # OUTPORTs are specified as logical switch port numbers, e.g. 123 for vif123.
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 for i in 1 2 3; do
     for j in 1 2 3; do
         for k in 1 2 3; do
@@ -1951,10 +1947,6 @@  vif_to_hv() {
     echo hv${1%?}
 }
 
-
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 for i in 1 2 3; do
     for j in 1 2 3; do
         : > $i$j.expected
@@ -2372,9 +2364,6 @@  sleep 1
 ip_to_hex() {
     printf "%02x%02x%02x%02x" "$@"
 }
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 
 # Packet to send.
 src_mac="f00000010203"
@@ -2474,9 +2463,6 @@  sleep 1
 ip_to_hex() {
     printf "%02x%02x%02x%02x" "$@"
 }
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 
 # Packet to send.
 src_mac="f00000010203"
@@ -2610,9 +2596,6 @@  sleep 1
 ip_to_hex() {
     printf "%02x%02x%02x%02x" "$@"
 }
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 
 # Packet to send.
 src_mac="f00000010203"
@@ -2768,9 +2751,6 @@  sleep 1
 ip_to_hex() {
     printf "%02x%02x%02x%02x" "$@"
 }
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 
 # Send ip packets between foo1 and alice1
 src_mac="f00000010203"
@@ -2865,9 +2845,6 @@  AT_CHECK([ovs-vsctl add-port br-int localvif1 -- set Interface localvif1 externa
 
 # Wait for packet to be received.
 OVS_WAIT_UNTIL([test `wc -c < "hv/snoopvif-tx.pcap"` -ge 50])
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv/snoopvif-tx.pcap | trim_zeros > packets
 expected="fffffffffffff0000000000108060001080006040001f00000000001c0a80102000000000000c0a80102"
 echo $expected > expout
@@ -2996,9 +2973,6 @@  sleep 1
 ip_to_hex() {
     printf "%02x%02x%02x%02x" "$@"
 }
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 
 # Send ip packets between foo1 and alice1
 src_mac="f00000010203"
@@ -3138,10 +3112,6 @@  sleep 2
 
 as hv1 ovs-vsctl show
 
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
-
 # This shell function sends a DHCP request packet
 # test_dhcp INPORT SRC_MAC DHCP_TYPE OFFER_IP ...
 test_dhcp() {
@@ -3443,9 +3413,6 @@  sleep 2
 ip_to_hex() {
     printf "%02x%02x%02x%02x" "$@"
 }
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 
 # Send ip packets between foo1 and alice1
 src_mac="f00000010203"
@@ -3590,9 +3557,6 @@  sleep 1
 ip_to_hex() {
     printf "%02x%02x%02x%02x" "$@"
 }
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 for i in 1 2; do
     : > vif$i.expected
 done
@@ -3756,9 +3720,6 @@  sleep 1
 vif_to_hv() {
     echo hv1${1%?}
 }
-trim_zeros() {
-    sed 's/\(00\)\{1,\}$//'
-}
 for i in 1 2; do
     : > $i.expected
 done