diff mbox series

[ovs-dev,v2,3/5] tests: Update macros waiting for packets.

Message ID 20241014101046.3309426-4-xsimonar@redhat.com
State Accepted
Headers show
Series Peer ports. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_ovn-kubernetes success github build: passed

Commit Message

Xavier Simonart Oct. 14, 2024, 10:10 a.m. UTC
- Add comments explaining what the macros do, highlighting the differences between them.
- Support "command" (e.g. cut) third argument for the macros were it was not yet supported.
- Cleanup.

Signed-off-by: Xavier Simonart <xsimonar@redhat.com>
---
 tests/ovn-macros.at | 82 ++++++++++++++++++++-------------------------
 1 file changed, 37 insertions(+), 45 deletions(-)

Comments

Ales Musil Nov. 7, 2024, 9:23 a.m. UTC | #1
On Mon, Oct 14, 2024 at 12:10 PM Xavier Simonart <xsimonar@redhat.com>
wrote:

> - Add comments explaining what the macros do, highlighting the differences
> between them.
> - Support "command" (e.g. cut) third argument for the macros were it was
> not yet supported.
> - Cleanup.
>
> Signed-off-by: Xavier Simonart <xsimonar@redhat.com>
> ---
>  tests/ovn-macros.at | 82 ++++++++++++++++++++-------------------------
>  1 file changed, 37 insertions(+), 45 deletions(-)
>
> diff --git a/tests/ovn-macros.at b/tests/ovn-macros.at
> index caa89ab47..35cfb2a1f 100644
> --- a/tests/ovn-macros.at
> +++ b/tests/ovn-macros.at
> @@ -23,76 +23,62 @@ m4_divert_text([PREPARE_TESTS],
>       diff -u $exp_text.sorted $rcv_text.sorted
>     }
>     ovn_check_packets__ () {
> -     if [[ -n "$4" ]]; then
> -       echo "$3: checking packets in $1 against $2: using $4"
> -     else
> -       echo "$3: checking packets in $1 against $2:"
> -     fi
>       rcv_pcap=$1
> -     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
>       exp_text=$2
> +     cmd=${4-cat}
> +     echo "$3: checking packets in $1 against $2:"
> +     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
>       exp_n=`wc -l < "$exp_text"`
>       OVS_WAIT_UNTIL(
> -       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > $rcv_text
> -        rcv_n=`wc -l < "$rcv_text"`
> +       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > rcv_tmp
> +        rcv_n=`wc -l < rcv_tmp`
>          echo "rcv_n=$rcv_n exp_n=$exp_n"
>          test $rcv_n -ge $exp_n],
>         [dump_diff__ "$rcv_pcap" "$exp_text"])
> -     if [[ -n "$4" ]]; then
> -       sort $exp_text | $4 > expout
> -       cat $rcv_text | $4 > rcv_tmp
> -       mv rcv_tmp $rcv_text
> -     else
> -       sort $exp_text > expout
> -     fi
> +     sort $exp_text | $cmd > expout
> +     cat rcv_tmp | $cmd > $rcv_text
>     }
>     ovn_check_packets_remove_broadcast__ () {
> -     echo "$3: checking packets in $1 against $2:"
>       rcv_pcap=$1
> -     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
>       exp_text=$2
> +     cmd=${4-cat}
> +     echo "$3: checking packets in $1 against $2:"
> +     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
>       exp_n=`wc -l < "$exp_text"`
>       OVS_WAIT_UNTIL(
> -       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > $rcv_text
> -        sed -i '/ffffffffffff/d' $rcv_text
> -        rcv_n=`wc -l < "$rcv_text"`
> +       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > rcv_tmp
> +        sed -i '/ffffffffffff/d' rcv_tmp
> +        rcv_n=`wc -l < rcv_tmp`
>          echo "rcv_n=$rcv_n exp_n=$exp_n"
>          test $rcv_n -ge $exp_n],
>         [dump_diff__ "$rcv_pcap" "$exp_text"])
> -     sort $exp_text > expout
> +     sort $exp_text | $cmd > expout
> +     cat rcv_tmp | $cmd > $rcv_text
>     }
>     ovn_wait_packets__ () {
> -     echo "$3: waiting for packets from $2 at $1:"
> -     if [[ -n "$4" ]]; then
> -       echo "$3: checking packets from $2 at $1: using $4"
> -     else
> -       echo "$3: checking packets from $2 at $1:"
> -     fi
>       rcv_pcap=$1
> -     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
>       exp_text=$2
> -     if [[ -n "$4" ]]; then
> -       cmd=$4
> -     else
> -       cmd=cat
> -     fi
> +     cmd=${4-cat}
> +     echo "$3: waiting packets from $2 at $1:"
> +     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
>       OVS_WAIT_UNTIL(
> -       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > $rcv_text
> +       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > rcv_tmp
>          sort $exp_text | $cmd > expout
> -        test x"$(sort $rcv_text | $cmd | comm -2 -3 expout -)" = "x"],
> +        cat rcv_tmp | $cmd > $rcv_text
> +        test x"$(sort $rcv_text | comm -2 -3 expout -)" = "x"],
>         [dump_diff__ "$rcv_pcap" "$exp_text"])
> -     cat $rcv_text | $cmd > rcv_tmp
> -     mv rcv_tmp $rcv_text
>     }
> +
>     ovn_wait_packets_uniq__ () {
> -     echo "$3: waiting for packets from $2 at $1:"
>       rcv_pcap=$1
> -     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
>       exp_text=$2
> +     cmd=${4-cat}
> +     echo "$3: waiting for packets from $2 at $1:"
> +     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
>       OVS_WAIT_UNTIL(
>         [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > $rcv_text
> -        sort $exp_text > expout
> -        test x"$(sort $rcv_text | uniq | comm -3 expout -)" = "x"],
> +        sort $exp_text | $cmd > expout
> +        test x"$(sort $rcv_text | $cmd | uniq | comm -3 expout -)" = "x"],
>         [dump_diff__ "$rcv_pcap" "$exp_text"])
>     }
>
> @@ -159,22 +145,28 @@ m4_divert_text([PREPARE_TESTS],
>     }
>  ])
>
> +# Wait to receive all packets in $2.
> +# Fails if any additional packet, or any duplicate packets is received,
>  m4_define([OVN_CHECK_PACKETS],
>    [AT_CHECK([$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $1 ], [0],
> [ignore])
>     ovn_check_packets__ "$1" "$2" "__file__:__line__" $3
>     AT_CHECK([sort $rcv_text], [0], [expout], [ignore], [dump_diff__ "$1"
> "$2"])])
>
> +# Wait to receive all packets in $2, potentially receiving extra
> broadcast packets.
> +# Fails if any (non bcast) additional packet, or any duplicate packets is
> received.
>  m4_define([OVN_CHECK_PACKETS_REMOVE_BROADCAST],
> -  [ovn_check_packets_remove_broadcast__ "$1" "$2" "__file__:__line__"
> +  [ovn_check_packets_remove_broadcast__ "$1" "$2" "__file__:__line__" "$3"
>     AT_CHECK([sort $rcv_text], [0], [expout], [ignore], [dump_diff__ "$1"
> "$2"])])
>
> +# Wait to receive all packets from $2.
> +# Any additional and duplicate packets are accepted.
>  m4_define([OVN_CHECK_PACKETS_CONTAIN],
>    [ovn_wait_packets__ "$1" "$2" "__file__:__line__" $3])
>
> -# OVN_CHECK_PACKETS_UNIQ succeeds if some expected packets are duplicated.
> -# It fails if unexpected packets are received.
> +# Wait to receive all packets from $2.
> +# Duplicate packets are accepted, but the macro fails if unexpected
> packets are received.
>  m4_define([OVN_CHECK_PACKETS_UNIQ],
> -  [ovn_wait_packets_uniq__ "$1" "$2" "__file__:__line__"])
> +  [ovn_wait_packets_uniq__ "$1" "$2" "__file__:__line__" $3])
>
>  m4_define([OVN_WAIT_PATCH_PORT_FLOWS],
>    [ovn_wait_patch_port_flows "$1" "$2" "__file__:__line__"])
> --
> 2.31.1
>
>
Looks good to me, thanks.

