All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomasz Kulasek <tomaszx.kulasek@intel.com>
To: dev@dpdk.org
Subject: [PATCH v3 2/5] test: add rte_pktmbuf_linearize unit tests
Date: Thu,  5 Jan 2017 10:12:33 +0100	[thread overview]
Message-ID: <1483607556-21460-3-git-send-email-tomaszx.kulasek@intel.com> (raw)
In-Reply-To: <1483607556-21460-1-git-send-email-tomaszx.kulasek@intel.com>

This patch tests rte_pktmbuf_linearize 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 <tomaszx.kulasek@intel.com>
---
 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

  parent reply	other threads:[~2017-01-05  9:12 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02 17:07 [PATCH 0/4] Chained Mbufs support in SW PMDs Tomasz Kulasek
2016-12-02 17:07 ` [PATCH 1/4] rte_mbuf: add rte_pktmbuf_coalesce Tomasz Kulasek
2016-12-16 10:06   ` Olivier Matz
2016-12-29 15:58     ` Kulasek, TomaszX
2016-12-02 17:07 ` [PATCH 2/4] test: add rte_pktmbuf_coalesce unit tests Tomasz Kulasek
2016-12-02 17:07 ` [PATCH 3/4] crypto: add sgl support for sw PMDs Tomasz Kulasek
2016-12-03  8:28   ` Michał Mirosław
2016-12-12 10:01     ` Kulasek, TomaszX
2016-12-02 17:07 ` [PATCH 4/4] test: add sgl unit tests for crypto devices Tomasz Kulasek
2016-12-29 17:12 ` [PATCH v2 0/5] Chained Mbufs support in SW PMDs Tomasz Kulasek
2016-12-29 17:12   ` [PATCH v2 1/5] rte_mbuf: add rte_pktmbuf_linearize Tomasz Kulasek
2016-12-29 17:12   ` [PATCH v2 2/5] test: add rte_pktmbuf_linearize unit tests Tomasz Kulasek
2016-12-29 17:12   ` [PATCH v2 3/5] crypto: add sgl support in sw PMDs Tomasz Kulasek
2016-12-29 17:12   ` [PATCH v2 4/5] crypto: add sgl support in openssl PMD Tomasz Kulasek
2016-12-29 17:12   ` [PATCH v2 5/5] test: add sgl unit tests for crypto devices Tomasz Kulasek
2017-01-05  9:12   ` [PATCH v3 0/5] Chained Mbufs support in SW PMDs Tomasz Kulasek
2017-01-05  9:12     ` [PATCH v3 1/5] rte_mbuf: add rte_pktmbuf_linearize Tomasz Kulasek
2017-01-05 15:37       ` De Lara Guarch, Pablo
2017-01-05 16:52         ` Kulasek, TomaszX
2017-01-05  9:12     ` Tomasz Kulasek [this message]
2017-01-05  9:12     ` [PATCH v3 3/5] crypto: add sgl support in sw PMDs Tomasz Kulasek
2017-01-05  9:12     ` [PATCH v3 4/5] crypto: add sgl support in openssl PMD Tomasz Kulasek
2017-01-05  9:12     ` [PATCH v3 5/5] test: add sgl unit tests for crypto devices Tomasz Kulasek
2017-01-05 16:44     ` [PATCH v4] rte_mbuf: add rte_pktmbuf_linearize Tomasz Kulasek
2017-01-10 16:50       ` Olivier MATZ
2017-01-12  9:40       ` [PATCH v5] mbuf: add a function to linearize a packet Tomasz Kulasek
2017-01-13 15:32         ` Olivier Matz
2017-01-13 15:40           ` Kulasek, TomaszX
2017-01-15 18:32           ` Thomas Monjalon
2017-01-05 16:46     ` [PATCH v4 0/3] Chained Mbufs support in SW PMDs Tomasz Kulasek
2017-01-05 16:46       ` [PATCH v4 1/3] crypto: add sgl support in sw PMDs Tomasz Kulasek
2017-01-05 16:46       ` [PATCH v4 2/3] crypto: add sgl support in openssl PMD Tomasz Kulasek
2017-01-05 16:46       ` [PATCH v4 3/3] test: add sgl unit tests for crypto devices Tomasz Kulasek
2017-01-13 15:23       ` [PATCH v5 0/3] Chained Mbufs support in SW PMDs Tomasz Kulasek
2017-01-13 15:23         ` [PATCH v5 1/3] crypto: add sgl support in sw PMDs Tomasz Kulasek
2017-01-16 16:08           ` Declan Doherty
2017-01-13 15:23         ` [PATCH v5 2/3] crypto: add sgl support in openssl PMD Tomasz Kulasek
2017-01-16 16:10           ` Declan Doherty
2017-01-13 15:23         ` [PATCH v5 3/3] test: add sgl unit tests for crypto devices Tomasz Kulasek
2017-01-16 16:11           ` Declan Doherty
2017-01-16 19:00         ` [PATCH v5 0/3] Chained Mbufs support in SW PMDs De Lara Guarch, Pablo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1483607556-21460-3-git-send-email-tomaszx.kulasek@intel.com \
    --to=tomaszx.kulasek@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.