4 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/queue.h>
44 #include <rte_common.h>
45 #include <rte_debug.h>
47 #include <rte_common.h>
48 #include <rte_memory.h>
49 #include <rte_memcpy.h>
50 #include <rte_memzone.h>
51 #include <rte_launch.h>
52 #include <rte_tailq.h>
54 #include <rte_per_lcore.h>
55 #include <rte_lcore.h>
56 #include <rte_atomic.h>
57 #include <rte_branch_prediction.h>
59 #include <rte_mempool.h>
61 #include <rte_random.h>
62 #include <rte_cycles.h>
64 #include <cmdline_parse.h>
68 #define MBUF_SIZE 2048
70 #define MBUF_TEST_DATA_LEN 1464
71 #define MBUF_TEST_DATA_LEN2 50
72 #define MBUF_TEST_HDR1_LEN 20
73 #define MBUF_TEST_HDR2_LEN 30
74 #define MBUF_TEST_ALL_HDRS_LEN (MBUF_TEST_HDR1_LEN+MBUF_TEST_HDR2_LEN)
76 #define REFCNT_MAX_ITER 64
77 #define REFCNT_MAX_TIMEOUT 10
78 #define REFCNT_MAX_REF (RTE_MAX_LCORE)
79 #define REFCNT_MBUF_NUM 64
80 #define REFCNT_MBUF_SIZE (sizeof (struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
81 #define REFCNT_RING_SIZE (REFCNT_MBUF_NUM * REFCNT_MAX_REF)
83 #define MAKE_STRING(x) # x
85 static struct rte_mempool *pktmbuf_pool = NULL;
86 static struct rte_mempool *ctrlmbuf_pool = NULL;
88 #if defined RTE_MBUF_SCATTER_GATHER && defined RTE_MBUF_REFCNT_ATOMIC
90 static struct rte_mempool *refcnt_pool = NULL;
91 static struct rte_ring *refcnt_mbuf_ring = NULL;
92 static volatile uint32_t refcnt_stop_slaves;
93 static unsigned refcnt_lcore[RTE_MAX_LCORE];
101 * #. Allocate a mbuf pool.
103 * - The pool contains NB_MBUF elements, where each mbuf is MBUF_SIZE
106 * #. Test multiple allocations of mbufs from this pool.
108 * - Allocate NB_MBUF and store pointers in a table.
109 * - If an allocation fails, return an error.
110 * - Free all these mbufs.
111 * - Repeat the same test to check that mbufs were freed correctly.
113 * #. Test data manipulation in pktmbuf.
116 * - Append data using rte_pktmbuf_append().
117 * - Test for error in rte_pktmbuf_append() when len is too large.
118 * - Trim data at the end of mbuf using rte_pktmbuf_trim().
119 * - Test for error in rte_pktmbuf_trim() when len is too large.
120 * - Prepend a header using rte_pktmbuf_prepend().
121 * - Test for error in rte_pktmbuf_prepend() when len is too large.
122 * - Remove data at the beginning of mbuf using rte_pktmbuf_adj().
123 * - Test for error in rte_pktmbuf_adj() when len is too large.
124 * - Check that appended data is not corrupt.
126 * - Between all these tests, check data_len and pkt_len, and
127 * that the mbuf is contiguous.
128 * - Repeat the test to check that allocation operations
129 * reinitialize the mbuf correctly.
133 #define GOTO_FAIL(str, ...) do { \
134 printf("mbuf test FAILED (l.%d): <" str ">\n", \
135 __LINE__, ##__VA_ARGS__); \
140 * test data manipulation in mbuf with non-ascii data
143 test_pktmbuf_with_non_ascii_data(void)
145 struct rte_mbuf *m = NULL;
148 m = rte_pktmbuf_alloc(pktmbuf_pool);
150 GOTO_FAIL("Cannot allocate mbuf");
151 if (rte_pktmbuf_pkt_len(m) != 0)
152 GOTO_FAIL("Bad length");
154 data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN);
156 GOTO_FAIL("Cannot append data");
157 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
158 GOTO_FAIL("Bad pkt length");
159 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
160 GOTO_FAIL("Bad data length");
161 memset(data, 0xff, rte_pktmbuf_pkt_len(m));
162 if (!rte_pktmbuf_is_contiguous(m))
163 GOTO_FAIL("Buffer should be continuous");
164 rte_pktmbuf_dump(m, MBUF_TEST_DATA_LEN);
178 * test data manipulation in mbuf
181 test_one_pktmbuf(void)
183 struct rte_mbuf *m = NULL;
184 char *data, *data2, *hdr;
187 printf("Test pktmbuf API\n");
191 m = rte_pktmbuf_alloc(pktmbuf_pool);
193 GOTO_FAIL("Cannot allocate mbuf");
194 if (rte_pktmbuf_pkt_len(m) != 0)
195 GOTO_FAIL("Bad length");
197 rte_pktmbuf_dump(m, 0);
201 data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN);
203 GOTO_FAIL("Cannot append data");
204 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
205 GOTO_FAIL("Bad pkt length");
206 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
207 GOTO_FAIL("Bad data length");
208 memset(data, 0x66, rte_pktmbuf_pkt_len(m));
209 if (!rte_pktmbuf_is_contiguous(m))
210 GOTO_FAIL("Buffer should be continuous");
211 rte_pktmbuf_dump(m, MBUF_TEST_DATA_LEN);
212 rte_pktmbuf_dump(m, 2*MBUF_TEST_DATA_LEN);
214 /* this append should fail */
216 data2 = rte_pktmbuf_append(m, (uint16_t)(rte_pktmbuf_tailroom(m) + 1));
218 GOTO_FAIL("Append should not succeed");
220 /* append some more data */
222 data2 = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN2);
224 GOTO_FAIL("Cannot append data");
225 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_DATA_LEN2)
226 GOTO_FAIL("Bad pkt length");
227 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_DATA_LEN2)
228 GOTO_FAIL("Bad data length");
229 if (!rte_pktmbuf_is_contiguous(m))
230 GOTO_FAIL("Buffer should be continuous");
232 /* trim data at the end of mbuf */
234 if (rte_pktmbuf_trim(m, MBUF_TEST_DATA_LEN2) < 0)
235 GOTO_FAIL("Cannot trim data");
236 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
237 GOTO_FAIL("Bad pkt length");
238 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
239 GOTO_FAIL("Bad data length");
240 if (!rte_pktmbuf_is_contiguous(m))
241 GOTO_FAIL("Buffer should be continuous");
243 /* this trim should fail */
245 if (rte_pktmbuf_trim(m, (uint16_t)(rte_pktmbuf_data_len(m) + 1)) == 0)
246 GOTO_FAIL("trim should not succeed");
248 /* prepend one header */
250 hdr = rte_pktmbuf_prepend(m, MBUF_TEST_HDR1_LEN);
252 GOTO_FAIL("Cannot prepend");
253 if (data - hdr != MBUF_TEST_HDR1_LEN)
254 GOTO_FAIL("Prepend failed");
255 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_HDR1_LEN)
256 GOTO_FAIL("Bad pkt length");
257 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_HDR1_LEN)
258 GOTO_FAIL("Bad data length");
259 if (!rte_pktmbuf_is_contiguous(m))
260 GOTO_FAIL("Buffer should be continuous");
261 memset(hdr, 0x55, MBUF_TEST_HDR1_LEN);
263 /* prepend another header */
265 hdr = rte_pktmbuf_prepend(m, MBUF_TEST_HDR2_LEN);
267 GOTO_FAIL("Cannot prepend");
268 if (data - hdr != MBUF_TEST_ALL_HDRS_LEN)
269 GOTO_FAIL("Prepend failed");
270 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_ALL_HDRS_LEN)
271 GOTO_FAIL("Bad pkt length");
272 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_ALL_HDRS_LEN)
273 GOTO_FAIL("Bad data length");
274 if (!rte_pktmbuf_is_contiguous(m))
275 GOTO_FAIL("Buffer should be continuous");
276 memset(hdr, 0x55, MBUF_TEST_HDR2_LEN);
278 rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 1);
279 rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 0);
280 rte_pktmbuf_dump(m, 0);
282 /* this prepend should fail */
284 hdr = rte_pktmbuf_prepend(m, (uint16_t)(rte_pktmbuf_headroom(m) + 1));
286 GOTO_FAIL("prepend should not succeed");
288 /* remove data at beginning of mbuf (adj) */
290 if (data != rte_pktmbuf_adj(m, MBUF_TEST_ALL_HDRS_LEN))
291 GOTO_FAIL("rte_pktmbuf_adj failed");
292 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
293 GOTO_FAIL("Bad pkt length");
294 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
295 GOTO_FAIL("Bad data length");
296 if (!rte_pktmbuf_is_contiguous(m))
297 GOTO_FAIL("Buffer should be continuous");
299 /* this adj should fail */
301 if (rte_pktmbuf_adj(m, (uint16_t)(rte_pktmbuf_data_len(m) + 1)) != NULL)
302 GOTO_FAIL("rte_pktmbuf_adj should not succeed");
306 if (!rte_pktmbuf_is_contiguous(m))
307 GOTO_FAIL("Buffer should be continuous");
309 for (i=0; i<MBUF_TEST_DATA_LEN; i++) {
311 GOTO_FAIL("Data corrupted at offset %u", i);
330 test_one_ctrlmbuf(void)
332 struct rte_mbuf *m = NULL;
333 char message[] = "This is a message carried by a ctrlmbuf";
335 printf("Test ctrlmbuf API\n");
339 m = rte_ctrlmbuf_alloc(ctrlmbuf_pool);
341 GOTO_FAIL("Cannot allocate mbuf");
342 if (rte_ctrlmbuf_len(m) != 0)
343 GOTO_FAIL("Bad length");
346 rte_ctrlmbuf_data(m) = &message;
347 rte_ctrlmbuf_len(m) = sizeof(message);
350 if (rte_ctrlmbuf_data(m) != message)
351 GOTO_FAIL("Invalid data pointer");
352 if (rte_ctrlmbuf_len(m) != sizeof(message))
353 GOTO_FAIL("Invalid len");
355 rte_mbuf_sanity_check(m, RTE_MBUF_CTRL, 0);
358 rte_ctrlmbuf_free(m);
364 rte_ctrlmbuf_free(m);
369 testclone_testupdate_testdetach(void)
371 #ifndef RTE_MBUF_SCATTER_GATHER
374 struct rte_mbuf *mc = NULL;
375 struct rte_mbuf *clone = NULL;
379 mc = rte_pktmbuf_alloc(pktmbuf_pool);
381 GOTO_FAIL("ooops not allocating mbuf");
383 if (rte_pktmbuf_pkt_len(mc) != 0)
384 GOTO_FAIL("Bad length");
387 /* clone the allocated mbuf */
388 clone = rte_pktmbuf_clone(mc, pktmbuf_pool);
390 GOTO_FAIL("cannot clone data\n");
391 rte_pktmbuf_free(clone);
393 mc->pkt.next = rte_pktmbuf_alloc(pktmbuf_pool);
394 if(mc->pkt.next == NULL)
395 GOTO_FAIL("Next Pkt Null\n");
397 clone = rte_pktmbuf_clone(mc, pktmbuf_pool);
399 GOTO_FAIL("cannot clone data\n");
402 rte_pktmbuf_free(mc);
403 rte_pktmbuf_free(clone);
410 rte_pktmbuf_free(mc);
412 #endif /* RTE_MBUF_SCATTER_GATHER */
419 * test allocation and free of mbufs
422 test_pktmbuf_pool(void)
425 struct rte_mbuf *m[NB_MBUF];
428 for (i=0; i<NB_MBUF; i++)
431 /* alloc NB_MBUF mbufs */
432 for (i=0; i<NB_MBUF; i++) {
433 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
435 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
439 struct rte_mbuf *extra = NULL;
440 extra = rte_pktmbuf_alloc(pktmbuf_pool);
442 printf("Error pool not empty");
445 #ifdef RTE_MBUF_SCATTER_GATHER
446 extra = rte_pktmbuf_clone(m[0], pktmbuf_pool);
448 printf("Error pool not empty");
453 for (i=0; i<NB_MBUF; i++) {
455 rte_pktmbuf_free(m[i]);
462 * test that the pointer to the data on a packet mbuf is set properly
465 test_pktmbuf_pool_ptr(void)
468 struct rte_mbuf *m[NB_MBUF];
471 for (i=0; i<NB_MBUF; i++)
474 /* alloc NB_MBUF mbufs */
475 for (i=0; i<NB_MBUF; i++) {
476 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
478 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
481 m[i]->pkt.data = RTE_PTR_ADD(m[i]->pkt.data, 64);
485 for (i=0; i<NB_MBUF; i++) {
487 rte_pktmbuf_free(m[i]);
490 for (i=0; i<NB_MBUF; i++)
493 /* alloc NB_MBUF mbufs */
494 for (i=0; i<NB_MBUF; i++) {
495 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
497 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
500 if (m[i]->pkt.data != RTE_PTR_ADD(m[i]->buf_addr, RTE_PKTMBUF_HEADROOM)) {
501 printf ("pkt.data pointer not set properly\n");
507 for (i=0; i<NB_MBUF; i++) {
509 rte_pktmbuf_free(m[i]);
516 test_pktmbuf_free_segment(void)
519 struct rte_mbuf *m[NB_MBUF];
522 for (i=0; i<NB_MBUF; i++)
525 /* alloc NB_MBUF mbufs */
526 for (i=0; i<NB_MBUF; i++) {
527 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
529 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
535 for (i=0; i<NB_MBUF; i++) {
537 struct rte_mbuf *mb, *mt;
543 rte_pktmbuf_free_seg(mt);
552 * Stress test for rte_mbuf atomic refcnt.
554 * RTE_MBUF_SCATTER_GATHER and RTE_MBUF_REFCNT_ATOMIC are both defined.
555 * For more efficency, recomended to run with RTE_LIBRTE_MBUF_DEBUG defined.
558 #if defined RTE_MBUF_SCATTER_GATHER && defined RTE_MBUF_REFCNT_ATOMIC
561 test_refcnt_slave(__attribute__((unused)) void *arg)
563 unsigned lcore, free;
566 lcore = rte_lcore_id();
567 printf("%s started at lcore %u\n", __func__, lcore);
570 while (refcnt_stop_slaves == 0) {
571 if (rte_ring_dequeue(refcnt_mbuf_ring, &mp) == 0) {
573 rte_pktmbuf_free((struct rte_mbuf *)mp);
577 refcnt_lcore[lcore] += free;
578 printf("%s finished at lcore %u, "
579 "number of freed mbufs: %u\n",
580 __func__, lcore, free);
585 test_refcnt_iter(unsigned lcore, unsigned iter)
588 unsigned i, n, tref, wn;
593 /* For each mbuf in the pool:
595 * - increment it's reference up to N+1,
596 * - enqueue it N times into the ring for slave cores to free.
598 for (i = 0, n = rte_mempool_count(refcnt_pool);
599 i != n && (m = rte_pktmbuf_alloc(refcnt_pool)) != NULL;
601 ref = RTE_MAX(rte_rand() % REFCNT_MAX_REF, 1UL);
603 if ((ref & 1) != 0) {
604 rte_pktmbuf_refcnt_update(m, ref);
606 rte_ring_enqueue(refcnt_mbuf_ring, m);
609 rte_pktmbuf_refcnt_update(m, 1);
610 rte_ring_enqueue(refcnt_mbuf_ring, m);
617 rte_panic("(lcore=%u, iter=%u): was able to allocate only "
618 "%u from %u mbufs\n", lcore, iter, i, n);
620 /* wait till slave lcores will consume all mbufs */
621 while (!rte_ring_empty(refcnt_mbuf_ring))
624 /* check that all mbufs are back into mempool by now */
625 for (wn = 0; wn != REFCNT_MAX_TIMEOUT; wn++) {
626 if ((i = rte_mempool_count(refcnt_pool)) == n) {
627 refcnt_lcore[lcore] += tref;
628 printf("%s(lcore=%u, iter=%u) completed, "
629 "%u references processed\n",
630 __func__, lcore, iter, tref);
636 rte_panic("(lcore=%u, iter=%u): after %us only "
637 "%u of %u mbufs left free\n", lcore, iter, wn, i, n);
641 test_refcnt_master(void)
645 lcore = rte_lcore_id();
646 printf("%s started at lcore %u\n", __func__, lcore);
648 for (i = 0; i != REFCNT_MAX_ITER; i++)
649 test_refcnt_iter(lcore, i);
651 refcnt_stop_slaves = 1;
654 printf("%s finished at lcore %u\n", __func__, lcore);
661 test_refcnt_mbuf(void)
663 #if defined RTE_MBUF_SCATTER_GATHER && defined RTE_MBUF_REFCNT_ATOMIC
665 unsigned lnum, master, slave, tref;
668 if ((lnum = rte_lcore_count()) == 1) {
669 printf("skipping %s, number of lcores: %u is not enough\n",
674 printf("starting %s, at %u lcores\n", __func__, lnum);
676 /* create refcnt pool & ring if they don't exist */
678 if (refcnt_pool == NULL &&
679 (refcnt_pool = rte_mempool_create(
680 MAKE_STRING(refcnt_pool),
681 REFCNT_MBUF_NUM, REFCNT_MBUF_SIZE, 0,
682 sizeof(struct rte_pktmbuf_pool_private),
683 rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL,
684 SOCKET_ID_ANY, 0)) == NULL) {
685 printf("%s: cannot allocate " MAKE_STRING(refcnt_pool) "\n",
690 if (refcnt_mbuf_ring == NULL &&
691 (refcnt_mbuf_ring = rte_ring_create("refcnt_mbuf_ring",
692 REFCNT_RING_SIZE, SOCKET_ID_ANY,
693 RING_F_SP_ENQ)) == NULL) {
694 printf("%s: cannot allocate " MAKE_STRING(refcnt_mbuf_ring)
699 refcnt_stop_slaves = 0;
700 memset(refcnt_lcore, 0, sizeof (refcnt_lcore));
702 rte_eal_mp_remote_launch(test_refcnt_slave, NULL, SKIP_MASTER);
704 test_refcnt_master();
706 rte_eal_mp_wait_lcore();
708 /* check that we porcessed all references */
710 master = rte_get_master_lcore();
712 RTE_LCORE_FOREACH_SLAVE(slave)
713 tref += refcnt_lcore[slave];
715 if (tref != refcnt_lcore[master])
716 rte_panic("refernced mbufs: %u, freed mbufs: %u\n",
717 tref, refcnt_lcore[master]);
719 rte_mempool_dump(refcnt_pool);
720 rte_ring_dump(refcnt_mbuf_ring);
726 #ifdef RTE_EXEC_ENV_BAREMETAL
728 /* baremetal - don't test failing sanity checks */
730 test_failing_mbuf_sanity_check(void)
738 #include <sys/wait.h>
740 /* linuxapp - use fork() to test mbuf errors panic */
742 verify_mbuf_check_panics(struct rte_mbuf *buf)
750 rte_mbuf_sanity_check(buf, RTE_MBUF_PKT, 1); /* should panic */
751 exit(0); /* return normally if it doesn't panic */
753 printf("Fork Failed\n");
764 test_failing_mbuf_sanity_check(void)
766 struct rte_mbuf *buf;
767 struct rte_mbuf badbuf;
769 printf("Checking rte_mbuf_sanity_check for failure conditions\n");
771 /* get a good mbuf to use to make copies */
772 buf = rte_pktmbuf_alloc(pktmbuf_pool);
775 printf("Checking good mbuf initially\n");
776 if (verify_mbuf_check_panics(buf) != -1)
779 printf("Now checking for error conditions\n");
781 if (verify_mbuf_check_panics(NULL)) {
782 printf("Error with NULL mbuf test\n");
787 badbuf.type = (uint8_t)-1;
788 if (verify_mbuf_check_panics(&badbuf)) {
789 printf("Error with bad-type mbuf test\n");
795 if (verify_mbuf_check_panics(&badbuf)) {
796 printf("Error with bad-pool mbuf test\n");
801 badbuf.buf_physaddr = 0;
802 if (verify_mbuf_check_panics(&badbuf)) {
803 printf("Error with bad-physaddr mbuf test\n");
808 badbuf.buf_addr = NULL;
809 if (verify_mbuf_check_panics(&badbuf)) {
810 printf("Error with bad-addr mbuf test\n");
814 #ifdef RTE_MBUF_SCATTER_GATHER
817 if (verify_mbuf_check_panics(&badbuf)) {
818 printf("Error with bad-refcnt(0) mbuf test\n");
823 badbuf.refcnt = UINT16_MAX;
824 if (verify_mbuf_check_panics(&badbuf)) {
825 printf("Error with bad-refcnt(MAX) mbuf test\n");
838 RTE_BUILD_BUG_ON(sizeof(struct rte_mbuf) != 64);
840 /* create pktmbuf pool if it does not exist */
841 if (pktmbuf_pool == NULL) {
843 rte_mempool_create("test_pktmbuf_pool", NB_MBUF,
845 sizeof(struct rte_pktmbuf_pool_private),
846 rte_pktmbuf_pool_init, NULL,
847 rte_pktmbuf_init, NULL,
851 if (pktmbuf_pool == NULL) {
852 printf("cannot allocate mbuf pool\n");
856 /* test multiple mbuf alloc */
857 if (test_pktmbuf_pool() < 0) {
858 printf("test_mbuf_pool() failed\n");
862 /* do it another time to check that all mbufs were freed */
863 if (test_pktmbuf_pool() < 0) {
864 printf("test_mbuf_pool() failed (2)\n");
868 /* test that the pointer to the data on a packet mbuf is set properly */
869 if (test_pktmbuf_pool_ptr() < 0) {
870 printf("test_pktmbuf_pool_ptr() failed\n");
874 /* test data manipulation in mbuf */
875 if (test_one_pktmbuf() < 0) {
876 printf("test_one_mbuf() failed\n");
882 * do it another time, to check that allocation reinitialize
885 if (test_one_pktmbuf() < 0) {
886 printf("test_one_mbuf() failed (2)\n");
890 if (test_pktmbuf_with_non_ascii_data() < 0) {
891 printf("test_pktmbuf_with_non_ascii_data() failed\n");
895 /* create ctrlmbuf pool if it does not exist */
896 if (ctrlmbuf_pool == NULL) {
898 rte_mempool_create("test_ctrlmbuf_pool", NB_MBUF,
899 sizeof(struct rte_mbuf), 32, 0,
901 rte_ctrlmbuf_init, NULL,
905 /* test control mbuf */
906 if (test_one_ctrlmbuf() < 0) {
907 printf("test_one_ctrlmbuf() failed\n");
911 /* test free pktmbuf segment one by one */
912 if (test_pktmbuf_free_segment() < 0) {
913 printf("test_pktmbuf_free_segment() failed.\n");
917 if (testclone_testupdate_testdetach()<0){
918 printf("testclone_and_testupdate() failed \n");
922 if (test_refcnt_mbuf()<0){
923 printf("test_refcnt_mbuf() failed \n");
927 if (test_failing_mbuf_sanity_check() < 0) {
928 printf("test_failing_mbuf_sanity_check() failed\n");