[dpdk-dev,5/5] test/mbuf: verify that cloning a clone works properly

Message ID 1427302838-8285-6-git-send-email-olivier.matz@6wind.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Olivier Matz March 25, 2015, 5 p.m. UTC
  Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 app/test/test_mbuf.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
  

Comments

Olivier Matz March 26, 2015, 8:48 a.m. UTC | #1
On 03/25/2015 06:00 PM, Olivier Matz wrote:
> Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
> ---
>   app/test/test_mbuf.c | 26 ++++++++++++++++++++++++++
>   1 file changed, 26 insertions(+)
>
> [...]
>
> @@ -394,6 +418,8 @@ fail:
>   		rte_pktmbuf_free(m);
>   	if (clone)
>   		rte_pktmbuf_free(clone);
> +	if (clone2)
> +		rte_pktmbuf_free(clone);
>   	return -1;
>   }
>   #undef GOTO_FAIL
>

Self-nak on this one, it should of course be rte_pktmbuf_free(clone2)
  

Patch

diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c
index 9d8ee4e..68cd4de 100644
--- a/app/test/test_mbuf.c
+++ b/app/test/test_mbuf.c
@@ -325,6 +325,7 @@  testclone_testupdate_testdetach(void)
 {
 	struct rte_mbuf *m = NULL;
 	struct rte_mbuf *clone = NULL;
+	struct rte_mbuf *clone2 = NULL;
 	uint32_t *data;
 
 	/* alloc a mbuf */
@@ -382,11 +383,34 @@  testclone_testupdate_testdetach(void)
 	if (rte_mbuf_refcnt_read(m->next) != 2)
 		GOTO_FAIL("invalid refcnt in m->next\n");
 
+	/* try to clone the clone */
+
+	clone2 = rte_pktmbuf_clone(clone, pktmbuf_pool);
+	if (clone2 == NULL)
+		GOTO_FAIL("cannot clone the clone\n");
+
+	data = rte_pktmbuf_mtod(clone2, uint32_t *);
+	if (*data != MAGIC_DATA)
+		GOTO_FAIL("invalid data in clone2\n");
+
+	data = rte_pktmbuf_mtod(clone2->next, uint32_t *);
+	if (*data != MAGIC_DATA)
+		GOTO_FAIL("invalid data in clone2->next\n");
+
+	if (rte_mbuf_refcnt_read(m) != 3)
+		GOTO_FAIL("invalid refcnt in m\n");
+
+	if (rte_mbuf_refcnt_read(m->next) != 3)
+		GOTO_FAIL("invalid refcnt in m->next\n");
+
 	/* free mbuf */
 	rte_pktmbuf_free(m);
 	rte_pktmbuf_free(clone);
+	rte_pktmbuf_free(clone2);
+
 	m = NULL;
 	clone = NULL;
+	clone2 = NULL;
 	return 0;
 
 fail:
@@ -394,6 +418,8 @@  fail:
 		rte_pktmbuf_free(m);
 	if (clone)
 		rte_pktmbuf_free(clone);
+	if (clone2)
+		rte_pktmbuf_free(clone);
 	return -1;
 }
 #undef GOTO_FAIL