All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH 1/4] test: update alarm test
Date: Thu, 18 Jul 2024 12:07:12 -0700	[thread overview]
Message-ID: <20240718191049.84865-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20240718191049.84865-1-stephen@networkplumber.org>

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");
 
-#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);
-- 
2.43.0


  reply	other threads:[~2024-07-18 19:11 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-18 19:07 [PATCH 0/4] Enable more unit tests Stephen Hemminger
2024-07-18 19:07 ` Stephen Hemminger [this message]
2024-07-19 10:17   ` [PATCH 1/4] test: update alarm test Bruce Richardson
2024-07-19 17:09     ` Stephen Hemminger
2024-08-06 12:45   ` David Marchand
2024-08-07 22:24     ` Stephen Hemminger
2024-08-08 18:52     ` Stephen Hemminger
2024-07-18 19:07 ` [PATCH 2/4] test: run cksum tests as part of perf test suite Stephen Hemminger
2024-07-19  8:45   ` Bruce Richardson
2024-07-18 19:07 ` [PATCH 3/4] test: make red test part of fast suite Stephen Hemminger
2024-07-19  9:14   ` Bruce Richardson
2024-08-06 12:28   ` David Marchand
2024-08-06 12:49     ` Bruce Richardson
2024-08-08 16:12     ` Stephen Hemminger
2024-10-04 12:17       ` David Marchand
2025-12-02 17:20         ` David Marchand
2024-07-18 19:07 ` [PATCH 4/4] test: run timer secondary tests as " Stephen Hemminger
2024-07-19  9:27   ` Bruce Richardson
2024-10-04 12:20   ` David Marchand
2024-10-04 12:51 ` [PATCH 0/4] Enable more unit tests David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240718191049.84865-2-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=roretzla@linux.microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.