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 1CDFEA04F3; Fri, 20 Dec 2019 05:46:08 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AD9F91BF78; Fri, 20 Dec 2019 05:46:02 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 2A2AC1BF73 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 0EEAA106F; 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 E821D3F86C; Thu, 19 Dec 2019 20:45:56 -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:10 -0600 Message-Id: <20191220044524.32910-4-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 03/17] test/ring: add functional tests for rte_ring_xxx_elem APIs 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" Add basic infrastructure to test rte_ring_xxx_elem APIs. Add test cases for testing burst and bulk tests. Signed-off-by: Honnappa Nagarahalli Reviewed-by: Gavin Hu --- app/test/test_ring.c | 466 ++++++++++++++++++++----------------------- app/test/test_ring.h | 203 +++++++++++++++++++ 2 files changed, 419 insertions(+), 250 deletions(-) create mode 100644 app/test/test_ring.h diff --git a/app/test/test_ring.c b/app/test/test_ring.c index aaf1e70ad..e7a8b468b 100644 --- a/app/test/test_ring.c +++ b/app/test/test_ring.c @@ -23,11 +23,13 @@ #include #include #include +#include #include #include #include #include "test.h" +#include "test_ring.h" /* * Ring @@ -67,6 +69,50 @@ static rte_atomic32_t synchro; #define TEST_RING_FULL_EMTPY_ITER 8 +static int esize[] = {-1, 4, 8, 16}; + +static void +test_ring_mem_init(void *obj, unsigned int count, int esize) +{ + unsigned int i; + + /* Legacy queue APIs? */ + if (esize == -1) + for (i = 0; i < count; i++) + ((void **)obj)[i] = (void *)(unsigned long)i; + else + for (i = 0; i < (count * esize / sizeof(uint32_t)); i++) + ((uint32_t *)obj)[i] = i; +} + +static void +test_ring_print_test_string(const char *istr, unsigned int api_type, int esize) +{ + printf("\n%s: ", istr); + + if (esize == -1) + printf("legacy APIs: "); + else + printf("elem APIs: element size %dB ", esize); + + if (api_type == TEST_RING_IGNORE_API_TYPE) + return; + + if ((api_type & TEST_RING_N) == TEST_RING_N) + printf(": default enqueue/dequeue: "); + else if ((api_type & TEST_RING_S) == TEST_RING_S) + printf(": SP/SC: "); + else if ((api_type & TEST_RING_M) == TEST_RING_M) + printf(": MP/MC: "); + + if ((api_type & TEST_RING_SL) == TEST_RING_SL) + printf("single\n"); + else if ((api_type & TEST_RING_BL) == TEST_RING_BL) + printf("bulk\n"); + else if ((api_type & TEST_RING_BR) == TEST_RING_BR) + printf("burst\n"); +} + /* * helper routine for test_ring_basic */ @@ -314,286 +360,203 @@ test_ring_basic(struct rte_ring *r) return -1; } +/* + * Burst and bulk operations with sp/sc, mp/mc and default (during creation) + */ static int -test_ring_burst_basic(struct rte_ring *r) +test_ring_burst_bulk_tests(unsigned int api_type) { + struct rte_ring *r; void **src = NULL, **cur_src = NULL, **dst = NULL, **cur_dst = NULL; int ret; - unsigned i; + unsigned int i, j; + unsigned int num_elems; - /* alloc dummy object pointers */ - src = malloc(RING_SIZE*2*sizeof(void *)); - if (src == NULL) - goto fail; - - for (i = 0; i < RING_SIZE*2 ; i++) { - src[i] = (void *)(unsigned long)i; - } - cur_src = src; + for (i = 0; i < RTE_DIM(esize); i++) { + test_ring_print_test_string("Test standard ring", api_type, + esize[i]); - /* alloc some room for copied objects */ - dst = malloc(RING_SIZE*2*sizeof(void *)); - if (dst == NULL) - goto fail; + /* Create the ring */ + TEST_RING_CREATE("test_ring_burst_bulk_tests", esize[i], + RING_SIZE, SOCKET_ID_ANY, 0, r); - memset(dst, 0, RING_SIZE*2*sizeof(void *)); - cur_dst = dst; - - printf("Test SP & SC basic functions \n"); - printf("enqueue 1 obj\n"); - ret = rte_ring_sp_enqueue_burst(r, cur_src, 1, NULL); - cur_src += 1; - if (ret != 1) - goto fail; - - printf("enqueue 2 objs\n"); - ret = rte_ring_sp_enqueue_burst(r, cur_src, 2, NULL); - cur_src += 2; - if (ret != 2) - goto fail; - - printf("enqueue MAX_BULK objs\n"); - ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK, NULL); - cur_src += MAX_BULK; - if (ret != MAX_BULK) - goto fail; - - printf("dequeue 1 obj\n"); - ret = rte_ring_sc_dequeue_burst(r, cur_dst, 1, NULL); - cur_dst += 1; - if (ret != 1) - goto fail; - - printf("dequeue 2 objs\n"); - ret = rte_ring_sc_dequeue_burst(r, cur_dst, 2, NULL); - cur_dst += 2; - if (ret != 2) - goto fail; + /* alloc dummy object pointers */ + src = test_ring_calloc(RING_SIZE * 2, esize[i]); + if (src == NULL) + goto fail; + test_ring_mem_init(src, RING_SIZE * 2, esize[i]); + cur_src = src; - printf("dequeue MAX_BULK objs\n"); - ret = rte_ring_sc_dequeue_burst(r, cur_dst, MAX_BULK, NULL); - cur_dst += MAX_BULK; - if (ret != MAX_BULK) - goto fail; + /* alloc some room for copied objects */ + dst = test_ring_calloc(RING_SIZE * 2, esize[i]); + if (dst == NULL) + goto fail; + cur_dst = dst; - /* check data */ - if (memcmp(src, dst, cur_dst - dst)) { - rte_hexdump(stdout, "src", src, cur_src - src); - rte_hexdump(stdout, "dst", dst, cur_dst - dst); - printf("data after dequeue is not the same\n"); - goto fail; - } + printf("enqueue 1 obj\n"); + TEST_RING_ENQUEUE(r, cur_src, esize[i], 1, ret, api_type); + if (ret != 1) + goto fail; + TEST_RING_INCP(cur_src, esize[i], 1); - cur_src = src; - cur_dst = dst; + printf("enqueue 2 objs\n"); + TEST_RING_ENQUEUE(r, cur_src, esize[i], 2, ret, api_type); + if (ret != 2) + goto fail; + TEST_RING_INCP(cur_src, esize[i], 2); - printf("Test enqueue without enough memory space \n"); - for (i = 0; i< (RING_SIZE/MAX_BULK - 1); i++) { - ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK, NULL); - cur_src += MAX_BULK; + printf("enqueue MAX_BULK objs\n"); + TEST_RING_ENQUEUE(r, cur_src, esize[i], MAX_BULK, ret, + api_type); if (ret != MAX_BULK) goto fail; - } - - printf("Enqueue 2 objects, free entries = MAX_BULK - 2 \n"); - ret = rte_ring_sp_enqueue_burst(r, cur_src, 2, NULL); - cur_src += 2; - if (ret != 2) - goto fail; + TEST_RING_INCP(cur_src, esize[i], MAX_BULK); - printf("Enqueue the remaining entries = MAX_BULK - 2 \n"); - /* Always one free entry left */ - ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK, NULL); - cur_src += MAX_BULK - 3; - if (ret != MAX_BULK - 3) - goto fail; - - printf("Test if ring is full \n"); - if (rte_ring_full(r) != 1) - goto fail; + printf("dequeue 1 obj\n"); + TEST_RING_DEQUEUE(r, cur_dst, esize[i], 1, ret, api_type); + if (ret != 1) + goto fail; + TEST_RING_INCP(cur_dst, esize[i], 1); - printf("Test enqueue for a full entry \n"); - ret = rte_ring_sp_enqueue_burst(r, cur_src, MAX_BULK, NULL); - if (ret != 0) - goto fail; + printf("dequeue 2 objs\n"); + TEST_RING_DEQUEUE(r, cur_dst, esize[i], 2, ret, api_type); + if (ret != 2) + goto fail; + TEST_RING_INCP(cur_dst, esize[i], 2); - printf("Test dequeue without enough objects \n"); - for (i = 0; i +#include +#include + +/* API type to call + * N - Calls default APIs + * S - Calls SP or SC API + * M - Calls MP or MC API + */ +#define TEST_RING_N 1 +#define TEST_RING_S 2 +#define TEST_RING_M 4 + +/* API type to call + * SL - Calls single element APIs + * BL - Calls bulk APIs + * BR - Calls burst APIs + */ +#define TEST_RING_SL 8 +#define TEST_RING_BL 16 +#define TEST_RING_BR 32 + +#define TEST_RING_IGNORE_API_TYPE ~0U + +#define TEST_RING_INCP(obj, esize, n) do { \ + /* Legacy queue APIs? */ \ + if ((esize) == -1) \ + obj = ((void **)obj) + n; \ + else \ + obj = (void **)(((uint32_t *)obj) + \ + (n * esize / sizeof(uint32_t))); \ +} while (0) + +#define TEST_RING_CREATE(name, esize, count, socket_id, flags, r) do { \ + /* Legacy queue APIs? */ \ + if ((esize) == -1) \ + r = rte_ring_create((name), (count), (socket_id), (flags)); \ + else \ + r = rte_ring_create_elem((name), (esize), (count), \ + (socket_id), (flags)); \ +} while (0) + +#define TEST_RING_ENQUEUE(r, obj, esize, n, ret, api_type) do { \ + /* Legacy queue APIs? */ \ + if ((esize) == -1) \ + switch (api_type) { \ + case (TEST_RING_N | TEST_RING_SL): \ + ret = rte_ring_enqueue(r, obj); \ + break; \ + case (TEST_RING_S | TEST_RING_SL): \ + ret = rte_ring_sp_enqueue(r, obj); \ + break; \ + case (TEST_RING_M | TEST_RING_SL): \ + ret = rte_ring_mp_enqueue(r, obj); \ + break; \ + case (TEST_RING_N | TEST_RING_BL): \ + ret = rte_ring_enqueue_bulk(r, obj, n, NULL); \ + break; \ + case (TEST_RING_S | TEST_RING_BL): \ + ret = rte_ring_sp_enqueue_bulk(r, obj, n, NULL); \ + break; \ + case (TEST_RING_M | TEST_RING_BL): \ + ret = rte_ring_mp_enqueue_bulk(r, obj, n, NULL); \ + break; \ + case (TEST_RING_N | TEST_RING_BR): \ + ret = rte_ring_enqueue_burst(r, obj, n, NULL); \ + break; \ + case (TEST_RING_S | TEST_RING_BR): \ + ret = rte_ring_sp_enqueue_burst(r, obj, n, NULL); \ + break; \ + case (TEST_RING_M | TEST_RING_BR): \ + ret = rte_ring_mp_enqueue_burst(r, obj, n, NULL); \ + } \ + else \ + switch (api_type) { \ + case (TEST_RING_N | TEST_RING_SL): \ + ret = rte_ring_enqueue_elem(r, obj, esize); \ + break; \ + case (TEST_RING_S | TEST_RING_SL): \ + ret = rte_ring_sp_enqueue_elem(r, obj, esize); \ + break; \ + case (TEST_RING_M | TEST_RING_SL): \ + ret = rte_ring_mp_enqueue_elem(r, obj, esize); \ + break; \ + case (TEST_RING_N | TEST_RING_BL): \ + ret = rte_ring_enqueue_bulk_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_S | TEST_RING_BL): \ + ret = rte_ring_sp_enqueue_bulk_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_M | TEST_RING_BL): \ + ret = rte_ring_mp_enqueue_bulk_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_N | TEST_RING_BR): \ + ret = rte_ring_enqueue_burst_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_S | TEST_RING_BR): \ + ret = rte_ring_sp_enqueue_burst_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_M | TEST_RING_BR): \ + ret = rte_ring_mp_enqueue_burst_elem(r, obj, esize, n, \ + NULL); \ + } \ +} while (0) + +#define TEST_RING_DEQUEUE(r, obj, esize, n, ret, api_type) do { \ + /* Legacy queue APIs? */ \ + if ((esize) == -1) \ + switch (api_type) { \ + case (TEST_RING_N | TEST_RING_SL): \ + ret = rte_ring_dequeue(r, obj); \ + break; \ + case (TEST_RING_S | TEST_RING_SL): \ + ret = rte_ring_sc_dequeue(r, obj); \ + break; \ + case (TEST_RING_M | TEST_RING_SL): \ + ret = rte_ring_mc_dequeue(r, obj); \ + break; \ + case (TEST_RING_N | TEST_RING_BL): \ + ret = rte_ring_dequeue_bulk(r, obj, n, NULL); \ + break; \ + case (TEST_RING_S | TEST_RING_BL): \ + ret = rte_ring_sc_dequeue_bulk(r, obj, n, NULL); \ + break; \ + case (TEST_RING_M | TEST_RING_BL): \ + ret = rte_ring_mc_dequeue_bulk(r, obj, n, NULL); \ + break; \ + case (TEST_RING_N | TEST_RING_BR): \ + ret = rte_ring_dequeue_burst(r, obj, n, NULL); \ + break; \ + case (TEST_RING_S | TEST_RING_BR): \ + ret = rte_ring_sc_dequeue_burst(r, obj, n, NULL); \ + break; \ + case (TEST_RING_M | TEST_RING_BR): \ + ret = rte_ring_mc_dequeue_burst(r, obj, n, NULL); \ + } \ + else \ + switch (api_type) { \ + case (TEST_RING_N | TEST_RING_SL): \ + ret = rte_ring_dequeue_elem(r, obj, esize); \ + break; \ + case (TEST_RING_S | TEST_RING_SL): \ + ret = rte_ring_sc_dequeue_elem(r, obj, esize); \ + break; \ + case (TEST_RING_M | TEST_RING_SL): \ + ret = rte_ring_mc_dequeue_elem(r, obj, esize); \ + break; \ + case (TEST_RING_N | TEST_RING_BL): \ + ret = rte_ring_dequeue_bulk_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_S | TEST_RING_BL): \ + ret = rte_ring_sc_dequeue_bulk_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_M | TEST_RING_BL): \ + ret = rte_ring_mc_dequeue_bulk_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_N | TEST_RING_BR): \ + ret = rte_ring_dequeue_burst_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_S | TEST_RING_BR): \ + ret = rte_ring_sc_dequeue_burst_elem(r, obj, esize, n, \ + NULL); \ + break; \ + case (TEST_RING_M | TEST_RING_BR): \ + ret = rte_ring_mc_dequeue_burst_elem(r, obj, esize, n, \ + NULL); \ + } \ +} while (0) + +/* This function is placed here as it is required for both + * performance and functional tests. + */ +static __rte_always_inline void * +test_ring_calloc(unsigned int rsize, int esize) +{ + unsigned int sz; + void *p; + + /* Legacy queue APIs? */ + if (esize == -1) + sz = sizeof(void *); + else + sz = esize; + + p = rte_zmalloc(NULL, rsize * sz, RTE_CACHE_LINE_SIZE); + if (p == NULL) + printf("Failed to allocate memory\n"); + + return p; +} -- 2.17.1