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>
52 #include <rte_per_lcore.h>
53 #include <rte_lcore.h>
54 #include <rte_atomic.h>
55 #include <rte_branch_prediction.h>
57 #include <rte_mempool.h>
59 #include <rte_random.h>
60 #include <rte_cycles.h>
64 #define MBUF_DATA_SIZE 2048
66 #define MBUF_TEST_DATA_LEN 1464
67 #define MBUF_TEST_DATA_LEN2 50
68 #define MBUF_TEST_HDR1_LEN 20
69 #define MBUF_TEST_HDR2_LEN 30
70 #define MBUF_TEST_ALL_HDRS_LEN (MBUF_TEST_HDR1_LEN+MBUF_TEST_HDR2_LEN)
72 #define REFCNT_MAX_ITER 64
73 #define REFCNT_MAX_TIMEOUT 10
74 #define REFCNT_MAX_REF (RTE_MAX_LCORE)
75 #define REFCNT_MBUF_NUM 64
76 #define REFCNT_RING_SIZE (REFCNT_MBUF_NUM * REFCNT_MAX_REF)
78 #define MAGIC_DATA 0x42424242
80 #define MAKE_STRING(x) # x
82 static struct rte_mempool *pktmbuf_pool = NULL;
84 #ifdef RTE_MBUF_REFCNT_ATOMIC
86 static struct rte_mempool *refcnt_pool = NULL;
87 static struct rte_ring *refcnt_mbuf_ring = NULL;
88 static volatile uint32_t refcnt_stop_slaves;
89 static unsigned refcnt_lcore[RTE_MAX_LCORE];
97 * #. Allocate a mbuf pool.
99 * - The pool contains NB_MBUF elements, where each mbuf is MBUF_SIZE
102 * #. Test multiple allocations of mbufs from this pool.
104 * - Allocate NB_MBUF and store pointers in a table.
105 * - If an allocation fails, return an error.
106 * - Free all these mbufs.
107 * - Repeat the same test to check that mbufs were freed correctly.
109 * #. Test data manipulation in pktmbuf.
112 * - Append data using rte_pktmbuf_append().
113 * - Test for error in rte_pktmbuf_append() when len is too large.
114 * - Trim data at the end of mbuf using rte_pktmbuf_trim().
115 * - Test for error in rte_pktmbuf_trim() when len is too large.
116 * - Prepend a header using rte_pktmbuf_prepend().
117 * - Test for error in rte_pktmbuf_prepend() when len is too large.
118 * - Remove data at the beginning of mbuf using rte_pktmbuf_adj().
119 * - Test for error in rte_pktmbuf_adj() when len is too large.
120 * - Check that appended data is not corrupt.
122 * - Between all these tests, check data_len and pkt_len, and
123 * that the mbuf is contiguous.
124 * - Repeat the test to check that allocation operations
125 * reinitialize the mbuf correctly.
127 * #. Test packet cloning
128 * - Clone a mbuf and verify the data
129 * - Clone the cloned mbuf and verify the data
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(stdout, 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(stdout, 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(stdout, m, MBUF_TEST_DATA_LEN);
211 rte_pktmbuf_dump(stdout, 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, 1);
278 rte_mbuf_sanity_check(m, 0);
279 rte_pktmbuf_dump(stdout, 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);
326 testclone_testupdate_testdetach(void)
328 struct rte_mbuf *m = NULL;
329 struct rte_mbuf *clone = NULL;
330 struct rte_mbuf *clone2 = NULL;
334 m = rte_pktmbuf_alloc(pktmbuf_pool);
336 GOTO_FAIL("ooops not allocating mbuf");
338 if (rte_pktmbuf_pkt_len(m) != 0)
339 GOTO_FAIL("Bad length");
341 rte_pktmbuf_append(m, sizeof(uint32_t));
342 data = rte_pktmbuf_mtod(m, uint32_t *);
345 /* clone the allocated mbuf */
346 clone = rte_pktmbuf_clone(m, pktmbuf_pool);
348 GOTO_FAIL("cannot clone data\n");
350 data = rte_pktmbuf_mtod(clone, uint32_t *);
351 if (*data != MAGIC_DATA)
352 GOTO_FAIL("invalid data in clone\n");
354 if (rte_mbuf_refcnt_read(m) != 2)
355 GOTO_FAIL("invalid refcnt in m\n");
358 rte_pktmbuf_free(clone);
361 /* same test with a chained mbuf */
362 m->next = rte_pktmbuf_alloc(pktmbuf_pool);
364 GOTO_FAIL("Next Pkt Null\n");
366 rte_pktmbuf_append(m->next, sizeof(uint32_t));
367 data = rte_pktmbuf_mtod(m->next, uint32_t *);
370 clone = rte_pktmbuf_clone(m, pktmbuf_pool);
372 GOTO_FAIL("cannot clone data\n");
374 data = rte_pktmbuf_mtod(clone, uint32_t *);
375 if (*data != MAGIC_DATA)
376 GOTO_FAIL("invalid data in clone\n");
378 data = rte_pktmbuf_mtod(clone->next, uint32_t *);
379 if (*data != MAGIC_DATA)
380 GOTO_FAIL("invalid data in clone->next\n");
382 if (rte_mbuf_refcnt_read(m) != 2)
383 GOTO_FAIL("invalid refcnt in m\n");
385 if (rte_mbuf_refcnt_read(m->next) != 2)
386 GOTO_FAIL("invalid refcnt in m->next\n");
388 /* try to clone the clone */
390 clone2 = rte_pktmbuf_clone(clone, pktmbuf_pool);
392 GOTO_FAIL("cannot clone the clone\n");
394 data = rte_pktmbuf_mtod(clone2, uint32_t *);
395 if (*data != MAGIC_DATA)
396 GOTO_FAIL("invalid data in clone2\n");
398 data = rte_pktmbuf_mtod(clone2->next, uint32_t *);
399 if (*data != MAGIC_DATA)
400 GOTO_FAIL("invalid data in clone2->next\n");
402 if (rte_mbuf_refcnt_read(m) != 3)
403 GOTO_FAIL("invalid refcnt in m\n");
405 if (rte_mbuf_refcnt_read(m->next) != 3)
406 GOTO_FAIL("invalid refcnt in m->next\n");
410 rte_pktmbuf_free(clone);
411 rte_pktmbuf_free(clone2);
416 printf("%s ok\n", __func__);
423 rte_pktmbuf_free(clone);
425 rte_pktmbuf_free(clone2);
433 * test allocation and free of mbufs
436 test_pktmbuf_pool(void)
439 struct rte_mbuf *m[NB_MBUF];
442 for (i=0; i<NB_MBUF; i++)
445 /* alloc NB_MBUF mbufs */
446 for (i=0; i<NB_MBUF; i++) {
447 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
449 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
453 struct rte_mbuf *extra = NULL;
454 extra = rte_pktmbuf_alloc(pktmbuf_pool);
456 printf("Error pool not empty");
459 extra = rte_pktmbuf_clone(m[0], pktmbuf_pool);
461 printf("Error pool not empty");
465 for (i=0; i<NB_MBUF; i++) {
467 rte_pktmbuf_free(m[i]);
474 * test that the pointer to the data on a packet mbuf is set properly
477 test_pktmbuf_pool_ptr(void)
480 struct rte_mbuf *m[NB_MBUF];
483 for (i=0; i<NB_MBUF; i++)
486 /* alloc NB_MBUF mbufs */
487 for (i=0; i<NB_MBUF; i++) {
488 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
490 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
493 m[i]->data_off += 64;
497 for (i=0; i<NB_MBUF; i++) {
499 rte_pktmbuf_free(m[i]);
502 for (i=0; i<NB_MBUF; i++)
505 /* alloc NB_MBUF mbufs */
506 for (i=0; i<NB_MBUF; i++) {
507 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
509 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
512 if (m[i]->data_off != RTE_PKTMBUF_HEADROOM) {
513 printf("invalid data_off\n");
519 for (i=0; i<NB_MBUF; i++) {
521 rte_pktmbuf_free(m[i]);
528 test_pktmbuf_free_segment(void)
531 struct rte_mbuf *m[NB_MBUF];
534 for (i=0; i<NB_MBUF; i++)
537 /* alloc NB_MBUF mbufs */
538 for (i=0; i<NB_MBUF; i++) {
539 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
541 printf("rte_pktmbuf_alloc() failed (%u)\n", i);
547 for (i=0; i<NB_MBUF; i++) {
549 struct rte_mbuf *mb, *mt;
555 rte_pktmbuf_free_seg(mt);
564 * Stress test for rte_mbuf atomic refcnt.
565 * Implies that RTE_MBUF_REFCNT_ATOMIC is defined.
566 * For more efficency, recomended to run with RTE_LIBRTE_MBUF_DEBUG defined.
569 #ifdef RTE_MBUF_REFCNT_ATOMIC
572 test_refcnt_slave(__attribute__((unused)) void *arg)
574 unsigned lcore, free;
577 lcore = rte_lcore_id();
578 printf("%s started at lcore %u\n", __func__, lcore);
581 while (refcnt_stop_slaves == 0) {
582 if (rte_ring_dequeue(refcnt_mbuf_ring, &mp) == 0) {
584 rte_pktmbuf_free((struct rte_mbuf *)mp);
588 refcnt_lcore[lcore] += free;
589 printf("%s finished at lcore %u, "
590 "number of freed mbufs: %u\n",
591 __func__, lcore, free);
596 test_refcnt_iter(unsigned lcore, unsigned iter)
599 unsigned i, n, tref, wn;
604 /* For each mbuf in the pool:
606 * - increment it's reference up to N+1,
607 * - enqueue it N times into the ring for slave cores to free.
609 for (i = 0, n = rte_mempool_count(refcnt_pool);
610 i != n && (m = rte_pktmbuf_alloc(refcnt_pool)) != NULL;
612 ref = RTE_MAX(rte_rand() % REFCNT_MAX_REF, 1UL);
614 if ((ref & 1) != 0) {
615 rte_pktmbuf_refcnt_update(m, ref);
617 rte_ring_enqueue(refcnt_mbuf_ring, m);
620 rte_pktmbuf_refcnt_update(m, 1);
621 rte_ring_enqueue(refcnt_mbuf_ring, m);
628 rte_panic("(lcore=%u, iter=%u): was able to allocate only "
629 "%u from %u mbufs\n", lcore, iter, i, n);
631 /* wait till slave lcores will consume all mbufs */
632 while (!rte_ring_empty(refcnt_mbuf_ring))
635 /* check that all mbufs are back into mempool by now */
636 for (wn = 0; wn != REFCNT_MAX_TIMEOUT; wn++) {
637 if ((i = rte_mempool_count(refcnt_pool)) == n) {
638 refcnt_lcore[lcore] += tref;
639 printf("%s(lcore=%u, iter=%u) completed, "
640 "%u references processed\n",
641 __func__, lcore, iter, tref);
647 rte_panic("(lcore=%u, iter=%u): after %us only "
648 "%u of %u mbufs left free\n", lcore, iter, wn, i, n);
652 test_refcnt_master(void)
656 lcore = rte_lcore_id();
657 printf("%s started at lcore %u\n", __func__, lcore);
659 for (i = 0; i != REFCNT_MAX_ITER; i++)
660 test_refcnt_iter(lcore, i);
662 refcnt_stop_slaves = 1;
665 printf("%s finished at lcore %u\n", __func__, lcore);
672 test_refcnt_mbuf(void)
674 #ifdef RTE_MBUF_REFCNT_ATOMIC
676 unsigned lnum, master, slave, tref;
679 if ((lnum = rte_lcore_count()) == 1) {
680 printf("skipping %s, number of lcores: %u is not enough\n",
685 printf("starting %s, at %u lcores\n", __func__, lnum);
687 /* create refcnt pool & ring if they don't exist */
689 if (refcnt_pool == NULL &&
690 (refcnt_pool = rte_pktmbuf_pool_create(
691 MAKE_STRING(refcnt_pool),
692 REFCNT_MBUF_NUM, 0, 0, 0,
693 SOCKET_ID_ANY)) == NULL) {
694 printf("%s: cannot allocate " MAKE_STRING(refcnt_pool) "\n",
699 if (refcnt_mbuf_ring == NULL &&
700 (refcnt_mbuf_ring = rte_ring_create("refcnt_mbuf_ring",
701 REFCNT_RING_SIZE, SOCKET_ID_ANY,
702 RING_F_SP_ENQ)) == NULL) {
703 printf("%s: cannot allocate " MAKE_STRING(refcnt_mbuf_ring)
708 refcnt_stop_slaves = 0;
709 memset(refcnt_lcore, 0, sizeof (refcnt_lcore));
711 rte_eal_mp_remote_launch(test_refcnt_slave, NULL, SKIP_MASTER);
713 test_refcnt_master();
715 rte_eal_mp_wait_lcore();
717 /* check that we porcessed all references */
719 master = rte_get_master_lcore();
721 RTE_LCORE_FOREACH_SLAVE(slave)
722 tref += refcnt_lcore[slave];
724 if (tref != refcnt_lcore[master])
725 rte_panic("refernced mbufs: %u, freed mbufs: %u\n",
726 tref, refcnt_lcore[master]);
728 rte_mempool_dump(stdout, refcnt_pool);
729 rte_ring_dump(stdout, refcnt_mbuf_ring);
736 #include <sys/wait.h>
738 /* use fork() to test mbuf errors panic */
740 verify_mbuf_check_panics(struct rte_mbuf *buf)
748 rte_mbuf_sanity_check(buf, 1); /* should panic */
749 exit(0); /* return normally if it doesn't panic */
751 printf("Fork Failed\n");
762 test_failing_mbuf_sanity_check(void)
764 struct rte_mbuf *buf;
765 struct rte_mbuf badbuf;
767 printf("Checking rte_mbuf_sanity_check for failure conditions\n");
769 /* get a good mbuf to use to make copies */
770 buf = rte_pktmbuf_alloc(pktmbuf_pool);
773 printf("Checking good mbuf initially\n");
774 if (verify_mbuf_check_panics(buf) != -1)
777 printf("Now checking for error conditions\n");
779 if (verify_mbuf_check_panics(NULL)) {
780 printf("Error with NULL mbuf test\n");
786 if (verify_mbuf_check_panics(&badbuf)) {
787 printf("Error with bad-pool mbuf test\n");
792 badbuf.buf_physaddr = 0;
793 if (verify_mbuf_check_panics(&badbuf)) {
794 printf("Error with bad-physaddr mbuf test\n");
799 badbuf.buf_addr = NULL;
800 if (verify_mbuf_check_panics(&badbuf)) {
801 printf("Error with bad-addr mbuf test\n");
807 if (verify_mbuf_check_panics(&badbuf)) {
808 printf("Error with bad-refcnt(0) mbuf test\n");
813 badbuf.refcnt = UINT16_MAX;
814 if (verify_mbuf_check_panics(&badbuf)) {
815 printf("Error with bad-refcnt(MAX) mbuf test\n");
826 RTE_BUILD_BUG_ON(sizeof(struct rte_mbuf) != RTE_CACHE_LINE_SIZE * 2);
828 /* create pktmbuf pool if it does not exist */
829 if (pktmbuf_pool == NULL) {
830 pktmbuf_pool = rte_pktmbuf_pool_create("test_pktmbuf_pool",
831 NB_MBUF, 32, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY);
834 if (pktmbuf_pool == NULL) {
835 printf("cannot allocate mbuf pool\n");
839 /* test multiple mbuf alloc */
840 if (test_pktmbuf_pool() < 0) {
841 printf("test_mbuf_pool() failed\n");
845 /* do it another time to check that all mbufs were freed */
846 if (test_pktmbuf_pool() < 0) {
847 printf("test_mbuf_pool() failed (2)\n");
851 /* test that the pointer to the data on a packet mbuf is set properly */
852 if (test_pktmbuf_pool_ptr() < 0) {
853 printf("test_pktmbuf_pool_ptr() failed\n");
857 /* test data manipulation in mbuf */
858 if (test_one_pktmbuf() < 0) {
859 printf("test_one_mbuf() failed\n");
865 * do it another time, to check that allocation reinitialize
868 if (test_one_pktmbuf() < 0) {
869 printf("test_one_mbuf() failed (2)\n");
873 if (test_pktmbuf_with_non_ascii_data() < 0) {
874 printf("test_pktmbuf_with_non_ascii_data() failed\n");
878 /* test free pktmbuf segment one by one */
879 if (test_pktmbuf_free_segment() < 0) {
880 printf("test_pktmbuf_free_segment() failed.\n");
884 if (testclone_testupdate_testdetach()<0){
885 printf("testclone_and_testupdate() failed \n");
889 if (test_refcnt_mbuf()<0){
890 printf("test_refcnt_mbuf() failed \n");
894 if (test_failing_mbuf_sanity_check() < 0) {
895 printf("test_failing_mbuf_sanity_check() failed\n");
901 static struct test_command mbuf_cmd = {
902 .command = "mbuf_autotest",
903 .callback = test_mbuf,
905 REGISTER_TEST_COMMAND(mbuf_cmd);