[v3,3/3] app/test: add test for rte_ffs32 and rte_ffs64 functions.
Checks
Commit Message
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(+)
@@ -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),