X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=blobdiff_plain;f=app%2Ftest%2Ftest_mbuf.c;h=a96ba3fa11ef85d03062bb4d4c955d5566cb6165;hp=8200b4f71e47671e36bd3fd090c3b9a6f358fdf3;hb=a617494eeb01ff;hpb=5d3e7176ee49efdb81a607a9c13dcfd5c2757de1 diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index 8200b4f71e..a96ba3fa11 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -1157,7 +1157,7 @@ test_refcnt_mbuf(void) tref += refcnt_lcore[slave]; if (tref != refcnt_lcore[master]) - rte_panic("refernced mbufs: %u, freed mbufs: %u\n", + rte_panic("referenced mbufs: %u, freed mbufs: %u\n", tref, refcnt_lcore[master]); rte_mempool_dump(stdout, refcnt_pool); @@ -2647,7 +2647,7 @@ test_mbuf_dyn(struct rte_mempool *pktmbuf_pool) flag3 = rte_mbuf_dynflag_register_bitnum(&dynflag3, rte_bsf64(PKT_LAST_FREE)); if (flag3 != rte_bsf64(PKT_LAST_FREE)) - GOTO_FAIL("failed to register dynamic flag 3, flag2=%d: %s", + GOTO_FAIL("failed to register dynamic flag 3, flag3=%d: %s", flag3, strerror(errno)); printf("dynflag: flag=%d, flag2=%d, flag3=%d\n", flag, flag2, flag3); @@ -2675,6 +2675,82 @@ fail: return -1; } +static void +my_free_cb(void *addr, void *opaque __rte_unused) +{ + rte_free(addr); +} + +static int +test_shinfo_in_mbuf(struct rte_mempool *pktmbuf_pool) +{ + struct rte_mbuf_ext_shared_info *shinfo = NULL; + struct rte_mbuf *m2 = NULL; + struct rte_mbuf *m = NULL; + size_t buf_len = 256; + rte_iova_t iova; + char *buf = NULL; + + m = rte_pktmbuf_alloc(pktmbuf_pool); + printf("%s() m=%p\n", __func__, m); + if (m == NULL) + GOTO_FAIL("cannot allocate mbuf m"); + rte_pktmbuf_dump(stdout, m, 0); + + if (rte_pktmbuf_tailroom(m) < sizeof(*shinfo)) + GOTO_FAIL("tailroom too small"); + + buf = rte_malloc(NULL, buf_len, RTE_CACHE_LINE_SIZE); + if (buf == NULL) + GOTO_FAIL("cannot allocate buffer"); + + shinfo = rte_pktmbuf_mtod(m, struct rte_mbuf_ext_shared_info *); + shinfo->free_cb = my_free_cb; + shinfo->fcb_opaque = NULL; + rte_mbuf_ext_refcnt_set(shinfo, 1); + iova = rte_malloc_virt2iova(buf); + rte_pktmbuf_attach_extbuf(m, buf, iova, buf_len, shinfo); + printf("%s() m is attached to the ext buf\n", __func__); + rte_pktmbuf_dump(stdout, m, 0); + + m2 = rte_pktmbuf_alloc(pktmbuf_pool); + printf("%s() m2=%p\n", __func__, m2); + if (m2 == NULL) + GOTO_FAIL("cannot allocate mbuf m2"); + rte_pktmbuf_dump(stdout, m2, 0); + + rte_pktmbuf_attach(m2, m); + rte_pktmbuf_dump(stdout, m2, 0); + rte_pktmbuf_dump(stdout, m, 0); + rte_pktmbuf_free(m); + m = NULL; + + m = rte_pktmbuf_alloc(pktmbuf_pool); + printf("%s() m=%p\n", __func__, m); + if (m == NULL) + GOTO_FAIL("cannot allocate mbuf m"); + + /* clobber data in the mbuf we just allocated */ + shinfo = rte_pktmbuf_mtod(m, struct rte_mbuf_ext_shared_info *); + shinfo->free_cb = NULL; + + rte_pktmbuf_free(m); + m = NULL; + + rte_pktmbuf_free(m2); + m2 = NULL; + + printf("done\n"); + return 0; + + +fail: + rte_pktmbuf_free(m2); + rte_pktmbuf_free(m); + rte_free(buf); + return -1; +} + static int test_mbuf(void) { @@ -2695,6 +2771,16 @@ test_mbuf(void) goto err; } + if (test_shinfo_in_mbuf(pktmbuf_pool) < 0) { + printf("mbuf shinfo in mbuf failed\n"); + goto err; + } + + if (1) { + ret = 0; + goto err; + } + /* test registration of dynamic fields and flags */ if (test_mbuf_dyn(pktmbuf_pool) < 0) { printf("mbuf dynflag test failed\n");