From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 425925699 for ; Thu, 29 Dec 2016 18:13:26 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 29 Dec 2016 09:12:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,428,1477983600"; d="scan'208";a="1087894994" Received: from unknown (HELO Sent) ([10.103.102.79]) by fmsmga001.fm.intel.com with SMTP; 29 Dec 2016 09:12:33 -0800 Received: by Sent (sSMTP sendmail emulation); Thu, 29 Dec 2016 18:12:32 +0100 From: Tomasz Kulasek To: dev@dpdk.org Cc: olivier.matz@6wind.com Date: Thu, 29 Dec 2016 18:12:20 +0100 Message-Id: <1483031543-21196-3-git-send-email-tomaszx.kulasek@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1483031543-21196-1-git-send-email-tomaszx.kulasek@intel.com> References: <1480698466-17620-1-git-send-email-tomaszx.kulasek@intel.com> <1483031543-21196-1-git-send-email-tomaszx.kulasek@intel.com> Subject: [dpdk-dev] [PATCH v2 2/5] test: add rte_pktmbuf_linearize 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: Thu, 29 Dec 2016 17:13:27 -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_linearize to coalesce segmented buffer into one contiguous. 5) Verifies data in linearized buffer. Signed-off-by: Tomasz Kulasek --- app/test/test_mbuf.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index c0823ea..39577e7 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -930,6 +930,124 @@ return 0; } +static int +test_mbuf_linearize(int pkt_len, int nb_segs) { + + struct rte_mbuf *m = NULL, *mbuf_src = 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 */ + if (rte_pktmbuf_linearize(mbuf_src)) { + printf("Mbuf linearization failed\n"); + goto fail; + } + + if (!rte_pktmbuf_is_contiguous(mbuf_src)) { + printf("Source buffer should be contiguous after " + "linearization\n"); + goto fail; + } + + src = rte_pktmbuf_mtod(mbuf_src, uint8_t *); + + if (memcmp(src, data, rte_pktmbuf_pkt_len(mbuf_src))) { + printf("Incorrect data in coalesced mbuf\n"); + goto fail; + } + + if (mbuf_src) + rte_pktmbuf_free(mbuf_src); + return 0; + +fail: + if (mbuf_src) + rte_pktmbuf_free(mbuf_src); + return -1; +} + +static int +test_mbuf_linearize_check(void) +{ + struct test_mbuf_array { + int size; + int nb_segs; + } mbuf_array[5] = { + { 128, 1 }, + { 64, 64 }, + { 512, 10 }, + { 250, 11 }, + { 123, 8 }, + }; + unsigned int i; + + printf("Test mbuf linearize API\n"); + + for (i = 0; i < RTE_DIM(mbuf_array); i++) + if (test_mbuf_linearize(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 +1141,11 @@ printf("test_failing_mbuf_sanity_check() failed\n"); return -1; } + + if (test_mbuf_linearize_check() < 0) { + printf("test_mbuf_linearize_check() failed\n"); + return -1; + } return 0; } -- 1.7.9.5