| 422 | } |
| 423 | |
| 424 | static int |
| 425 | test_pktmbuf_copy(struct rte_mempool *pktmbuf_pool, |
| 426 | struct rte_mempool *clone_pool) |
| 427 | { |
| 428 | struct rte_mbuf *m = NULL; |
| 429 | struct rte_mbuf *copy = NULL; |
| 430 | struct rte_mbuf *copy2 = NULL; |
| 431 | struct rte_mbuf *clone = NULL; |
| 432 | unaligned_uint32_t *data; |
| 433 | |
| 434 | /* alloc a mbuf */ |
| 435 | m = rte_pktmbuf_alloc(pktmbuf_pool); |
| 436 | if (m == NULL) |
| 437 | GOTO_FAIL("ooops not allocating mbuf"); |
| 438 | |
| 439 | if (rte_pktmbuf_pkt_len(m) != 0) |
| 440 | GOTO_FAIL("Bad length"); |
| 441 | |
| 442 | rte_pktmbuf_append(m, sizeof(uint32_t)); |
| 443 | data = rte_pktmbuf_mtod(m, unaligned_uint32_t *); |
| 444 | *data = MAGIC_DATA; |
| 445 | |
| 446 | /* copy the allocated mbuf */ |
| 447 | copy = rte_pktmbuf_copy(m, pktmbuf_pool, 0, UINT32_MAX); |
| 448 | if (copy == NULL) |
| 449 | GOTO_FAIL("cannot copy data\n"); |
| 450 | |
| 451 | if (rte_pktmbuf_pkt_len(copy) != sizeof(uint32_t)) |
| 452 | GOTO_FAIL("copy length incorrect\n"); |
| 453 | |
| 454 | if (rte_pktmbuf_data_len(copy) != sizeof(uint32_t)) |
| 455 | GOTO_FAIL("copy data length incorrect\n"); |
| 456 | |
| 457 | data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *); |
| 458 | if (*data != MAGIC_DATA) |
| 459 | GOTO_FAIL("invalid data in copy\n"); |
| 460 | |
| 461 | /* free the copy */ |
| 462 | rte_pktmbuf_free(copy); |
| 463 | copy = NULL; |
| 464 | |
| 465 | /* same test with a cloned mbuf */ |
| 466 | clone = rte_pktmbuf_clone(m, clone_pool); |
| 467 | if (clone == NULL) |
| 468 | GOTO_FAIL("cannot clone data\n"); |
| 469 | |
| 470 | if ((!RTE_MBUF_HAS_PINNED_EXTBUF(m) && |
| 471 | !RTE_MBUF_CLONED(clone)) || |
| 472 | (RTE_MBUF_HAS_PINNED_EXTBUF(m) && |
| 473 | !RTE_MBUF_HAS_EXTBUF(clone))) |
| 474 | GOTO_FAIL("clone did not give a cloned mbuf\n"); |
| 475 | |
| 476 | copy = rte_pktmbuf_copy(clone, pktmbuf_pool, 0, UINT32_MAX); |
| 477 | if (copy == NULL) |
| 478 | GOTO_FAIL("cannot copy cloned mbuf\n"); |
| 479 | |
| 480 | if (RTE_MBUF_CLONED(copy)) |
| 481 | GOTO_FAIL("copy of clone is cloned?\n"); |
no test coverage detected