From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 55A46A04F3; Fri, 20 Dec 2019 05:46:53 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AC6C11BF9D; Fri, 20 Dec 2019 05:46:13 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id AAADD1BF73 for ; Fri, 20 Dec 2019 05:45:58 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 386EC11FB; Thu, 19 Dec 2019 20:45:57 -0800 (PST) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.14.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2D4093F718; Thu, 19 Dec 2019 20:45:57 -0800 (PST) From: Honnappa Nagarahalli To: olivier.matz@6wind.com, sthemmin@microsoft.com, jerinj@marvell.com, bruce.richardson@intel.com, david.marchand@redhat.com, pbhagavatula@marvell.com, konstantin.ananyev@intel.com, honnappa.nagarahalli@arm.com Cc: dev@dpdk.org, dharmik.thakkar@arm.com, ruifeng.wang@arm.com, gavin.hu@arm.com, nd@arm.com Date: Thu, 19 Dec 2019 22:45:13 -0600 Message-Id: <20191220044524.32910-7-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191220044524.32910-1-honnappa.nagarahalli@arm.com> References: <20190906190510.11146-1-honnappa.nagarahalli@arm.com> <20191220044524.32910-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v7 06/17] test/ring: rte_ring_xxx_elem test cases for exact size ring X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Test cases for the exact size ring are changed to test rte_ring_xxx_elem APIs. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Gavin Hu --- app/test/test_ring.c | 147 ++++++++++++++++++++++++++----------------- 1 file changed, 89 insertions(+), 58 deletions(-) diff --git a/app/test/test_ring.c b/app/test/test_ring.c index 1025097c8..294e3ee10 100644 --- a/app/test/test_ring.c +++ b/app/test/test_ring.c @@ -727,75 +727,106 @@ test_ring_basic_ex(void) return -1; } +/* + * Basic test cases with exact size ring. + */ static int test_ring_with_exact_size(void) { - struct rte_ring *std_ring = NULL, *exact_sz_ring = NULL; - void *ptr_array[16]; - static const unsigned int ring_sz = RTE_DIM(ptr_array); - unsigned int i; + struct rte_ring *std_r = NULL, *exact_sz_r = NULL; + void *obj; + const unsigned int ring_sz = 16; + unsigned int i, j; int ret = -1; - std_ring = rte_ring_create("std", ring_sz, rte_socket_id(), - RING_F_SP_ENQ | RING_F_SC_DEQ); - if (std_ring == NULL) { - printf("%s: error, can't create std ring\n", __func__); - goto end; - } - exact_sz_ring = rte_ring_create("exact sz", ring_sz, rte_socket_id(), - RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ); - if (exact_sz_ring == NULL) { - printf("%s: error, can't create exact size ring\n", __func__); - goto end; - } - - /* - * Check that the exact size ring is bigger than the standard ring - */ - if (rte_ring_get_size(std_ring) >= rte_ring_get_size(exact_sz_ring)) { - printf("%s: error, std ring (size: %u) is not smaller than exact size one (size %u)\n", - __func__, - rte_ring_get_size(std_ring), - rte_ring_get_size(exact_sz_ring)); - goto end; - } - /* - * check that the exact_sz_ring can hold one more element than the - * standard ring. (16 vs 15 elements) - */ - for (i = 0; i < ring_sz - 1; i++) { - rte_ring_enqueue(std_ring, NULL); - rte_ring_enqueue(exact_sz_ring, NULL); - } - if (rte_ring_enqueue(std_ring, NULL) != -ENOBUFS) { - printf("%s: error, unexpected successful enqueue\n", __func__); - goto end; - } - if (rte_ring_enqueue(exact_sz_ring, NULL) == -ENOBUFS) { - printf("%s: error, enqueue failed\n", __func__); - goto end; - } + for (i = 0; i < RTE_DIM(esize); i++) { + test_ring_print_test_string("Test exact size ring", + TEST_RING_IGNORE_API_TYPE, + esize[i]); + + /* alloc object pointers */ + obj = test_ring_calloc(16, esize[i]); + if (obj == NULL) + goto test_fail; + + TEST_RING_CREATE("std", esize[i], ring_sz, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ, std_r); + if (std_r == NULL) { + printf("%s: error, can't create std ring\n", __func__); + goto test_fail; + } + TEST_RING_CREATE("exact sz", esize[i], ring_sz, rte_socket_id(), + RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ, + exact_sz_r); + if (exact_sz_r == NULL) { + printf("%s: error, can't create exact size ring\n", + __func__); + goto test_fail; + } - /* check that dequeue returns the expected number of elements */ - if (rte_ring_dequeue_burst(exact_sz_ring, ptr_array, - RTE_DIM(ptr_array), NULL) != ring_sz) { - printf("%s: error, failed to dequeue expected nb of elements\n", + /* + * Check that the exact size ring is bigger than the + * standard ring + */ + if (rte_ring_get_size(std_r) >= rte_ring_get_size(exact_sz_r)) { + printf("%s: error, std ring (size: %u) is not smaller than exact size one (size %u)\n", + __func__, + rte_ring_get_size(std_r), + rte_ring_get_size(exact_sz_r)); + goto test_fail; + } + /* + * check that the exact_sz_ring can hold one more element + * than the standard ring. (16 vs 15 elements) + */ + for (j = 0; j < ring_sz - 1; j++) { + TEST_RING_ENQUEUE(std_r, obj, esize[i], 1, ret, + TEST_RING_N | TEST_RING_SL); + TEST_RING_ENQUEUE(exact_sz_r, obj, esize[i], 1, + ret, TEST_RING_N | TEST_RING_SL); + } + TEST_RING_ENQUEUE(std_r, obj, esize[i], 1, ret, + TEST_RING_N | TEST_RING_SL); + if (ret != -ENOBUFS) { + printf("%s: error, unexpected successful enqueue\n", __func__); - goto end; - } + goto test_fail; + } + TEST_RING_ENQUEUE(exact_sz_r, obj, esize[i], 1, ret, + TEST_RING_N | TEST_RING_SL); + if (ret == -ENOBUFS) { + printf("%s: error, enqueue failed\n", __func__); + goto test_fail; + } - /* check that the capacity function returns expected value */ - if (rte_ring_get_capacity(exact_sz_ring) != ring_sz) { - printf("%s: error, incorrect ring capacity reported\n", + /* check that dequeue returns the expected number of elements */ + TEST_RING_DEQUEUE(exact_sz_r, obj, esize[i], ring_sz, + ret, TEST_RING_N | TEST_RING_BR); + if (ret != (int)ring_sz) { + printf("%s: error, failed to dequeue expected nb of elements\n", __func__); - goto end; + goto test_fail; + } + + /* check that the capacity function returns expected value */ + if (rte_ring_get_capacity(exact_sz_r) != ring_sz) { + printf("%s: error, incorrect ring capacity reported\n", + __func__); + goto test_fail; + } + + rte_free(obj); + rte_ring_free(std_r); + rte_ring_free(exact_sz_r); } - ret = 0; /* all ok if we get here */ -end: - rte_ring_free(std_ring); - rte_ring_free(exact_sz_ring); - return ret; + return 0; + +test_fail: + rte_free(obj); + rte_ring_free(std_r); + rte_ring_free(exact_sz_r); + return -1; } static int -- 2.17.1