LCOV - code coverage report
Current view: top level - app/test - test_mbuf.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 752 1127 66.7 %
Date: 2024-01-22 15:35:40 Functions: 37 37 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 464 838 55.4 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "test.h"
       6                 :            : 
       7                 :            : #include <string.h>
       8                 :            : #include <stdarg.h>
       9                 :            : #include <stdio.h>
      10                 :            : #include <stdlib.h>
      11                 :            : #include <stdint.h>
      12                 :            : #include <inttypes.h>
      13                 :            : #include <errno.h>
      14                 :            : #include <sys/queue.h>
      15                 :            : 
      16                 :            : #include <rte_common.h>
      17                 :            : #include <rte_errno.h>
      18                 :            : #include <rte_debug.h>
      19                 :            : #include <rte_log.h>
      20                 :            : #include <rte_memory.h>
      21                 :            : #include <rte_memcpy.h>
      22                 :            : #include <rte_launch.h>
      23                 :            : #include <rte_eal.h>
      24                 :            : #include <rte_per_lcore.h>
      25                 :            : #include <rte_lcore.h>
      26                 :            : #include <rte_branch_prediction.h>
      27                 :            : #include <rte_ring.h>
      28                 :            : #include <rte_mempool.h>
      29                 :            : #include <rte_mbuf.h>
      30                 :            : #include <rte_random.h>
      31                 :            : #include <rte_cycles.h>
      32                 :            : #include <rte_malloc.h>
      33                 :            : #include <rte_ether.h>
      34                 :            : #include <rte_ip.h>
      35                 :            : #include <rte_tcp.h>
      36                 :            : #include <rte_mbuf_dyn.h>
      37                 :            : 
      38                 :            : #define MEMPOOL_CACHE_SIZE      32
      39                 :            : #define MBUF_DATA_SIZE          2048
      40                 :            : #define NB_MBUF                 128
      41                 :            : #define MBUF_TEST_DATA_LEN      1464
      42                 :            : #define MBUF_TEST_DATA_LEN2     50
      43                 :            : #define MBUF_TEST_DATA_LEN3     256
      44                 :            : #define MBUF_TEST_HDR1_LEN      20
      45                 :            : #define MBUF_TEST_HDR2_LEN      30
      46                 :            : #define MBUF_TEST_ALL_HDRS_LEN  (MBUF_TEST_HDR1_LEN+MBUF_TEST_HDR2_LEN)
      47                 :            : #define MBUF_TEST_SEG_SIZE      64
      48                 :            : #define MBUF_TEST_BURST         8
      49                 :            : #define EXT_BUF_TEST_DATA_LEN   1024
      50                 :            : #define MBUF_MAX_SEG            16
      51                 :            : #define MBUF_NO_HEADER          0
      52                 :            : #define MBUF_HEADER             1
      53                 :            : #define MBUF_NEG_TEST_READ      2
      54                 :            : #define VAL_NAME(flag)          { flag, #flag }
      55                 :            : 
      56                 :            : /* chain length in bulk test */
      57                 :            : #define CHAIN_LEN 16
      58                 :            : 
      59                 :            : /* size of private data for mbuf in pktmbuf_pool2 */
      60                 :            : #define MBUF2_PRIV_SIZE         128
      61                 :            : 
      62                 :            : #define REFCNT_MAX_ITER         64
      63                 :            : #define REFCNT_MAX_TIMEOUT      10
      64                 :            : #define REFCNT_MAX_REF          (RTE_MAX_LCORE)
      65                 :            : #define REFCNT_MBUF_NUM         64
      66                 :            : #define REFCNT_RING_SIZE        (REFCNT_MBUF_NUM * REFCNT_MAX_REF)
      67                 :            : 
      68                 :            : #define MAGIC_DATA              0x42424242
      69                 :            : 
      70                 :            : #define MAKE_STRING(x)          # x
      71                 :            : 
      72                 :            : #ifdef RTE_MBUF_REFCNT_ATOMIC
      73                 :            : 
      74                 :            : static volatile uint32_t refcnt_stop_workers;
      75                 :            : static unsigned refcnt_lcore[RTE_MAX_LCORE];
      76                 :            : 
      77                 :            : #endif
      78                 :            : 
      79                 :            : /*
      80                 :            :  * MBUF
      81                 :            :  * ====
      82                 :            :  *
      83                 :            :  * #. Allocate a mbuf pool.
      84                 :            :  *
      85                 :            :  *    - The pool contains NB_MBUF elements, where each mbuf is MBUF_SIZE
      86                 :            :  *      bytes long.
      87                 :            :  *
      88                 :            :  * #. Test multiple allocations of mbufs from this pool.
      89                 :            :  *
      90                 :            :  *    - Allocate NB_MBUF and store pointers in a table.
      91                 :            :  *    - If an allocation fails, return an error.
      92                 :            :  *    - Free all these mbufs.
      93                 :            :  *    - Repeat the same test to check that mbufs were freed correctly.
      94                 :            :  *
      95                 :            :  * #. Test data manipulation in pktmbuf.
      96                 :            :  *
      97                 :            :  *    - Alloc an mbuf.
      98                 :            :  *    - Append data using rte_pktmbuf_append().
      99                 :            :  *    - Test for error in rte_pktmbuf_append() when len is too large.
     100                 :            :  *    - Trim data at the end of mbuf using rte_pktmbuf_trim().
     101                 :            :  *    - Test for error in rte_pktmbuf_trim() when len is too large.
     102                 :            :  *    - Prepend a header using rte_pktmbuf_prepend().
     103                 :            :  *    - Test for error in rte_pktmbuf_prepend() when len is too large.
     104                 :            :  *    - Remove data at the beginning of mbuf using rte_pktmbuf_adj().
     105                 :            :  *    - Test for error in rte_pktmbuf_adj() when len is too large.
     106                 :            :  *    - Check that appended data is not corrupt.
     107                 :            :  *    - Free the mbuf.
     108                 :            :  *    - Between all these tests, check data_len and pkt_len, and
     109                 :            :  *      that the mbuf is contiguous.
     110                 :            :  *    - Repeat the test to check that allocation operations
     111                 :            :  *      reinitialize the mbuf correctly.
     112                 :            :  *
     113                 :            :  * #. Test packet cloning
     114                 :            :  *    - Clone a mbuf and verify the data
     115                 :            :  *    - Clone the cloned mbuf and verify the data
     116                 :            :  *    - Attach a mbuf to another that does not have the same priv_size.
     117                 :            :  */
     118                 :            : 
     119                 :            : #define GOTO_FAIL(str, ...) do {                                        \
     120                 :            :                 printf("mbuf test FAILED (l.%d): <" str ">\n",                \
     121                 :            :                        __LINE__,  ##__VA_ARGS__);                       \
     122                 :            :                 goto fail;                                              \
     123                 :            : } while(0)
     124                 :            : 
     125                 :            : /*
     126                 :            :  * test data manipulation in mbuf with non-ascii data
     127                 :            :  */
     128                 :            : static int
     129                 :          2 : test_pktmbuf_with_non_ascii_data(struct rte_mempool *pktmbuf_pool)
     130                 :            : {
     131                 :            :         struct rte_mbuf *m = NULL;
     132                 :            :         char *data;
     133                 :            : 
     134                 :          2 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
     135         [ -  + ]:          2 :         if (m == NULL)
     136                 :          0 :                 GOTO_FAIL("Cannot allocate mbuf");
     137         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != 0)
     138                 :          0 :                 GOTO_FAIL("Bad length");
     139                 :            : 
     140                 :            :         data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN);
     141         [ -  + ]:          2 :         if (data == NULL)
     142                 :          0 :                 GOTO_FAIL("Cannot append data");
     143         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
     144                 :          0 :                 GOTO_FAIL("Bad pkt length");
     145         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
     146                 :          0 :                 GOTO_FAIL("Bad data length");
     147                 :            :         memset(data, 0xff, rte_pktmbuf_pkt_len(m));
     148         [ -  + ]:          2 :         if (!rte_pktmbuf_is_contiguous(m))
     149                 :          0 :                 GOTO_FAIL("Buffer should be continuous");
     150                 :          2 :         rte_pktmbuf_dump(stdout, m, MBUF_TEST_DATA_LEN);
     151                 :            : 
     152                 :          2 :         rte_pktmbuf_free(m);
     153                 :            : 
     154                 :          2 :         return 0;
     155                 :            : 
     156                 :          0 : fail:
     157         [ #  # ]:          0 :         if(m) {
     158                 :          0 :                 rte_pktmbuf_free(m);
     159                 :            :         }
     160                 :            :         return -1;
     161                 :            : }
     162                 :            : 
     163                 :            : /*
     164                 :            :  * test data manipulation in mbuf
     165                 :            :  */
     166                 :            : static int
     167                 :          2 : test_one_pktmbuf(struct rte_mempool *pktmbuf_pool)
     168                 :            : {
     169                 :            :         struct rte_mbuf *m = NULL;
     170                 :            :         char *data, *data2, *hdr;
     171                 :            :         unsigned i;
     172                 :            : 
     173                 :            :         printf("Test pktmbuf API\n");
     174                 :            : 
     175                 :            :         /* alloc a mbuf */
     176                 :            : 
     177                 :          2 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
     178         [ -  + ]:          2 :         if (m == NULL)
     179                 :          0 :                 GOTO_FAIL("Cannot allocate mbuf");
     180         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != 0)
     181                 :          0 :                 GOTO_FAIL("Bad length");
     182                 :            : 
     183                 :          2 :         rte_pktmbuf_dump(stdout, m, 0);
     184                 :            : 
     185                 :            :         /* append data */
     186                 :            : 
     187                 :            :         data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN);
     188         [ -  + ]:          2 :         if (data == NULL)
     189                 :          0 :                 GOTO_FAIL("Cannot append data");
     190         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
     191                 :          0 :                 GOTO_FAIL("Bad pkt length");
     192         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
     193                 :          0 :                 GOTO_FAIL("Bad data length");
     194                 :            :         memset(data, 0x66, rte_pktmbuf_pkt_len(m));
     195         [ -  + ]:          2 :         if (!rte_pktmbuf_is_contiguous(m))
     196                 :          0 :                 GOTO_FAIL("Buffer should be continuous");
     197                 :          2 :         rte_pktmbuf_dump(stdout, m, MBUF_TEST_DATA_LEN);
     198                 :          2 :         rte_pktmbuf_dump(stdout, m, 2*MBUF_TEST_DATA_LEN);
     199                 :            : 
     200                 :            :         /* this append should fail */
     201                 :            : 
     202                 :          2 :         data2 = rte_pktmbuf_append(m, (uint16_t)(rte_pktmbuf_tailroom(m) + 1));
     203         [ #  # ]:          0 :         if (data2 != NULL)
     204                 :          0 :                 GOTO_FAIL("Append should not succeed");
     205                 :            : 
     206                 :            :         /* append some more data */
     207                 :            : 
     208                 :            :         data2 = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN2);
     209         [ -  + ]:          2 :         if (data2 == NULL)
     210                 :          0 :                 GOTO_FAIL("Cannot append data");
     211         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_DATA_LEN2)
     212                 :          0 :                 GOTO_FAIL("Bad pkt length");
     213         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_DATA_LEN2)
     214                 :          0 :                 GOTO_FAIL("Bad data length");
     215         [ -  + ]:          2 :         if (!rte_pktmbuf_is_contiguous(m))
     216                 :          0 :                 GOTO_FAIL("Buffer should be continuous");
     217                 :            : 
     218                 :            :         /* trim data at the end of mbuf */
     219                 :            : 
     220                 :            :         if (rte_pktmbuf_trim(m, MBUF_TEST_DATA_LEN2) < 0)
     221                 :          0 :                 GOTO_FAIL("Cannot trim data");
     222         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
     223                 :          0 :                 GOTO_FAIL("Bad pkt length");
     224         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
     225                 :          0 :                 GOTO_FAIL("Bad data length");
     226         [ -  + ]:          2 :         if (!rte_pktmbuf_is_contiguous(m))
     227                 :          0 :                 GOTO_FAIL("Buffer should be continuous");
     228                 :            : 
     229                 :            :         /* this trim should fail */
     230                 :            : 
     231                 :            :         if (rte_pktmbuf_trim(m, (uint16_t)(rte_pktmbuf_data_len(m) + 1)) == 0)
     232                 :          0 :                 GOTO_FAIL("trim should not succeed");
     233                 :            : 
     234                 :            :         /* prepend one header */
     235                 :            : 
     236                 :            :         hdr = rte_pktmbuf_prepend(m, MBUF_TEST_HDR1_LEN);
     237         [ -  + ]:          2 :         if (hdr == NULL)
     238                 :          0 :                 GOTO_FAIL("Cannot prepend");
     239         [ -  + ]:          2 :         if (data - hdr != MBUF_TEST_HDR1_LEN)
     240                 :          0 :                 GOTO_FAIL("Prepend failed");
     241                 :            :         if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_HDR1_LEN)
     242                 :            :                 GOTO_FAIL("Bad pkt length");
     243                 :            :         if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_HDR1_LEN)
     244                 :            :                 GOTO_FAIL("Bad data length");
     245                 :            :         if (!rte_pktmbuf_is_contiguous(m))
     246                 :            :                 GOTO_FAIL("Buffer should be continuous");
     247                 :            :         memset(hdr, 0x55, MBUF_TEST_HDR1_LEN);
     248                 :            : 
     249                 :            :         /* prepend another header */
     250                 :            : 
     251                 :            :         hdr = rte_pktmbuf_prepend(m, MBUF_TEST_HDR2_LEN);
     252         [ -  + ]:          2 :         if (hdr == NULL)
     253                 :          0 :                 GOTO_FAIL("Cannot prepend");
     254         [ -  + ]:          2 :         if (data - hdr != MBUF_TEST_ALL_HDRS_LEN)
     255                 :          0 :                 GOTO_FAIL("Prepend failed");
     256         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_ALL_HDRS_LEN)
     257                 :          0 :                 GOTO_FAIL("Bad pkt length");
     258         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN + MBUF_TEST_ALL_HDRS_LEN)
     259                 :          0 :                 GOTO_FAIL("Bad data length");
     260         [ -  + ]:          2 :         if (!rte_pktmbuf_is_contiguous(m))
     261                 :          0 :                 GOTO_FAIL("Buffer should be continuous");
     262                 :            :         memset(hdr, 0x55, MBUF_TEST_HDR2_LEN);
     263                 :            : 
     264                 :          2 :         rte_mbuf_sanity_check(m, 1);
     265                 :          2 :         rte_mbuf_sanity_check(m, 0);
     266                 :          2 :         rte_pktmbuf_dump(stdout, m, 0);
     267                 :            : 
     268                 :            :         /* this prepend should fail */
     269                 :            : 
     270         [ +  - ]:          2 :         hdr = rte_pktmbuf_prepend(m, (uint16_t)(rte_pktmbuf_headroom(m) + 1));
     271                 :            :         if (hdr != NULL)
     272                 :          0 :                 GOTO_FAIL("prepend should not succeed");
     273                 :            : 
     274                 :            :         /* remove data at beginning of mbuf (adj) */
     275                 :            : 
     276         [ -  + ]:          2 :         if (data != rte_pktmbuf_adj(m, MBUF_TEST_ALL_HDRS_LEN))
     277                 :          0 :                 GOTO_FAIL("rte_pktmbuf_adj failed");
     278         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN)
     279                 :          0 :                 GOTO_FAIL("Bad pkt length");
     280         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(m) != MBUF_TEST_DATA_LEN)
     281                 :          0 :                 GOTO_FAIL("Bad data length");
     282         [ -  + ]:          2 :         if (!rte_pktmbuf_is_contiguous(m))
     283                 :          0 :                 GOTO_FAIL("Buffer should be continuous");
     284                 :            : 
     285                 :            :         /* this adj should fail */
     286                 :            : 
     287                 :            :         if (rte_pktmbuf_adj(m, (uint16_t)(rte_pktmbuf_data_len(m) + 1)) != NULL)
     288                 :            :                 GOTO_FAIL("rte_pktmbuf_adj should not succeed");
     289                 :            : 
     290                 :            :         /* check data */
     291                 :            : 
     292                 :            :         if (!rte_pktmbuf_is_contiguous(m))
     293                 :            :                 GOTO_FAIL("Buffer should be continuous");
     294                 :            : 
     295         [ +  + ]:       2930 :         for (i=0; i<MBUF_TEST_DATA_LEN; i++) {
     296         [ -  + ]:       2928 :                 if (data[i] != 0x66)
     297                 :          0 :                         GOTO_FAIL("Data corrupted at offset %u", i);
     298                 :            :         }
     299                 :            : 
     300                 :            :         /* free mbuf */
     301                 :            : 
     302                 :          2 :         rte_pktmbuf_free(m);
     303                 :            :         m = NULL;
     304                 :          2 :         return 0;
     305                 :            : 
     306                 :          0 : fail:
     307                 :          0 :         rte_pktmbuf_free(m);
     308                 :          0 :         return -1;
     309                 :            : }
     310                 :            : 
     311                 :            : static uint16_t
     312                 :         10 : testclone_refcnt_read(struct rte_mbuf *m)
     313                 :            : {
     314         [ +  - ]:         10 :         return RTE_MBUF_HAS_PINNED_EXTBUF(m) ?
     315         [ +  + ]:         10 :                rte_mbuf_ext_refcnt_read(m->shinfo) :
     316                 :            :                rte_mbuf_refcnt_read(m);
     317                 :            : }
     318                 :            : 
     319                 :            : static int
     320                 :          2 : testclone_testupdate_testdetach(struct rte_mempool *pktmbuf_pool,
     321                 :            :                                 struct rte_mempool *clone_pool)
     322                 :            : {
     323                 :            :         struct rte_mbuf *m = NULL;
     324                 :            :         struct rte_mbuf *clone = NULL;
     325                 :            :         struct rte_mbuf *clone2 = NULL;
     326                 :            :         unaligned_uint32_t *data;
     327                 :            : 
     328                 :            :         /* alloc a mbuf */
     329                 :          2 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
     330         [ -  + ]:          2 :         if (m == NULL)
     331                 :          0 :                 GOTO_FAIL("ooops not allocating mbuf");
     332                 :            : 
     333         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != 0)
     334                 :          0 :                 GOTO_FAIL("Bad length");
     335                 :            : 
     336                 :            :         rte_pktmbuf_append(m, sizeof(uint32_t));
     337                 :          2 :         data = rte_pktmbuf_mtod(m, unaligned_uint32_t *);
     338                 :          2 :         *data = MAGIC_DATA;
     339                 :            : 
     340                 :            :         /* clone the allocated mbuf */
     341                 :          2 :         clone = rte_pktmbuf_clone(m, clone_pool);
     342         [ -  + ]:          2 :         if (clone == NULL)
     343                 :          0 :                 GOTO_FAIL("cannot clone data\n");
     344                 :            : 
     345                 :          2 :         data = rte_pktmbuf_mtod(clone, unaligned_uint32_t *);
     346         [ -  + ]:          2 :         if (*data != MAGIC_DATA)
     347                 :          0 :                 GOTO_FAIL("invalid data in clone\n");
     348                 :            : 
     349         [ -  + ]:          2 :         if (testclone_refcnt_read(m) != 2)
     350                 :          0 :                 GOTO_FAIL("invalid refcnt in m\n");
     351                 :            : 
     352                 :            :         /* free the clone */
     353                 :          2 :         rte_pktmbuf_free(clone);
     354                 :            :         clone = NULL;
     355                 :            : 
     356                 :            :         /* same test with a chained mbuf */
     357                 :          2 :         m->next = rte_pktmbuf_alloc(pktmbuf_pool);
     358         [ -  + ]:          2 :         if (m->next == NULL)
     359                 :          0 :                 GOTO_FAIL("Next Pkt Null\n");
     360                 :          2 :         m->nb_segs = 2;
     361                 :            : 
     362                 :            :         rte_pktmbuf_append(m->next, sizeof(uint32_t));
     363                 :          2 :         m->pkt_len = 2 * sizeof(uint32_t);
     364                 :            : 
     365                 :          2 :         data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *);
     366                 :          2 :         *data = MAGIC_DATA;
     367                 :            : 
     368                 :          2 :         clone = rte_pktmbuf_clone(m, clone_pool);
     369         [ -  + ]:          2 :         if (clone == NULL)
     370                 :          0 :                 GOTO_FAIL("cannot clone data\n");
     371                 :            : 
     372                 :          2 :         data = rte_pktmbuf_mtod(clone, unaligned_uint32_t *);
     373         [ -  + ]:          2 :         if (*data != MAGIC_DATA)
     374                 :          0 :                 GOTO_FAIL("invalid data in clone\n");
     375                 :            : 
     376                 :          2 :         data = rte_pktmbuf_mtod(clone->next, unaligned_uint32_t *);
     377         [ -  + ]:          2 :         if (*data != MAGIC_DATA)
     378                 :          0 :                 GOTO_FAIL("invalid data in clone->next\n");
     379                 :            : 
     380         [ -  + ]:          2 :         if (testclone_refcnt_read(m) != 2)
     381                 :          0 :                 GOTO_FAIL("invalid refcnt in m\n");
     382                 :            : 
     383         [ -  + ]:          2 :         if (testclone_refcnt_read(m->next) != 2)
     384                 :          0 :                 GOTO_FAIL("invalid refcnt in m->next\n");
     385                 :            : 
     386                 :            :         /* try to clone the clone */
     387                 :            : 
     388                 :          2 :         clone2 = rte_pktmbuf_clone(clone, clone_pool);
     389         [ -  + ]:          2 :         if (clone2 == NULL)
     390                 :          0 :                 GOTO_FAIL("cannot clone the clone\n");
     391                 :            : 
     392                 :          2 :         data = rte_pktmbuf_mtod(clone2, unaligned_uint32_t *);
     393         [ -  + ]:          2 :         if (*data != MAGIC_DATA)
     394                 :          0 :                 GOTO_FAIL("invalid data in clone2\n");
     395                 :            : 
     396                 :          2 :         data = rte_pktmbuf_mtod(clone2->next, unaligned_uint32_t *);
     397         [ -  + ]:          2 :         if (*data != MAGIC_DATA)
     398                 :          0 :                 GOTO_FAIL("invalid data in clone2->next\n");
     399                 :            : 
     400         [ -  + ]:          2 :         if (testclone_refcnt_read(m) != 3)
     401                 :          0 :                 GOTO_FAIL("invalid refcnt in m\n");
     402                 :            : 
     403         [ -  + ]:          2 :         if (testclone_refcnt_read(m->next) != 3)
     404                 :          0 :                 GOTO_FAIL("invalid refcnt in m->next\n");
     405                 :            : 
     406                 :            :         /* free mbuf */
     407                 :          2 :         rte_pktmbuf_free(m);
     408                 :          2 :         rte_pktmbuf_free(clone);
     409                 :          2 :         rte_pktmbuf_free(clone2);
     410                 :            : 
     411                 :            :         m = NULL;
     412                 :            :         clone = NULL;
     413                 :            :         clone2 = NULL;
     414                 :            :         printf("%s ok\n", __func__);
     415                 :          2 :         return 0;
     416                 :            : 
     417                 :          0 : fail:
     418                 :          0 :         rte_pktmbuf_free(m);
     419                 :          0 :         rte_pktmbuf_free(clone);
     420                 :          0 :         rte_pktmbuf_free(clone2);
     421                 :          0 :         return -1;
     422                 :            : }
     423                 :            : 
     424                 :            : static int
     425                 :          2 : 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                 :          2 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
     436         [ -  + ]:          2 :         if (m == NULL)
     437                 :          0 :                 GOTO_FAIL("ooops not allocating mbuf");
     438                 :            : 
     439         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != 0)
     440                 :          0 :                 GOTO_FAIL("Bad length");
     441                 :            : 
     442                 :            :         rte_pktmbuf_append(m, sizeof(uint32_t));
     443                 :          2 :         data = rte_pktmbuf_mtod(m, unaligned_uint32_t *);
     444                 :          2 :         *data = MAGIC_DATA;
     445                 :            : 
     446                 :            :         /* copy the allocated mbuf */
     447                 :          2 :         copy = rte_pktmbuf_copy(m, pktmbuf_pool, 0, UINT32_MAX);
     448         [ -  + ]:          2 :         if (copy == NULL)
     449                 :          0 :                 GOTO_FAIL("cannot copy data\n");
     450                 :            : 
     451         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(copy) != sizeof(uint32_t))
     452                 :          0 :                 GOTO_FAIL("copy length incorrect\n");
     453                 :            : 
     454         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(copy) != sizeof(uint32_t))
     455                 :          0 :                 GOTO_FAIL("copy data length incorrect\n");
     456                 :            : 
     457                 :          2 :         data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *);
     458         [ -  + ]:          2 :         if (*data != MAGIC_DATA)
     459                 :          0 :                 GOTO_FAIL("invalid data in copy\n");
     460                 :            : 
     461                 :            :         /* free the copy */
     462                 :          2 :         rte_pktmbuf_free(copy);
     463                 :            :         copy = NULL;
     464                 :            : 
     465                 :            :         /* same test with a cloned mbuf */
     466                 :          2 :         clone = rte_pktmbuf_clone(m, clone_pool);
     467         [ -  + ]:          2 :         if (clone == NULL)
     468                 :          0 :                 GOTO_FAIL("cannot clone data\n");
     469                 :            : 
     470   [ +  -  +  + ]:          4 :         if ((!RTE_MBUF_HAS_PINNED_EXTBUF(m) &&
     471   [ +  -  +  + ]:          2 :              !RTE_MBUF_CLONED(clone)) ||
     472                 :          1 :             (RTE_MBUF_HAS_PINNED_EXTBUF(m) &&
     473         [ -  + ]:          1 :              !RTE_MBUF_HAS_EXTBUF(clone)))
     474                 :          0 :                 GOTO_FAIL("clone did not give a cloned mbuf\n");
     475                 :            : 
     476                 :          2 :         copy = rte_pktmbuf_copy(clone, pktmbuf_pool, 0, UINT32_MAX);
     477         [ -  + ]:          2 :         if (copy == NULL)
     478                 :          0 :                 GOTO_FAIL("cannot copy cloned mbuf\n");
     479                 :            : 
     480         [ -  + ]:          2 :         if (RTE_MBUF_CLONED(copy))
     481                 :          0 :                 GOTO_FAIL("copy of clone is cloned?\n");
     482                 :            : 
     483         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(copy) != sizeof(uint32_t))
     484                 :          0 :                 GOTO_FAIL("copy clone length incorrect\n");
     485                 :            : 
     486         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(copy) != sizeof(uint32_t))
     487                 :          0 :                 GOTO_FAIL("copy clone data length incorrect\n");
     488                 :            : 
     489                 :          2 :         data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *);
     490         [ -  + ]:          2 :         if (*data != MAGIC_DATA)
     491                 :          0 :                 GOTO_FAIL("invalid data in clone copy\n");
     492                 :          2 :         rte_pktmbuf_free(clone);
     493                 :          2 :         rte_pktmbuf_free(copy);
     494                 :            :         copy = NULL;
     495                 :            :         clone = NULL;
     496                 :            : 
     497                 :            : 
     498                 :            :         /* same test with a chained mbuf */
     499                 :          2 :         m->next = rte_pktmbuf_alloc(pktmbuf_pool);
     500         [ -  + ]:          2 :         if (m->next == NULL)
     501                 :          0 :                 GOTO_FAIL("Next Pkt Null\n");
     502                 :          2 :         m->nb_segs = 2;
     503                 :            : 
     504                 :            :         rte_pktmbuf_append(m->next, sizeof(uint32_t));
     505                 :          2 :         m->pkt_len = 2 * sizeof(uint32_t);
     506                 :          2 :         data = rte_pktmbuf_mtod(m->next, unaligned_uint32_t *);
     507                 :          2 :         *data = MAGIC_DATA + 1;
     508                 :            : 
     509                 :          2 :         copy = rte_pktmbuf_copy(m, pktmbuf_pool, 0, UINT32_MAX);
     510         [ -  + ]:          2 :         if (copy == NULL)
     511                 :          0 :                 GOTO_FAIL("cannot copy data\n");
     512                 :            : 
     513         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(copy) != 2 * sizeof(uint32_t))
     514                 :          0 :                 GOTO_FAIL("chain copy length incorrect\n");
     515                 :            : 
     516         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(copy) != 2 * sizeof(uint32_t))
     517                 :          0 :                 GOTO_FAIL("chain copy data length incorrect\n");
     518                 :            : 
     519                 :          2 :         data = rte_pktmbuf_mtod(copy, unaligned_uint32_t *);
     520   [ +  -  -  + ]:          2 :         if (data[0] != MAGIC_DATA || data[1] != MAGIC_DATA + 1)
     521                 :          0 :                 GOTO_FAIL("invalid data in copy\n");
     522                 :            : 
     523                 :          2 :         rte_pktmbuf_free(copy2);
     524                 :            : 
     525                 :            :         /* test offset copy */
     526                 :          2 :         copy2 = rte_pktmbuf_copy(copy, pktmbuf_pool,
     527                 :            :                                  sizeof(uint32_t), UINT32_MAX);
     528         [ -  + ]:          2 :         if (copy2 == NULL)
     529                 :          0 :                 GOTO_FAIL("cannot copy the copy\n");
     530                 :            : 
     531         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(copy2) != sizeof(uint32_t))
     532                 :          0 :                 GOTO_FAIL("copy with offset, length incorrect\n");
     533                 :            : 
     534         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(copy2) != sizeof(uint32_t))
     535                 :          0 :                 GOTO_FAIL("copy with offset, data length incorrect\n");
     536                 :            : 
     537                 :          2 :         data = rte_pktmbuf_mtod(copy2, unaligned_uint32_t *);
     538         [ -  + ]:          2 :         if (data[0] != MAGIC_DATA + 1)
     539                 :          0 :                 GOTO_FAIL("copy with offset, invalid data\n");
     540                 :            : 
     541                 :          2 :         rte_pktmbuf_free(copy2);
     542                 :            : 
     543                 :            :         /* test truncation copy */
     544                 :          2 :         copy2 = rte_pktmbuf_copy(copy, pktmbuf_pool,
     545                 :            :                                  0, sizeof(uint32_t));
     546         [ -  + ]:          2 :         if (copy2 == NULL)
     547                 :          0 :                 GOTO_FAIL("cannot copy the copy\n");
     548                 :            : 
     549         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(copy2) != sizeof(uint32_t))
     550                 :          0 :                 GOTO_FAIL("copy with truncate, length incorrect\n");
     551                 :            : 
     552         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(copy2) != sizeof(uint32_t))
     553                 :          0 :                 GOTO_FAIL("copy with truncate, data length incorrect\n");
     554                 :            : 
     555                 :          2 :         data = rte_pktmbuf_mtod(copy2, unaligned_uint32_t *);
     556         [ -  + ]:          2 :         if (data[0] != MAGIC_DATA)
     557                 :          0 :                 GOTO_FAIL("copy with truncate, invalid data\n");
     558                 :            : 
     559                 :            :         /* free mbuf */
     560                 :          2 :         rte_pktmbuf_free(m);
     561                 :          2 :         rte_pktmbuf_free(copy);
     562                 :          2 :         rte_pktmbuf_free(copy2);
     563                 :            : 
     564                 :            :         m = NULL;
     565                 :            :         copy = NULL;
     566                 :            :         copy2 = NULL;
     567                 :            :         printf("%s ok\n", __func__);
     568                 :          2 :         return 0;
     569                 :            : 
     570                 :          0 : fail:
     571                 :          0 :         rte_pktmbuf_free(m);
     572                 :          0 :         rte_pktmbuf_free(copy);
     573                 :          0 :         rte_pktmbuf_free(copy2);
     574                 :          0 :         return -1;
     575                 :            : }
     576                 :            : 
     577                 :            : static int
     578                 :          1 : test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool,
     579                 :            :                                 struct rte_mempool *pktmbuf_pool2)
     580                 :            : {
     581                 :            :         struct rte_mbuf *m = NULL;
     582                 :            :         struct rte_mbuf *clone = NULL;
     583                 :            :         struct rte_mbuf *clone2 = NULL;
     584                 :            :         char *data, *c_data, *c_data2;
     585                 :            : 
     586                 :            :         /* alloc a mbuf */
     587                 :          1 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
     588         [ -  + ]:          1 :         if (m == NULL)
     589                 :          0 :                 GOTO_FAIL("cannot allocate mbuf");
     590                 :            : 
     591         [ -  + ]:          1 :         if (rte_pktmbuf_pkt_len(m) != 0)
     592                 :          0 :                 GOTO_FAIL("Bad length");
     593                 :            : 
     594                 :          1 :         data = rte_pktmbuf_mtod(m, char *);
     595                 :            : 
     596                 :            :         /* allocate a new mbuf from the second pool, and attach it to the first
     597                 :            :          * mbuf */
     598                 :          1 :         clone = rte_pktmbuf_alloc(pktmbuf_pool2);
     599         [ -  + ]:          1 :         if (clone == NULL)
     600                 :          0 :                 GOTO_FAIL("cannot allocate mbuf from second pool\n");
     601                 :            : 
     602                 :            :         /* check data room size and priv size, and erase priv */
     603   [ +  -  -  + ]:          2 :         if (rte_pktmbuf_data_room_size(clone->pool) != 0)
     604                 :          0 :                 GOTO_FAIL("data room size should be 0\n");
     605         [ -  + ]:          1 :         if (rte_pktmbuf_priv_size(clone->pool) != MBUF2_PRIV_SIZE)
     606                 :          0 :                 GOTO_FAIL("data room size should be %d\n", MBUF2_PRIV_SIZE);
     607         [ -  + ]:          1 :         memset(clone + 1, 0, MBUF2_PRIV_SIZE);
     608                 :            : 
     609                 :            :         /* save data pointer to compare it after detach() */
     610                 :          1 :         c_data = rte_pktmbuf_mtod(clone, char *);
     611         [ -  + ]:          1 :         if (c_data != (char *)clone + sizeof(*clone) + MBUF2_PRIV_SIZE)
     612                 :          0 :                 GOTO_FAIL("bad data pointer in clone");
     613         [ -  + ]:          1 :         if (rte_pktmbuf_headroom(clone) != 0)
     614                 :          0 :                 GOTO_FAIL("bad headroom in clone");
     615                 :            : 
     616                 :          1 :         rte_pktmbuf_attach(clone, m);
     617                 :            : 
     618         [ -  + ]:          1 :         if (rte_pktmbuf_mtod(clone, char *) != data)
     619                 :          0 :                 GOTO_FAIL("clone was not attached properly\n");
     620         [ -  + ]:          1 :         if (rte_pktmbuf_headroom(clone) != RTE_PKTMBUF_HEADROOM)
     621                 :          0 :                 GOTO_FAIL("bad headroom in clone after attach");
     622         [ -  + ]:          1 :         if (rte_mbuf_refcnt_read(m) != 2)
     623                 :          0 :                 GOTO_FAIL("invalid refcnt in m\n");
     624                 :            : 
     625                 :            :         /* allocate a new mbuf from the second pool, and attach it to the first
     626                 :            :          * cloned mbuf */
     627                 :          1 :         clone2 = rte_pktmbuf_alloc(pktmbuf_pool2);
     628         [ -  + ]:          1 :         if (clone2 == NULL)
     629                 :          0 :                 GOTO_FAIL("cannot allocate clone2 from second pool\n");
     630                 :            : 
     631                 :            :         /* check data room size and priv size, and erase priv */
     632   [ +  -  -  + ]:          2 :         if (rte_pktmbuf_data_room_size(clone2->pool) != 0)
     633                 :          0 :                 GOTO_FAIL("data room size should be 0\n");
     634         [ -  + ]:          1 :         if (rte_pktmbuf_priv_size(clone2->pool) != MBUF2_PRIV_SIZE)
     635                 :          0 :                 GOTO_FAIL("data room size should be %d\n", MBUF2_PRIV_SIZE);
     636         [ -  + ]:          1 :         memset(clone2 + 1, 0, MBUF2_PRIV_SIZE);
     637                 :            : 
     638                 :            :         /* save data pointer to compare it after detach() */
     639                 :          1 :         c_data2 = rte_pktmbuf_mtod(clone2, char *);
     640         [ -  + ]:          1 :         if (c_data2 != (char *)clone2 + sizeof(*clone2) + MBUF2_PRIV_SIZE)
     641                 :          0 :                 GOTO_FAIL("bad data pointer in clone2");
     642         [ -  + ]:          1 :         if (rte_pktmbuf_headroom(clone2) != 0)
     643                 :          0 :                 GOTO_FAIL("bad headroom in clone2");
     644                 :            : 
     645                 :          1 :         rte_pktmbuf_attach(clone2, clone);
     646                 :            : 
     647         [ -  + ]:          1 :         if (rte_pktmbuf_mtod(clone2, char *) != data)
     648                 :          0 :                 GOTO_FAIL("clone2 was not attached properly\n");
     649         [ -  + ]:          1 :         if (rte_pktmbuf_headroom(clone2) != RTE_PKTMBUF_HEADROOM)
     650                 :          0 :                 GOTO_FAIL("bad headroom in clone2 after attach");
     651         [ -  + ]:          1 :         if (rte_mbuf_refcnt_read(m) != 3)
     652                 :          0 :                 GOTO_FAIL("invalid refcnt in m\n");
     653                 :            : 
     654                 :            :         /* detach the clones */
     655                 :          1 :         rte_pktmbuf_detach(clone);
     656         [ -  + ]:          1 :         if (c_data != rte_pktmbuf_mtod(clone, char *))
     657                 :          0 :                 GOTO_FAIL("clone was not detached properly\n");
     658         [ -  + ]:          1 :         if (rte_mbuf_refcnt_read(m) != 2)
     659                 :          0 :                 GOTO_FAIL("invalid refcnt in m\n");
     660                 :            : 
     661                 :          1 :         rte_pktmbuf_detach(clone2);
     662         [ -  + ]:          1 :         if (c_data2 != rte_pktmbuf_mtod(clone2, char *))
     663                 :          0 :                 GOTO_FAIL("clone2 was not detached properly\n");
     664         [ -  + ]:          1 :         if (rte_mbuf_refcnt_read(m) != 1)
     665                 :          0 :                 GOTO_FAIL("invalid refcnt in m\n");
     666                 :            : 
     667                 :            :         /* free the clones and the initial mbuf */
     668                 :          1 :         rte_pktmbuf_free(clone2);
     669                 :          1 :         rte_pktmbuf_free(clone);
     670                 :          1 :         rte_pktmbuf_free(m);
     671                 :            :         printf("%s ok\n", __func__);
     672                 :          1 :         return 0;
     673                 :            : 
     674                 :          0 : fail:
     675                 :          0 :         rte_pktmbuf_free(m);
     676                 :          0 :         rte_pktmbuf_free(clone);
     677                 :          0 :         rte_pktmbuf_free(clone2);
     678                 :          0 :         return -1;
     679                 :            : }
     680                 :            : 
     681                 :            : /*
     682                 :            :  * test allocation and free of mbufs
     683                 :            :  */
     684                 :            : static int
     685                 :          4 : test_pktmbuf_pool(struct rte_mempool *pktmbuf_pool)
     686                 :            : {
     687                 :            :         unsigned i;
     688                 :            :         struct rte_mbuf *m[NB_MBUF];
     689                 :            :         int ret = 0;
     690                 :            : 
     691         [ +  + ]:        516 :         for (i=0; i<NB_MBUF; i++)
     692                 :        512 :                 m[i] = NULL;
     693                 :            : 
     694                 :            :         /* alloc NB_MBUF mbufs */
     695         [ +  + ]:        516 :         for (i=0; i<NB_MBUF; i++) {
     696                 :        512 :                 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
     697         [ -  + ]:        512 :                 if (m[i] == NULL) {
     698                 :            :                         printf("rte_pktmbuf_alloc() failed (%u)\n", i);
     699                 :            :                         ret = -1;
     700                 :            :                 }
     701                 :            :         }
     702                 :            :         struct rte_mbuf *extra = NULL;
     703                 :          4 :         extra = rte_pktmbuf_alloc(pktmbuf_pool);
     704         [ -  + ]:          4 :         if(extra != NULL) {
     705                 :            :                 printf("Error pool not empty");
     706                 :            :                 ret = -1;
     707                 :            :         }
     708                 :          4 :         extra = rte_pktmbuf_clone(m[0], pktmbuf_pool);
     709         [ -  + ]:          4 :         if(extra != NULL) {
     710                 :            :                 printf("Error pool not empty");
     711                 :            :                 ret = -1;
     712                 :            :         }
     713                 :            :         /* free them */
     714         [ +  + ]:        516 :         for (i=0; i<NB_MBUF; i++) {
     715                 :        512 :                 rte_pktmbuf_free(m[i]);
     716                 :            :         }
     717                 :            : 
     718                 :          4 :         return ret;
     719                 :            : }
     720                 :            : 
     721                 :            : /*
     722                 :            :  * test bulk allocation and bulk free of mbufs
     723                 :            :  */
     724                 :            : static int
     725                 :          1 : 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                 :          1 :         pool = rte_pktmbuf_pool_create("test_pktmbuf_bulk",
     740                 :            :                         NB_MBUF, 0, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY);
     741         [ -  + ]:          1 :         if (pool == NULL) {
     742                 :          0 :                 printf("rte_pktmbuf_pool_create() failed. rte_errno %d\n",
     743                 :            :                        rte_errno);
     744                 :          0 :                 goto err;
     745                 :            :         }
     746                 :          1 :         pool2 = rte_pktmbuf_pool_create("test_pktmbuf_bulk2",
     747                 :            :                         NB_MBUF, 0, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY);
     748         [ -  + ]:          1 :         if (pool2 == NULL) {
     749                 :          0 :                 printf("rte_pktmbuf_pool_create() failed. rte_errno %d\n",
     750                 :            :                        rte_errno);
     751                 :          0 :                 goto err;
     752                 :            :         }
     753                 :            : 
     754                 :            :         /* Preconditions: Mempools must be full. */
     755   [ +  -  -  + ]:          2 :         if (!(rte_mempool_full(pool) && rte_mempool_full(pool2))) {
     756                 :            :                 printf("Test precondition failed: mempools not full\n");
     757                 :          0 :                 goto err;
     758                 :            :         }
     759   [ +  -  -  + ]:          2 :         if (!(rte_mempool_avail_count(pool) == NB_MBUF &&
     760                 :          1 :                         rte_mempool_avail_count(pool2) == NB_MBUF)) {
     761                 :          0 :                 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                 :          0 :                 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                 :          1 :         ret = rte_pktmbuf_alloc_bulk(pool, mbufs, NB_MBUF);
     772         [ -  + ]:          1 :         if (ret != 0) {
     773                 :            :                 printf("rte_pktmbuf_alloc_bulk() failed: %d\n", ret);
     774                 :          0 :                 goto err;
     775                 :            :         }
     776                 :            :         /* Test that they have been removed from the pool. */
     777         [ -  + ]:          1 :         if (!rte_mempool_empty(pool)) {
     778                 :            :                 printf("mempool not empty\n");
     779                 :          0 :                 goto err;
     780                 :            :         }
     781                 :            :         /* Bulk free all mbufs, in four steps. */
     782                 :            :         RTE_BUILD_BUG_ON(NB_MBUF % 4 != 0);
     783         [ +  + ]:          5 :         for (i = 0; i < NB_MBUF; i += NB_MBUF / 4) {
     784                 :          4 :                 rte_pktmbuf_free_bulk(&mbufs[i], NB_MBUF / 4);
     785                 :            :                 /* Test that they have been returned to the pool. */
     786         [ +  - ]:          4 :                 if (rte_mempool_avail_count(pool) != i + NB_MBUF / 4) {
     787                 :            :                         printf("mempool avail count incorrect\n");
     788                 :          0 :                         goto err;
     789                 :            :                 }
     790                 :            :         }
     791                 :            : 
     792                 :            :         printf("Test multiple bulk alloc, followed by single bulk free.\n");
     793                 :            : 
     794                 :            :         /* Bulk allocate all mbufs in the pool, in four steps. */
     795         [ +  + ]:          5 :         for (i = 0; i < NB_MBUF; i += NB_MBUF / 4) {
     796                 :          4 :                 ret = rte_pktmbuf_alloc_bulk(pool, &mbufs[i], NB_MBUF / 4);
     797         [ -  + ]:          4 :                 if (ret != 0) {
     798                 :            :                         printf("rte_pktmbuf_alloc_bulk() failed: %d\n", ret);
     799                 :          0 :                         goto err;
     800                 :            :                 }
     801                 :            :         }
     802                 :            :         /* Test that they have been removed from the pool. */
     803         [ -  + ]:          1 :         if (!rte_mempool_empty(pool)) {
     804                 :            :                 printf("mempool not empty\n");
     805                 :          0 :                 goto err;
     806                 :            :         }
     807                 :            :         /* Bulk free all mbufs, in one go. */
     808                 :          1 :         rte_pktmbuf_free_bulk(mbufs, NB_MBUF);
     809                 :            :         /* Test that they have been returned to the pool. */
     810         [ -  + ]:          1 :         if (!rte_mempool_full(pool)) {
     811                 :            :                 printf("mempool not full\n");
     812                 :          0 :                 goto err;
     813                 :            :         }
     814                 :            : 
     815                 :            :         printf("Test bulk free of single long chain.\n");
     816                 :            : 
     817                 :            :         /* Bulk allocate all mbufs in the pool, in one go. */
     818                 :          1 :         ret = rte_pktmbuf_alloc_bulk(pool, mbufs, NB_MBUF);
     819         [ +  - ]:          1 :         if (ret != 0) {
     820                 :            :                 printf("rte_pktmbuf_alloc_bulk() failed: %d\n", ret);
     821                 :          0 :                 goto err;
     822                 :            :         }
     823                 :            :         /* Create a long mbuf chain. */
     824         [ +  + ]:        128 :         for (i = 1; i < NB_MBUF; i++) {
     825         [ -  + ]:        127 :                 ret = rte_pktmbuf_chain(mbufs[0], mbufs[i]);
     826                 :            :                 if (ret != 0) {
     827                 :            :                         printf("rte_pktmbuf_chain() failed: %d\n", ret);
     828                 :          0 :                         goto err;
     829                 :            :                 }
     830                 :        127 :                 mbufs[i] = NULL;
     831                 :            :         }
     832                 :            :         /* Free the mbuf chain containing all the mbufs. */
     833                 :          1 :         rte_pktmbuf_free_bulk(mbufs, 1);
     834                 :            :         /* Test that they have been returned to the pool. */
     835         [ -  + ]:          1 :         if (!rte_mempool_full(pool)) {
     836                 :            :                 printf("mempool not full\n");
     837                 :          0 :                 goto err;
     838                 :            :         }
     839                 :            : 
     840                 :            :         printf("Test bulk free of multiple chains using multiple pools.\n");
     841                 :            : 
     842                 :            :         /* Create mbuf chains containing mbufs from different pools. */
     843                 :            :         RTE_BUILD_BUG_ON(CHAIN_LEN % 2 != 0);
     844                 :            :         RTE_BUILD_BUG_ON(NB_MBUF % (CHAIN_LEN / 2) != 0);
     845         [ +  + ]:        257 :         for (i = 0; i < NB_MBUF * 2; i++) {
     846         [ +  + ]:        384 :                 m = rte_pktmbuf_alloc((i & 4) ? pool2 : pool);
     847         [ -  + ]:        256 :                 if (m == NULL) {
     848                 :            :                         printf("rte_pktmbuf_alloc() failed (%u)\n", i);
     849                 :          0 :                         goto err;
     850                 :            :                 }
     851         [ +  + ]:        256 :                 if ((i % CHAIN_LEN) == 0)
     852                 :         16 :                         mbufs[i / CHAIN_LEN] = m;
     853                 :            :                 else
     854         [ +  - ]:        240 :                         rte_pktmbuf_chain(mbufs[i / CHAIN_LEN], m);
     855                 :            :         }
     856                 :            :         /* Test that both pools have been emptied. */
     857   [ +  -  -  + ]:          2 :         if (!(rte_mempool_empty(pool) && rte_mempool_empty(pool2))) {
     858                 :            :                 printf("mempools not empty\n");
     859                 :          0 :                 goto err;
     860                 :            :         }
     861                 :            :         /* Free one mbuf chain. */
     862                 :          1 :         rte_pktmbuf_free_bulk(mbufs, 1);
     863                 :            :         /* Test that the segments have been returned to the pools. */
     864   [ +  -  -  + ]:          2 :         if (!(rte_mempool_avail_count(pool) == CHAIN_LEN / 2 &&
     865                 :          1 :                         rte_mempool_avail_count(pool2) == CHAIN_LEN / 2)) {
     866                 :            :                 printf("all segments of first mbuf have not been returned\n");
     867                 :          0 :                 goto err;
     868                 :            :         }
     869                 :            :         /* Free the remaining mbuf chains. */
     870                 :          1 :         rte_pktmbuf_free_bulk(&mbufs[1], NB_MBUF * 2 / CHAIN_LEN - 1);
     871                 :            :         /* Test that they have been returned to the pools. */
     872   [ +  -  -  + ]:          2 :         if (!(rte_mempool_full(pool) && rte_mempool_full(pool2))) {
     873                 :            :                 printf("mempools not full\n");
     874                 :          0 :                 goto err;
     875                 :            :         }
     876                 :            : 
     877                 :            :         ret = 0;
     878                 :          1 :         goto done;
     879                 :            : 
     880                 :            : err:
     881                 :            :         ret = -1;
     882                 :            : 
     883                 :          1 : done:
     884                 :            :         printf("Free mbuf pools for bulk allocation.\n");
     885                 :          1 :         rte_mempool_free(pool);
     886                 :          1 :         rte_mempool_free(pool2);
     887                 :          1 :         return ret;
     888                 :            : }
     889                 :            : 
     890                 :            : /*
     891                 :            :  * test that the pointer to the data on a packet mbuf is set properly
     892                 :            :  */
     893                 :            : static int
     894                 :          2 : test_pktmbuf_pool_ptr(struct rte_mempool *pktmbuf_pool)
     895                 :            : {
     896                 :            :         unsigned i;
     897                 :            :         struct rte_mbuf *m[NB_MBUF];
     898                 :            :         int ret = 0;
     899                 :            : 
     900         [ +  + ]:        258 :         for (i=0; i<NB_MBUF; i++)
     901                 :        256 :                 m[i] = NULL;
     902                 :            : 
     903                 :            :         /* alloc NB_MBUF mbufs */
     904         [ +  + ]:        258 :         for (i=0; i<NB_MBUF; i++) {
     905                 :        256 :                 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
     906         [ -  + ]:        256 :                 if (m[i] == NULL) {
     907                 :            :                         printf("rte_pktmbuf_alloc() failed (%u)\n", i);
     908                 :            :                         ret = -1;
     909                 :          0 :                         break;
     910                 :            :                 }
     911                 :        256 :                 m[i]->data_off += 64;
     912                 :            :         }
     913                 :            : 
     914                 :            :         /* free them */
     915         [ +  + ]:        258 :         for (i=0; i<NB_MBUF; i++) {
     916                 :        256 :                 rte_pktmbuf_free(m[i]);
     917                 :            :         }
     918                 :            : 
     919         [ +  + ]:        258 :         for (i=0; i<NB_MBUF; i++)
     920                 :        256 :                 m[i] = NULL;
     921                 :            : 
     922                 :            :         /* alloc NB_MBUF mbufs */
     923         [ +  + ]:        258 :         for (i=0; i<NB_MBUF; i++) {
     924                 :        256 :                 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
     925         [ -  + ]:        256 :                 if (m[i] == NULL) {
     926                 :            :                         printf("rte_pktmbuf_alloc() failed (%u)\n", i);
     927                 :            :                         ret = -1;
     928                 :          0 :                         break;
     929                 :            :                 }
     930         [ -  + ]:        256 :                 if (m[i]->data_off != RTE_PKTMBUF_HEADROOM) {
     931                 :            :                         printf("invalid data_off\n");
     932                 :            :                         ret = -1;
     933                 :            :                 }
     934                 :            :         }
     935                 :            : 
     936                 :            :         /* free them */
     937         [ +  + ]:        258 :         for (i=0; i<NB_MBUF; i++) {
     938                 :        256 :                 rte_pktmbuf_free(m[i]);
     939                 :            :         }
     940                 :            : 
     941                 :          2 :         return ret;
     942                 :            : }
     943                 :            : 
     944                 :            : static int
     945                 :          2 : test_pktmbuf_free_segment(struct rte_mempool *pktmbuf_pool)
     946                 :            : {
     947                 :            :         unsigned i;
     948                 :            :         struct rte_mbuf *m[NB_MBUF];
     949                 :            :         int ret = 0;
     950                 :            : 
     951         [ +  + ]:        258 :         for (i=0; i<NB_MBUF; i++)
     952                 :        256 :                 m[i] = NULL;
     953                 :            : 
     954                 :            :         /* alloc NB_MBUF mbufs */
     955         [ +  + ]:        258 :         for (i=0; i<NB_MBUF; i++) {
     956                 :        256 :                 m[i] = rte_pktmbuf_alloc(pktmbuf_pool);
     957         [ -  + ]:        256 :                 if (m[i] == NULL) {
     958                 :            :                         printf("rte_pktmbuf_alloc() failed (%u)\n", i);
     959                 :            :                         ret = -1;
     960                 :            :                 }
     961                 :            :         }
     962                 :            : 
     963                 :            :         /* free them */
     964         [ +  + ]:        258 :         for (i=0; i<NB_MBUF; i++) {
     965         [ +  - ]:        256 :                 if (m[i] != NULL) {
     966                 :            :                         struct rte_mbuf *mb, *mt;
     967                 :            : 
     968                 :            :                         mb = m[i];
     969         [ +  + ]:        512 :                         while(mb != NULL) {
     970                 :            :                                 mt = mb;
     971                 :        256 :                                 mb = mb->next;
     972                 :            :                                 rte_pktmbuf_free_seg(mt);
     973                 :            :                         }
     974                 :            :                 }
     975                 :            :         }
     976                 :            : 
     977                 :          2 :         return ret;
     978                 :            : }
     979                 :            : 
     980                 :            : /*
     981                 :            :  * Stress test for rte_mbuf atomic refcnt.
     982                 :            :  * Implies that RTE_MBUF_REFCNT_ATOMIC is defined.
     983                 :            :  * For more efficiency, recommended to run with RTE_LIBRTE_MBUF_DEBUG defined.
     984                 :            :  */
     985                 :            : 
     986                 :            : #ifdef RTE_MBUF_REFCNT_ATOMIC
     987                 :            : 
     988                 :            : static int
     989                 :          1 : test_refcnt_worker(void *arg)
     990                 :            : {
     991                 :            :         unsigned lcore, free;
     992                 :          1 :         void *mp = 0;
     993                 :            :         struct rte_ring *refcnt_mbuf_ring = arg;
     994                 :            : 
     995                 :            :         lcore = rte_lcore_id();
     996                 :            :         printf("%s started at lcore %u\n", __func__, lcore);
     997                 :            : 
     998                 :            :         free = 0;
     999         [ +  + ]:     283853 :         while (refcnt_stop_workers == 0) {
    1000                 :            :                 if (rte_ring_dequeue(refcnt_mbuf_ring, &mp) == 0) {
    1001                 :     261870 :                         free++;
    1002                 :     261870 :                         rte_pktmbuf_free(mp);
    1003                 :            :                 }
    1004                 :            :         }
    1005                 :            : 
    1006                 :          1 :         refcnt_lcore[lcore] += free;
    1007                 :            :         printf("%s finished at lcore %u, "
    1008                 :            :                "number of freed mbufs: %u\n",
    1009                 :            :                __func__, lcore, free);
    1010                 :          1 :         return 0;
    1011                 :            : }
    1012                 :            : 
    1013                 :            : static void
    1014                 :         64 : test_refcnt_iter(unsigned int lcore, unsigned int iter,
    1015                 :            :                  struct rte_mempool *refcnt_pool,
    1016                 :            :                  struct rte_ring *refcnt_mbuf_ring)
    1017                 :            : {
    1018                 :            :         uint16_t ref;
    1019                 :            :         unsigned i, n, tref, wn;
    1020                 :            :         struct rte_mbuf *m;
    1021                 :            : 
    1022                 :            :         tref = 0;
    1023                 :            : 
    1024                 :            :         /* For each mbuf in the pool:
    1025                 :            :          * - allocate mbuf,
    1026                 :            :          * - increment it's reference up to N+1,
    1027                 :            :          * - enqueue it N times into the ring for worker cores to free.
    1028                 :            :          */
    1029                 :         64 :         for (i = 0, n = rte_mempool_avail_count(refcnt_pool);
    1030   [ +  +  +  - ]:       4160 :             i != n && (m = rte_pktmbuf_alloc(refcnt_pool)) != NULL;
    1031                 :       4096 :             i++) {
    1032                 :       4096 :                 ref = RTE_MAX(rte_rand() % REFCNT_MAX_REF, 1UL);
    1033                 :       4096 :                 tref += ref;
    1034         [ +  + ]:       4096 :                 if ((ref & 1) != 0) {
    1035                 :       2070 :                         rte_pktmbuf_refcnt_update(m, ref);
    1036         [ +  + ]:     131844 :                         while (ref-- != 0)
    1037                 :     129774 :                                 rte_ring_enqueue(refcnt_mbuf_ring, m);
    1038                 :            :                 } else {
    1039         [ +  + ]:     134122 :                         while (ref-- != 0) {
    1040                 :            :                                 rte_pktmbuf_refcnt_update(m, 1);
    1041                 :     132096 :                                 rte_ring_enqueue(refcnt_mbuf_ring, m);
    1042                 :            :                         }
    1043                 :            :                 }
    1044                 :       4096 :                 rte_pktmbuf_free(m);
    1045                 :            :         }
    1046                 :            : 
    1047         [ -  + ]:         64 :         if (i != n)
    1048                 :          0 :                 rte_panic("(lcore=%u, iter=%u): was able to allocate only "
    1049                 :            :                           "%u from %u mbufs\n", lcore, iter, i, n);
    1050                 :            : 
    1051                 :            :         /* wait till worker lcores  will consume all mbufs */
    1052         [ +  + ]:   14355272 :         while (!rte_ring_empty(refcnt_mbuf_ring))
    1053                 :            :                 ;
    1054                 :            : 
    1055                 :            :         /* check that all mbufs are back into mempool by now */
    1056         [ +  - ]:         64 :         for (wn = 0; wn != REFCNT_MAX_TIMEOUT; wn++) {
    1057         [ +  - ]:         64 :                 if ((i = rte_mempool_avail_count(refcnt_pool)) == n) {
    1058                 :         64 :                         refcnt_lcore[lcore] += tref;
    1059                 :            :                         printf("%s(lcore=%u, iter=%u) completed, "
    1060                 :            :                             "%u references processed\n",
    1061                 :            :                             __func__, lcore, iter, tref);
    1062                 :         64 :                         return;
    1063                 :            :                 }
    1064                 :            :                 rte_delay_ms(100);
    1065                 :            :         }
    1066                 :            : 
    1067                 :          0 :         rte_panic("(lcore=%u, iter=%u): after %us only "
    1068                 :            :                   "%u of %u mbufs left free\n", lcore, iter, wn, i, n);
    1069                 :            : }
    1070                 :            : 
    1071                 :            : static int
    1072                 :          1 : test_refcnt_main(struct rte_mempool *refcnt_pool,
    1073                 :            :                    struct rte_ring *refcnt_mbuf_ring)
    1074                 :            : {
    1075                 :            :         unsigned i, lcore;
    1076                 :            : 
    1077                 :            :         lcore = rte_lcore_id();
    1078                 :            :         printf("%s started at lcore %u\n", __func__, lcore);
    1079                 :            : 
    1080         [ +  + ]:         65 :         for (i = 0; i != REFCNT_MAX_ITER; i++)
    1081                 :         64 :                 test_refcnt_iter(lcore, i, refcnt_pool, refcnt_mbuf_ring);
    1082                 :            : 
    1083                 :          1 :         refcnt_stop_workers = 1;
    1084                 :            :         rte_wmb();
    1085                 :            : 
    1086                 :            :         printf("%s finished at lcore %u\n", __func__, lcore);
    1087                 :          1 :         return 0;
    1088                 :            : }
    1089                 :            : 
    1090                 :            : #endif
    1091                 :            : 
    1092                 :            : static int
    1093                 :          1 : test_refcnt_mbuf(void)
    1094                 :            : {
    1095                 :            : #ifdef RTE_MBUF_REFCNT_ATOMIC
    1096                 :            :         unsigned int main_lcore, worker, tref;
    1097                 :            :         int ret = -1;
    1098                 :            :         struct rte_mempool *refcnt_pool = NULL;
    1099                 :            :         struct rte_ring *refcnt_mbuf_ring = NULL;
    1100                 :            : 
    1101         [ -  + ]:          1 :         if (rte_lcore_count() < 2) {
    1102                 :            :                 printf("Not enough cores for test_refcnt_mbuf, expecting at least 2\n");
    1103                 :          0 :                 return TEST_SKIPPED;
    1104                 :            :         }
    1105                 :            : 
    1106                 :          1 :         printf("starting %s, at %u lcores\n", __func__, rte_lcore_count());
    1107                 :            : 
    1108                 :            :         /* create refcnt pool & ring if they don't exist */
    1109                 :            : 
    1110                 :          1 :         refcnt_pool = rte_pktmbuf_pool_create(MAKE_STRING(refcnt_pool),
    1111                 :            :                                               REFCNT_MBUF_NUM, 0, 0, 0,
    1112                 :            :                                               SOCKET_ID_ANY);
    1113         [ -  + ]:          1 :         if (refcnt_pool == NULL) {
    1114                 :            :                 printf("%s: cannot allocate " MAKE_STRING(refcnt_pool) "\n",
    1115                 :            :                        __func__);
    1116                 :          0 :                 return -1;
    1117                 :            :         }
    1118                 :            : 
    1119                 :          1 :         refcnt_mbuf_ring = rte_ring_create("refcnt_mbuf_ring",
    1120                 :            :                                            rte_align32pow2(REFCNT_RING_SIZE), SOCKET_ID_ANY,
    1121                 :            :                                            RING_F_SP_ENQ);
    1122         [ -  + ]:          1 :         if (refcnt_mbuf_ring == NULL) {
    1123                 :            :                 printf("%s: cannot allocate " MAKE_STRING(refcnt_mbuf_ring)
    1124                 :            :                        "\n", __func__);
    1125                 :          0 :                 goto err;
    1126                 :            :         }
    1127                 :            : 
    1128                 :          1 :         refcnt_stop_workers = 0;
    1129                 :            :         memset(refcnt_lcore, 0, sizeof (refcnt_lcore));
    1130                 :            : 
    1131                 :          1 :         rte_eal_mp_remote_launch(test_refcnt_worker, refcnt_mbuf_ring, SKIP_MAIN);
    1132                 :            : 
    1133                 :          1 :         test_refcnt_main(refcnt_pool, refcnt_mbuf_ring);
    1134                 :            : 
    1135                 :          1 :         rte_eal_mp_wait_lcore();
    1136                 :            : 
    1137                 :            :         /* check that we processed all references */
    1138                 :            :         tref = 0;
    1139                 :          1 :         main_lcore = rte_get_main_lcore();
    1140                 :            : 
    1141         [ +  + ]:          2 :         RTE_LCORE_FOREACH_WORKER(worker)
    1142                 :          1 :                 tref += refcnt_lcore[worker];
    1143                 :            : 
    1144         [ -  + ]:          1 :         if (tref != refcnt_lcore[main_lcore])
    1145                 :          0 :                 rte_panic("referenced mbufs: %u, freed mbufs: %u\n",
    1146                 :            :                           tref, refcnt_lcore[main_lcore]);
    1147                 :            : 
    1148                 :          1 :         rte_mempool_dump(stdout, refcnt_pool);
    1149                 :          1 :         rte_ring_dump(stdout, refcnt_mbuf_ring);
    1150                 :            : 
    1151                 :            :         ret = 0;
    1152                 :            : 
    1153                 :          1 : err:
    1154                 :          1 :         rte_mempool_free(refcnt_pool);
    1155                 :          1 :         rte_ring_free(refcnt_mbuf_ring);
    1156                 :          1 :         return ret;
    1157                 :            : #else
    1158                 :            :         return 0;
    1159                 :            : #endif
    1160                 :            : }
    1161                 :            : 
    1162                 :            : #ifdef RTE_EXEC_ENV_WINDOWS
    1163                 :            : static int
    1164                 :            : test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool)
    1165                 :            : {
    1166                 :            :         RTE_SET_USED(pktmbuf_pool);
    1167                 :            :         return TEST_SKIPPED;
    1168                 :            : }
    1169                 :            : #else
    1170                 :            : /* Verify if mbuf can pass the check */
    1171                 :            : static bool
    1172                 :            : mbuf_check_pass(struct rte_mbuf *buf)
    1173                 :            : {
    1174                 :            :         const char *reason;
    1175                 :            : 
    1176   [ -  +  -  +  :         12 :         if (rte_mbuf_check(buf, 1, &reason) == 0)
          -  +  -  +  -  
             +  -  +  -  
                      + ]
    1177                 :            :                 return true;
    1178                 :            : 
    1179                 :            :         return false;
    1180                 :            : }
    1181                 :            : 
    1182                 :            : static int
    1183                 :          2 : test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool)
    1184                 :            : {
    1185                 :            :         struct rte_mbuf *buf;
    1186                 :            :         struct rte_mbuf badbuf;
    1187                 :            : 
    1188                 :            :         printf("Checking rte_mbuf_sanity_check for failure conditions\n");
    1189                 :            : 
    1190                 :            :         /* get a good mbuf to use to make copies */
    1191                 :          2 :         buf = rte_pktmbuf_alloc(pktmbuf_pool);
    1192         [ +  - ]:          2 :         if (buf == NULL)
    1193                 :            :                 return -1;
    1194                 :            : 
    1195                 :            :         printf("Checking good mbuf initially\n");
    1196                 :            :         if (!mbuf_check_pass(buf))
    1197                 :          0 :                 return -1;
    1198                 :            : 
    1199                 :            :         printf("Now checking for error conditions\n");
    1200                 :            : 
    1201                 :            :         if (mbuf_check_pass(NULL)) {
    1202                 :            :                 printf("Error with NULL mbuf test\n");
    1203                 :          0 :                 return -1;
    1204                 :            :         }
    1205                 :            : 
    1206                 :          2 :         badbuf = *buf;
    1207                 :          2 :         badbuf.pool = NULL;
    1208                 :            :         if (mbuf_check_pass(&badbuf)) {
    1209                 :            :                 printf("Error with bad-pool mbuf test\n");
    1210                 :          0 :                 return -1;
    1211                 :            :         }
    1212                 :            : 
    1213                 :            :         if (RTE_IOVA_IN_MBUF) {
    1214                 :          2 :                 badbuf = *buf;
    1215                 :            :                 rte_mbuf_iova_set(&badbuf, 0);
    1216                 :            :                 if (mbuf_check_pass(&badbuf)) {
    1217                 :            :                         printf("Error with bad-physaddr mbuf test\n");
    1218                 :          0 :                         return -1;
    1219                 :            :                 }
    1220                 :            :         }
    1221                 :            : 
    1222                 :          2 :         badbuf = *buf;
    1223                 :          2 :         badbuf.buf_addr = NULL;
    1224                 :            :         if (mbuf_check_pass(&badbuf)) {
    1225                 :            :                 printf("Error with bad-addr mbuf test\n");
    1226                 :          0 :                 return -1;
    1227                 :            :         }
    1228                 :            : 
    1229                 :          2 :         badbuf = *buf;
    1230                 :          2 :         badbuf.refcnt = 0;
    1231                 :            :         if (mbuf_check_pass(&badbuf)) {
    1232                 :            :                 printf("Error with bad-refcnt(0) mbuf test\n");
    1233                 :          0 :                 return -1;
    1234                 :            :         }
    1235                 :            : 
    1236                 :          2 :         badbuf = *buf;
    1237                 :          2 :         badbuf.refcnt = UINT16_MAX;
    1238                 :            :         if (mbuf_check_pass(&badbuf)) {
    1239                 :            :                 printf("Error with bad-refcnt(MAX) mbuf test\n");
    1240                 :          0 :                 return -1;
    1241                 :            :         }
    1242                 :            : 
    1243                 :            :         return 0;
    1244                 :            : }
    1245                 :            : 
    1246                 :            : #endif /* !RTE_EXEC_ENV_WINDOWS */
    1247                 :            : 
    1248                 :            : static int
    1249                 :         10 : test_mbuf_linearize(struct rte_mempool *pktmbuf_pool, int pkt_len,
    1250                 :            :                     int nb_segs)
    1251                 :            : {
    1252                 :            : 
    1253                 :            :         struct rte_mbuf *m = NULL, *mbuf = NULL;
    1254                 :            :         uint8_t *data;
    1255                 :            :         int data_len = 0;
    1256                 :            :         int remain;
    1257                 :            :         int seg, seg_len;
    1258                 :            :         int i;
    1259                 :            : 
    1260         [ -  + ]:         10 :         if (pkt_len < 1) {
    1261                 :            :                 printf("Packet size must be 1 or more (is %d)\n", pkt_len);
    1262                 :          0 :                 return -1;
    1263                 :            :         }
    1264                 :            : 
    1265         [ -  + ]:         10 :         if (nb_segs < 1) {
    1266                 :            :                 printf("Number of segments must be 1 or more (is %d)\n",
    1267                 :            :                                 nb_segs);
    1268                 :          0 :                 return -1;
    1269                 :            :         }
    1270                 :            : 
    1271                 :         10 :         seg_len = pkt_len / nb_segs;
    1272         [ -  + ]:         10 :         if (seg_len == 0)
    1273                 :            :                 seg_len = 1;
    1274                 :            : 
    1275                 :            :         remain = pkt_len;
    1276                 :            : 
    1277                 :            :         /* Create chained mbuf_src and fill it generated data */
    1278         [ +  + ]:        204 :         for (seg = 0; remain > 0; seg++) {
    1279                 :            : 
    1280                 :        194 :                 m = rte_pktmbuf_alloc(pktmbuf_pool);
    1281         [ -  + ]:        194 :                 if (m == NULL) {
    1282                 :            :                         printf("Cannot create segment for source mbuf");
    1283                 :          0 :                         goto fail;
    1284                 :            :                 }
    1285                 :            : 
    1286                 :            :                 /* Make sure if tailroom is zeroed */
    1287                 :        194 :                 memset(rte_pktmbuf_mtod(m, uint8_t *), 0,
    1288                 :            :                                 rte_pktmbuf_tailroom(m));
    1289                 :            : 
    1290                 :            :                 data_len = remain;
    1291                 :            :                 if (data_len > seg_len)
    1292                 :            :                         data_len = seg_len;
    1293                 :            : 
    1294                 :        194 :                 data = (uint8_t *)rte_pktmbuf_append(m, data_len);
    1295         [ -  + ]:        194 :                 if (data == NULL) {
    1296                 :            :                         printf("Cannot append %d bytes to the mbuf\n",
    1297                 :            :                                         data_len);
    1298                 :          0 :                         goto fail;
    1299                 :            :                 }
    1300                 :            : 
    1301         [ +  + ]:       2348 :                 for (i = 0; i < data_len; i++)
    1302                 :       2154 :                         data[i] = (seg * seg_len + i) % 0x0ff;
    1303                 :            : 
    1304         [ +  + ]:        194 :                 if (seg == 0)
    1305                 :            :                         mbuf = m;
    1306                 :            :                 else
    1307                 :            :                         rte_pktmbuf_chain(mbuf, m);
    1308                 :            : 
    1309                 :        194 :                 remain -= data_len;
    1310                 :            :         }
    1311                 :            : 
    1312                 :            :         /* Create destination buffer to store coalesced data */
    1313         [ -  + ]:          8 :         if (rte_pktmbuf_linearize(mbuf)) {
    1314                 :            :                 printf("Mbuf linearization failed\n");
    1315                 :          0 :                 goto fail;
    1316                 :            :         }
    1317                 :            : 
    1318         [ -  + ]:         10 :         if (!rte_pktmbuf_is_contiguous(mbuf)) {
    1319                 :            :                 printf("Source buffer should be contiguous after "
    1320                 :            :                                 "linearization\n");
    1321                 :          0 :                 goto fail;
    1322                 :            :         }
    1323                 :            : 
    1324                 :         10 :         data = rte_pktmbuf_mtod(mbuf, uint8_t *);
    1325                 :            : 
    1326         [ +  + ]:       2164 :         for (i = 0; i < pkt_len; i++)
    1327         [ -  + ]:       2154 :                 if (data[i] != (i % 0x0ff)) {
    1328                 :            :                         printf("Incorrect data in linearized mbuf\n");
    1329                 :          0 :                         goto fail;
    1330                 :            :                 }
    1331                 :            : 
    1332                 :         10 :         rte_pktmbuf_free(mbuf);
    1333                 :         10 :         return 0;
    1334                 :            : 
    1335                 :          0 : fail:
    1336                 :          0 :         rte_pktmbuf_free(mbuf);
    1337                 :          0 :         return -1;
    1338                 :            : }
    1339                 :            : 
    1340                 :            : static int
    1341                 :          2 : test_mbuf_linearize_check(struct rte_mempool *pktmbuf_pool)
    1342                 :            : {
    1343                 :            :         struct test_mbuf_array {
    1344                 :            :                 int size;
    1345                 :            :                 int nb_segs;
    1346                 :          2 :         } mbuf_array[] = {
    1347                 :            :                         { 128, 1 },
    1348                 :            :                         { 64, 64 },
    1349                 :            :                         { 512, 10 },
    1350                 :            :                         { 250, 11 },
    1351                 :            :                         { 123, 8 },
    1352                 :            :         };
    1353                 :            :         unsigned int i;
    1354                 :            : 
    1355                 :            :         printf("Test mbuf linearize API\n");
    1356                 :            : 
    1357         [ +  + ]:         12 :         for (i = 0; i < RTE_DIM(mbuf_array); i++)
    1358         [ -  + ]:         10 :                 if (test_mbuf_linearize(pktmbuf_pool, mbuf_array[i].size,
    1359                 :            :                                 mbuf_array[i].nb_segs)) {
    1360                 :            :                         printf("Test failed for %d, %d\n", mbuf_array[i].size,
    1361                 :            :                                         mbuf_array[i].nb_segs);
    1362                 :          0 :                         return -1;
    1363                 :            :                 }
    1364                 :            : 
    1365                 :            :         return 0;
    1366                 :            : }
    1367                 :            : 
    1368                 :            : /*
    1369                 :            :  * Helper function for test_tx_ofload
    1370                 :            :  */
    1371                 :            : static inline void
    1372                 :            : set_tx_offload(struct rte_mbuf *mb, uint64_t il2, uint64_t il3, uint64_t il4,
    1373                 :            :         uint64_t tso, uint64_t ol3, uint64_t ol2)
    1374                 :            : {
    1375                 :      65536 :         mb->l2_len = il2;
    1376                 :      65536 :         mb->l3_len = il3;
    1377                 :      65536 :         mb->l4_len = il4;
    1378                 :      65536 :         mb->tso_segsz = tso;
    1379                 :      65536 :         mb->outer_l3_len = ol3;
    1380                 :      65536 :         mb->outer_l2_len = ol2;
    1381                 :            : }
    1382                 :            : 
    1383                 :            : static int
    1384                 :          1 : test_tx_offload(void)
    1385                 :            : {
    1386                 :            :         struct rte_mbuf *mb;
    1387                 :            :         uint64_t tm, v1, v2;
    1388                 :            :         size_t sz;
    1389                 :            :         uint32_t i;
    1390                 :            : 
    1391                 :            :         static volatile struct {
    1392                 :            :                 uint16_t l2;
    1393                 :            :                 uint16_t l3;
    1394                 :            :                 uint16_t l4;
    1395                 :            :                 uint16_t tso;
    1396                 :            :         } txof;
    1397                 :            : 
    1398                 :            :         const uint32_t num = 0x10000;
    1399                 :            : 
    1400                 :          1 :         txof.l2 = rte_rand() % (1 <<  RTE_MBUF_L2_LEN_BITS);
    1401                 :          1 :         txof.l3 = rte_rand() % (1 <<  RTE_MBUF_L3_LEN_BITS);
    1402                 :          1 :         txof.l4 = rte_rand() % (1 <<  RTE_MBUF_L4_LEN_BITS);
    1403                 :          1 :         txof.tso = rte_rand() % (1 <<   RTE_MBUF_TSO_SEGSZ_BITS);
    1404                 :            : 
    1405                 :          1 :         printf("%s started, tx_offload = {\n"
    1406                 :            :                 "\tl2_len=%#hx,\n"
    1407                 :            :                 "\tl3_len=%#hx,\n"
    1408                 :            :                 "\tl4_len=%#hx,\n"
    1409                 :            :                 "\ttso_segsz=%#hx,\n"
    1410                 :            :                 "\touter_l3_len=%#x,\n"
    1411                 :            :                 "\touter_l2_len=%#x,\n"
    1412                 :            :                 "};\n",
    1413                 :            :                 __func__,
    1414                 :          1 :                 txof.l2, txof.l3, txof.l4, txof.tso, txof.l3, txof.l2);
    1415                 :            : 
    1416                 :            :         sz = sizeof(*mb) * num;
    1417                 :          1 :         mb = rte_zmalloc(NULL, sz, RTE_CACHE_LINE_SIZE);
    1418         [ -  + ]:          1 :         if (mb == NULL) {
    1419                 :            :                 printf("%s failed, out of memory\n", __func__);
    1420                 :          0 :                 return -ENOMEM;
    1421                 :            :         }
    1422                 :            : 
    1423                 :            :         memset(mb, 0, sz);
    1424                 :            :         tm = rte_rdtsc_precise();
    1425                 :            : 
    1426         [ +  + ]:      65537 :         for (i = 0; i != num; i++)
    1427                 :      65536 :                 set_tx_offload(mb + i, txof.l2, txof.l3, txof.l4,
    1428                 :      65536 :                         txof.tso, txof.l3, txof.l2);
    1429                 :            : 
    1430                 :          1 :         tm = rte_rdtsc_precise() - tm;
    1431                 :          1 :         printf("%s set tx_offload by bit-fields: %u iterations, %"
    1432                 :            :                 PRIu64 " cycles, %#Lf cycles/iter\n",
    1433                 :          1 :                 __func__, num, tm, (long double)tm / num);
    1434                 :            : 
    1435                 :          1 :         v1 = mb[rte_rand() % num].tx_offload;
    1436                 :            : 
    1437                 :            :         memset(mb, 0, sz);
    1438                 :            :         tm = rte_rdtsc_precise();
    1439                 :            : 
    1440         [ +  + ]:      65537 :         for (i = 0; i != num; i++)
    1441                 :      65536 :                 mb[i].tx_offload = rte_mbuf_tx_offload(txof.l2, txof.l3,
    1442                 :      65536 :                         txof.l4, txof.tso, txof.l3, txof.l2, 0);
    1443                 :            : 
    1444                 :          1 :         tm = rte_rdtsc_precise() - tm;
    1445                 :          1 :         printf("%s set raw tx_offload: %u iterations, %"
    1446                 :            :                 PRIu64 " cycles, %#Lf cycles/iter\n",
    1447                 :          1 :                 __func__, num, tm, (long double)tm / num);
    1448                 :            : 
    1449                 :          1 :         v2 = mb[rte_rand() % num].tx_offload;
    1450                 :            : 
    1451                 :          1 :         rte_free(mb);
    1452                 :            : 
    1453                 :            :         printf("%s finished\n"
    1454                 :            :                 "expected tx_offload value: 0x%" PRIx64 ";\n"
    1455                 :            :                 "rte_mbuf_tx_offload value: 0x%" PRIx64 ";\n",
    1456                 :            :                 __func__, v1, v2);
    1457                 :            : 
    1458         [ -  + ]:          1 :         return (v1 == v2) ? 0 : -EINVAL;
    1459                 :            : }
    1460                 :            : 
    1461                 :            : static int
    1462                 :          1 : test_get_rx_ol_flag_list(void)
    1463                 :            : {
    1464                 :            :         int len = 6, ret = 0;
    1465                 :          1 :         char buf[256] = "";
    1466                 :            :         int buflen = 0;
    1467                 :            : 
    1468                 :            :         /* Test case to check with null buffer */
    1469                 :          1 :         ret = rte_get_rx_ol_flag_list(0, NULL, 0);
    1470         [ -  + ]:          1 :         if (ret != -1)
    1471                 :          0 :                 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
    1472                 :            : 
    1473                 :            :         /* Test case to check with zero buffer len */
    1474                 :          1 :         ret = rte_get_rx_ol_flag_list(RTE_MBUF_F_RX_L4_CKSUM_MASK, buf, 0);
    1475         [ -  + ]:          1 :         if (ret != -1)
    1476                 :          0 :                 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
    1477                 :            : 
    1478                 :          1 :         buflen = strlen(buf);
    1479         [ -  + ]:          1 :         if (buflen != 0)
    1480                 :          0 :                 GOTO_FAIL("%s buffer should be empty, received = %d\n",
    1481                 :            :                                 __func__, buflen);
    1482                 :            : 
    1483                 :            :         /* Test case to check with reduced buffer len */
    1484                 :          1 :         ret = rte_get_rx_ol_flag_list(0, buf, len);
    1485         [ -  + ]:          1 :         if (ret != -1)
    1486                 :          0 :                 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
    1487                 :            : 
    1488                 :          1 :         buflen = strlen(buf);
    1489         [ -  + ]:          1 :         if (buflen != (len - 1))
    1490                 :          0 :                 GOTO_FAIL("%s invalid buffer length retrieved, expected: %d,"
    1491                 :            :                                 "received = %d\n", __func__,
    1492                 :            :                                 (len - 1), buflen);
    1493                 :            : 
    1494                 :            :         /* Test case to check with zero mask value */
    1495                 :          1 :         ret = rte_get_rx_ol_flag_list(0, buf, sizeof(buf));
    1496         [ -  + ]:          1 :         if (ret != 0)
    1497                 :          0 :                 GOTO_FAIL("%s expected: 0, received = %d\n", __func__, ret);
    1498                 :            : 
    1499                 :          1 :         buflen = strlen(buf);
    1500         [ -  + ]:          1 :         if (buflen == 0)
    1501                 :          0 :                 GOTO_FAIL("%s expected: %s, received length = 0\n", __func__,
    1502                 :            :                                 "non-zero, buffer should not be empty");
    1503                 :            : 
    1504                 :            :         /* Test case to check with valid mask value */
    1505                 :          1 :         ret = rte_get_rx_ol_flag_list(RTE_MBUF_F_RX_SEC_OFFLOAD, buf,
    1506                 :            :                                       sizeof(buf));
    1507         [ -  + ]:          1 :         if (ret != 0)
    1508                 :          0 :                 GOTO_FAIL("%s expected: 0, received = %d\n", __func__, ret);
    1509                 :            : 
    1510                 :          1 :         buflen = strlen(buf);
    1511         [ -  + ]:          1 :         if (buflen == 0)
    1512                 :          0 :                 GOTO_FAIL("%s expected: %s, received length = 0\n", __func__,
    1513                 :            :                                 "non-zero, buffer should not be empty");
    1514                 :            : 
    1515                 :            :         return 0;
    1516                 :            : fail:
    1517                 :            :         return -1;
    1518                 :            : }
    1519                 :            : 
    1520                 :            : static int
    1521                 :          1 : test_get_tx_ol_flag_list(void)
    1522                 :            : {
    1523                 :            :         int len = 6, ret = 0;
    1524                 :          1 :         char buf[256] = "";
    1525                 :            :         int buflen = 0;
    1526                 :            : 
    1527                 :            :         /* Test case to check with null buffer */
    1528                 :          1 :         ret = rte_get_tx_ol_flag_list(0, NULL, 0);
    1529         [ -  + ]:          1 :         if (ret != -1)
    1530                 :          0 :                 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
    1531                 :            : 
    1532                 :            :         /* Test case to check with zero buffer len */
    1533                 :          1 :         ret = rte_get_tx_ol_flag_list(RTE_MBUF_F_TX_IP_CKSUM, buf, 0);
    1534         [ -  + ]:          1 :         if (ret != -1)
    1535                 :          0 :                 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
    1536                 :            : 
    1537                 :          1 :         buflen = strlen(buf);
    1538         [ -  + ]:          1 :         if (buflen != 0) {
    1539                 :          0 :                 GOTO_FAIL("%s buffer should be empty, received = %d\n",
    1540                 :            :                                 __func__, buflen);
    1541                 :            :         }
    1542                 :            : 
    1543                 :            :         /* Test case to check with reduced buffer len */
    1544                 :          1 :         ret = rte_get_tx_ol_flag_list(0, buf, len);
    1545         [ -  + ]:          1 :         if (ret != -1)
    1546                 :          0 :                 GOTO_FAIL("%s expected: -1, received = %d\n", __func__, ret);
    1547                 :            : 
    1548                 :          1 :         buflen = strlen(buf);
    1549         [ -  + ]:          1 :         if (buflen != (len - 1))
    1550                 :          0 :                 GOTO_FAIL("%s invalid buffer length retrieved, expected: %d,"
    1551                 :            :                                 "received = %d\n", __func__,
    1552                 :            :                                 (len - 1), buflen);
    1553                 :            : 
    1554                 :            :         /* Test case to check with zero mask value */
    1555                 :          1 :         ret = rte_get_tx_ol_flag_list(0, buf, sizeof(buf));
    1556         [ -  + ]:          1 :         if (ret != 0)
    1557                 :          0 :                 GOTO_FAIL("%s expected: 0, received = %d\n", __func__, ret);
    1558                 :            : 
    1559                 :          1 :         buflen = strlen(buf);
    1560         [ -  + ]:          1 :         if (buflen == 0)
    1561                 :          0 :                 GOTO_FAIL("%s expected: %s, received length = 0\n", __func__,
    1562                 :            :                                 "non-zero, buffer should not be empty");
    1563                 :            : 
    1564                 :            :         /* Test case to check with valid mask value */
    1565                 :          1 :         ret = rte_get_tx_ol_flag_list(RTE_MBUF_F_TX_UDP_CKSUM, buf,
    1566                 :            :                                       sizeof(buf));
    1567         [ -  + ]:          1 :         if (ret != 0)
    1568                 :          0 :                 GOTO_FAIL("%s expected: 0, received = %d\n", __func__, ret);
    1569                 :            : 
    1570                 :          1 :         buflen = strlen(buf);
    1571         [ -  + ]:          1 :         if (buflen == 0)
    1572                 :          0 :                 GOTO_FAIL("%s expected: %s, received length = 0\n", __func__,
    1573                 :            :                                 "non-zero, buffer should not be empty");
    1574                 :            : 
    1575                 :            :         return 0;
    1576                 :            : fail:
    1577                 :            :         return -1;
    1578                 :            : 
    1579                 :            : }
    1580                 :            : 
    1581                 :            : struct flag_name {
    1582                 :            :         uint64_t flag;
    1583                 :            :         const char *name;
    1584                 :            : };
    1585                 :            : 
    1586                 :            : static int
    1587                 :          1 : test_get_rx_ol_flag_name(void)
    1588                 :            : {
    1589                 :            :         uint16_t i;
    1590                 :            :         const char *flag_str = NULL;
    1591                 :          1 :         const struct flag_name rx_flags[] = {
    1592                 :            :                 VAL_NAME(RTE_MBUF_F_RX_VLAN),
    1593                 :            :                 VAL_NAME(RTE_MBUF_F_RX_RSS_HASH),
    1594                 :            :                 VAL_NAME(RTE_MBUF_F_RX_FDIR),
    1595                 :            :                 VAL_NAME(RTE_MBUF_F_RX_L4_CKSUM_BAD),
    1596                 :            :                 VAL_NAME(RTE_MBUF_F_RX_L4_CKSUM_GOOD),
    1597                 :            :                 VAL_NAME(RTE_MBUF_F_RX_L4_CKSUM_NONE),
    1598                 :            :                 VAL_NAME(RTE_MBUF_F_RX_IP_CKSUM_BAD),
    1599                 :            :                 VAL_NAME(RTE_MBUF_F_RX_IP_CKSUM_GOOD),
    1600                 :            :                 VAL_NAME(RTE_MBUF_F_RX_IP_CKSUM_NONE),
    1601                 :            :                 VAL_NAME(RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD),
    1602                 :            :                 VAL_NAME(RTE_MBUF_F_RX_VLAN_STRIPPED),
    1603                 :            :                 VAL_NAME(RTE_MBUF_F_RX_IEEE1588_PTP),
    1604                 :            :                 VAL_NAME(RTE_MBUF_F_RX_IEEE1588_TMST),
    1605                 :            :                 VAL_NAME(RTE_MBUF_F_RX_FDIR_ID),
    1606                 :            :                 VAL_NAME(RTE_MBUF_F_RX_FDIR_FLX),
    1607                 :            :                 VAL_NAME(RTE_MBUF_F_RX_QINQ_STRIPPED),
    1608                 :            :                 VAL_NAME(RTE_MBUF_F_RX_LRO),
    1609                 :            :                 VAL_NAME(RTE_MBUF_F_RX_SEC_OFFLOAD),
    1610                 :            :                 VAL_NAME(RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED),
    1611                 :            :                 VAL_NAME(RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD),
    1612                 :            :                 VAL_NAME(RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD),
    1613                 :            :                 VAL_NAME(RTE_MBUF_F_RX_OUTER_L4_CKSUM_INVALID),
    1614                 :            :         };
    1615                 :            : 
    1616                 :            :         /* Test case to check with valid flag */
    1617         [ +  + ]:         23 :         for (i = 0; i < RTE_DIM(rx_flags); i++) {
    1618                 :         22 :                 flag_str = rte_get_rx_ol_flag_name(rx_flags[i].flag);
    1619         [ -  + ]:         22 :                 if (flag_str == NULL)
    1620                 :          0 :                         GOTO_FAIL("%s: Expected flagname = %s; received null\n",
    1621                 :            :                                         __func__, rx_flags[i].name);
    1622         [ -  + ]:         22 :                 if (strcmp(flag_str, rx_flags[i].name) != 0)
    1623                 :          0 :                         GOTO_FAIL("%s: Expected flagname = %s; received = %s\n",
    1624                 :            :                                 __func__, rx_flags[i].name, flag_str);
    1625                 :            :         }
    1626                 :            :         /* Test case to check with invalid flag */
    1627                 :          1 :         flag_str = rte_get_rx_ol_flag_name(0);
    1628         [ -  + ]:          1 :         if (flag_str != NULL) {
    1629                 :          0 :                 GOTO_FAIL("%s: Expected flag name = null; received = %s\n",
    1630                 :            :                                 __func__, flag_str);
    1631                 :            :         }
    1632                 :            : 
    1633                 :            :         return 0;
    1634                 :            : fail:
    1635                 :            :         return -1;
    1636                 :            : }
    1637                 :            : 
    1638                 :            : static int
    1639                 :          1 : test_get_tx_ol_flag_name(void)
    1640                 :            : {
    1641                 :            :         uint16_t i;
    1642                 :            :         const char *flag_str = NULL;
    1643                 :          1 :         const struct flag_name tx_flags[] = {
    1644                 :            :                 VAL_NAME(RTE_MBUF_F_TX_VLAN),
    1645                 :            :                 VAL_NAME(RTE_MBUF_F_TX_IP_CKSUM),
    1646                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TCP_CKSUM),
    1647                 :            :                 VAL_NAME(RTE_MBUF_F_TX_SCTP_CKSUM),
    1648                 :            :                 VAL_NAME(RTE_MBUF_F_TX_UDP_CKSUM),
    1649                 :            :                 VAL_NAME(RTE_MBUF_F_TX_IEEE1588_TMST),
    1650                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TCP_SEG),
    1651                 :            :                 VAL_NAME(RTE_MBUF_F_TX_IPV4),
    1652                 :            :                 VAL_NAME(RTE_MBUF_F_TX_IPV6),
    1653                 :            :                 VAL_NAME(RTE_MBUF_F_TX_OUTER_IP_CKSUM),
    1654                 :            :                 VAL_NAME(RTE_MBUF_F_TX_OUTER_IPV4),
    1655                 :            :                 VAL_NAME(RTE_MBUF_F_TX_OUTER_IPV6),
    1656                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TUNNEL_VXLAN),
    1657                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TUNNEL_GRE),
    1658                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TUNNEL_IPIP),
    1659                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TUNNEL_GENEVE),
    1660                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TUNNEL_MPLSINUDP),
    1661                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE),
    1662                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TUNNEL_IP),
    1663                 :            :                 VAL_NAME(RTE_MBUF_F_TX_TUNNEL_UDP),
    1664                 :            :                 VAL_NAME(RTE_MBUF_F_TX_QINQ),
    1665                 :            :                 VAL_NAME(RTE_MBUF_F_TX_MACSEC),
    1666                 :            :                 VAL_NAME(RTE_MBUF_F_TX_SEC_OFFLOAD),
    1667                 :            :                 VAL_NAME(RTE_MBUF_F_TX_UDP_SEG),
    1668                 :            :                 VAL_NAME(RTE_MBUF_F_TX_OUTER_UDP_CKSUM),
    1669                 :            :         };
    1670                 :            : 
    1671                 :            :         /* Test case to check with valid flag */
    1672         [ +  + ]:         26 :         for (i = 0; i < RTE_DIM(tx_flags); i++) {
    1673                 :         25 :                 flag_str = rte_get_tx_ol_flag_name(tx_flags[i].flag);
    1674         [ -  + ]:         25 :                 if (flag_str == NULL)
    1675                 :          0 :                         GOTO_FAIL("%s: Expected flagname = %s; received null\n",
    1676                 :            :                                 __func__, tx_flags[i].name);
    1677         [ -  + ]:         25 :                 if (strcmp(flag_str, tx_flags[i].name) != 0)
    1678                 :          0 :                         GOTO_FAIL("%s: Expected flagname = %s; received = %s\n",
    1679                 :            :                                 __func__, tx_flags[i].name, flag_str);
    1680                 :            :         }
    1681                 :            :         /* Test case to check with invalid flag */
    1682                 :          1 :         flag_str = rte_get_tx_ol_flag_name(0);
    1683         [ -  + ]:          1 :         if (flag_str != NULL) {
    1684                 :          0 :                 GOTO_FAIL("%s: Expected flag name = null; received = %s\n",
    1685                 :            :                                 __func__, flag_str);
    1686                 :            :         }
    1687                 :            : 
    1688                 :            :         return 0;
    1689                 :            : fail:
    1690                 :            :         return -1;
    1691                 :            : 
    1692                 :            : }
    1693                 :            : 
    1694                 :            : static int
    1695                 :         11 : test_mbuf_validate_tx_offload(const char *test_name,
    1696                 :            :                 struct rte_mempool *pktmbuf_pool,
    1697                 :            :                 uint64_t ol_flags,
    1698                 :            :                 uint16_t segsize,
    1699                 :            :                 int expected_retval)
    1700                 :            : {
    1701                 :            :         struct rte_mbuf *m = NULL;
    1702                 :            :         int ret = 0;
    1703                 :            : 
    1704                 :            :         /* alloc a mbuf and do sanity check */
    1705                 :         11 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
    1706         [ -  + ]:         11 :         if (m == NULL)
    1707                 :          0 :                 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
    1708         [ -  + ]:         11 :         if (rte_pktmbuf_pkt_len(m) != 0)
    1709                 :          0 :                 GOTO_FAIL("%s: Bad packet length\n", __func__);
    1710                 :         11 :         rte_mbuf_sanity_check(m, 0);
    1711                 :         11 :         m->ol_flags = ol_flags;
    1712                 :         11 :         m->tso_segsz = segsize;
    1713                 :         11 :         ret = rte_validate_tx_offload(m);
    1714         [ -  + ]:         11 :         if (ret != expected_retval)
    1715                 :          0 :                 GOTO_FAIL("%s(%s): expected ret val: %d; received: %d\n",
    1716                 :            :                                 __func__, test_name, expected_retval, ret);
    1717                 :         11 :         rte_pktmbuf_free(m);
    1718                 :            :         m = NULL;
    1719                 :         11 :         return 0;
    1720                 :          0 : fail:
    1721         [ #  # ]:          0 :         if (m) {
    1722                 :          0 :                 rte_pktmbuf_free(m);
    1723                 :            :                 m = NULL;
    1724                 :            :         }
    1725                 :            :         return -1;
    1726                 :            : }
    1727                 :            : 
    1728                 :            : static int
    1729                 :          1 : test_mbuf_validate_tx_offload_one(struct rte_mempool *pktmbuf_pool)
    1730                 :            : {
    1731                 :            :         /* test to validate tx offload flags */
    1732                 :            :         uint64_t ol_flags = 0;
    1733                 :            : 
    1734                 :            :         /* test to validate if IP checksum is counted only for IPV4 packet */
    1735                 :            :         /* set both IP checksum and IPV6 flags */
    1736                 :            :         ol_flags |= RTE_MBUF_F_TX_IP_CKSUM;
    1737                 :            :         ol_flags |= RTE_MBUF_F_TX_IPV6;
    1738         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_IP_CKSUM_IPV6_SET",
    1739                 :            :                                 pktmbuf_pool,
    1740                 :            :                                 ol_flags, 0, -EINVAL) < 0)
    1741                 :          0 :                 GOTO_FAIL("%s failed: IP cksum is set incorrect.\n", __func__);
    1742                 :            :         /* resetting ol_flags for next testcase */
    1743                 :            :         ol_flags = 0;
    1744                 :            : 
    1745                 :            :         /* test to validate if IP type is set when required */
    1746                 :            :         ol_flags |= RTE_MBUF_F_TX_L4_MASK;
    1747         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_IP_TYPE_NOT_SET",
    1748                 :            :                                 pktmbuf_pool,
    1749                 :            :                                 ol_flags, 0, -EINVAL) < 0)
    1750                 :          0 :                 GOTO_FAIL("%s failed: IP type is not set.\n", __func__);
    1751                 :            : 
    1752                 :            :         /* test if IP type is set when TCP SEG is on */
    1753                 :            :         ol_flags |= RTE_MBUF_F_TX_TCP_SEG;
    1754         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_IP_TYPE_NOT_SET",
    1755                 :            :                                 pktmbuf_pool,
    1756                 :            :                                 ol_flags, 0, -EINVAL) < 0)
    1757                 :          0 :                 GOTO_FAIL("%s failed: IP type is not set.\n", __func__);
    1758                 :            : 
    1759                 :            :         ol_flags = 0;
    1760                 :            :         /* test to confirm IP type (IPV4/IPV6) is set */
    1761                 :            :         ol_flags = RTE_MBUF_F_TX_L4_MASK;
    1762                 :            :         ol_flags |= RTE_MBUF_F_TX_IPV6;
    1763         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_IP_TYPE_SET",
    1764                 :            :                                 pktmbuf_pool,
    1765                 :            :                                 ol_flags, 0, 0) < 0)
    1766                 :          0 :                 GOTO_FAIL("%s failed: tx offload flag error.\n", __func__);
    1767                 :            : 
    1768                 :            :         ol_flags = 0;
    1769                 :            :         /* test to check TSO segment size is non-zero */
    1770                 :            :         ol_flags |= RTE_MBUF_F_TX_IPV4;
    1771                 :            :         ol_flags |= RTE_MBUF_F_TX_TCP_SEG;
    1772                 :            :         /* set 0 tso segment size */
    1773         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_NULL_TSO_SEGSZ",
    1774                 :            :                                 pktmbuf_pool,
    1775                 :            :                                 ol_flags, 0, -EINVAL) < 0)
    1776                 :          0 :                 GOTO_FAIL("%s failed: tso segment size is null.\n", __func__);
    1777                 :            : 
    1778                 :            :         /* retain IPV4 and RTE_MBUF_F_TX_TCP_SEG mask */
    1779                 :            :         /* set valid tso segment size but IP CKSUM not set */
    1780         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_TSO_IP_CKSUM_NOT_SET",
    1781                 :            :                                 pktmbuf_pool,
    1782                 :            :                                 ol_flags, 512, -EINVAL) < 0)
    1783                 :          0 :                 GOTO_FAIL("%s failed: IP CKSUM is not set.\n", __func__);
    1784                 :            : 
    1785                 :            :         /* test to validate if IP checksum is set for TSO capability */
    1786                 :            :         /* retain IPV4, TCP_SEG, tso_seg size */
    1787                 :            :         ol_flags |= RTE_MBUF_F_TX_IP_CKSUM;
    1788         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_TSO_IP_CKSUM_SET",
    1789                 :            :                                 pktmbuf_pool,
    1790                 :            :                                 ol_flags, 512, 0) < 0)
    1791                 :          0 :                 GOTO_FAIL("%s failed: tx offload flag error.\n", __func__);
    1792                 :            : 
    1793                 :            :         /* test to confirm TSO for IPV6 type */
    1794                 :            :         ol_flags = 0;
    1795                 :            :         ol_flags |= RTE_MBUF_F_TX_IPV6;
    1796                 :            :         ol_flags |= RTE_MBUF_F_TX_TCP_SEG;
    1797         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_TSO_IPV6_SET",
    1798                 :            :                                 pktmbuf_pool,
    1799                 :            :                                 ol_flags, 512, 0) < 0)
    1800                 :          0 :                 GOTO_FAIL("%s failed: TSO req not met.\n", __func__);
    1801                 :            : 
    1802                 :            :         ol_flags = 0;
    1803                 :            :         /* test if outer IP checksum set for non outer IPv4 packet */
    1804                 :            :         ol_flags |= RTE_MBUF_F_TX_IPV6;
    1805                 :            :         ol_flags |= RTE_MBUF_F_TX_OUTER_IP_CKSUM;
    1806         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_OUTER_IPV4_NOT_SET",
    1807                 :            :                                 pktmbuf_pool,
    1808                 :            :                                 ol_flags, 512, -EINVAL) < 0)
    1809                 :          0 :                 GOTO_FAIL("%s failed: Outer IP cksum set.\n", __func__);
    1810                 :            : 
    1811                 :            :         ol_flags = 0;
    1812                 :            :         /* test to confirm outer IP checksum is set for outer IPV4 packet */
    1813                 :            :         ol_flags |= RTE_MBUF_F_TX_OUTER_IP_CKSUM;
    1814                 :            :         ol_flags |= RTE_MBUF_F_TX_OUTER_IPV4;
    1815         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_OUTER_IPV4_SET",
    1816                 :            :                                 pktmbuf_pool,
    1817                 :            :                                 ol_flags, 512, 0) < 0)
    1818                 :          0 :                 GOTO_FAIL("%s failed: tx offload flag error.\n", __func__);
    1819                 :            : 
    1820                 :            :         ol_flags = 0;
    1821                 :            :         /* test to confirm if packets with no TX_OFFLOAD_MASK are skipped */
    1822         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload("MBUF_TEST_OL_MASK_NOT_SET",
    1823                 :            :                                 pktmbuf_pool,
    1824                 :            :                                 ol_flags, 512, 0) < 0)
    1825                 :          0 :                 GOTO_FAIL("%s failed: tx offload flag error.\n", __func__);
    1826                 :            :         return 0;
    1827                 :            : fail:
    1828                 :            :         return -1;
    1829                 :            : }
    1830                 :            : 
    1831                 :            : /*
    1832                 :            :  * Test for allocating a bulk of mbufs
    1833                 :            :  * define an array with positive sizes for mbufs allocations.
    1834                 :            :  */
    1835                 :            : static int
    1836                 :          2 : test_pktmbuf_alloc_bulk(struct rte_mempool *pktmbuf_pool)
    1837                 :            : {
    1838                 :            :         int ret = 0;
    1839                 :            :         unsigned int idx, loop;
    1840                 :          2 :         unsigned int alloc_counts[] = {
    1841                 :            :                 0,
    1842                 :            :                 MEMPOOL_CACHE_SIZE - 1,
    1843                 :            :                 MEMPOOL_CACHE_SIZE + 1,
    1844                 :            :                 MEMPOOL_CACHE_SIZE * 1.5,
    1845                 :            :                 MEMPOOL_CACHE_SIZE * 2,
    1846                 :            :                 MEMPOOL_CACHE_SIZE * 2 - 1,
    1847                 :            :                 MEMPOOL_CACHE_SIZE * 2 + 1,
    1848                 :            :                 MEMPOOL_CACHE_SIZE,
    1849                 :            :         };
    1850                 :            : 
    1851                 :            :         /* allocate a large array of mbuf pointers */
    1852                 :          2 :         struct rte_mbuf *mbufs[NB_MBUF] = { 0 };
    1853         [ +  + ]:         18 :         for (idx = 0; idx < RTE_DIM(alloc_counts); idx++) {
    1854                 :         16 :                 ret = rte_pktmbuf_alloc_bulk(pktmbuf_pool, mbufs,
    1855                 :            :                                 alloc_counts[idx]);
    1856         [ +  - ]:         16 :                 if (ret == 0) {
    1857         [ +  + ]:        688 :                         for (loop = 0; loop < alloc_counts[idx] &&
    1858         [ +  - ]:       1344 :                                         mbufs[loop] != NULL; loop++)
    1859                 :        672 :                                 rte_pktmbuf_free(mbufs[loop]);
    1860                 :            :                 } else if (ret != 0) {
    1861                 :            :                         printf("%s: Bulk alloc failed count(%u); ret val(%d)\n",
    1862                 :            :                                         __func__, alloc_counts[idx], ret);
    1863                 :          0 :                         return -1;
    1864                 :            :                 }
    1865                 :            :         }
    1866                 :            :         return 0;
    1867                 :            : }
    1868                 :            : 
    1869                 :            : /*
    1870                 :            :  * Negative testing for allocating a bulk of mbufs
    1871                 :            :  */
    1872                 :            : static int
    1873                 :          2 : test_neg_pktmbuf_alloc_bulk(struct rte_mempool *pktmbuf_pool)
    1874                 :            : {
    1875                 :            :         int ret = 0;
    1876                 :            :         unsigned int idx, loop;
    1877                 :          2 :         unsigned int neg_alloc_counts[] = {
    1878                 :            :                 MEMPOOL_CACHE_SIZE - NB_MBUF,
    1879                 :            :                 NB_MBUF + 1,
    1880                 :            :                 NB_MBUF * 8,
    1881                 :            :                 UINT_MAX
    1882                 :            :         };
    1883                 :          2 :         struct rte_mbuf *mbufs[NB_MBUF * 8] = { 0 };
    1884                 :            : 
    1885         [ +  + ]:         10 :         for (idx = 0; idx < RTE_DIM(neg_alloc_counts); idx++) {
    1886                 :          8 :                 ret = rte_pktmbuf_alloc_bulk(pktmbuf_pool, mbufs,
    1887                 :            :                                 neg_alloc_counts[idx]);
    1888         [ -  + ]:          8 :                 if (ret == 0) {
    1889                 :            :                         printf("%s: Bulk alloc must fail! count(%u); ret(%d)\n",
    1890                 :            :                                         __func__, neg_alloc_counts[idx], ret);
    1891         [ #  # ]:          0 :                         for (loop = 0; loop < neg_alloc_counts[idx] &&
    1892         [ #  # ]:          0 :                                         mbufs[loop] != NULL; loop++)
    1893                 :          0 :                                 rte_pktmbuf_free(mbufs[loop]);
    1894                 :            :                         return -1;
    1895                 :            :                 }
    1896                 :            :         }
    1897                 :            :         return 0;
    1898                 :            : }
    1899                 :            : 
    1900                 :            : /*
    1901                 :            :  * Test to read mbuf packet using rte_pktmbuf_read
    1902                 :            :  */
    1903                 :            : static int
    1904                 :          2 : test_pktmbuf_read(struct rte_mempool *pktmbuf_pool)
    1905                 :            : {
    1906                 :            :         struct rte_mbuf *m = NULL;
    1907                 :            :         char *data = NULL;
    1908                 :            :         const char *data_copy = NULL;
    1909                 :            :         int off;
    1910                 :            : 
    1911                 :            :         /* alloc a mbuf */
    1912                 :          2 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
    1913         [ -  + ]:          2 :         if (m == NULL)
    1914                 :          0 :                 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
    1915         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != 0)
    1916                 :          0 :                 GOTO_FAIL("%s: Bad packet length\n", __func__);
    1917                 :          2 :         rte_mbuf_sanity_check(m, 0);
    1918                 :            : 
    1919                 :            :         data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN2);
    1920         [ -  + ]:          2 :         if (data == NULL)
    1921                 :          0 :                 GOTO_FAIL("%s: Cannot append data\n", __func__);
    1922         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != MBUF_TEST_DATA_LEN2)
    1923                 :          0 :                 GOTO_FAIL("%s: Bad packet length\n", __func__);
    1924                 :            :         memset(data, 0xfe, MBUF_TEST_DATA_LEN2);
    1925                 :            : 
    1926                 :            :         /* read the data from mbuf */
    1927                 :            :         data_copy = rte_pktmbuf_read(m, 0, MBUF_TEST_DATA_LEN2, NULL);
    1928         [ -  + ]:          2 :         if (data_copy == NULL)
    1929                 :          0 :                 GOTO_FAIL("%s: Error in reading data!\n", __func__);
    1930         [ +  + ]:        102 :         for (off = 0; off < MBUF_TEST_DATA_LEN2; off++) {
    1931         [ -  + ]:        100 :                 if (data_copy[off] != (char)0xfe)
    1932                 :          0 :                         GOTO_FAIL("Data corrupted at offset %u", off);
    1933                 :            :         }
    1934                 :          2 :         rte_pktmbuf_free(m);
    1935                 :            :         m = NULL;
    1936                 :            : 
    1937                 :          2 :         return 0;
    1938                 :          0 : fail:
    1939         [ #  # ]:          0 :         if (m) {
    1940                 :          0 :                 rte_pktmbuf_free(m);
    1941                 :            :                 m = NULL;
    1942                 :            :         }
    1943                 :            :         return -1;
    1944                 :            : }
    1945                 :            : 
    1946                 :            : /*
    1947                 :            :  * Test to read mbuf packet data from offset
    1948                 :            :  */
    1949                 :            : static int
    1950                 :          2 : test_pktmbuf_read_from_offset(struct rte_mempool *pktmbuf_pool)
    1951                 :            : {
    1952                 :            :         struct rte_mbuf *m = NULL;
    1953                 :            :         struct ether_hdr *hdr = NULL;
    1954                 :            :         char *data = NULL;
    1955                 :            :         const char *data_copy = NULL;
    1956                 :            :         unsigned int off;
    1957                 :            :         unsigned int hdr_len = sizeof(struct rte_ether_hdr);
    1958                 :            : 
    1959                 :            :         /* alloc a mbuf */
    1960                 :          2 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
    1961         [ -  + ]:          2 :         if (m == NULL)
    1962                 :          0 :                 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
    1963                 :            : 
    1964         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != 0)
    1965                 :          0 :                 GOTO_FAIL("%s: Bad packet length\n", __func__);
    1966                 :          2 :         rte_mbuf_sanity_check(m, 0);
    1967                 :            : 
    1968                 :            :         /* prepend an ethernet header */
    1969                 :            :         hdr = (struct ether_hdr *)rte_pktmbuf_prepend(m, hdr_len);
    1970         [ -  + ]:          2 :         if (hdr == NULL)
    1971                 :          0 :                 GOTO_FAIL("%s: Cannot prepend header\n", __func__);
    1972         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != hdr_len)
    1973                 :          0 :                 GOTO_FAIL("%s: Bad pkt length", __func__);
    1974         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(m) != hdr_len)
    1975                 :          0 :                 GOTO_FAIL("%s: Bad data length", __func__);
    1976                 :            :         memset(hdr, 0xde, hdr_len);
    1977                 :            : 
    1978                 :            :         /* read mbuf header info from 0 offset */
    1979                 :            :         data_copy = rte_pktmbuf_read(m, 0, hdr_len, NULL);
    1980         [ -  + ]:          2 :         if (data_copy == NULL)
    1981                 :          0 :                 GOTO_FAIL("%s: Error in reading header!\n", __func__);
    1982         [ +  + ]:         30 :         for (off = 0; off < hdr_len; off++) {
    1983         [ -  + ]:         28 :                 if (data_copy[off] != (char)0xde)
    1984                 :          0 :                         GOTO_FAIL("Header info corrupted at offset %u", off);
    1985                 :            :         }
    1986                 :            : 
    1987                 :            :         /* append sample data after ethernet header */
    1988                 :            :         data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN2);
    1989         [ -  + ]:          2 :         if (data == NULL)
    1990                 :          0 :                 GOTO_FAIL("%s: Cannot append data\n", __func__);
    1991         [ -  + ]:          2 :         if (rte_pktmbuf_pkt_len(m) != hdr_len + MBUF_TEST_DATA_LEN2)
    1992                 :          0 :                 GOTO_FAIL("%s: Bad packet length\n", __func__);
    1993         [ -  + ]:          2 :         if (rte_pktmbuf_data_len(m) != hdr_len + MBUF_TEST_DATA_LEN2)
    1994                 :          0 :                 GOTO_FAIL("%s: Bad data length\n", __func__);
    1995                 :            :         memset(data, 0xcc, MBUF_TEST_DATA_LEN2);
    1996                 :            : 
    1997                 :            :         /* read mbuf data after header info */
    1998                 :            :         data_copy = rte_pktmbuf_read(m, hdr_len, MBUF_TEST_DATA_LEN2, NULL);
    1999         [ -  + ]:          2 :         if (data_copy == NULL)
    2000                 :          0 :                 GOTO_FAIL("%s: Error in reading header data!\n", __func__);
    2001         [ +  + ]:        102 :         for (off = 0; off < MBUF_TEST_DATA_LEN2; off++) {
    2002         [ -  + ]:        100 :                 if (data_copy[off] != (char)0xcc)
    2003                 :          0 :                         GOTO_FAIL("Data corrupted at offset %u", off);
    2004                 :            :         }
    2005                 :            : 
    2006                 :            :         /* partial reading of mbuf data */
    2007                 :            :         data_copy = rte_pktmbuf_read(m, hdr_len + 5, MBUF_TEST_DATA_LEN2 - 5,
    2008                 :            :                         NULL);
    2009         [ -  + ]:          2 :         if (data_copy == NULL)
    2010                 :          0 :                 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
    2011         [ +  + ]:         92 :         for (off = 0; off < MBUF_TEST_DATA_LEN2 - 5; off++) {
    2012         [ -  + ]:         90 :                 if (data_copy[off] != (char)0xcc)
    2013                 :          0 :                         GOTO_FAIL("Data corrupted at offset %u", off);
    2014                 :            :         }
    2015                 :            : 
    2016                 :            :         /* read length greater than mbuf data_len */
    2017         [ -  + ]:          2 :         if (rte_pktmbuf_read(m, hdr_len, rte_pktmbuf_data_len(m) + 1,
    2018                 :            :                                 NULL) != NULL)
    2019                 :          0 :                 GOTO_FAIL("%s: Requested len is larger than mbuf data len!\n",
    2020                 :            :                                 __func__);
    2021                 :            : 
    2022                 :            :         /* read length greater than mbuf pkt_len */
    2023   [ -  +  -  + ]:          4 :         if (rte_pktmbuf_read(m, hdr_len, rte_pktmbuf_pkt_len(m) + 1,
    2024                 :            :                                 NULL) != NULL)
    2025                 :          0 :                 GOTO_FAIL("%s: Requested len is larger than mbuf pkt len!\n",
    2026                 :            :                                 __func__);
    2027                 :            : 
    2028                 :            :         /* read data of zero len from valid offset */
    2029                 :            :         data_copy = rte_pktmbuf_read(m, hdr_len, 0, NULL);
    2030         [ -  + ]:          2 :         if (data_copy == NULL)
    2031                 :          0 :                 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
    2032         [ +  + ]:        102 :         for (off = 0; off < MBUF_TEST_DATA_LEN2; off++) {
    2033         [ -  + ]:        100 :                 if (data_copy[off] != (char)0xcc)
    2034                 :          0 :                         GOTO_FAIL("Data corrupted at offset %u", off);
    2035                 :            :         }
    2036                 :            : 
    2037                 :            :         /* read data of zero length from zero offset */
    2038                 :            :         data_copy = rte_pktmbuf_read(m, 0, 0, NULL);
    2039         [ -  + ]:          2 :         if (data_copy == NULL)
    2040                 :          0 :                 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
    2041                 :            :         /* check if the received address is the beginning of header info */
    2042         [ -  + ]:          2 :         if (hdr != (const struct ether_hdr *)data_copy)
    2043                 :          0 :                 GOTO_FAIL("%s: Corrupted data address!\n", __func__);
    2044                 :            : 
    2045                 :            :         /* read data of max length from valid offset */
    2046                 :            :         data_copy = rte_pktmbuf_read(m, hdr_len, UINT_MAX, NULL);
    2047         [ -  + ]:          2 :         if (data_copy == NULL)
    2048                 :          0 :                 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
    2049                 :            :         /* check if the received address is the beginning of data segment */
    2050         [ -  + ]:          2 :         if (data_copy != data)
    2051                 :          0 :                 GOTO_FAIL("%s: Corrupted data address!\n", __func__);
    2052                 :            : 
    2053                 :            :         /* try to read from mbuf with max size offset */
    2054                 :            :         data_copy = rte_pktmbuf_read(m, UINT_MAX, 0, NULL);
    2055         [ -  + ]:          2 :         if (data_copy != NULL)
    2056                 :          0 :                 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
    2057                 :            : 
    2058                 :            :         /* try to read from mbuf with max size offset and len */
    2059                 :            :         data_copy = rte_pktmbuf_read(m, UINT_MAX, UINT_MAX, NULL);
    2060         [ -  + ]:          2 :         if (data_copy != NULL)
    2061                 :          0 :                 GOTO_FAIL("%s: Error in reading packet data!\n", __func__);
    2062                 :            : 
    2063                 :          2 :         rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
    2064                 :            : 
    2065                 :          2 :         rte_pktmbuf_free(m);
    2066                 :            :         m = NULL;
    2067                 :            : 
    2068                 :          2 :         return 0;
    2069                 :          0 : fail:
    2070         [ #  # ]:          0 :         if (m) {
    2071                 :          0 :                 rte_pktmbuf_free(m);
    2072                 :            :                 m = NULL;
    2073                 :            :         }
    2074                 :            :         return -1;
    2075                 :            : }
    2076                 :            : 
    2077                 :            : struct test_case {
    2078                 :            :         unsigned int seg_count;
    2079                 :            :         unsigned int flags;
    2080                 :            :         uint32_t read_off;
    2081                 :            :         uint32_t read_len;
    2082                 :            :         unsigned int seg_lengths[MBUF_MAX_SEG];
    2083                 :            : };
    2084                 :            : 
    2085                 :            : /* create a mbuf with different sized segments
    2086                 :            :  *  and fill with data [0x00 0x01 0x02 ...]
    2087                 :            :  */
    2088                 :            : static struct rte_mbuf *
    2089                 :         16 : create_packet(struct rte_mempool *pktmbuf_pool,
    2090                 :            :                 struct test_case *test_data)
    2091                 :            : {
    2092                 :            :         uint16_t i, ret, seg, seg_len = 0;
    2093                 :            :         uint32_t last_index = 0;
    2094                 :            :         unsigned int seg_lengths[MBUF_MAX_SEG];
    2095                 :            :         unsigned int hdr_len;
    2096                 :            :         struct rte_mbuf *pkt = NULL;
    2097                 :            :         struct rte_mbuf *pkt_seg = NULL;
    2098                 :            :         char *hdr = NULL;
    2099                 :            :         char *data = NULL;
    2100                 :            : 
    2101                 :         16 :         memcpy(seg_lengths, test_data->seg_lengths,
    2102                 :         16 :                         sizeof(unsigned int)*test_data->seg_count);
    2103         [ +  + ]:         62 :         for (seg = 0; seg < test_data->seg_count; seg++) {
    2104                 :            :                 hdr_len = 0;
    2105                 :         46 :                 seg_len =  seg_lengths[seg];
    2106                 :         46 :                 pkt_seg = rte_pktmbuf_alloc(pktmbuf_pool);
    2107         [ -  + ]:         46 :                 if (pkt_seg == NULL)
    2108                 :          0 :                         GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
    2109         [ -  + ]:         46 :                 if (rte_pktmbuf_pkt_len(pkt_seg) != 0)
    2110                 :          0 :                         GOTO_FAIL("%s: Bad packet length\n", __func__);
    2111                 :         46 :                 rte_mbuf_sanity_check(pkt_seg, 0);
    2112                 :            :                 /* Add header only for the first segment */
    2113   [ +  +  +  + ]:         46 :                 if (test_data->flags == MBUF_HEADER && seg == 0) {
    2114                 :            :                         hdr_len = sizeof(struct rte_ether_hdr);
    2115                 :            :                         /* prepend a header and fill with dummy data */
    2116                 :            :                         hdr = (char *)rte_pktmbuf_prepend(pkt_seg, hdr_len);
    2117         [ -  + ]:          2 :                         if (hdr == NULL)
    2118                 :          0 :                                 GOTO_FAIL("%s: Cannot prepend header\n",
    2119                 :            :                                                 __func__);
    2120         [ -  + ]:          2 :                         if (rte_pktmbuf_pkt_len(pkt_seg) != hdr_len)
    2121                 :          0 :                                 GOTO_FAIL("%s: Bad pkt length", __func__);
    2122         [ -  + ]:          2 :                         if (rte_pktmbuf_data_len(pkt_seg) != hdr_len)
    2123                 :          0 :                                 GOTO_FAIL("%s: Bad data length", __func__);
    2124         [ +  + ]:         30 :                         for (i = 0; i < hdr_len; i++)
    2125                 :         28 :                                 hdr[i] = (last_index + i) % 0xffff;
    2126                 :          2 :                         last_index += hdr_len;
    2127                 :            :                 }
    2128                 :            :                 /* skip appending segment with 0 length */
    2129         [ +  + ]:         46 :                 if (seg_len == 0)
    2130                 :          2 :                         continue;
    2131                 :            :                 data = rte_pktmbuf_append(pkt_seg, seg_len);
    2132         [ -  + ]:         44 :                 if (data == NULL)
    2133                 :          0 :                         GOTO_FAIL("%s: Cannot append data segment\n", __func__);
    2134         [ -  + ]:         44 :                 if (rte_pktmbuf_pkt_len(pkt_seg) != hdr_len + seg_len)
    2135                 :          0 :                         GOTO_FAIL("%s: Bad packet segment length: %d\n",
    2136                 :            :                                         __func__, rte_pktmbuf_pkt_len(pkt_seg));
    2137         [ -  + ]:         44 :                 if (rte_pktmbuf_data_len(pkt_seg) != hdr_len + seg_len)
    2138                 :          0 :                         GOTO_FAIL("%s: Bad data length\n", __func__);
    2139         [ +  + ]:      16004 :                 for (i = 0; i < seg_len; i++)
    2140                 :      15960 :                         data[i] = (last_index + i) % 0xffff;
    2141                 :            :                 /* to fill continuous data from one seg to another */
    2142                 :         44 :                 last_index += i;
    2143                 :            :                 /* create chained mbufs */
    2144         [ +  + ]:         44 :                 if (seg == 0)
    2145                 :            :                         pkt = pkt_seg;
    2146                 :            :                 else {
    2147                 :         28 :                         ret = rte_pktmbuf_chain(pkt, pkt_seg);
    2148         [ -  + ]:         28 :                         if (ret != 0)
    2149                 :          0 :                                 GOTO_FAIL("%s:FAIL: Chained mbuf creation %d\n",
    2150                 :            :                                                 __func__, ret);
    2151                 :            :                 }
    2152                 :            : 
    2153                 :            :                 pkt_seg = pkt_seg->next;
    2154                 :            :         }
    2155                 :            :         return pkt;
    2156                 :          0 : fail:
    2157         [ #  # ]:          0 :         if (pkt != NULL) {
    2158                 :          0 :                 rte_pktmbuf_free(pkt);
    2159                 :            :                 pkt = NULL;
    2160                 :            :         }
    2161         [ #  # ]:          0 :         if (pkt_seg != NULL) {
    2162                 :          0 :                 rte_pktmbuf_free(pkt_seg);
    2163                 :            :                 pkt_seg = NULL;
    2164                 :            :         }
    2165                 :            :         return NULL;
    2166                 :            : }
    2167                 :            : 
    2168                 :            : static int
    2169                 :          2 : test_pktmbuf_read_from_chain(struct rte_mempool *pktmbuf_pool)
    2170                 :            : {
    2171                 :            :         struct rte_mbuf *m;
    2172                 :          2 :         struct test_case test_cases[] = {
    2173                 :            :                 {
    2174                 :            :                         .seg_lengths = { 100, 100, 100 },
    2175                 :            :                         .seg_count = 3,
    2176                 :            :                         .flags = MBUF_NO_HEADER,
    2177                 :            :                         .read_off = 0,
    2178                 :            :                         .read_len = 300
    2179                 :            :                 },
    2180                 :            :                 {
    2181                 :            :                         .seg_lengths = { 100, 125, 150 },
    2182                 :            :                         .seg_count = 3,
    2183                 :            :                         .flags = MBUF_NO_HEADER,
    2184                 :            :                         .read_off = 99,
    2185                 :            :                         .read_len = 201
    2186                 :            :                 },
    2187                 :            :                 {
    2188                 :            :                         .seg_lengths = { 100, 100 },
    2189                 :            :                         .seg_count = 2,
    2190                 :            :                         .flags = MBUF_NO_HEADER,
    2191                 :            :                         .read_off = 0,
    2192                 :            :                         .read_len = 100
    2193                 :            :                 },
    2194                 :            :                 {
    2195                 :            :                         .seg_lengths = { 100, 200 },
    2196                 :            :                         .seg_count = 2,
    2197                 :            :                         .flags = MBUF_HEADER,
    2198                 :            :                         .read_off = sizeof(struct rte_ether_hdr),
    2199                 :            :                         .read_len = 150
    2200                 :            :                 },
    2201                 :            :                 {
    2202                 :            :                         .seg_lengths = { 1000, 100 },
    2203                 :            :                         .seg_count = 2,
    2204                 :            :                         .flags = MBUF_NO_HEADER,
    2205                 :            :                         .read_off = 0,
    2206                 :            :                         .read_len = 1000
    2207                 :            :                 },
    2208                 :            :                 {
    2209                 :            :                         .seg_lengths = { 1024, 0, 100 },
    2210                 :            :                         .seg_count = 3,
    2211                 :            :                         .flags = MBUF_NO_HEADER,
    2212                 :            :                         .read_off = 100,
    2213                 :            :                         .read_len = 1001
    2214                 :            :                 },
    2215                 :            :                 {
    2216                 :            :                         .seg_lengths = { 1000, 1, 1000 },
    2217                 :            :                         .seg_count = 3,
    2218                 :            :                         .flags = MBUF_NO_HEADER,
    2219                 :            :                         .read_off = 1000,
    2220                 :            :                         .read_len = 2
    2221                 :            :                 },
    2222                 :            :                 {
    2223                 :            :                         .seg_lengths = { MBUF_TEST_DATA_LEN,
    2224                 :            :                                         MBUF_TEST_DATA_LEN2,
    2225                 :            :                                         MBUF_TEST_DATA_LEN3, 800, 10 },
    2226                 :            :                         .seg_count = 5,
    2227                 :            :                         .flags = MBUF_NEG_TEST_READ,
    2228                 :            :                         .read_off = 1000,
    2229                 :            :                         .read_len = MBUF_DATA_SIZE
    2230                 :            :                 },
    2231                 :            :         };
    2232                 :            : 
    2233                 :            :         uint32_t i, pos;
    2234                 :            :         const char *data_copy = NULL;
    2235                 :            :         char data_buf[MBUF_DATA_SIZE];
    2236                 :            : 
    2237                 :            :         memset(data_buf, 0, MBUF_DATA_SIZE);
    2238                 :            : 
    2239         [ +  + ]:         18 :         for (i = 0; i < RTE_DIM(test_cases); i++) {
    2240                 :         16 :                 m = create_packet(pktmbuf_pool, &test_cases[i]);
    2241         [ -  + ]:         16 :                 if (m == NULL)
    2242                 :          0 :                         GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
    2243                 :            : 
    2244         [ +  + ]:         16 :                 data_copy = rte_pktmbuf_read(m, test_cases[i].read_off,
    2245                 :            :                                 test_cases[i].read_len, data_buf);
    2246         [ +  + ]:         16 :                 if (test_cases[i].flags == MBUF_NEG_TEST_READ) {
    2247         [ -  + ]:          2 :                         if (data_copy != NULL)
    2248                 :          0 :                                 GOTO_FAIL("%s: mbuf data read should fail!\n",
    2249                 :            :                                                 __func__);
    2250                 :            :                         else {
    2251                 :          2 :                                 rte_pktmbuf_free(m);
    2252                 :            :                                 m = NULL;
    2253                 :          2 :                                 continue;
    2254                 :            :                         }
    2255                 :            :                 }
    2256         [ -  + ]:         14 :                 if (data_copy == NULL)
    2257                 :          0 :                         GOTO_FAIL("%s: Error in reading packet data!\n",
    2258                 :            :                                         __func__);
    2259         [ +  + ]:       5522 :                 for (pos = 0; pos < test_cases[i].read_len; pos++) {
    2260                 :       5508 :                         if (data_copy[pos] !=
    2261                 :       5508 :                                         (char)((test_cases[i].read_off + pos)
    2262         [ -  + ]:       5508 :                                                 % 0xffff))
    2263                 :          0 :                                 GOTO_FAIL("Data corrupted at offset %u is %2X",
    2264                 :            :                                                 pos, data_copy[pos]);
    2265                 :            :                 }
    2266                 :         14 :                 rte_pktmbuf_dump(stdout, m, rte_pktmbuf_pkt_len(m));
    2267                 :         14 :                 rte_pktmbuf_free(m);
    2268                 :            :                 m = NULL;
    2269                 :            :         }
    2270                 :            :         return 0;
    2271                 :            : 
    2272                 :          0 : fail:
    2273         [ #  # ]:          0 :         if (m != NULL) {
    2274                 :          0 :                 rte_pktmbuf_free(m);
    2275                 :            :                 m = NULL;
    2276                 :            :         }
    2277                 :            :         return -1;
    2278                 :            : }
    2279                 :            : 
    2280                 :            : /* Define a free call back function to be used for external buffer */
    2281                 :            : static void
    2282                 :          1 : ext_buf_free_callback_fn(void *addr, void *opaque)
    2283                 :            : {
    2284                 :            :         bool *freed = opaque;
    2285                 :            : 
    2286         [ -  + ]:          1 :         if (addr == NULL) {
    2287                 :            :                 printf("External buffer address is invalid\n");
    2288                 :          0 :                 return;
    2289                 :            :         }
    2290                 :          1 :         rte_free(addr);
    2291                 :          1 :         *freed = true;
    2292                 :            :         printf("External buffer freed via callback\n");
    2293                 :            : }
    2294                 :            : 
    2295                 :            : /*
    2296                 :            :  * Test to initialize shared data in external buffer before attaching to mbuf
    2297                 :            :  *  - Allocate mbuf with no data.
    2298                 :            :  *  - Allocate external buffer with size should be large enough to accommodate
    2299                 :            :  *     rte_mbuf_ext_shared_info.
    2300                 :            :  *  - Invoke pktmbuf_ext_shinfo_init_helper to initialize shared data.
    2301                 :            :  *  - Invoke rte_pktmbuf_attach_extbuf to attach external buffer to the mbuf.
    2302                 :            :  *  - Clone another mbuf and attach the same external buffer to it.
    2303                 :            :  *  - Invoke rte_pktmbuf_detach_extbuf to detach the external buffer from mbuf.
    2304                 :            :  */
    2305                 :            : static int
    2306                 :          1 : test_pktmbuf_ext_shinfo_init_helper(struct rte_mempool *pktmbuf_pool)
    2307                 :            : {
    2308                 :            :         struct rte_mbuf *m = NULL;
    2309                 :            :         struct rte_mbuf *clone = NULL;
    2310                 :            :         struct rte_mbuf_ext_shared_info *ret_shinfo = NULL;
    2311                 :            :         rte_iova_t buf_iova;
    2312                 :            :         void *ext_buf_addr = NULL;
    2313                 :            :         uint16_t buf_len = EXT_BUF_TEST_DATA_LEN +
    2314                 :            :                                 sizeof(struct rte_mbuf_ext_shared_info);
    2315                 :          1 :         bool freed = false;
    2316                 :            : 
    2317                 :            :         /* alloc a mbuf */
    2318                 :          1 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
    2319         [ -  + ]:          1 :         if (m == NULL)
    2320                 :          0 :                 GOTO_FAIL("%s: mbuf allocation failed!\n", __func__);
    2321         [ -  + ]:          1 :         if (rte_pktmbuf_pkt_len(m) != 0)
    2322                 :          0 :                 GOTO_FAIL("%s: Bad packet length\n", __func__);
    2323                 :          1 :         rte_mbuf_sanity_check(m, 0);
    2324                 :            : 
    2325                 :          1 :         ext_buf_addr = rte_malloc("External buffer", buf_len,
    2326                 :            :                         RTE_CACHE_LINE_SIZE);
    2327         [ -  + ]:          1 :         if (ext_buf_addr == NULL)
    2328                 :          0 :                 GOTO_FAIL("%s: External buffer allocation failed\n", __func__);
    2329                 :            : 
    2330                 :            :         ret_shinfo = rte_pktmbuf_ext_shinfo_init_helper(ext_buf_addr, &buf_len,
    2331                 :            :                 ext_buf_free_callback_fn, &freed);
    2332                 :            :         if (ret_shinfo == NULL)
    2333                 :          0 :                 GOTO_FAIL("%s: Shared info initialization failed!\n", __func__);
    2334                 :            : 
    2335         [ -  + ]:          1 :         if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 1)
    2336                 :          0 :                 GOTO_FAIL("%s: External refcount is not 1\n", __func__);
    2337                 :            : 
    2338         [ -  + ]:          1 :         if (rte_mbuf_refcnt_read(m) != 1)
    2339                 :          0 :                 GOTO_FAIL("%s: Invalid refcnt in mbuf\n", __func__);
    2340                 :            : 
    2341                 :          1 :         buf_iova = rte_mem_virt2iova(ext_buf_addr);
    2342                 :            :         rte_pktmbuf_attach_extbuf(m, ext_buf_addr, buf_iova, buf_len,
    2343                 :            :                 ret_shinfo);
    2344         [ -  + ]:          1 :         if (m->ol_flags != RTE_MBUF_F_EXTERNAL)
    2345                 :          0 :                 GOTO_FAIL("%s: External buffer is not attached to mbuf\n",
    2346                 :            :                                 __func__);
    2347                 :            : 
    2348                 :            :         /* allocate one more mbuf */
    2349                 :          1 :         clone = rte_pktmbuf_clone(m, pktmbuf_pool);
    2350         [ -  + ]:          1 :         if (clone == NULL)
    2351                 :          0 :                 GOTO_FAIL("%s: mbuf clone allocation failed!\n", __func__);
    2352         [ -  + ]:          1 :         if (rte_pktmbuf_pkt_len(clone) != 0)
    2353                 :          0 :                 GOTO_FAIL("%s: Bad packet length\n", __func__);
    2354                 :            : 
    2355                 :            :         /* attach the same external buffer to the cloned mbuf */
    2356                 :            :         rte_pktmbuf_attach_extbuf(clone, ext_buf_addr, buf_iova, buf_len,
    2357                 :            :                         ret_shinfo);
    2358         [ -  + ]:          1 :         if (clone->ol_flags != RTE_MBUF_F_EXTERNAL)
    2359                 :          0 :                 GOTO_FAIL("%s: External buffer is not attached to mbuf\n",
    2360                 :            :                                 __func__);
    2361                 :            : 
    2362         [ -  + ]:          1 :         if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 2)
    2363                 :          0 :                 GOTO_FAIL("%s: Invalid ext_buf ref_cnt\n", __func__);
    2364         [ -  + ]:          1 :         if (freed)
    2365                 :          0 :                 GOTO_FAIL("%s: extbuf should not be freed\n", __func__);
    2366                 :            : 
    2367                 :            :         /* test to manually update ext_buf_ref_cnt from 2 to 3*/
    2368                 :          1 :         rte_mbuf_ext_refcnt_update(ret_shinfo, 1);
    2369         [ -  + ]:          1 :         if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 3)
    2370                 :          0 :                 GOTO_FAIL("%s: Update ext_buf ref_cnt failed\n", __func__);
    2371         [ -  + ]:          1 :         if (freed)
    2372                 :          0 :                 GOTO_FAIL("%s: extbuf should not be freed\n", __func__);
    2373                 :            : 
    2374                 :            :         /* reset the ext_refcnt before freeing the external buffer */
    2375                 :            :         rte_mbuf_ext_refcnt_set(ret_shinfo, 2);
    2376         [ -  + ]:          1 :         if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 2)
    2377                 :          0 :                 GOTO_FAIL("%s: set ext_buf ref_cnt failed\n", __func__);
    2378         [ -  + ]:          1 :         if (freed)
    2379                 :          0 :                 GOTO_FAIL("%s: extbuf should not be freed\n", __func__);
    2380                 :            : 
    2381                 :            :         /* detach the external buffer from mbufs */
    2382                 :          1 :         rte_pktmbuf_detach_extbuf(m);
    2383                 :            :         /* check if ref cnt is decremented */
    2384         [ -  + ]:          1 :         if (rte_mbuf_ext_refcnt_read(ret_shinfo) != 1)
    2385                 :          0 :                 GOTO_FAIL("%s: Invalid ext_buf ref_cnt\n", __func__);
    2386         [ -  + ]:          1 :         if (freed)
    2387                 :          0 :                 GOTO_FAIL("%s: extbuf should not be freed\n", __func__);
    2388                 :            : 
    2389                 :          1 :         rte_pktmbuf_detach_extbuf(clone);
    2390         [ -  + ]:          1 :         if (!freed)
    2391                 :          0 :                 GOTO_FAIL("%s: extbuf should be freed\n", __func__);
    2392                 :          1 :         freed = false;
    2393                 :            : 
    2394                 :          1 :         rte_pktmbuf_free(m);
    2395                 :            :         m = NULL;
    2396                 :          1 :         rte_pktmbuf_free(clone);
    2397                 :            :         clone = NULL;
    2398                 :            : 
    2399                 :          1 :         return 0;
    2400                 :            : 
    2401                 :          0 : fail:
    2402         [ #  # ]:          0 :         if (m) {
    2403                 :          0 :                 rte_pktmbuf_free(m);
    2404                 :            :                 m = NULL;
    2405                 :            :         }
    2406         [ #  # ]:          0 :         if (clone) {
    2407                 :          0 :                 rte_pktmbuf_free(clone);
    2408                 :            :                 clone = NULL;
    2409                 :            :         }
    2410         [ #  # ]:          0 :         if (ext_buf_addr != NULL) {
    2411                 :          0 :                 rte_free(ext_buf_addr);
    2412                 :            :                 ext_buf_addr = NULL;
    2413                 :            :         }
    2414                 :            :         return -1;
    2415                 :            : }
    2416                 :            : 
    2417                 :            : /*
    2418                 :            :  * Test the mbuf pool with pinned external data buffers
    2419                 :            :  *  - Allocate memory zone for external buffer
    2420                 :            :  *  - Create the mbuf pool with pinned external buffer
    2421                 :            :  *  - Check the created pool with relevant mbuf pool unit tests
    2422                 :            :  */
    2423                 :            : static int
    2424                 :          1 : test_pktmbuf_ext_pinned_buffer(struct rte_mempool *std_pool)
    2425                 :            : {
    2426                 :            : 
    2427                 :            :         struct rte_pktmbuf_extmem ext_mem;
    2428                 :            :         struct rte_mempool *pinned_pool = NULL;
    2429                 :            :         const struct rte_memzone *mz = NULL;
    2430                 :            : 
    2431                 :            :         printf("Test mbuf pool with external pinned data buffers\n");
    2432                 :            : 
    2433                 :            :         /* Allocate memzone for the external data buffer */
    2434                 :          1 :         mz = rte_memzone_reserve("pinned_pool",
    2435                 :            :                                  NB_MBUF * MBUF_DATA_SIZE,
    2436                 :            :                                  SOCKET_ID_ANY,
    2437                 :            :                                  RTE_MEMZONE_2MB | RTE_MEMZONE_SIZE_HINT_ONLY);
    2438         [ -  + ]:          1 :         if (mz == NULL)
    2439                 :          0 :                 GOTO_FAIL("%s: Memzone allocation failed\n", __func__);
    2440                 :            : 
    2441                 :            :         /* Create the mbuf pool with pinned external data buffer */
    2442                 :          1 :         ext_mem.buf_ptr = mz->addr;
    2443                 :          1 :         ext_mem.buf_iova = mz->iova;
    2444                 :          1 :         ext_mem.buf_len = mz->len;
    2445                 :          1 :         ext_mem.elt_size = MBUF_DATA_SIZE;
    2446                 :            : 
    2447                 :          1 :         pinned_pool = rte_pktmbuf_pool_create_extbuf("test_pinned_pool",
    2448                 :            :                                 NB_MBUF, MEMPOOL_CACHE_SIZE, 0,
    2449                 :            :                                 MBUF_DATA_SIZE, SOCKET_ID_ANY,
    2450                 :            :                                 &ext_mem, 1);
    2451         [ -  + ]:          1 :         if (pinned_pool == NULL)
    2452                 :          0 :                 GOTO_FAIL("%s: Mbuf pool with pinned external"
    2453                 :            :                           " buffer creation failed\n", __func__);
    2454                 :            :         /* test multiple mbuf alloc */
    2455         [ -  + ]:          1 :         if (test_pktmbuf_pool(pinned_pool) < 0)
    2456                 :          0 :                 GOTO_FAIL("%s: test_mbuf_pool(pinned) failed\n",
    2457                 :            :                           __func__);
    2458                 :            : 
    2459                 :            :         /* do it another time to check that all mbufs were freed */
    2460         [ -  + ]:          1 :         if (test_pktmbuf_pool(pinned_pool) < 0)
    2461                 :          0 :                 GOTO_FAIL("%s: test_mbuf_pool(pinned) failed (2)\n",
    2462                 :            :                           __func__);
    2463                 :            : 
    2464                 :            :         /* test that the data pointer on a packet mbuf is set properly */
    2465         [ -  + ]:          1 :         if (test_pktmbuf_pool_ptr(pinned_pool) < 0)
    2466                 :          0 :                 GOTO_FAIL("%s: test_pktmbuf_pool_ptr(pinned) failed\n",
    2467                 :            :                           __func__);
    2468                 :            : 
    2469                 :            :         /* test data manipulation in mbuf with non-ascii data */
    2470         [ -  + ]:          1 :         if (test_pktmbuf_with_non_ascii_data(pinned_pool) < 0)
    2471                 :          0 :                 GOTO_FAIL("%s: test_pktmbuf_with_non_ascii_data(pinned)"
    2472                 :            :                           " failed\n", __func__);
    2473                 :            : 
    2474                 :            :         /* test free pktmbuf segment one by one */
    2475         [ -  + ]:          1 :         if (test_pktmbuf_free_segment(pinned_pool) < 0)
    2476                 :          0 :                 GOTO_FAIL("%s: test_pktmbuf_free_segment(pinned) failed\n",
    2477                 :            :                           __func__);
    2478                 :            : 
    2479         [ -  + ]:          1 :         if (testclone_testupdate_testdetach(pinned_pool, std_pool) < 0)
    2480                 :          0 :                 GOTO_FAIL("%s: testclone_and_testupdate(pinned) failed\n",
    2481                 :            :                           __func__);
    2482                 :            : 
    2483         [ -  + ]:          1 :         if (test_pktmbuf_copy(pinned_pool, std_pool) < 0)
    2484                 :          0 :                 GOTO_FAIL("%s: test_pktmbuf_copy(pinned) failed\n",
    2485                 :            :                           __func__);
    2486                 :            : 
    2487         [ -  + ]:          1 :         if (test_failing_mbuf_sanity_check(pinned_pool) < 0)
    2488                 :          0 :                 GOTO_FAIL("%s: test_failing_mbuf_sanity_check(pinned)"
    2489                 :            :                           " failed\n", __func__);
    2490                 :            : 
    2491         [ -  + ]:          1 :         if (test_mbuf_linearize_check(pinned_pool) < 0)
    2492                 :          0 :                 GOTO_FAIL("%s: test_mbuf_linearize_check(pinned) failed\n",
    2493                 :            :                           __func__);
    2494                 :            : 
    2495                 :            :         /* test for allocating a bulk of mbufs with various sizes */
    2496         [ -  + ]:          1 :         if (test_pktmbuf_alloc_bulk(pinned_pool) < 0)
    2497                 :          0 :                 GOTO_FAIL("%s: test_rte_pktmbuf_alloc_bulk(pinned) failed\n",
    2498                 :            :                           __func__);
    2499                 :            : 
    2500                 :            :         /* test for allocating a bulk of mbufs with various sizes */
    2501         [ -  + ]:          1 :         if (test_neg_pktmbuf_alloc_bulk(pinned_pool) < 0)
    2502                 :          0 :                 GOTO_FAIL("%s: test_neg_rte_pktmbuf_alloc_bulk(pinned)"
    2503                 :            :                           " failed\n", __func__);
    2504                 :            : 
    2505                 :            :         /* test to read mbuf packet */
    2506         [ -  + ]:          1 :         if (test_pktmbuf_read(pinned_pool) < 0)
    2507                 :          0 :                 GOTO_FAIL("%s: test_rte_pktmbuf_read(pinned) failed\n",
    2508                 :            :                           __func__);
    2509                 :            : 
    2510                 :            :         /* test to read mbuf packet from offset */
    2511         [ -  + ]:          1 :         if (test_pktmbuf_read_from_offset(pinned_pool) < 0)
    2512                 :          0 :                 GOTO_FAIL("%s: test_rte_pktmbuf_read_from_offset(pinned)"
    2513                 :            :                           " failed\n", __func__);
    2514                 :            : 
    2515                 :            :         /* test to read data from chain of mbufs with data segments */
    2516         [ -  + ]:          1 :         if (test_pktmbuf_read_from_chain(pinned_pool) < 0)
    2517                 :          0 :                 GOTO_FAIL("%s: test_rte_pktmbuf_read_from_chain(pinned)"
    2518                 :            :                           " failed\n", __func__);
    2519                 :            : 
    2520                 :            :         RTE_SET_USED(std_pool);
    2521                 :          1 :         rte_mempool_free(pinned_pool);
    2522                 :          1 :         rte_memzone_free(mz);
    2523                 :          1 :         return 0;
    2524                 :            : 
    2525                 :          0 : fail:
    2526                 :          0 :         rte_mempool_free(pinned_pool);
    2527                 :          0 :         rte_memzone_free(mz);
    2528                 :          0 :         return -1;
    2529                 :            : }
    2530                 :            : 
    2531                 :            : static int
    2532                 :          1 : test_mbuf_dyn(struct rte_mempool *pktmbuf_pool)
    2533                 :            : {
    2534                 :          1 :         const struct rte_mbuf_dynfield dynfield = {
    2535                 :            :                 .name = "test-dynfield",
    2536                 :            :                 .size = sizeof(uint8_t),
    2537                 :            :                 .align = __alignof__(uint8_t),
    2538                 :            :                 .flags = 0,
    2539                 :            :         };
    2540                 :          1 :         const struct rte_mbuf_dynfield dynfield2 = {
    2541                 :            :                 .name = "test-dynfield2",
    2542                 :            :                 .size = sizeof(uint16_t),
    2543                 :            :                 .align = __alignof__(uint16_t),
    2544                 :            :                 .flags = 0,
    2545                 :            :         };
    2546                 :          1 :         const struct rte_mbuf_dynfield dynfield3 = {
    2547                 :            :                 .name = "test-dynfield3",
    2548                 :            :                 .size = sizeof(uint8_t),
    2549                 :            :                 .align = __alignof__(uint8_t),
    2550                 :            :                 .flags = 0,
    2551                 :            :         };
    2552                 :          1 :         const struct rte_mbuf_dynfield dynfield_fail_big = {
    2553                 :            :                 .name = "test-dynfield-fail-big",
    2554                 :            :                 .size = 256,
    2555                 :            :                 .align = 1,
    2556                 :            :                 .flags = 0,
    2557                 :            :         };
    2558                 :          1 :         const struct rte_mbuf_dynfield dynfield_fail_align = {
    2559                 :            :                 .name = "test-dynfield-fail-align",
    2560                 :            :                 .size = 1,
    2561                 :            :                 .align = 3,
    2562                 :            :                 .flags = 0,
    2563                 :            :         };
    2564                 :          1 :         const struct rte_mbuf_dynfield dynfield_fail_flag = {
    2565                 :            :                 .name = "test-dynfield",
    2566                 :            :                 .size = sizeof(uint8_t),
    2567                 :            :                 .align = __alignof__(uint8_t),
    2568                 :            :                 .flags = 1,
    2569                 :            :         };
    2570                 :          1 :         const struct rte_mbuf_dynflag dynflag_fail_flag = {
    2571                 :            :                 .name = "test-dynflag",
    2572                 :            :                 .flags = 1,
    2573                 :            :         };
    2574                 :          1 :         const struct rte_mbuf_dynflag dynflag = {
    2575                 :            :                 .name = "test-dynflag",
    2576                 :            :                 .flags = 0,
    2577                 :            :         };
    2578                 :          1 :         const struct rte_mbuf_dynflag dynflag2 = {
    2579                 :            :                 .name = "test-dynflag2",
    2580                 :            :                 .flags = 0,
    2581                 :            :         };
    2582                 :          1 :         const struct rte_mbuf_dynflag dynflag3 = {
    2583                 :            :                 .name = "test-dynflag3",
    2584                 :            :                 .flags = 0,
    2585                 :            :         };
    2586                 :            :         struct rte_mbuf *m = NULL;
    2587                 :            :         int offset, offset2, offset3;
    2588                 :            :         int flag, flag2, flag3;
    2589                 :            :         int ret;
    2590                 :            : 
    2591                 :            :         printf("Test mbuf dynamic fields and flags\n");
    2592                 :          1 :         rte_mbuf_dyn_dump(stdout);
    2593                 :            : 
    2594                 :          1 :         offset = rte_mbuf_dynfield_register(&dynfield);
    2595         [ -  + ]:          1 :         if (offset == -1)
    2596                 :          0 :                 GOTO_FAIL("failed to register dynamic field, offset=%d: %s",
    2597                 :            :                         offset, strerror(errno));
    2598                 :            : 
    2599                 :          1 :         ret = rte_mbuf_dynfield_register(&dynfield);
    2600         [ -  + ]:          1 :         if (ret != offset)
    2601                 :          0 :                 GOTO_FAIL("failed to lookup dynamic field, ret=%d: %s",
    2602                 :            :                         ret, strerror(errno));
    2603                 :            : 
    2604                 :          1 :         offset2 = rte_mbuf_dynfield_register(&dynfield2);
    2605   [ +  -  -  + ]:          1 :         if (offset2 == -1 || offset2 == offset || (offset2 & 1))
    2606                 :          0 :                 GOTO_FAIL("failed to register dynamic field 2, offset2=%d: %s",
    2607                 :            :                         offset2, strerror(errno));
    2608                 :            : 
    2609                 :          1 :         offset3 = rte_mbuf_dynfield_register_offset(&dynfield3,
    2610                 :            :                                 offsetof(struct rte_mbuf, dynfield1[1]));
    2611         [ -  + ]:          1 :         if (offset3 != offsetof(struct rte_mbuf, dynfield1[1])) {
    2612         [ #  # ]:          0 :                 if (rte_errno == EBUSY)
    2613                 :            :                         printf("mbuf test error skipped: dynfield is busy\n");
    2614                 :            :                 else
    2615                 :          0 :                         GOTO_FAIL("failed to register dynamic field 3, offset="
    2616                 :            :                                 "%d: %s", offset3, strerror(errno));
    2617                 :            :         }
    2618                 :            : 
    2619                 :            :         printf("dynfield: offset=%d, offset2=%d, offset3=%d\n",
    2620                 :            :                 offset, offset2, offset3);
    2621                 :            : 
    2622                 :          1 :         ret = rte_mbuf_dynfield_register(&dynfield_fail_big);
    2623         [ -  + ]:          1 :         if (ret != -1)
    2624                 :          0 :                 GOTO_FAIL("dynamic field creation should fail (too big)");
    2625                 :            : 
    2626                 :          1 :         ret = rte_mbuf_dynfield_register(&dynfield_fail_align);
    2627         [ -  + ]:          1 :         if (ret != -1)
    2628                 :          0 :                 GOTO_FAIL("dynamic field creation should fail (bad alignment)");
    2629                 :            : 
    2630                 :          1 :         ret = rte_mbuf_dynfield_register_offset(&dynfield_fail_align,
    2631                 :            :                                 offsetof(struct rte_mbuf, ol_flags));
    2632         [ -  + ]:          1 :         if (ret != -1)
    2633                 :          0 :                 GOTO_FAIL("dynamic field creation should fail (not avail)");
    2634                 :            : 
    2635                 :          1 :         ret = rte_mbuf_dynfield_register(&dynfield_fail_flag);
    2636         [ -  + ]:          1 :         if (ret != -1)
    2637                 :          0 :                 GOTO_FAIL("dynamic field creation should fail (invalid flag)");
    2638                 :            : 
    2639                 :          1 :         ret = rte_mbuf_dynflag_register(&dynflag_fail_flag);
    2640         [ -  + ]:          1 :         if (ret != -1)
    2641                 :          0 :                 GOTO_FAIL("dynamic flag creation should fail (invalid flag)");
    2642                 :            : 
    2643                 :          1 :         flag = rte_mbuf_dynflag_register(&dynflag);
    2644         [ -  + ]:          1 :         if (flag == -1)
    2645                 :          0 :                 GOTO_FAIL("failed to register dynamic flag, flag=%d: %s",
    2646                 :            :                         flag, strerror(errno));
    2647                 :            : 
    2648                 :          1 :         ret = rte_mbuf_dynflag_register(&dynflag);
    2649         [ -  + ]:          1 :         if (ret != flag)
    2650                 :          0 :                 GOTO_FAIL("failed to lookup dynamic flag, ret=%d: %s",
    2651                 :            :                         ret, strerror(errno));
    2652                 :            : 
    2653                 :          1 :         flag2 = rte_mbuf_dynflag_register(&dynflag2);
    2654         [ -  + ]:          1 :         if (flag2 == -1 || flag2 == flag)
    2655                 :          0 :                 GOTO_FAIL("failed to register dynamic flag 2, flag2=%d: %s",
    2656                 :            :                         flag2, strerror(errno));
    2657                 :            : 
    2658                 :          1 :         flag3 = rte_mbuf_dynflag_register_bitnum(&dynflag3,
    2659                 :            :                                                 rte_bsf64(RTE_MBUF_F_LAST_FREE));
    2660         [ -  + ]:          1 :         if ((uint32_t)flag3 != rte_bsf64(RTE_MBUF_F_LAST_FREE))
    2661                 :          0 :                 GOTO_FAIL("failed to register dynamic flag 3, flag3=%d: %s",
    2662                 :            :                         flag3, strerror(errno));
    2663                 :            : 
    2664                 :            :         printf("dynflag: flag=%d, flag2=%d, flag3=%d\n", flag, flag2, flag3);
    2665                 :            : 
    2666                 :            :         /* set, get dynamic field */
    2667                 :          1 :         m = rte_pktmbuf_alloc(pktmbuf_pool);
    2668         [ -  + ]:          1 :         if (m == NULL)
    2669                 :          0 :                 GOTO_FAIL("Cannot allocate mbuf");
    2670                 :            : 
    2671                 :          1 :         *RTE_MBUF_DYNFIELD(m, offset, uint8_t *) = 1;
    2672                 :            :         if (*RTE_MBUF_DYNFIELD(m, offset, uint8_t *) != 1)
    2673                 :            :                 GOTO_FAIL("failed to read dynamic field");
    2674                 :          1 :         *RTE_MBUF_DYNFIELD(m, offset2, uint16_t *) = 1000;
    2675                 :            :         if (*RTE_MBUF_DYNFIELD(m, offset2, uint16_t *) != 1000)
    2676                 :            :                 GOTO_FAIL("failed to read dynamic field");
    2677                 :            : 
    2678                 :            :         /* set a dynamic flag */
    2679                 :          1 :         m->ol_flags |= (1ULL << flag);
    2680                 :            : 
    2681                 :          1 :         rte_mbuf_dyn_dump(stdout);
    2682                 :          1 :         rte_pktmbuf_free(m);
    2683                 :          1 :         return 0;
    2684                 :          0 : fail:
    2685                 :          0 :         rte_pktmbuf_free(m);
    2686                 :          0 :         return -1;
    2687                 :            : }
    2688                 :            : 
    2689                 :            : /* check that m->nb_segs and m->next are reset on mbuf free */
    2690                 :            : static int
    2691                 :          1 : test_nb_segs_and_next_reset(void)
    2692                 :            : {
    2693                 :            :         struct rte_mbuf *m0 = NULL, *m1 = NULL, *m2 = NULL;
    2694                 :            :         struct rte_mempool *pool = NULL;
    2695                 :            : 
    2696                 :          1 :         pool = rte_pktmbuf_pool_create("test_mbuf_reset",
    2697                 :            :                         3, 0, 0, MBUF_DATA_SIZE, SOCKET_ID_ANY);
    2698         [ -  + ]:          1 :         if (pool == NULL)
    2699                 :          0 :                 GOTO_FAIL("Failed to create mbuf pool");
    2700                 :            : 
    2701                 :            :         /* alloc mbufs */
    2702                 :          1 :         m0 = rte_pktmbuf_alloc(pool);
    2703                 :          1 :         m1 = rte_pktmbuf_alloc(pool);
    2704                 :          1 :         m2 = rte_pktmbuf_alloc(pool);
    2705   [ +  -  -  + ]:          1 :         if (m0 == NULL || m1 == NULL || m2 == NULL)
    2706                 :          0 :                 GOTO_FAIL("Failed to allocate mbuf");
    2707                 :            : 
    2708                 :            :         /* append data in all of them */
    2709   [ +  -  +  - ]:          2 :         if (rte_pktmbuf_append(m0, 500) == NULL ||
    2710         [ -  + ]:          1 :                         rte_pktmbuf_append(m1, 500) == NULL ||
    2711                 :            :                         rte_pktmbuf_append(m2, 500) == NULL)
    2712                 :          0 :                 GOTO_FAIL("Failed to append data in mbuf");
    2713                 :            : 
    2714                 :            :         /* chain them in one mbuf m0 */
    2715                 :            :         rte_pktmbuf_chain(m1, m2);
    2716                 :            :         rte_pktmbuf_chain(m0, m1);
    2717   [ +  -  +  -  :          1 :         if (m0->nb_segs != 3 || m0->next != m1 || m1->next != m2 ||
                   +  - ]
    2718         [ -  + ]:          1 :                         m2->next != NULL) {
    2719                 :            :                 m1 = m2 = NULL;
    2720                 :          0 :                 GOTO_FAIL("Failed to chain mbufs");
    2721                 :            :         }
    2722                 :            : 
    2723                 :            :         /* split m0 chain in two, between m1 and m2 */
    2724                 :          1 :         m0->nb_segs = 2;
    2725                 :          1 :         m0->pkt_len -= m2->data_len;
    2726                 :          1 :         m1->next = NULL;
    2727                 :          1 :         m2->nb_segs = 1;
    2728                 :            : 
    2729                 :            :         /* free the 2 mbuf chains m0 and m2  */
    2730                 :          1 :         rte_pktmbuf_free(m0);
    2731                 :          1 :         rte_pktmbuf_free(m2);
    2732                 :            : 
    2733                 :            :         /* realloc the 3 mbufs */
    2734                 :          1 :         m0 = rte_mbuf_raw_alloc(pool);
    2735                 :          1 :         m1 = rte_mbuf_raw_alloc(pool);
    2736                 :          1 :         m2 = rte_mbuf_raw_alloc(pool);
    2737   [ +  -  -  + ]:          1 :         if (m0 == NULL || m1 == NULL || m2 == NULL)
    2738                 :          0 :                 GOTO_FAIL("Failed to reallocate mbuf");
    2739                 :            : 
    2740                 :            :         /* ensure that m->next and m->nb_segs are reset allocated mbufs */
    2741   [ +  -  +  - ]:          1 :         if (m0->nb_segs != 1 || m0->next != NULL ||
    2742   [ +  -  +  - ]:          1 :                         m1->nb_segs != 1 || m1->next != NULL ||
    2743   [ +  -  -  + ]:          1 :                         m2->nb_segs != 1 || m2->next != NULL)
    2744                 :          0 :                 GOTO_FAIL("nb_segs or next was not reset properly");
    2745                 :            : 
    2746                 :          1 :         rte_mempool_free(pool);
    2747                 :          1 :         return 0;
    2748                 :            : 
    2749                 :          0 : fail:
    2750                 :          0 :         rte_mempool_free(pool);
    2751                 :          0 :         return -1;
    2752                 :            : }
    2753                 :            : 
    2754                 :            : static int
    2755                 :          1 : test_mbuf(void)
    2756                 :            : {
    2757                 :            :         int ret = -1;
    2758                 :            :         struct rte_mempool *pktmbuf_pool = NULL;
    2759                 :            :         struct rte_mempool *pktmbuf_pool2 = NULL;
    2760                 :            : 
    2761                 :            : 
    2762                 :            :         RTE_BUILD_BUG_ON(sizeof(struct rte_mbuf) != RTE_CACHE_LINE_MIN_SIZE * 2);
    2763                 :            : 
    2764                 :            :         /* create pktmbuf pool if it does not exist */
    2765                 :          1 :         pktmbuf_pool = rte_pktmbuf_pool_create("test_pktmbuf_pool",
    2766                 :            :                         NB_MBUF, MEMPOOL_CACHE_SIZE, 0, MBUF_DATA_SIZE,
    2767                 :            :                         SOCKET_ID_ANY);
    2768                 :            : 
    2769         [ -  + ]:          1 :         if (pktmbuf_pool == NULL) {
    2770                 :            :                 printf("cannot allocate mbuf pool\n");
    2771                 :          0 :                 goto err;
    2772                 :            :         }
    2773                 :            : 
    2774                 :            :         /* test registration of dynamic fields and flags */
    2775         [ -  + ]:          1 :         if (test_mbuf_dyn(pktmbuf_pool) < 0) {
    2776                 :            :                 printf("mbuf dynflag test failed\n");
    2777                 :          0 :                 goto err;
    2778                 :            :         }
    2779                 :            : 
    2780                 :            :         /* create a specific pktmbuf pool with a priv_size != 0 and no data
    2781                 :            :          * room size */
    2782                 :          1 :         pktmbuf_pool2 = rte_pktmbuf_pool_create("test_pktmbuf_pool2",
    2783                 :            :                         NB_MBUF, MEMPOOL_CACHE_SIZE, MBUF2_PRIV_SIZE, 0,
    2784                 :            :                         SOCKET_ID_ANY);
    2785                 :            : 
    2786         [ -  + ]:          1 :         if (pktmbuf_pool2 == NULL) {
    2787                 :            :                 printf("cannot allocate mbuf pool\n");
    2788                 :          0 :                 goto err;
    2789                 :            :         }
    2790                 :            : 
    2791                 :            :         /* test multiple mbuf alloc */
    2792         [ -  + ]:          1 :         if (test_pktmbuf_pool(pktmbuf_pool) < 0) {
    2793                 :            :                 printf("test_mbuf_pool() failed\n");
    2794                 :          0 :                 goto err;
    2795                 :            :         }
    2796                 :            : 
    2797                 :            :         /* do it another time to check that all mbufs were freed */
    2798         [ -  + ]:          1 :         if (test_pktmbuf_pool(pktmbuf_pool) < 0) {
    2799                 :            :                 printf("test_mbuf_pool() failed (2)\n");
    2800                 :          0 :                 goto err;
    2801                 :            :         }
    2802                 :            : 
    2803                 :            :         /* test bulk mbuf alloc and free */
    2804         [ -  + ]:          1 :         if (test_pktmbuf_pool_bulk() < 0) {
    2805                 :            :                 printf("test_pktmbuf_pool_bulk() failed\n");
    2806                 :          0 :                 goto err;
    2807                 :            :         }
    2808                 :            : 
    2809                 :            :         /* test that the pointer to the data on a packet mbuf is set properly */
    2810         [ -  + ]:          1 :         if (test_pktmbuf_pool_ptr(pktmbuf_pool) < 0) {
    2811                 :            :                 printf("test_pktmbuf_pool_ptr() failed\n");
    2812                 :          0 :                 goto err;
    2813                 :            :         }
    2814                 :            : 
    2815                 :            :         /* test data manipulation in mbuf */
    2816         [ -  + ]:          1 :         if (test_one_pktmbuf(pktmbuf_pool) < 0) {
    2817                 :            :                 printf("test_one_mbuf() failed\n");
    2818                 :          0 :                 goto err;
    2819                 :            :         }
    2820                 :            : 
    2821                 :            : 
    2822                 :            :         /*
    2823                 :            :          * do it another time, to check that allocation reinitialize
    2824                 :            :          * the mbuf correctly
    2825                 :            :          */
    2826         [ -  + ]:          1 :         if (test_one_pktmbuf(pktmbuf_pool) < 0) {
    2827                 :            :                 printf("test_one_mbuf() failed (2)\n");
    2828                 :          0 :                 goto err;
    2829                 :            :         }
    2830                 :            : 
    2831         [ -  + ]:          1 :         if (test_pktmbuf_with_non_ascii_data(pktmbuf_pool) < 0) {
    2832                 :            :                 printf("test_pktmbuf_with_non_ascii_data() failed\n");
    2833                 :          0 :                 goto err;
    2834                 :            :         }
    2835                 :            : 
    2836                 :            :         /* test free pktmbuf segment one by one */
    2837         [ -  + ]:          1 :         if (test_pktmbuf_free_segment(pktmbuf_pool) < 0) {
    2838                 :            :                 printf("test_pktmbuf_free_segment() failed.\n");
    2839                 :          0 :                 goto err;
    2840                 :            :         }
    2841                 :            : 
    2842         [ -  + ]:          1 :         if (testclone_testupdate_testdetach(pktmbuf_pool, pktmbuf_pool) < 0) {
    2843                 :            :                 printf("testclone_and_testupdate() failed \n");
    2844                 :          0 :                 goto err;
    2845                 :            :         }
    2846                 :            : 
    2847         [ -  + ]:          1 :         if (test_pktmbuf_copy(pktmbuf_pool, pktmbuf_pool) < 0) {
    2848                 :            :                 printf("test_pktmbuf_copy() failed\n");
    2849                 :          0 :                 goto err;
    2850                 :            :         }
    2851                 :            : 
    2852         [ -  + ]:          1 :         if (test_attach_from_different_pool(pktmbuf_pool, pktmbuf_pool2) < 0) {
    2853                 :            :                 printf("test_attach_from_different_pool() failed\n");
    2854                 :          0 :                 goto err;
    2855                 :            :         }
    2856                 :            : 
    2857         [ -  + ]:          1 :         if (test_refcnt_mbuf() < 0) {
    2858                 :            :                 printf("test_refcnt_mbuf() failed \n");
    2859                 :          0 :                 goto err;
    2860                 :            :         }
    2861                 :            : 
    2862         [ -  + ]:          1 :         if (test_failing_mbuf_sanity_check(pktmbuf_pool) < 0) {
    2863                 :            :                 printf("test_failing_mbuf_sanity_check() failed\n");
    2864                 :          0 :                 goto err;
    2865                 :            :         }
    2866                 :            : 
    2867         [ -  + ]:          1 :         if (test_mbuf_linearize_check(pktmbuf_pool) < 0) {
    2868                 :            :                 printf("test_mbuf_linearize_check() failed\n");
    2869                 :          0 :                 goto err;
    2870                 :            :         }
    2871                 :            : 
    2872         [ -  + ]:          1 :         if (test_tx_offload() < 0) {
    2873                 :            :                 printf("test_tx_offload() failed\n");
    2874                 :          0 :                 goto err;
    2875                 :            :         }
    2876                 :            : 
    2877         [ -  + ]:          1 :         if (test_get_rx_ol_flag_list() < 0) {
    2878                 :            :                 printf("test_rte_get_rx_ol_flag_list() failed\n");
    2879                 :          0 :                 goto err;
    2880                 :            :         }
    2881                 :            : 
    2882         [ -  + ]:          1 :         if (test_get_tx_ol_flag_list() < 0) {
    2883                 :            :                 printf("test_rte_get_tx_ol_flag_list() failed\n");
    2884                 :          0 :                 goto err;
    2885                 :            :         }
    2886                 :            : 
    2887         [ -  + ]:          1 :         if (test_get_rx_ol_flag_name() < 0) {
    2888                 :            :                 printf("test_rte_get_rx_ol_flag_name() failed\n");
    2889                 :          0 :                 goto err;
    2890                 :            :         }
    2891                 :            : 
    2892         [ -  + ]:          1 :         if (test_get_tx_ol_flag_name() < 0) {
    2893                 :            :                 printf("test_rte_get_tx_ol_flag_name() failed\n");
    2894                 :          0 :                 goto err;
    2895                 :            :         }
    2896                 :            : 
    2897         [ -  + ]:          1 :         if (test_mbuf_validate_tx_offload_one(pktmbuf_pool) < 0) {
    2898                 :            :                 printf("test_mbuf_validate_tx_offload_one() failed\n");
    2899                 :          0 :                 goto err;
    2900                 :            :         }
    2901                 :            : 
    2902                 :            :         /* test for allocating a bulk of mbufs with various sizes */
    2903         [ -  + ]:          1 :         if (test_pktmbuf_alloc_bulk(pktmbuf_pool) < 0) {
    2904                 :            :                 printf("test_rte_pktmbuf_alloc_bulk() failed\n");
    2905                 :          0 :                 goto err;
    2906                 :            :         }
    2907                 :            : 
    2908                 :            :         /* test for allocating a bulk of mbufs with various sizes */
    2909         [ -  + ]:          1 :         if (test_neg_pktmbuf_alloc_bulk(pktmbuf_pool) < 0) {
    2910                 :            :                 printf("test_neg_rte_pktmbuf_alloc_bulk() failed\n");
    2911                 :          0 :                 goto err;
    2912                 :            :         }
    2913                 :            : 
    2914                 :            :         /* test to read mbuf packet */
    2915         [ -  + ]:          1 :         if (test_pktmbuf_read(pktmbuf_pool) < 0) {
    2916                 :            :                 printf("test_rte_pktmbuf_read() failed\n");
    2917                 :          0 :                 goto err;
    2918                 :            :         }
    2919                 :            : 
    2920                 :            :         /* test to read mbuf packet from offset */
    2921         [ -  + ]:          1 :         if (test_pktmbuf_read_from_offset(pktmbuf_pool) < 0) {
    2922                 :            :                 printf("test_rte_pktmbuf_read_from_offset() failed\n");
    2923                 :          0 :                 goto err;
    2924                 :            :         }
    2925                 :            : 
    2926                 :            :         /* test to read data from chain of mbufs with data segments */
    2927         [ -  + ]:          1 :         if (test_pktmbuf_read_from_chain(pktmbuf_pool) < 0) {
    2928                 :            :                 printf("test_rte_pktmbuf_read_from_chain() failed\n");
    2929                 :          0 :                 goto err;
    2930                 :            :         }
    2931                 :            : 
    2932                 :            :         /* test to initialize shared info. at the end of external buffer */
    2933         [ -  + ]:          1 :         if (test_pktmbuf_ext_shinfo_init_helper(pktmbuf_pool) < 0) {
    2934                 :            :                 printf("test_pktmbuf_ext_shinfo_init_helper() failed\n");
    2935                 :          0 :                 goto err;
    2936                 :            :         }
    2937                 :            : 
    2938                 :            :         /* test the mbuf pool with pinned external data buffers */
    2939         [ -  + ]:          1 :         if (test_pktmbuf_ext_pinned_buffer(pktmbuf_pool) < 0) {
    2940                 :            :                 printf("test_pktmbuf_ext_pinned_buffer() failed\n");
    2941                 :          0 :                 goto err;
    2942                 :            :         }
    2943                 :            : 
    2944                 :            :         /* test reset of m->nb_segs and m->next on mbuf free */
    2945         [ -  + ]:          1 :         if (test_nb_segs_and_next_reset() < 0) {
    2946                 :            :                 printf("test_nb_segs_and_next_reset() failed\n");
    2947                 :          0 :                 goto err;
    2948                 :            :         }
    2949                 :            : 
    2950                 :            :         ret = 0;
    2951                 :          1 : err:
    2952                 :          1 :         rte_mempool_free(pktmbuf_pool);
    2953                 :          1 :         rte_mempool_free(pktmbuf_pool2);
    2954                 :          1 :         return ret;
    2955                 :            : }
    2956                 :            : #undef GOTO_FAIL
    2957                 :            : 
    2958                 :        235 : REGISTER_FAST_TEST(mbuf_autotest, false, true, test_mbuf);

Generated by: LCOV version 1.14