4 * Copyright(c) 2010-2014 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.
41 #include <sys/queue.h>
43 #include <rte_common.h>
44 #include <rte_debug.h>
46 #include <rte_common.h>
47 #include <rte_memory.h>
48 #include <rte_memcpy.h>
49 #include <rte_memzone.h>
50 #include <rte_launch.h>
51 #include <rte_tailq.h>
53 #include <rte_per_lcore.h>
54 #include <rte_lcore.h>
55 #include <rte_atomic.h>
56 #include <rte_branch_prediction.h>
58 #include <rte_mempool.h>
60 #include <rte_random.h>
61 #include <rte_cycles.h>
63 #include <cmdline_parse.h>
67 #define MBUF_SIZE 2048
69 #define MBUF_TEST_DATA_LEN 1464
70 #define MBUF_TEST_DATA_LEN2 50
71 #define MBUF_TEST_HDR1_LEN 20
72 #define MBUF_TEST_HDR2_LEN 30
73 #define MBUF_TEST_ALL_HDRS_LEN (MBUF_TEST_HDR1_LEN+MBUF_TEST_HDR2_LEN)
75 #define REFCNT_MAX_ITER 64
76 #define REFCNT_MAX_TIMEOUT 10
77 #define REFCNT_MAX_REF (RTE_MAX_LCORE)
78 #define REFCNT_MBUF_NUM 64
79 #define REFCNT_MBUF_SIZE (sizeof (struct rte_mbuf) + RTE_PKTMBUF_HEADROOM)
80 #define REFCNT_RING_SIZE (REFCNT_MBUF_NUM * REFCNT_MAX_REF)
82 #define MAKE_STRING(x) # x
84 static struct rte_mempool *pktmbuf_pool = NULL;
85 static struct rte_mempool *ctrlmbuf_pool = NULL;
87 #if defined RTE_MBUF_SCATTER_GATHER && defined RTE_MBUF_REFCNT_ATOMIC
89 static struct rte_mempool *refcnt_pool = NULL;
90 static struct rte_ring *refcnt_mbuf_ring = NULL;
91 static volatile uint32_t refcnt_stop_slaves;
92 static unsigned refcnt_lcore[RTE_MAX_LCORE];
100 * #. Allocate a mbuf pool.
102 * - The pool contains NB_MBUF elements, where each mbuf is MBUF_SIZE
105 * #. Test multiple allocations of mbufs from this pool.
107 * - Allocate NB_MBUF and store pointers in a table.
108 * - If an allocation fails, return an error.
109 * - Free all these mbufs.
110 * - Repeat the same test to check that mbufs were freed correctly.
112 * #. Test data manipulation in pktmbuf.
115 * - Append data using rte_pktmbuf_append().
116 * - Test for error in rte_pktmbuf_append() when len is too large.
117 * - Trim data at the end of mbuf using rte_pktmbuf_trim().
118 * - Test for error in rte_pktmbuf_trim() when len is too large.
119 * - Prepend a header using rte_pktmbuf_prepend().
120 * - Test for error in rte_pktmbuf_prepend() when len is too large.
121 * - Remove data at the beginning of mbuf using rte_pktmbuf_adj().
122 * - Test for error in rte_pktmbuf_adj() when len is too large.
123 * - Check that appended data is not corrupt.
125 * - Between all these tests, check data_len and pkt_len, and
126 * that the mbuf is contiguous.
127 * - Repeat the test to check that allocation operations
128 * reinitialize the mbuf correctly.
132 #define GOTO_FAIL(str, ...) do { \
133 printf("mbuf test FAILED (l.%d): <" str ">\n", \
134 __LINE__, ##__VA_ARGS__); \
139 * test data manipulation in mbuf with non-ascii data
142 test_pktmbuf_with_non_ascii_data(void)
144 struct rte_mbuf *m = NULL;
147 m = rte_pktmbuf_alloc(pktmbuf_pool);
149 GOTO_FAIL("Cannot allocate mbuf");
150 if (rte_pktmbuf_pkt_len(m) != 0)
151 GOTO_FAIL("Bad length");
153 data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN);
155 GOTO_FAIL("Cannot append data");
156 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
157 GOTO_FAIL("Bad pkt length");
158 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
159 GOTO_FAIL("Bad data length");
160 memset(data, 0xff, rte_pktmbuf_pkt_len(m));
161 if (!rte_pktmbuf_is_contiguous(m))
162 GOTO_FAIL("Buffer should be continuous");
163 rte_pktmbuf_dump(m, MBUF_TEST_DATA_LEN);
177 * test data manipulation in mbuf
180 test_one_pktmbuf(void)
182 struct rte_mbuf *m = NULL;
183 char *data, *data2, *hdr;
186 printf("Test pktmbuf API\n");
190 m = rte_pktmbuf_alloc(pktmbuf_pool);
192 GOTO_FAIL("Cannot allocate mbuf");
193 if (rte_pktmbuf_pkt_len(m) != 0)
194 GOTO_FAIL("Bad length");
196 rte_pktmbuf_dump(m, 0);
200 data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN);
202 GOTO_FAIL("Cannot append data");
203 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
204 GOTO_FAIL("Bad pkt length");
205 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
206 GOTO_FAIL("Bad data length");
207 memset(data, 0x66, rte_pktmbuf_pkt_len(m));
208 if (!rte_pktmbuf_is_contiguous(m))
209 GOTO_FAIL("Buffer should be continuous");
210 rte_pktmbuf_dump(m, MBUF_TEST_DATA_LEN);
211 rte_pktmbuf_dump(m, 2*MBUF_TEST_DATA_LEN);
213 /* this append should fail */
215 data2 = rte_pktmbuf_append(m, (uint16_t)(rte_pktmbuf_tailroom(m) + 1));
217 GOTO_FAIL("Append should not succeed");
219 /* append some more data */
221 data2 = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN2);
223 GOTO_FAIL("Cannot append data");
224 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_DATA_LEN2)
225 GOTO_FAIL("Bad pkt length");
226 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_DATA_LEN2)
227 GOTO_FAIL("Bad data length");
228 if (!rte_pktmbuf_is_contiguous(m))
229 GOTO_FAIL("Buffer should be continuous");
231 /* trim data at the end of mbuf */
233 if (rte_pktmbuf_trim(m, MBUF_TEST_DATA_LEN2) < 0)
234 GOTO_FAIL("Cannot trim data");
235 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
236 GOTO_FAIL("Bad pkt length");
237 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
238 GOTO_FAIL("Bad data length");
239 if (!rte_pktmbuf_is_contiguous(m))
240 GOTO_FAIL("Buffer should be continuous");
242 /* this trim should fail */
244 if (rte_pktmbuf_trim(m, (uint16_t)(rte_pktmbuf_data_len(m) + 1)) == 0)
245 GOTO_FAIL("trim should not succeed");
247 /* prepend one header */
249 hdr = rte_pktmbuf_prepend(m, MBUF_TEST_HDR1_LEN);
251 GOTO_FAIL("Cannot prepend");
252 if (data - hdr != MBUF_TEST_HDR1_LEN)
253 GOTO_FAIL("Prepend failed");
254 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_HDR1_LEN)
255 GOTO_FAIL("Bad pkt length");
256 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_HDR1_LEN)
257 GOTO_FAIL("Bad data length");
258 if (!rte_pktmbuf_is_contiguous(m))
259 GOTO_FAIL("Buffer should be continuous");
260 memset(hdr, 0x55, MBUF_TEST_HDR1_LEN);
262 /* prepend another header */
264 hdr = rte_pktmbuf_prepend(m, MBUF_TEST_HDR2_LEN);
266 GOTO_FAIL("Cannot prepend");
267 if (data - hdr != MBUF_TEST_ALL_HDRS_LEN)
268 GOTO_FAIL("Prepend failed");
269 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_ALL_HDRS_LEN)
270 GOTO_FAIL("Bad pkt length");
271 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_ALL_HDRS_LEN)
272 GOTO_FAIL("Bad data length");
273 if (!rte_pktmbuf_is_contiguous(m))
274 GOTO_FAIL("Buffer should be continuous");
275 memset(hdr, 0x55, MBUF_TEST_HDR2_LEN);
277 rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 1);
278 rte_mbuf_sanity_check(m, RTE_MBUF_PKT, 0);
279 rte_pktmbuf_dump(m, 0);
281 /* this prepend should fail */
283 hdr = rte_pktmbuf_prepend(m, (uint16_t)(rte_pktmbuf_headroom(m) + 1));
285 GOTO_FAIL("prepend should not succeed");
287 /* remove data at beginning of mbuf (adj) */
289 if (data != rte_pktmbuf_adj(m, MBUF_TEST_ALL_HDRS_LEN))
290 GOTO_FAIL("rte_pktmbuf_adj failed");
291 if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
292 GOTO_FAIL("Bad pkt length");
293 if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
294 GOTO_FAIL("Bad data length");
295 if (!rte_pktmbuf_is_contiguous(m))
296 GOTO_FAIL("Buffer should be continuous");
298 /* this adj should fail */
300 if (rte_pktmbuf_adj(m, (uint16_t)(rte_pktmbuf_data_len(m) + 1)) != NULL)
301 GOTO_FAIL("rte_pktmbuf_adj should not succeed");
305 if (!rte_pktmbuf_is_contiguous(m))
306 GOTO_FAIL("Buffer should be continuous");
308 for (i=0; i<MBUF_TEST_DATA_LEN; i++) {
310 GOTO_FAIL("Data corrupted at offset %u", i);
329 test_one_ctrlmbuf(void)
331 struct rte_mbuf *m = NULL;
332 char message[] = "This is a message carried by a ctrlmbuf";
334 printf("Test ctrlmbuf API\n");
338 m = rte_ctrlmbuf_alloc(ctrlmbuf_pool);
340 GOTO_FAIL("Cannot allocate mbuf");
341 if (rte_ctrlmbuf_len(m) != 0)
342 GOTO_FAIL("Bad length");
345 rte_ctrlmbuf_data(m) = &message;
346 rte_ctrlmbuf_len(m) = sizeof(message);
349 if (rte_ctrlmbuf_data(m) != message)
350 GOTO_FAIL("Invalid data pointer");
351 if (rte_ctrlmbuf_len(m) != sizeof(message))
352 GOTO_FAIL("Invalid len");
354 rte_mbuf_sanity_check(m, RTE_MBUF_CTRL, 0);
357 rte_ctrlmbuf_free(m);
363 rte_ctrlmbuf_free(m);
368 testclone_testupdate_testdetach(void)
370 #ifndef RTE_MBUF_SCATTER_GATHER
373 struct rte_mbuf *mc = NULL;
374 struct rte_mbuf *clone = NULL;
378 mc = rte_pktmbuf_alloc(pktmbuf_pool);
380 GOTO_FAIL("ooops not allocating mbuf");
382 if (rte_pktmbuf_pkt_len(mc) != 0)
383 GOTO_FAIL("Bad length");
386 /* clone the allocated mbuf */
387 clone = rte_pktmbuf_clone(mc, pktmbuf_pool);
389 GOTO_FAIL("cannot clone data\n");
390 rte_pktmbuf_free(clone);
392 mc->pkt.next = rte_pktmbuf_alloc(pktmbuf_pool);
393 if(mc->pkt.next == NULL)
394 GOTO_FAIL("Next Pkt Null\n");
396 clone = rte_pktmbuf_clone(mc, pktmbuf_pool);
398 GOTO_FAIL("cannot clone data\n");
401 rte_pktmbuf_free(mc);
402 rte_pktmbuf_free(clone);
409 rte_pktmbuf_free(mc);
411 #endif /* RTE_MBUF_SCATTER_GATHER */
418 * test allocation and free of mbufs
421 test_pktmbuf_pool(void)
424 struct rte_mbuf *m[NB_MBUF];
427 for (i=0; i<NB_MBUF; i++)
430 /* alloc NB_MBUF mbufs */
431 for (i=0; i<NB_MBUF; i++) {
432 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
434 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
438 struct rte_mbuf *extra = NULL;
439 extra = rte_pktmbuf_alloc(pktmbuf_pool);
441 printf("Error pool not empty");
444 #ifdef RTE_MBUF_SCATTER_GATHER
445 extra = rte_pktmbuf_clone(m[0], pktmbuf_pool);
447 printf("Error pool not empty");
452 for (i=0; i<NB_MBUF; i++) {
454 rte_pktmbuf_free(m[i]);
461 * test that the pointer to the data on a packet mbuf is set properly
464 test_pktmbuf_pool_ptr(void)
467 struct rte_mbuf *m[NB_MBUF];
470 for (i=0; i<NB_MBUF; i++)
473 /* alloc NB_MBUF mbufs */
474 for (i=0; i<NB_MBUF; i++) {
475 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
477 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
480 m[i]->pkt.data = RTE_PTR_ADD(m[i]->pkt.data, 64);
484 for (i=0; i<NB_MBUF; i++) {
486 rte_pktmbuf_free(m[i]);
489 for (i=0; i<NB_MBUF; i++)
492 /* alloc NB_MBUF mbufs */
493 for (i=0; i<NB_MBUF; i++) {
494 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
496 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
499 if (m[i]->pkt.data != RTE_PTR_ADD(m[i]->buf_addr, RTE_PKTMBUF_HEADROOM)) {
500 printf ("pkt.data pointer not set properly\n");
506 for (i=0; i<NB_MBUF; i++) {
508 rte_pktmbuf_free(m[i]);
515 test_pktmbuf_free_segment(void)
518 struct rte_mbuf *m[NB_MBUF];
521 for (i=0; i<NB_MBUF; i++)
524 /* alloc NB_MBUF mbufs */
525 for (i=0; i<NB_MBUF; i++) {
526 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
528 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
534 for (i=0; i<NB_MBUF; i++) {
536 struct rte_mbuf *mb, *mt;
542 rte_pktmbuf_free_seg(mt);
551 * Stress test for rte_mbuf atomic refcnt.
553 * RTE_MBUF_SCATTER_GATHER and RTE_MBUF_REFCNT_ATOMIC are both defined.
554 * For more efficency, recomended to run with RTE_LIBRTE_MBUF_DEBUG defined.
557 #if defined RTE_MBUF_SCATTER_GATHER && defined RTE_MBUF_REFCNT_ATOMIC
560 test_refcnt_slave(__attribute__((unused)) void *arg)
562 unsigned lcore, free;
565 lcore = rte_lcore_id();
566 printf("%s started at lcore %u\n", __func__, lcore);
569 while (refcnt_stop_slaves == 0) {
570 if (rte_ring_dequeue(refcnt_mbuf_ring, &mp) == 0) {
572 rte_pktmbuf_free((struct rte_mbuf *)mp);
576 refcnt_lcore[lcore] += free;
577 printf("%s finished at lcore %u, "
578 "number of freed mbufs: %u\n",
579 __func__, lcore, free);
584 test_refcnt_iter(unsigned lcore, unsigned iter)
587 unsigned i, n, tref, wn;
592 /* For each mbuf in the pool:
594 * - increment it's reference up to N+1,
595 * - enqueue it N times into the ring for slave cores to free.
597 for (i = 0, n = rte_mempool_count(refcnt_pool);
598 i != n && (m = rte_pktmbuf_alloc(refcnt_pool)) != NULL;
600 ref = RTE_MAX(rte_rand() % REFCNT_MAX_REF, 1UL);
602 if ((ref & 1) != 0) {
603 rte_pktmbuf_refcnt_update(m, ref);
605 rte_ring_enqueue(refcnt_mbuf_ring, m);
608 rte_pktmbuf_refcnt_update(m, 1);
609 rte_ring_enqueue(refcnt_mbuf_ring, m);
616 rte_panic("(lcore=%u, iter=%u): was able to allocate only "
617 "%u from %u mbufs\n", lcore, iter, i, n);
619 /* wait till slave lcores will consume all mbufs */
620 while (!rte_ring_empty(refcnt_mbuf_ring))
623 /* check that all mbufs are back into mempool by now */
624 for (wn = 0; wn != REFCNT_MAX_TIMEOUT; wn++) {
625 if ((i = rte_mempool_count(refcnt_pool)) == n) {
626 refcnt_lcore[lcore] += tref;
627 printf("%s(lcore=%u, iter=%u) completed, "
628 "%u references processed\n",
629 __func__, lcore, iter, tref);
635 rte_panic("(lcore=%u, iter=%u): after %us only "
636 "%u of %u mbufs left free\n", lcore, iter, wn, i, n);
640 test_refcnt_master(void)
644 lcore = rte_lcore_id();
645 printf("%s started at lcore %u\n", __func__, lcore);
647 for (i = 0; i != REFCNT_MAX_ITER; i++)
648 test_refcnt_iter(lcore, i);
650 refcnt_stop_slaves = 1;
653 printf("%s finished at lcore %u\n", __func__, lcore);
660 test_refcnt_mbuf(void)
662 #if defined RTE_MBUF_SCATTER_GATHER && defined RTE_MBUF_REFCNT_ATOMIC
664 unsigned lnum, master, slave, tref;
667 if ((lnum = rte_lcore_count()) == 1) {
668 printf("skipping %s, number of lcores: %u is not enough\n",
673 printf("starting %s, at %u lcores\n", __func__, lnum);
675 /* create refcnt pool & ring if they don't exist */
677 if (refcnt_pool == NULL &&
678 (refcnt_pool = rte_mempool_create(
679 MAKE_STRING(refcnt_pool),
680 REFCNT_MBUF_NUM, REFCNT_MBUF_SIZE, 0,
681 sizeof(struct rte_pktmbuf_pool_private),
682 rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL,
683 SOCKET_ID_ANY, 0)) == NULL) {
684 printf("%s: cannot allocate " MAKE_STRING(refcnt_pool) "\n",
689 if (refcnt_mbuf_ring == NULL &&
690 (refcnt_mbuf_ring = rte_ring_create("refcnt_mbuf_ring",
691 REFCNT_RING_SIZE, SOCKET_ID_ANY,
692 RING_F_SP_ENQ)) == NULL) {
693 printf("%s: cannot allocate " MAKE_STRING(refcnt_mbuf_ring)
698 refcnt_stop_slaves = 0;
699 memset(refcnt_lcore, 0, sizeof (refcnt_lcore));
701 rte_eal_mp_remote_launch(test_refcnt_slave, NULL, SKIP_MASTER);
703 test_refcnt_master();
705 rte_eal_mp_wait_lcore();
707 /* check that we porcessed all references */
709 master = rte_get_master_lcore();
711 RTE_LCORE_FOREACH_SLAVE(slave)
712 tref += refcnt_lcore[slave];
714 if (tref != refcnt_lcore[master])
715 rte_panic("refernced mbufs: %u, freed mbufs: %u\n",
716 tref, refcnt_lcore[master]);
718 rte_mempool_dump(refcnt_pool);
719 rte_ring_dump(refcnt_mbuf_ring);
725 #ifdef RTE_EXEC_ENV_BAREMETAL
727 /* baremetal - don't test failing sanity checks */
729 test_failing_mbuf_sanity_check(void)
737 #include <sys/wait.h>
739 /* linuxapp - use fork() to test mbuf errors panic */
741 verify_mbuf_check_panics(struct rte_mbuf *buf)
749 rte_mbuf_sanity_check(buf, RTE_MBUF_PKT, 1); /* should panic */
750 exit(0); /* return normally if it doesn't panic */
752 printf("Fork Failed\n");
763 test_failing_mbuf_sanity_check(void)
765 struct rte_mbuf *buf;
766 struct rte_mbuf badbuf;
768 printf("Checking rte_mbuf_sanity_check for failure conditions\n");
770 /* get a good mbuf to use to make copies */
771 buf = rte_pktmbuf_alloc(pktmbuf_pool);
774 printf("Checking good mbuf initially\n");
775 if (verify_mbuf_check_panics(buf) != -1)
778 printf("Now checking for error conditions\n");
780 if (verify_mbuf_check_panics(NULL)) {
781 printf("Error with NULL mbuf test\n");
786 badbuf.type = (uint8_t)-1;
787 if (verify_mbuf_check_panics(&badbuf)) {
788 printf("Error with bad-type mbuf test\n");
794 if (verify_mbuf_check_panics(&badbuf)) {
795 printf("Error with bad-pool mbuf test\n");
800 badbuf.buf_physaddr = 0;
801 if (verify_mbuf_check_panics(&badbuf)) {
802 printf("Error with bad-physaddr mbuf test\n");
807 badbuf.buf_addr = NULL;
808 if (verify_mbuf_check_panics(&badbuf)) {
809 printf("Error with bad-addr mbuf test\n");
813 #ifdef RTE_MBUF_SCATTER_GATHER
816 if (verify_mbuf_check_panics(&badbuf)) {
817 printf("Error with bad-refcnt(0) mbuf test\n");
822 badbuf.refcnt = UINT16_MAX;
823 if (verify_mbuf_check_panics(&badbuf)) {
824 printf("Error with bad-refcnt(MAX) mbuf test\n");
837 RTE_BUILD_BUG_ON(sizeof(struct rte_mbuf) != 64);
839 /* create pktmbuf pool if it does not exist */
840 if (pktmbuf_pool == NULL) {
842 rte_mempool_create("test_pktmbuf_pool", NB_MBUF,
844 sizeof(struct rte_pktmbuf_pool_private),
845 rte_pktmbuf_pool_init, NULL,
846 rte_pktmbuf_init, NULL,
850 if (pktmbuf_pool == NULL) {
851 printf("cannot allocate mbuf pool\n");
855 /* test multiple mbuf alloc */
856 if (test_pktmbuf_pool() < 0) {
857 printf("test_mbuf_pool() failed\n");
861 /* do it another time to check that all mbufs were freed */
862 if (test_pktmbuf_pool() < 0) {
863 printf("test_mbuf_pool() failed (2)\n");
867 /* test that the pointer to the data on a packet mbuf is set properly */
868 if (test_pktmbuf_pool_ptr() < 0) {
869 printf("test_pktmbuf_pool_ptr() failed\n");
873 /* test data manipulation in mbuf */
874 if (test_one_pktmbuf() < 0) {
875 printf("test_one_mbuf() failed\n");
881 * do it another time, to check that allocation reinitialize
884 if (test_one_pktmbuf() < 0) {
885 printf("test_one_mbuf() failed (2)\n");
889 if (test_pktmbuf_with_non_ascii_data() < 0) {
890 printf("test_pktmbuf_with_non_ascii_data() failed\n");
894 /* create ctrlmbuf pool if it does not exist */
895 if (ctrlmbuf_pool == NULL) {
897 rte_mempool_create("test_ctrlmbuf_pool", NB_MBUF,
898 sizeof(struct rte_mbuf), 32, 0,
900 rte_ctrlmbuf_init, NULL,
904 /* test control mbuf */
905 if (test_one_ctrlmbuf() < 0) {
906 printf("test_one_ctrlmbuf() failed\n");
910 /* test free pktmbuf segment one by one */
911 if (test_pktmbuf_free_segment() < 0) {
912 printf("test_pktmbuf_free_segment() failed.\n");
916 if (testclone_testupdate_testdetach()<0){
917 printf("testclone_and_testupdate() failed \n");
921 if (test_refcnt_mbuf()<0){
922 printf("test_refcnt_mbuf() failed \n");
926 if (test_failing_mbuf_sanity_check() < 0) {
927 printf("test_failing_mbuf_sanity_check() failed\n");