From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 2A196689B for ; Fri, 2 Dec 2016 18:07:59 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 02 Dec 2016 09:07:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,287,1477983600"; d="scan'208";a="1093750073" Received: from unknown (HELO Sent) ([10.103.102.79]) by fmsmga002.fm.intel.com with SMTP; 02 Dec 2016 09:07:57 -0800 Received: by Sent (sSMTP sendmail emulation); Fri, 02 Dec 2016 18:07:56 +0100 From: Tomasz Kulasek To: dev@dpdk.org Date: Fri, 2 Dec 2016 18:07:44 +0100 Message-Id: <1480698466-17620-3-git-send-email-tomaszx.kulasek@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1480698466-17620-1-git-send-email-tomaszx.kulasek@intel.com> References: <1480698466-17620-1-git-send-email-tomaszx.kulasek@intel.com> Subject: [dpdk-dev] [PATCH 2/4] test: add rte_pktmbuf_coalesce unit tests 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: , X-List-Received-Date: Fri, 02 Dec 2016 17:07:59 -0000 This patch tests rte_pktmbuf_coalesce functionality: 1) Creates banch of segmented mbufs with different size and number of segments. 2) Generates pkt_len bytes of random data. 3) Fills noncontigouos mbuf with randomly generated data. 4) Uses rte_pktmbuf_coalesce to coalesce segmented buffer into one contiguous. 5) Verifies data in destination buffer. Signed-off-by: Tomasz Kulasek --- app/test/test_mbuf.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index c0823ea..e3c7657 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -930,6 +930,135 @@ return 0; } +static int +test_mbuf_coalesce(int pkt_len, int nb_segs) { + + struct rte_mbuf *m = NULL, *mbuf_src = NULL, *mbuf_dst = NULL; + uint8_t data[pkt_len], *src, *dst; + int data_len = 0; + int i, size; + int t_len; + + if (pkt_len < 1) { + printf("Packet size must be 1 or more (is %d)\n", pkt_len); + return -1; + } + + if (nb_segs < 1) { + printf("Number of segments must be 1 or more (is %d)\n", + nb_segs); + return -1; + } + + /* Setup buffer */ + for (i = 0; i < pkt_len; i++) + data[i] = (uint8_t) rte_rand(); + + t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1; + src = data; + size = pkt_len; + + /* Create chained mbuf_src and fill it generated data */ + for (i = 0; size > 0; i++) { + + m = rte_pktmbuf_alloc(pktmbuf_pool); + if (i == 0) + mbuf_src = m; + + if (!m) { + printf("Cannot create segment for source mbuf"); + goto fail; + } + + /* Make sure if tailroom is zeroed */ + memset(rte_pktmbuf_mtod(m, uint8_t *), 0, + rte_pktmbuf_tailroom(m)); + + data_len = size > t_len ? t_len : size; + dst = (uint8_t *)rte_pktmbuf_append(m, data_len); + if (!dst) { + printf("Cannot append %d bytes to the mbuf\n", + data_len); + goto fail; + } + + rte_memcpy(dst, src, data_len); + src += data_len; + + if (mbuf_src != m) + rte_pktmbuf_chain(mbuf_src, m); + + size -= data_len; + + } + + /* Create destination buffer to store coalesced data */ + mbuf_dst = rte_pktmbuf_alloc(pktmbuf_pool); + if (!mbuf_dst) { + printf("Cannot create destination buffer\n"); + goto fail; + } + + dst = (uint8_t *)rte_pktmbuf_append(m, rte_pktmbuf_pkt_len(mbuf_dst)); + + if (rte_pktmbuf_coalesce(mbuf_dst, mbuf_src)) { + printf("Mbuf coalesce failed\n"); + goto fail; + } + + if (!rte_pktmbuf_is_contiguous(mbuf_dst)) { + printf("Destination buffer should be contiguous\n"); + goto fail; + } + + dst = rte_pktmbuf_mtod(mbuf_dst, uint8_t *); + + if (memcmp(dst, data, rte_pktmbuf_pkt_len(mbuf_src))) { + printf("Incorrect data in coalesced mbuf\n"); + goto fail; + } + + if (mbuf_src) + rte_pktmbuf_free(mbuf_src); + if (mbuf_dst) + rte_pktmbuf_free(mbuf_dst); + return 0; + +fail: + if (mbuf_src) + rte_pktmbuf_free(mbuf_src); + if (mbuf_dst) + rte_pktmbuf_free(mbuf_dst); + return -1; +} + +static int +test_mbuf_coalesce_check(void) +{ + struct test_mbuf_array { + int size; + int nb_segs; + } mbuf_array[5] = { + { 128, 2 }, + { 64, 64 }, + { 512, 10 }, + { 250, 11 }, + { 123, 8 }, + }; + unsigned i; + + printf("Test mbuf coalesce API\n"); + + for (i = 0; i < RTE_DIM(mbuf_array); i++) + if (test_mbuf_coalesce(mbuf_array[i].size, + mbuf_array[i].nb_segs)) { + printf("Test failed for %d, %d\n", mbuf_array[i].size, + mbuf_array[i].nb_segs); + return -1; + } + + return 0; +} static int test_mbuf(void) @@ -1023,6 +1152,11 @@ printf("test_failing_mbuf_sanity_check() failed\n"); return -1; } + + if (test_mbuf_coalesce_check() < 0) { + printf("test_mbuf_coalesce_check() failed\n"); + return -1; + } return 0; } -- 1.7.9.5