[1/4] test: update alarm test
Checks
Commit Message
This test should be using the TEST_ASSERT macros, and can be
run as part of the fast test suite now.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test/test_alarm.c | 53 ++++++++++++++++---------------------------
1 file changed, 20 insertions(+), 33 deletions(-)
Comments
On Thu, Jul 18, 2024 at 12:07:12PM -0700, Stephen Hemminger wrote:
> This test should be using the TEST_ASSERT macros, and can be
> run as part of the fast test suite now.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> app/test/test_alarm.c | 53 ++++++++++++++++---------------------------
> 1 file changed, 20 insertions(+), 33 deletions(-)
>
> diff --git a/app/test/test_alarm.c b/app/test/test_alarm.c
> index 70e97a3109..4ba8aa1af2 100644
> --- a/app/test/test_alarm.c
> +++ b/app/test/test_alarm.c
> @@ -10,7 +10,8 @@
>
> #include "test.h"
>
> -#ifndef RTE_EXEC_ENV_WINDOWS
> +#define US_PER_SEC 1000000
> +
> static volatile int flag;
>
> static void
> @@ -19,46 +20,32 @@ test_alarm_callback(void *cb_arg)
> flag = 1;
> printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg);
> }
> -#endif
>
> static int
> test_alarm(void)
> {
> -#ifdef RTE_EXEC_ENV_FREEBSD
> - printf("The alarm API is not supported on FreeBSD\n");
> - return 0;
> -#endif
> + int ret;
> +
> + ret = rte_eal_alarm_set(0, test_alarm_callback, NULL);
> + TEST_ASSERT_FAIL(ret, "should not be succeed with 0 us value");
> +
> + ret = rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback, NULL);
> + TEST_ASSERT_FAIL(ret, "should not be succeed with (UINT64_MAX-1) us value");
> +
> + ret = rte_eal_alarm_set(10, NULL, NULL);
> + TEST_ASSERT_FAIL(ret, "should not succeed with null callback parameter");
>
+1 to use of TEST_ASSERT_FAIL, the test is a lot cleaner now.
However, I think we still need the #ifdefs in it if some of it doesn't work
on Windows/BSD.
/Bruce
On Fri, 19 Jul 2024 11:17:43 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:
> On Thu, Jul 18, 2024 at 12:07:12PM -0700, Stephen Hemminger wrote:
> > This test should be using the TEST_ASSERT macros, and can be
> > run as part of the fast test suite now.
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> > app/test/test_alarm.c | 53 ++++++++++++++++---------------------------
> > 1 file changed, 20 insertions(+), 33 deletions(-)
> >
> > diff --git a/app/test/test_alarm.c b/app/test/test_alarm.c
> > index 70e97a3109..4ba8aa1af2 100644
> > --- a/app/test/test_alarm.c
> > +++ b/app/test/test_alarm.c
> > @@ -10,7 +10,8 @@
> >
> > #include "test.h"
> >
> > -#ifndef RTE_EXEC_ENV_WINDOWS
> > +#define US_PER_SEC 1000000
> > +
> > static volatile int flag;
> >
> > static void
> > @@ -19,46 +20,32 @@ test_alarm_callback(void *cb_arg)
> > flag = 1;
> > printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg);
> > }
> > -#endif
> >
> > static int
> > test_alarm(void)
> > {
> > -#ifdef RTE_EXEC_ENV_FREEBSD
> > - printf("The alarm API is not supported on FreeBSD\n");
> > - return 0;
> > -#endif
> > + int ret;
> > +
> > + ret = rte_eal_alarm_set(0, test_alarm_callback, NULL);
> > + TEST_ASSERT_FAIL(ret, "should not be succeed with 0 us value");
> > +
> > + ret = rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback, NULL);
> > + TEST_ASSERT_FAIL(ret, "should not be succeed with (UINT64_MAX-1) us value");
> > +
> > + ret = rte_eal_alarm_set(10, NULL, NULL);
> > + TEST_ASSERT_FAIL(ret, "should not succeed with null callback parameter");
> >
>
> +1 to use of TEST_ASSERT_FAIL, the test is a lot cleaner now.
> However, I think we still need the #ifdefs in it if some of it doesn't work
> on Windows/BSD.
>
> /Bruce
It looks like alarm API's exist on Windows (see lib/eal/windows/eal_alarm.c)
therefore should be tested but aren't being now.
On Thu, Jul 18, 2024 at 9:11 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> This test should be using the TEST_ASSERT macros, and can be
> run as part of the fast test suite now.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
[...]
> + ret = rte_eal_alarm_cancel(test_alarm_callback, NULL);
> + /* return is the number of the alarm set (or 0 if none or -1 if error) */
> + TEST_ASSERT(ret > 0, "could not cancel an alarm: %d", ret);
>
> return 0;
> }
>
> -REGISTER_TEST_COMMAND(alarm_autotest, test_alarm);
> +REGISTER_FAST_TEST(alarm_autotest, true, true, test_alarm);
This test was removed from the fast-tests list as it was triggering
false failures in some CI.
ee00af60170b ("test: remove strict timing requirements some tests")
On Tue, 6 Aug 2024 14:45:45 +0200
David Marchand <david.marchand@redhat.com> wrote:
> On Thu, Jul 18, 2024 at 9:11 PM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > This test should be using the TEST_ASSERT macros, and can be
> > run as part of the fast test suite now.
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>
> [...]
>
> > + ret = rte_eal_alarm_cancel(test_alarm_callback, NULL);
> > + /* return is the number of the alarm set (or 0 if none or -1 if error) */
> > + TEST_ASSERT(ret > 0, "could not cancel an alarm: %d", ret);
> >
> > return 0;
> > }
> >
> > -REGISTER_TEST_COMMAND(alarm_autotest, test_alarm);
> > +REGISTER_FAST_TEST(alarm_autotest, true, true, test_alarm);
>
> This test was removed from the fast-tests list as it was triggering
> false failures in some CI.
> ee00af60170b ("test: remove strict timing requirements some tests")
>
>
Maybe test can be fixed to use different time values.
Or like lcore tests, some yielding is needed.
On Tue, 6 Aug 2024 14:45:45 +0200
David Marchand <david.marchand@redhat.com> wrote:
> On Thu, Jul 18, 2024 at 9:11 PM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > This test should be using the TEST_ASSERT macros, and can be
> > run as part of the fast test suite now.
> >
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>
> [...]
>
> > + ret = rte_eal_alarm_cancel(test_alarm_callback, NULL);
> > + /* return is the number of the alarm set (or 0 if none or -1 if error) */
> > + TEST_ASSERT(ret > 0, "could not cancel an alarm: %d", ret);
> >
> > return 0;
> > }
> >
> > -REGISTER_TEST_COMMAND(alarm_autotest, test_alarm);
> > +REGISTER_FAST_TEST(alarm_autotest, true, true, test_alarm);
>
> This test was removed from the fast-tests list as it was triggering
> false failures in some CI.
> ee00af60170b ("test: remove strict timing requirements some tests")
I can see why that test failed (too short an alarm), but the whole test has lots
of other issues. Starting new series to address.
@@ -10,7 +10,8 @@
#include "test.h"
-#ifndef RTE_EXEC_ENV_WINDOWS
+#define US_PER_SEC 1000000
+
static volatile int flag;
static void
@@ -19,46 +20,32 @@ test_alarm_callback(void *cb_arg)
flag = 1;
printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg);
}
-#endif
static int
test_alarm(void)
{
-#ifdef RTE_EXEC_ENV_FREEBSD
- printf("The alarm API is not supported on FreeBSD\n");
- return 0;
-#endif
+ int ret;
+
+ ret = rte_eal_alarm_set(0, test_alarm_callback, NULL);
+ TEST_ASSERT_FAIL(ret, "should not be succeed with 0 us value");
+
+ ret = rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback, NULL);
+ TEST_ASSERT_FAIL(ret, "should not be succeed with (UINT64_MAX-1) us value");
+
+ ret = rte_eal_alarm_set(10, NULL, NULL);
+ TEST_ASSERT_FAIL(ret, "should not succeed with null callback parameter");
-#ifndef RTE_EXEC_ENV_WINDOWS
- /* check if it will fail to set alarm with wrong us value */
- printf("check if it will fail to set alarm with wrong ms values\n");
- if (rte_eal_alarm_set(0, test_alarm_callback,
- NULL) >= 0) {
- printf("should not be successful with 0 us value\n");
- return -1;
- }
- if (rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback,
- NULL) >= 0) {
- printf("should not be successful with (UINT64_MAX-1) us value\n");
- return -1;
- }
-#endif
+ ret = rte_eal_alarm_cancel(NULL, NULL);
+ TEST_ASSERT_FAIL(ret, "should not succeed to remove alarm with null callback parameter");
- /* check if it will fail to set alarm with null callback parameter */
- printf("check if it will fail to set alarm with null callback parameter\n");
- if (rte_eal_alarm_set(10 /* ms */, NULL, NULL) >= 0) {
- printf("should not be successful to set alarm with null callback parameter\n");
- return -1;
- }
+ ret = rte_eal_alarm_set(US_PER_SEC, test_alarm_callback, NULL);
+ TEST_ASSERT_SUCCESS(ret, "could not set an alarm");
- /* check if it will fail to remove alarm with null callback parameter */
- printf("check if it will fail to remove alarm with null callback parameter\n");
- if (rte_eal_alarm_cancel(NULL, NULL) == 0) {
- printf("should not be successful to remove alarm with null callback parameter");
- return -1;
- }
+ ret = rte_eal_alarm_cancel(test_alarm_callback, NULL);
+ /* return is the number of the alarm set (or 0 if none or -1 if error) */
+ TEST_ASSERT(ret > 0, "could not cancel an alarm: %d", ret);
return 0;
}
-REGISTER_TEST_COMMAND(alarm_autotest, test_alarm);
+REGISTER_FAST_TEST(alarm_autotest, true, true, test_alarm);