[v3,3/3] app/test: add test for rte_ffs32 and rte_ffs64 functions.

Message ID 1737735244-23234-4-git-send-email-andremue@linux.microsoft.com (mailing list archive)
State Accepted
Delegated to: David Marchand
Headers
Series provide rte_ffs32, rte_ffs64 and __rte_x86_movdiri for MSVC |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation warning apply issues

Commit Message

Andre Muezerie Jan. 24, 2025, 4:14 p.m. UTC
Add tests for new rte_ffs32 and rte_ffs64 functions.

Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
 app/test/test_bitcount.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
  

Patch

diff --git a/app/test/test_bitcount.c b/app/test/test_bitcount.c
index 83c68feb7b..8eb4a460f2 100644
--- a/app/test/test_bitcount.c
+++ b/app/test/test_bitcount.c
@@ -12,6 +12,42 @@ 
 
 RTE_LOG_REGISTER(bitcount_logtype_test, test.bitcount, INFO);
 
+static int
+test_bit_scan_forward(void)
+{
+	unsigned int bit_nr;
+
+	TEST_ASSERT((bit_nr = rte_ffs32(0)) == 0,
+		"rte_ffs32 returned unexpected %d", bit_nr);
+
+	for (int i = 0; i < 32; ++i) {
+		uint32_t n = RTE_BIT32(i);
+
+		TEST_ASSERT((bit_nr = rte_ffs32(n)) == (unsigned int)(i+1),
+			"rte_ffs32 returned unexpected %d", bit_nr);
+	}
+
+	return TEST_SUCCESS;
+}
+
+static int
+test_bit_scan_forward64(void)
+{
+	unsigned int bit_nr;
+
+	TEST_ASSERT((bit_nr = rte_ffs64(0)) == 0,
+		"rte_ffs64 returned unexpected %d", bit_nr);
+
+	for (int i = 0; i < 64; ++i) {
+		uint64_t n = RTE_BIT64(i);
+
+		TEST_ASSERT((bit_nr = rte_ffs64(n)) == (unsigned int)(i+1),
+			"rte_ffs64 returned unexpected %d", bit_nr);
+	}
+
+	return TEST_SUCCESS;
+}
+
 static int
 test_clz32(void)
 {
@@ -117,6 +153,8 @@  static struct unit_test_suite bitcount_test_suite = {
 	.setup = NULL,
 	.teardown = NULL,
 	.unit_test_cases = {
+		TEST_CASE(test_bit_scan_forward),
+		TEST_CASE(test_bit_scan_forward64),
 		TEST_CASE(test_clz32),
 		TEST_CASE(test_clz64),
 		TEST_CASE(test_ctz32),