This patch implements support for testing bitmap reverse scan.
Bits in bitmap are changed to be an exact multiple of slab size.

Signed-off-by: Vivek Sharma <vivek.sha...@caviumnetworks.com>
---
Prerequisite:
* Note that this patchset is dependent on patch:
  'http://patches.dpdk.org/patch/45307/'

 test/test/test_bitmap.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 70 insertions(+), 1 deletion(-)

diff --git a/test/test/test_bitmap.c b/test/test/test_bitmap.c
index 95c5184..21a193b 100644
--- a/test/test/test_bitmap.c
+++ b/test/test/test_bitmap.c
@@ -11,7 +11,7 @@
 
 #include "test.h"
 
-#define MAX_BITS 1000
+#define MAX_BITS 1024
 
 static int
 test_bitmap_scan_operations(struct rte_bitmap *bmp)
@@ -74,6 +74,72 @@ test_bitmap_scan_operations(struct rte_bitmap *bmp)
 }
 
 static int
+test_bitmap_scan_reverse_operations(struct rte_bitmap *bmp)
+{
+       uint32_t pos = 0;
+       uint64_t slab1_magic = 0xBADC0FFEEBADF00D;
+       uint64_t slab2_magic = 0xFEEDDEADDEADF00D;
+       uint64_t out_slab = 0;
+
+       rte_bitmap_reset(bmp);
+
+       rte_bitmap_set_slab(bmp, MAX_BITS - RTE_BITMAP_SLAB_BIT_SIZE,
+                           slab2_magic);
+       rte_bitmap_set_slab(bmp, MAX_BITS - (2 * RTE_BITMAP_SLAB_BIT_SIZE),
+                           slab1_magic);
+
+       if (!rte_bitmap_scan_generic(bmp, &pos, &out_slab,
+                                    RTE_BITMAP_REV_SCAN)) {
+               printf("Failed to get slab from bitmap.\n");
+               return TEST_FAILED;
+       }
+
+       if (slab2_magic != out_slab) {
+               printf("Scan operation sanity failed.\n");
+               return TEST_FAILED;
+       }
+
+       if (!rte_bitmap_scan_generic(bmp, &pos, &out_slab,
+                                    RTE_BITMAP_REV_SCAN)) {
+               printf("Failed to get slab from bitmap.\n");
+               return TEST_FAILED;
+       }
+
+       if (slab1_magic != out_slab) {
+               printf("Scan operation sanity failed.\n");
+               return TEST_FAILED;
+       }
+
+       /* Wrap around */
+       if (!rte_bitmap_scan_generic(bmp, &pos, &out_slab,
+                                    RTE_BITMAP_REV_SCAN)) {
+               printf("Failed to get slab from bitmap.\n");
+               return TEST_FAILED;
+       }
+
+       if (slab2_magic != out_slab) {
+               printf("Scan operation wrap around failed.\n");
+               return TEST_FAILED;
+       }
+
+       /* Scan reset check. */
+       __rte_bitmap_scan_init_generic(bmp, RTE_BITMAP_REV_SCAN);
+
+       if (!rte_bitmap_scan_generic(bmp, &pos, &out_slab,
+                                    RTE_BITMAP_REV_SCAN)) {
+               printf("Failed to get slab from bitmap.\n");
+               return TEST_FAILED;
+       }
+
+       if (slab2_magic != out_slab) {
+               printf("Scan reset operation failed.\n");
+               return TEST_FAILED;
+       }
+
+       return TEST_SUCCESS;
+}
+
+static int
 test_bitmap_slab_set_get(struct rte_bitmap *bmp)
 {
        uint32_t pos = 0;
@@ -176,6 +242,9 @@ test_bitmap(void)
        if (test_bitmap_scan_operations(bmp) < 0)
                return TEST_FAILED;
 
+       if (test_bitmap_scan_reverse_operations(bmp) < 0)
+               return TEST_FAILED;
+
        rte_bitmap_free(bmp);
        rte_free(mem);
 
-- 
2.7.4

Reply via email to