Acked-by: Ales Musil <amusil@redhat.com>
diff mbox series

Patch

diff --git a/tests/ovn-macros.at b/tests/ovn-macros.at
index caa89ab47..35cfb2a1f 100644
--- a/tests/ovn-macros.at
+++ b/tests/ovn-macros.at
@@ -23,76 +23,62 @@  m4_divert_text([PREPARE_TESTS],
      diff -u $exp_text.sorted $rcv_text.sorted
    }
    ovn_check_packets__ () {
-     if [[ -n "$4" ]]; then
-       echo "$3: checking packets in $1 against $2: using $4"
-     else
-       echo "$3: checking packets in $1 against $2:"
-     fi
      rcv_pcap=$1
-     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
      exp_text=$2
+     cmd=${4-cat}
+     echo "$3: checking packets in $1 against $2:"
+     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
      exp_n=`wc -l < "$exp_text"`
      OVS_WAIT_UNTIL(
-       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > $rcv_text
-        rcv_n=`wc -l < "$rcv_text"`
+       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > rcv_tmp
+        rcv_n=`wc -l < rcv_tmp`
         echo "rcv_n=$rcv_n exp_n=$exp_n"
         test $rcv_n -ge $exp_n],
        [dump_diff__ "$rcv_pcap" "$exp_text"])
