[dpdk-dev] [PATCH 1/2] test/bitmap: add additional tests

Chas Williams 3chas3 at gmail.com
Fri Feb 9 21:20:02 CET 2018


From: "Charles (Chas) Williams" <chas3 at att.com>

Add addtional units tests for the rte_bitmap_scan() routine.  Test that
we are gettting the bits returned that we expect.

Signed-off-by: Chas Williams <chas3 at att.com>
---
 test/test/test_bitmap.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/test/test/test_bitmap.c b/test/test/test_bitmap.c
index 05d547e..f498c02 100644
--- a/test/test/test_bitmap.c
+++ b/test/test/test_bitmap.c
@@ -74,6 +74,71 @@ test_bitmap_scan_operations(struct rte_bitmap *bmp)
 }
 
 static int
+test_bitmap_scan_operations2(struct rte_bitmap *bmp)
+{
+	uint32_t pos = 0;
+	uint64_t out_slab = 0;
+	uint32_t pattern[] = { 10, 11, 100, 101, 500, 501 };
+	uint32_t pattern2[] = { 11, 101, 501 };
+	uint32_t i;
+
+	rte_bitmap_reset(bmp);
+
+	/* Setup the initial bitmap. */
+	for (i = 0; i < sizeof(pattern)/sizeof(uint32_t); i++)
+		rte_bitmap_set(bmp, pattern[i]);
+
+	/* Iterate. */
+	for (i = 0; i < sizeof(pattern)/sizeof(uint32_t); i++) {
+		if (!rte_bitmap_scan(bmp, &pos, &out_slab) ||
+		    pos != pattern[i]) {
+			printf("Failed to get pos %d from bitmap.\n",
+			       pattern[i]);
+			return TEST_FAILED;
+		}
+	}
+
+	/* Check wrap around. */
+	if (!rte_bitmap_scan(bmp, &pos, &out_slab) || pos != pattern[0]) {
+		printf("Failed to get pos %d from bitmap.\n", pattern[0]);
+		return TEST_FAILED;
+	}
+
+	/* Delete half the entries in the slabs. */
+	rte_bitmap_clear(bmp, 10);
+	rte_bitmap_clear(bmp, 100);
+	rte_bitmap_clear(bmp, 500);
+
+	/* Iterate. */
+	for (i = 0; i < sizeof(pattern2)/sizeof(uint32_t); i++) {
+		if (!rte_bitmap_scan(bmp, &pos, &out_slab) ||
+		    pos != pattern2[i]) {
+			printf("Failed to get pos %d from bitmap.\n",
+			       pattern2[i]);
+			return TEST_FAILED;
+		}
+	}
+
+	/* Check wrap around. */
+	if (!rte_bitmap_scan(bmp, &pos, &out_slab) || pos != pattern2[0]) {
+		printf("Failed to get pos %d from bitmap.\n", pattern2[0]);
+		return TEST_FAILED;
+	}
+
+	rte_bitmap_clear(bmp, 11);
+	rte_bitmap_clear(bmp, 101);
+	rte_bitmap_clear(bmp, 501);
+
+	/* Ensure bitmap it empty. */
+	if (rte_bitmap_scan(bmp, &pos, &out_slab)) {
+		printf("Found pos %d in empty bitmap.\n", pos);
+		return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+static int
 test_bitmap_slab_set_get(struct rte_bitmap *bmp)
 {
 	uint32_t pos = 0;
@@ -158,6 +223,9 @@ test_bitmap(void)
 	if (test_bitmap_scan_operations(bmp) < 0)
 		return TEST_FAILED;
 
+	if (test_bitmap_scan_operations2(bmp) < 0)
+		return TEST_FAILED;
+
 	return TEST_SUCCESS;
 }
 
-- 
2.9.5



More information about the dev mailing list