diff mbox series

[ovs-dev,3/3] tests: check arguments count of OVS_WAIT_UNTIL

Message ID 20230420161455.134493-3-xsimonar@redhat.com
State Accepted
Headers show
Series [ovs-dev,1/3] tests: Fixed "1 LR with HA distributed router gateway port" | expand

Checks

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

Commit Message

Xavier Simonart April 20, 2023, 4:14 p.m. UTC
The macro has been used erroneously with the expectation
to take the third parameter as the expected output.
Fail if more than 2 arguments are used.
Also fail if the second argument is an integer (second arg expected to
be a command to execute in case of failure).
Same checks are used in ovs.

Signed-off-by: Xavier Simonart <xsimonar@redhat.com>
---
 tests/ovs-macros.at | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Ales Musil April 21, 2023, 7:58 a.m. UTC | #1
On Thu, Apr 20, 2023 at 6:15 PM Xavier Simonart <xsimonar@redhat.com> wrote:

> The macro has been used erroneously with the expectation
> to take the third parameter as the expected output.
> Fail if more than 2 arguments are used.
> Also fail if the second argument is an integer (second arg expected to
> be a command to execute in case of failure).
> Same checks are used in ovs.
>
> Signed-off-by: Xavier Simonart <xsimonar@redhat.com>
> ---
>  tests/ovs-macros.at | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at
> index 36b58b5ae..cc5f6e3b1 100644
> --- a/tests/ovs-macros.at
> +++ b/tests/ovs-macros.at
> @@ -256,6 +256,13 @@ ovs_wait () {
>      ovs_wait_failed
>      AT_FAIL_IF([:])
>  }
> +
> +check_ovs_wait_until_args() {
> +   AT_FAIL_IF([test $1 -ge 3])
> +   dnl The second argument should not be a number (confused with AT_CHECK
> ?).
> +   AT_FAIL_IF([test $1 -eq 2 && test "$2" -eq "$2" 2>/dev/null])
> +}
> +
>  OVS_END_SHELL_HELPERS
>  m4_define([OVS_WAIT], [dnl
>  ovs_wait_cond () {
> @@ -276,7 +283,8 @@ dnl zero code within reasonable time limit, then
>  dnl the test fails.  In that case, runs IF-FAILED
>  dnl before aborting.
>  m4_define([OVS_WAIT_UNTIL],
> -  [OVS_WAIT([$1], [$2], [AT_LINE], [until $1])])
> +  [check_ovs_wait_until_args "$#" "$2"
> +   OVS_WAIT([$1], [$2], [AT_LINE], [until $1])])
>
>  dnl OVS_WAIT_FOR_OUTPUT(COMMAND, EXIT-STATUS, STDOUT, STDERR)
>  dnl OVS_WAIT_FOR_OUTPUT_UNQUOTED(COMMAND, EXIT-STATUS, STDOUT, STDERR)
> --
> 2.31.1
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
>
Looks good to me, thanks.

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

Patch

diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at
index 36b58b5ae..cc5f6e3b1 100644
--- a/tests/ovs-macros.at
+++ b/tests/ovs-macros.at
@@ -256,6 +256,13 @@  ovs_wait () {
     ovs_wait_failed
     AT_FAIL_IF([:])
 }
+
+check_ovs_wait_until_args() {
+   AT_FAIL_IF([test $1 -ge 3])
+   dnl The second argument should not be a number (confused with AT_CHECK ?).
+   AT_FAIL_IF([test $1 -eq 2 && test "$2" -eq "$2" 2>/dev/null])
+}
+
 OVS_END_SHELL_HELPERS
 m4_define([OVS_WAIT], [dnl
 ovs_wait_cond () {
@@ -276,7 +283,8 @@  dnl zero code within reasonable time limit, then
 dnl the test fails.  In that case, runs IF-FAILED
 dnl before aborting.
 m4_define([OVS_WAIT_UNTIL],
-  [OVS_WAIT([$1], [$2], [AT_LINE], [until $1])])
+  [check_ovs_wait_until_args "$#" "$2"
+   OVS_WAIT([$1], [$2], [AT_LINE], [until $1])])
 
 dnl OVS_WAIT_FOR_OUTPUT(COMMAND, EXIT-STATUS, STDOUT, STDERR)
 dnl OVS_WAIT_FOR_OUTPUT_UNQUOTED(COMMAND, EXIT-STATUS, STDOUT, STDERR)