-     if [[ -n "$4" ]]; then
-       sort $exp_text | $4 > expout
-       cat $rcv_text | $4 > rcv_tmp
-       mv rcv_tmp $rcv_text
-     else
-       sort $exp_text > expout
-     fi
+     sort $exp_text | $cmd > expout
+     cat rcv_tmp | $cmd > $rcv_text
    }
    ovn_check_packets_remove_broadcast__ () {
-     echo "$3: checking packets in $1 against $2:"
      rcv_pcap=$1
-     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
      exp_text=$2
+     cmd=${4-cat}
+     echo "$3: checking packets in $1 against $2:"
+     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
      exp_n=`wc -l < "$exp_text"`
      OVS_WAIT_UNTIL(
-       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > $rcv_text
-        sed -i '/ffffffffffff/d' $rcv_text
-        rcv_n=`wc -l < "$rcv_text"`
+       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > rcv_tmp
+        sed -i '/ffffffffffff/d' rcv_tmp
+        rcv_n=`wc -l < rcv_tmp`
         echo "rcv_n=$rcv_n exp_n=$exp_n"
         test $rcv_n -ge $exp_n],
        [dump_diff__ "$rcv_pcap" "$exp_text"])
-     sort $exp_text > expout
+     sort $exp_text | $cmd > expout
+     cat rcv_tmp | $cmd > $rcv_text
    }
    ovn_wait_packets__ () {
-     echo "$3: waiting for packets from $2 at $1:"
-     if [[ -n "$4" ]]; then
-       echo "$3: checking packets from $2 at $1: using $4"
-     else
-       echo "$3: checking packets from $2 at $1:"
-     fi
      rcv_pcap=$1
-     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
      exp_text=$2
-     if [[ -n "$4" ]]; then
-       cmd=$4
-     else
-       cmd=cat
-     fi
+     cmd=${4-cat}
+     echo "$3: waiting packets from $2 at $1:"
+     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
      OVS_WAIT_UNTIL(
-       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > $rcv_text
+       [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > rcv_tmp
         sort $exp_text | $cmd > expout
-        test x"$(sort $rcv_text | $cmd | comm -2 -3 expout -)" = "x"],
+        cat rcv_tmp | $cmd > $rcv_text
+        test x"$(sort $rcv_text | comm -2 -3 expout -)" = "x"],
        [dump_diff__ "$rcv_pcap" "$exp_text"])
-     cat $rcv_text | $cmd > rcv_tmp
-     mv rcv_tmp $rcv_text
    }
+
    ovn_wait_packets_uniq__ () {
-     echo "$3: waiting for packets from $2 at $1:"
      rcv_pcap=$1
-     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
      exp_text=$2
+     cmd=${4-cat}
+     echo "$3: waiting for packets from $2 at $1:"
+     rcv_text=`echo "$rcv_pcap.packets" | sed 's/\.pcap//'`
      OVS_WAIT_UNTIL(
        [$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $rcv_pcap > $rcv_text
-        sort $exp_text > expout
-        test x"$(sort $rcv_text | uniq | comm -3 expout -)" = "x"],
+        sort $exp_text | $cmd > expout
+        test x"$(sort $rcv_text | $cmd | uniq | comm -3 expout -)" = "x"],
        [dump_diff__ "$rcv_pcap" "$exp_text"])
    }
 
@@ -159,22 +145,28 @@  m4_divert_text([PREPARE_TESTS],
    }
 ])
 
+# Wait to receive all packets in $2.
+# Fails if any additional packet, or any duplicate packets is received,
 m4_define([OVN_CHECK_PACKETS],
   [AT_CHECK([$PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $1 ], [0], [ignore])
    ovn_check_packets__ "$1" "$2" "__file__:__line__" $3
    AT_CHECK([sort $rcv_text], [0], [expout], [ignore], [dump_diff__ "$1" "$2"])])
 
+# Wait to receive all packets in $2, potentially receiving extra broadcast packets.
+# Fails if any (non bcast) additional packet, or any duplicate packets is received.
 m4_define([OVN_CHECK_PACKETS_REMOVE_BROADCAST],
-  [ovn_check_packets_remove_broadcast__ "$1" "$2" "__file__:__line__"
+  [ovn_check_packets_remove_broadcast__ "$1" "$2" "__file__:__line__" "$3"
    AT_CHECK([sort $rcv_text], [0], [expout], [ignore], [dump_diff__ "$1" "$2"])])
 
+# Wait to receive all packets from $2.
+# Any additional and duplicate packets are accepted.
 m4_define([OVN_CHECK_PACKETS_CONTAIN],
   [ovn_wait_packets__ "$1" "$2" "__file__:__line__" $3])
 
-# OVN_CHECK_PACKETS_UNIQ succeeds if some expected packets are duplicated.
-# It fails if unexpected packets are received.
+# Wait to receive all packets from $2.
+# Duplicate packets are accepted, but the macro fails if unexpected packets are received.
 m4_define([OVN_CHECK_PACKETS_UNIQ],
-  [ovn_wait_packets_uniq__ "$1" "$2" "__file__:__line__"])
+  [ovn_wait_packets_uniq__ "$1" "$2" "__file__:__line__" $3])
 
 m4_define([OVN_WAIT_PATCH_PORT_FLOWS],
   [ovn_wait_patch_port_flows "$1" "$2" "__file__:__line__"])