[2/2] test/bitmap: implement reverse bitmap scan test
diff mbox series

Message ID 1539071699-29963-3-git-send-email-vivek.sharma@caviumnetworks.com
State New
Delegated to: Cristian Dumitrescu
Headers show
Series
  • eal/bitmap: support reverse bitmap scan
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Vivek Sharma Oct. 9, 2018, 7:54 a.m. UTC
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.sharma@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(-)

Patch
diff mbox series

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);