diff mbox series

[v7,05/17] test/ring: add default, single element test cases

Message ID 20191220044524.32910-6-honnappa.nagarahalli@arm.com
State New
Headers show
Series lib/ring: APIs to support custom element size | expand

Commit Message

Honnappa Nagarahalli Dec. 20, 2019, 4:45 a.m. UTC
Add default, single element test cases for rte_ring_xxx_elem
APIs. The burst APIs are kept as is since they are being tested
with a ring created with SP/SC flags. They are further enhanced
with bulk APIs.

Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>

Reviewed-by: Gavin Hu <gavin.hu@arm.com>

---
 app/test/test_ring.c | 129 +++++++++++++++++++++++++++----------------
 1 file changed, 81 insertions(+), 48 deletions(-)

-- 
2.17.1
diff mbox series

Patch

diff --git a/app/test/test_ring.c b/app/test/test_ring.c
index d4f40ad20..1025097c8 100644
--- a/app/test/test_ring.c
+++ b/app/test/test_ring.c
@@ -620,78 +620,111 @@  test_lookup_null(void)
 }
 
 /*
- * it tests some more basic ring operations
+ * Test default, single element, bulk and burst APIs
  */
 static int
 test_ring_basic_ex(void)
 {
 	int ret = -1;
-	unsigned i;
+	unsigned int i, j;
 	struct rte_ring *rp = NULL;
-	void **obj = NULL;
+	void *obj = NULL;
 
-	obj = rte_calloc("test_ring_basic_ex_malloc", RING_SIZE, sizeof(void *), 0);
-	if (obj == NULL) {
-		printf("test_ring_basic_ex fail to rte_malloc\n");
-		goto fail_test;
-	}
+	for (i = 0; i < RTE_DIM(esize); i++) {
+		obj = test_ring_calloc(RING_SIZE, esize[i]);
+		if (obj == NULL) {
+			printf("test_ring_basic_ex fail to rte_malloc\n");
+			goto fail_test;
+		}
 
-	rp = rte_ring_create("test_ring_basic_ex", RING_SIZE, SOCKET_ID_ANY,
-			RING_F_SP_ENQ | RING_F_SC_DEQ);
-	if (rp == NULL) {
-		printf("test_ring_basic_ex fail to create ring\n");
-		goto fail_test;
-	}
+		TEST_RING_CREATE("test_ring_basic_ex", esize[i], RING_SIZE,
+					SOCKET_ID_ANY,
+					RING_F_SP_ENQ | RING_F_SC_DEQ, rp);
+		if (rp == NULL) {
+			printf("test_ring_basic_ex fail to create ring\n");
+			goto fail_test;
+		}
 
-	if (rte_ring_lookup("test_ring_basic_ex") != rp) {
-		goto fail_test;
-	}
+		if (rte_ring_lookup("test_ring_basic_ex") != rp) {
+			printf("test_ring_basic_ex ring is not found\n");
+			goto fail_test;
+		}
 
-	if (rte_ring_empty(rp) != 1) {
-		printf("test_ring_basic_ex ring is not empty but it should be\n");
-		goto fail_test;
-	}
+		if (rte_ring_empty(rp) != 1) {
+			printf("test_ring_basic_ex ring is not empty but it should be\n");
+			goto fail_test;
+		}
 
-	printf("%u ring entries are now free\n", rte_ring_free_count(rp));
+		printf("%u ring entries are now free\n",
+			rte_ring_free_count(rp));
 
-	for (i = 0; i < RING_SIZE; i ++) {
-		rte_ring_enqueue(rp, obj[i]);
-	}
+		for (j = 0; j < RING_SIZE; j++) {
+			TEST_RING_ENQUEUE(rp, obj, esize[i], 1, ret,
+						TEST_RING_N | TEST_RING_SL);
+		}
 
-	if (rte_ring_full(rp) != 1) {
-		printf("test_ring_basic_ex ring is not full but it should be\n");
-		goto fail_test;
-	}
+		if (rte_ring_full(rp) != 1) {
+			printf("test_ring_basic_ex ring is not full but it should be\n");
+			goto fail_test;
+		}
 
-	for (i = 0; i < RING_SIZE; i ++) {
-		rte_ring_dequeue(rp, &obj[i]);
-	}
+		for (j = 0; j < RING_SIZE; j++) {
+			TEST_RING_DEQUEUE(rp, obj, esize[i], 1, ret,
+						TEST_RING_N | TEST_RING_SL);
+		}
 
-	if (rte_ring_empty(rp) != 1) {
-		printf("test_ring_basic_ex ring is not empty but it should be\n");
-		goto fail_test;
-	}
+		if (rte_ring_empty(rp) != 1) {
+			printf("test_ring_basic_ex ring is not empty but it should be\n");
+			goto fail_test;
+		}
 
-	/* Covering the ring burst operation */
-	ret = rte_ring_enqueue_burst(rp, obj, 2, NULL);
-	if (ret != 2) {
-		printf("test_ring_basic_ex: rte_ring_enqueue_burst fails \n");
-		goto fail_test;
-	}
+		/* Following tests use the configured flags to decide
+		 * SP/SC or MP/MC.
+		 */
+		/* Covering the ring burst operation */
+		TEST_RING_ENQUEUE(rp, obj, esize[i], 2, ret,
+					TEST_RING_N | TEST_RING_BR);
+		if (ret != 2) {
+			printf("test_ring_basic_ex: rte_ring_enqueue_burst fails\n");
+			goto fail_test;
+		}
+
+		TEST_RING_DEQUEUE(rp, obj, esize[i], 2, ret,
+					TEST_RING_N | TEST_RING_BR);
+		if (ret != 2) {
+			printf("test_ring_basic_ex: rte_ring_dequeue_burst fails\n");
+			goto fail_test;
+		}
+
+		/* Covering the ring bulk operation */
+		TEST_RING_ENQUEUE(rp, obj, esize[i], 2, ret,
+					TEST_RING_N | TEST_RING_BL);
+		if (ret != 2) {
+			printf("test_ring_basic_ex: rte_ring_enqueue_bulk fails\n");
+			goto fail_test;
+		}
+
+		TEST_RING_DEQUEUE(rp, obj, esize[i], 2, ret,
+					TEST_RING_N | TEST_RING_BL);
+		if (ret != 2) {
+			printf("test_ring_basic_ex: rte_ring_dequeue_bulk fails\n");
+			goto fail_test;
+		}
 
-	ret = rte_ring_dequeue_burst(rp, obj, 2, NULL);
-	if (ret != 2) {
-		printf("test_ring_basic_ex: rte_ring_dequeue_burst fails \n");
-		goto fail_test;
+		rte_ring_free(rp);
+		rte_free(obj);
+		rp = NULL;
+		obj = NULL;
 	}
 
-	ret = 0;
+	return 0;
+
 fail_test:
 	rte_ring_free(rp);
 	if (obj != NULL)
 		rte_free(obj);
 
-	return ret;
+	return -1;
 }
 
 static int