* test bulk allocation and bulk free of mbufs */
| 722 | * test bulk allocation and bulk free of mbufs |
| 723 | */ |
| 724 | static int |
| 725 | test_pktmbuf_pool_bulk(void) |
| 726 | { |
| 727 | struct rte_mempool *pool = NULL; |
| 728 | struct rte_mempool *pool2 = NULL; |
| 729 | unsigned int i; |
| 730 | struct rte_mbuf *m; |
| 731 | struct rte_mbuf *mbufs[NB_MBUF]; |
| 732 | int ret = 0; |
| 733 | |
| 734 | /* We cannot use the preallocated mbuf pools because their caches |
| 735 | * prevent us from bulk allocating all objects in them. |
| 736 | * So we create our own mbuf pools without caches. |
| 737 | */ |
| 738 | printf("Create mbuf pools for bulk allocation.\n"); |
| 739 | pool = rte_pktmbuf_pool_create("test_pktmbuf_bulk", |
| 740 | NB_MBUF, 0, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY); |
| 741 | if (pool == NULL) { |
| 742 | printf("rte_pktmbuf_pool_create() failed. rte_errno %d\n", |
| 743 | rte_errno); |
| 744 | goto err; |
| 745 | } |
| 746 | pool2 = rte_pktmbuf_pool_create("test_pktmbuf_bulk2", |
| 747 | NB_MBUF, 0, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY); |
| 748 | if (pool2 == NULL) { |
| 749 | printf("rte_pktmbuf_pool_create() failed. rte_errno %d\n", |
| 750 | rte_errno); |
| 751 | goto err; |
| 752 | } |
| 753 | |
| 754 | /* Preconditions: Mempools must be full. */ |
| 755 | if (!(rte_mempool_full(pool) && rte_mempool_full(pool2))) { |
| 756 | printf("Test precondition failed: mempools not full\n"); |
| 757 | goto err; |
| 758 | } |
| 759 | if (!(rte_mempool_avail_count(pool) == NB_MBUF && |
| 760 | rte_mempool_avail_count(pool2) == NB_MBUF)) { |
| 761 | printf("Test precondition failed: mempools: %u+%u != %u+%u", |
| 762 | rte_mempool_avail_count(pool), |
| 763 | rte_mempool_avail_count(pool2), |
| 764 | NB_MBUF, NB_MBUF); |
| 765 | goto err; |
| 766 | } |
| 767 | |
| 768 | printf("Test single bulk alloc, followed by multiple bulk free.\n"); |
| 769 | |
| 770 | /* Bulk allocate all mbufs in the pool, in one go. */ |
| 771 | ret = rte_pktmbuf_alloc_bulk(pool, mbufs, NB_MBUF); |
| 772 | if (ret != 0) { |
| 773 | printf("rte_pktmbuf_alloc_bulk() failed: %d\n", ret); |
| 774 | goto err; |
| 775 | } |
| 776 | /* Test that they have been removed from the pool. */ |
| 777 | if (!rte_mempool_empty(pool)) { |
| 778 | printf("mempool not empty\n"); |
| 779 | goto err; |
| 780 | } |
| 781 | /* Bulk free all mbufs, in four steps. */ |
no test coverage detected