LCOV - code coverage report
Current view: top level - app/test - test_pmd_ring.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 164 250 65.6 %
Date: 2025-01-02 22:41:34 Functions: 13 14 92.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 153 318 48.1 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2015 Intel Corporation
       3                 :            :  */
       4                 :            : #include "test.h"
       5                 :            : #include <string.h>
       6                 :            : 
       7                 :            : #include <stdio.h>
       8                 :            : 
       9                 :            : #include <rte_eth_ring.h>
      10                 :            : #include <rte_ethdev.h>
      11                 :            : #include <rte_bus_vdev.h>
      12                 :            : 
      13                 :            : #define SOCKET0 0
      14                 :            : #define RING_SIZE 256
      15                 :            : #define NUM_RINGS 2
      16                 :            : #define NB_MBUF 512
      17                 :            : 
      18                 :            : static struct rte_mempool *mp;
      19                 :            : struct rte_ring *rxtx[NUM_RINGS];
      20                 :            : static int tx_porta, rx_portb, rxtx_portc, rxtx_portd, rxtx_porte;
      21                 :            : 
      22                 :            : static int
      23                 :          3 : test_ethdev_configure_port(int port)
      24                 :            : {
      25                 :            :         struct rte_eth_conf null_conf;
      26                 :            :         struct rte_eth_link link;
      27                 :            :         int ret;
      28                 :            : 
      29                 :            :         memset(&null_conf, 0, sizeof(struct rte_eth_conf));
      30                 :            : 
      31         [ -  + ]:          3 :         if (rte_eth_dev_configure(port, 1, 2, &null_conf) < 0) {
      32                 :            :                 printf("Configure failed for port %d\n", port);
      33                 :          0 :                 return -1;
      34                 :            :         }
      35                 :            : 
      36                 :            :         /* Test queue release */
      37         [ -  + ]:          3 :         if (rte_eth_dev_configure(port, 1, 1, &null_conf) < 0) {
      38                 :            :                 printf("Configure failed for port %d\n", port);
      39                 :          0 :                 return -1;
      40                 :            :         }
      41                 :            : 
      42         [ -  + ]:          3 :         if (rte_eth_tx_queue_setup(port, 0, RING_SIZE, SOCKET0, NULL) < 0) {
      43                 :            :                 printf("TX queue setup failed port %d\n", port);
      44                 :          0 :                 return -1;
      45                 :            :         }
      46                 :            : 
      47         [ -  + ]:          3 :         if (rte_eth_rx_queue_setup(port, 0, RING_SIZE, SOCKET0,
      48                 :            :                                 NULL, mp) < 0) {
      49                 :            :                 printf("RX queue setup failed port %d\n", port);
      50                 :          0 :                 return -1;
      51                 :            :         }
      52                 :            : 
      53         [ -  + ]:          3 :         if (rte_eth_dev_start(port) < 0) {
      54                 :            :                 printf("Error starting port %d\n", port);
      55                 :          0 :                 return -1;
      56                 :            :         }
      57                 :            : 
      58                 :          3 :         ret = rte_eth_link_get(port, &link);
      59         [ -  + ]:          3 :         if (ret < 0) {
      60                 :          0 :                 printf("Link get failed for port %u: %s",
      61                 :            :                        port, rte_strerror(-ret));
      62                 :          0 :                 return -1;
      63                 :            :         }
      64                 :            : 
      65                 :            :         return 0;
      66                 :            : }
      67                 :            : 
      68                 :            : static int
      69                 :          1 : test_send_basic_packets(void)
      70                 :            : {
      71                 :            :         struct rte_mbuf  bufs[RING_SIZE];
      72                 :            :         struct rte_mbuf *pbufs[RING_SIZE];
      73                 :            :         int i;
      74                 :            : 
      75                 :            :         printf("Testing send and receive RING_SIZE/2 packets (tx_porta -> rx_portb)\n");
      76                 :            : 
      77         [ +  + ]:        129 :         for (i = 0; i < RING_SIZE/2; i++)
      78                 :        128 :                 pbufs[i] = &bufs[i];
      79                 :            : 
      80         [ -  + ]:          1 :         if (rte_eth_tx_burst(tx_porta, 0, pbufs, RING_SIZE/2) < RING_SIZE/2) {
      81                 :          0 :                 printf("Failed to transmit packet burst port %d\n", tx_porta);
      82                 :          0 :                 return TEST_FAILED;
      83                 :            :         }
      84                 :            : 
      85         [ -  + ]:          1 :         if (rte_eth_rx_burst(rx_portb, 0, pbufs, RING_SIZE) != RING_SIZE/2) {
      86                 :          0 :                 printf("Failed to receive packet burst on port %d\n", rx_portb);
      87                 :          0 :                 return TEST_FAILED;
      88                 :            :         }
      89                 :            : 
      90         [ +  + ]:        129 :         for (i = 0; i < RING_SIZE/2; i++)
      91         [ -  + ]:        128 :                 if (pbufs[i] != &bufs[i]) {
      92                 :            :                         printf("Error: received data does not match that transmitted\n");
      93                 :          0 :                         return TEST_FAILED;
      94                 :            :                 }
      95                 :            : 
      96                 :            :         return TEST_SUCCESS;
      97                 :            : }
      98                 :            : 
      99                 :            : static int
     100                 :          0 : test_send_basic_packets_port(int port)
     101                 :            : {
     102                 :            :         struct rte_mbuf  bufs[RING_SIZE];
     103                 :            :         struct rte_mbuf *pbufs[RING_SIZE];
     104                 :            :         int i;
     105                 :            : 
     106                 :            :         printf("Testing send and receive RING_SIZE/2 packets (cmdl_port0 -> cmdl_port0)\n");
     107                 :            : 
     108         [ #  # ]:          0 :         for (i = 0; i < RING_SIZE/2; i++)
     109                 :          0 :                 pbufs[i] = &bufs[i];
     110                 :            : 
     111         [ #  # ]:          0 :         if (rte_eth_tx_burst(port, 0, pbufs, RING_SIZE/2) < RING_SIZE/2) {
     112                 :            :                 printf("Failed to transmit packet burst port %d\n", port);
     113                 :          0 :                 return -1;
     114                 :            :         }
     115                 :            : 
     116         [ #  # ]:          0 :         if (rte_eth_rx_burst(port, 0, pbufs, RING_SIZE) != RING_SIZE/2) {
     117                 :            :                 printf("Failed to receive packet burst on port %d\n", port);
     118                 :          0 :                 return -1;
     119                 :            :         }
     120                 :            : 
     121         [ #  # ]:          0 :         for (i = 0; i < RING_SIZE/2; i++)
     122         [ #  # ]:          0 :                 if (pbufs[i] != &bufs[i]) {
     123                 :            :                         printf("Error: received data does not match that transmitted\n");
     124                 :          0 :                         return -1;
     125                 :            :                 }
     126                 :            : 
     127                 :            :         return 0;
     128                 :            : }
     129                 :            : 
     130                 :            : 
     131                 :            : static int
     132                 :          1 : test_get_stats(int port)
     133                 :            : {
     134                 :            :         struct rte_eth_stats stats;
     135                 :          1 :         struct rte_mbuf buf, *pbuf = &buf;
     136                 :            : 
     137                 :            :         printf("Testing ring PMD stats_get port %d\n", port);
     138                 :            : 
     139                 :            :         /* check stats of RXTX port, should all be zero */
     140                 :            : 
     141                 :          1 :         rte_eth_stats_get(port, &stats);
     142   [ +  -  +  - ]:          1 :         if (stats.ipackets != 0 || stats.opackets != 0 ||
     143   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     144   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     145                 :            :                 printf("Error: port %d stats are not zero\n", port);
     146                 :          0 :                 return -1;
     147                 :            :         }
     148                 :            : 
     149                 :            :         /* send and receive 1 packet and check for stats update */
     150         [ -  + ]:          1 :         if (rte_eth_tx_burst(port, 0, &pbuf, 1) != 1) {
     151                 :            :                 printf("Error sending packet to port %d\n", port);
     152                 :          0 :                 return -1;
     153                 :            :         }
     154                 :            : 
     155         [ -  + ]:          1 :         if (rte_eth_rx_burst(port, 0, &pbuf, 1) != 1) {
     156                 :            :                 printf("Error receiving packet from port %d\n", port);
     157                 :          0 :                 return -1;
     158                 :            :         }
     159                 :            : 
     160                 :          1 :         rte_eth_stats_get(port, &stats);
     161   [ +  -  +  - ]:          1 :         if (stats.ipackets != 1 || stats.opackets != 1 ||
     162   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     163   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     164                 :            :                 printf("Error: port %d stats are not as expected\n", port);
     165                 :          0 :                 return -1;
     166                 :            :         }
     167                 :            :         return 0;
     168                 :            : }
     169                 :            : 
     170                 :            : static int
     171                 :          1 : test_stats_reset(int port)
     172                 :            : {
     173                 :            :         struct rte_eth_stats stats;
     174                 :          1 :         struct rte_mbuf buf, *pbuf = &buf;
     175                 :            : 
     176                 :            :         printf("Testing ring PMD stats_reset port %d\n", port);
     177                 :            : 
     178                 :          1 :         rte_eth_stats_reset(port);
     179                 :            : 
     180                 :            :         /* check stats of RXTX port, should all be zero */
     181                 :          1 :         rte_eth_stats_get(port, &stats);
     182   [ +  -  +  - ]:          1 :         if (stats.ipackets != 0 || stats.opackets != 0 ||
     183   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     184   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     185                 :            :                 printf("Error: port %d stats are not zero\n", port);
     186                 :          0 :                 return -1;
     187                 :            :         }
     188                 :            : 
     189                 :            :         /* send and receive 1 packet and check for stats update */
     190         [ -  + ]:          1 :         if (rte_eth_tx_burst(port, 0, &pbuf, 1) != 1) {
     191                 :            :                 printf("Error sending packet to port %d\n", port);
     192                 :          0 :                 return -1;
     193                 :            :         }
     194                 :            : 
     195         [ -  + ]:          1 :         if (rte_eth_rx_burst(port, 0, &pbuf, 1) != 1) {
     196                 :            :                 printf("Error receiving packet from port %d\n", port);
     197                 :          0 :                 return -1;
     198                 :            :         }
     199                 :            : 
     200                 :          1 :         rte_eth_stats_get(port, &stats);
     201   [ +  -  +  - ]:          1 :         if (stats.ipackets != 1 || stats.opackets != 1 ||
     202   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     203   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     204                 :            :                 printf("Error: port %d stats are not as expected\n", port);
     205                 :          0 :                 return -1;
     206                 :            :         }
     207                 :            : 
     208                 :          1 :         rte_eth_stats_reset(port);
     209                 :            : 
     210                 :            :         /* check stats of RXTX port, should all be zero */
     211                 :          1 :         rte_eth_stats_get(port, &stats);
     212   [ +  -  +  - ]:          1 :         if (stats.ipackets != 0 || stats.opackets != 0 ||
     213   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     214   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     215                 :            :                 printf("Error: port %d stats are not zero\n", port);
     216                 :          0 :                 return -1;
     217                 :            :         }
     218                 :            : 
     219                 :            :         return 0;
     220                 :            : }
     221                 :            : 
     222                 :            : static int
     223                 :          1 : test_pmd_ring_pair_create_attach(void)
     224                 :            : {
     225                 :            :         struct rte_eth_stats stats, stats2;
     226                 :          1 :         struct rte_mbuf buf, *pbuf = &buf;
     227                 :            :         struct rte_eth_conf null_conf;
     228                 :            :         int ret;
     229                 :            : 
     230                 :            :         memset(&null_conf, 0, sizeof(struct rte_eth_conf));
     231                 :            : 
     232         [ +  - ]:          1 :         if ((rte_eth_dev_configure(rxtx_portd, 1, 1, &null_conf) < 0)
     233         [ -  + ]:          1 :                         || (rte_eth_dev_configure(rxtx_porte, 1, 1,
     234                 :            :                                         &null_conf) < 0)) {
     235                 :            :                 printf("Configure failed for port\n");
     236                 :          0 :                 return TEST_FAILED;
     237                 :            :         }
     238                 :            : 
     239         [ +  - ]:          1 :         if ((rte_eth_tx_queue_setup(rxtx_portd, 0, RING_SIZE,
     240                 :            :                                         SOCKET0, NULL) < 0)
     241         [ -  + ]:          1 :                         || (rte_eth_tx_queue_setup(rxtx_porte, 0, RING_SIZE,
     242                 :            :                                         SOCKET0, NULL) < 0)) {
     243                 :            :                 printf("TX queue setup failed\n");
     244                 :          0 :                 return TEST_FAILED;
     245                 :            :         }
     246                 :            : 
     247         [ +  - ]:          1 :         if ((rte_eth_rx_queue_setup(rxtx_portd, 0, RING_SIZE,
     248                 :            :                                         SOCKET0, NULL, mp) < 0)
     249         [ -  + ]:          1 :                         || (rte_eth_rx_queue_setup(rxtx_porte, 0, RING_SIZE,
     250                 :            :                                         SOCKET0, NULL, mp) < 0)) {
     251                 :            :                 printf("RX queue setup failed\n");
     252                 :          0 :                 return TEST_FAILED;
     253                 :            :         }
     254                 :            : 
     255         [ +  - ]:          1 :         if ((rte_eth_dev_start(rxtx_portd) < 0)
     256         [ -  + ]:          1 :                         || (rte_eth_dev_start(rxtx_porte) < 0)) {
     257                 :            :                 printf("Error starting port\n");
     258                 :          0 :                 return TEST_FAILED;
     259                 :            :         }
     260                 :            : 
     261                 :          1 :         rte_eth_stats_reset(rxtx_portd);
     262                 :            :         /* check stats of port, should all be zero */
     263                 :          1 :         rte_eth_stats_get(rxtx_portd, &stats);
     264   [ +  -  +  - ]:          1 :         if (stats.ipackets != 0 || stats.opackets != 0 ||
     265   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     266   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     267                 :          0 :                 printf("Error: port %d stats are not zero\n", rxtx_portd);
     268                 :          0 :                 return TEST_FAILED;
     269                 :            :         }
     270                 :            : 
     271                 :          1 :         rte_eth_stats_reset(rxtx_porte);
     272                 :            :         /* check stats of port, should all be zero */
     273                 :          1 :         rte_eth_stats_get(rxtx_porte, &stats2);
     274   [ +  -  +  - ]:          1 :         if (stats2.ipackets != 0 || stats2.opackets != 0 ||
     275   [ +  -  +  - ]:          1 :                         stats2.ibytes != 0 || stats2.obytes != 0 ||
     276   [ +  -  -  + ]:          1 :                         stats2.ierrors != 0 || stats2.oerrors != 0) {
     277                 :          0 :                 printf("Error: port %d stats are not zero\n", rxtx_porte);
     278                 :          0 :                 return TEST_FAILED;
     279                 :            :         }
     280                 :            : 
     281                 :            :         /*
     282                 :            :          * send and receive 1 packet (rxtx_portd -> rxtx_porte)
     283                 :            :          * and check for stats update
     284                 :            :          */
     285                 :            :         printf("Testing send and receive 1 packet (rxtx_portd -> rxtx_porte)\n");
     286         [ -  + ]:          1 :         if (rte_eth_tx_burst(rxtx_portd, 0, &pbuf, 1) != 1) {
     287                 :          0 :                 printf("Error sending packet to port %d\n", rxtx_portd);
     288                 :          0 :                 return TEST_FAILED;
     289                 :            :         }
     290                 :            : 
     291         [ -  + ]:          1 :         if (rte_eth_rx_burst(rxtx_porte, 0, &pbuf, 1) != 1) {
     292                 :          0 :                 printf("Error receiving packet from port %d\n", rxtx_porte);
     293                 :          0 :                 return TEST_FAILED;
     294                 :            :         }
     295                 :            : 
     296                 :          1 :         rte_eth_stats_get(rxtx_portd, &stats);
     297                 :          1 :         rte_eth_stats_get(rxtx_porte, &stats2);
     298   [ +  -  +  - ]:          1 :         if (stats.ipackets != 0 || stats.opackets != 1 ||
     299   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     300   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     301                 :          0 :                 printf("Error: port %d stats are not as expected\n",
     302                 :            :                                 rxtx_portd);
     303                 :          0 :                 return TEST_FAILED;
     304                 :            :         }
     305                 :            : 
     306   [ +  -  +  - ]:          1 :         if (stats2.ipackets != 1 || stats2.opackets != 0 ||
     307   [ +  -  +  - ]:          1 :                         stats2.ibytes != 0 || stats2.obytes != 0 ||
     308   [ +  -  -  + ]:          1 :                         stats2.ierrors != 0 || stats2.oerrors != 0) {
     309                 :          0 :                 printf("Error: port %d stats are not as expected\n",
     310                 :            :                                 rxtx_porte);
     311                 :          0 :                 return TEST_FAILED;
     312                 :            :         }
     313                 :            : 
     314                 :            :         /*
     315                 :            :          * send and receive 1 packet (rxtx_porte -> rxtx_portd)
     316                 :            :          * and check for stats update
     317                 :            :          */
     318                 :            :         printf("Testing send and receive 1 packet "
     319                 :            :                         "(rxtx_porte -> rxtx_portd)\n");
     320         [ -  + ]:          1 :         if (rte_eth_tx_burst(rxtx_porte, 0, &pbuf, 1) != 1) {
     321                 :          0 :                 printf("Error sending packet to port %d\n", rxtx_porte);
     322                 :          0 :                 return TEST_FAILED;
     323                 :            :         }
     324                 :            : 
     325         [ -  + ]:          1 :         if (rte_eth_rx_burst(rxtx_portd, 0, &pbuf, 1) != 1) {
     326                 :          0 :                 printf("Error receiving packet from port %d\n", rxtx_portd);
     327                 :          0 :                 return TEST_FAILED;
     328                 :            :         }
     329                 :            : 
     330                 :          1 :         rte_eth_stats_get(rxtx_portd, &stats);
     331                 :          1 :         rte_eth_stats_get(rxtx_porte, &stats2);
     332   [ +  -  +  - ]:          1 :         if (stats.ipackets != 1 || stats.opackets != 1 ||
     333   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     334   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     335                 :          0 :                 printf("Error: port %d stats are not as expected\n",
     336                 :            :                                 rxtx_portd);
     337                 :          0 :                 return TEST_FAILED;
     338                 :            :         }
     339                 :            : 
     340   [ +  -  +  - ]:          1 :         if (stats2.ipackets != 1 || stats2.opackets != 1 ||
     341   [ +  -  +  - ]:          1 :                         stats2.ibytes != 0 || stats2.obytes != 0 ||
     342   [ +  -  -  + ]:          1 :                         stats2.ierrors != 0 || stats2.oerrors != 0) {
     343                 :          0 :                 printf("Error: port %d stats are not as expected\n",
     344                 :            :                                 rxtx_porte);
     345                 :          0 :                 return TEST_FAILED;
     346                 :            :         }
     347                 :            : 
     348                 :            :         /*
     349                 :            :          * send and receive 1 packet (rxtx_portd -> rxtx_portd)
     350                 :            :          * and check for stats update
     351                 :            :          */
     352                 :            :         printf("Testing send and receive 1 packet "
     353                 :            :                         "(rxtx_portd -> rxtx_portd)\n");
     354         [ -  + ]:          1 :         if (rte_eth_tx_burst(rxtx_portd, 0, &pbuf, 1) != 1) {
     355                 :          0 :                 printf("Error sending packet to port %d\n", rxtx_portd);
     356                 :          0 :                 return TEST_FAILED;
     357                 :            :         }
     358                 :            : 
     359         [ -  + ]:          1 :         if (rte_eth_rx_burst(rxtx_portd, 0, &pbuf, 1) != 1) {
     360                 :          0 :                 printf("Error receiving packet from port %d\n", rxtx_porte);
     361                 :          0 :                 return TEST_FAILED;
     362                 :            :         }
     363                 :            : 
     364                 :          1 :         rte_eth_stats_get(rxtx_portd, &stats);
     365                 :          1 :         rte_eth_stats_get(rxtx_porte, &stats2);
     366   [ +  -  +  - ]:          1 :         if (stats.ipackets != 2 || stats.opackets != 2 ||
     367   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     368   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     369                 :          0 :                 printf("Error: port %d stats are not as expected\n",
     370                 :            :                                 rxtx_portd);
     371                 :          0 :                 return TEST_FAILED;
     372                 :            :         }
     373                 :            : 
     374   [ +  -  +  - ]:          1 :         if (stats2.ipackets != 1 || stats2.opackets != 1 ||
     375   [ +  -  +  - ]:          1 :                         stats2.ibytes != 0 || stats2.obytes != 0 ||
     376   [ +  -  -  + ]:          1 :                         stats2.ierrors != 0 || stats2.oerrors != 0) {
     377                 :          0 :                 printf("Error: port %d stats are not as expected\n",
     378                 :            :                                 rxtx_porte);
     379                 :          0 :                 return TEST_FAILED;
     380                 :            :         }
     381                 :            : 
     382                 :            :         /*
     383                 :            :          * send and receive 1 packet (rxtx_porte -> rxtx_porte)
     384                 :            :          * and check for stats update
     385                 :            :          */
     386                 :            :         printf("Testing send and receive 1 packet "
     387                 :            :                         "(rxtx_porte -> rxtx_porte)\n");
     388         [ -  + ]:          1 :         if (rte_eth_tx_burst(rxtx_porte, 0, &pbuf, 1) != 1) {
     389                 :          0 :                 printf("Error sending packet to port %d\n", rxtx_porte);
     390                 :          0 :                 return TEST_FAILED;
     391                 :            :         }
     392                 :            : 
     393         [ -  + ]:          1 :         if (rte_eth_rx_burst(rxtx_porte, 0, &pbuf, 1) != 1) {
     394                 :          0 :                 printf("Error receiving packet from port %d\n", rxtx_porte);
     395                 :          0 :                 return TEST_FAILED;
     396                 :            :         }
     397                 :            : 
     398                 :          1 :         rte_eth_stats_get(rxtx_portd, &stats);
     399                 :          1 :         rte_eth_stats_get(rxtx_porte, &stats2);
     400   [ +  -  +  - ]:          1 :         if (stats.ipackets != 2 || stats.opackets != 2 ||
     401   [ +  -  +  - ]:          1 :                         stats.ibytes != 0 || stats.obytes != 0 ||
     402   [ +  -  -  + ]:          1 :                         stats.ierrors != 0 || stats.oerrors != 0) {
     403                 :          0 :                 printf("Error: port %d stats are not as expected\n",
     404                 :            :                                 rxtx_portd);
     405                 :          0 :                 return TEST_FAILED;
     406                 :            :         }
     407                 :            : 
     408   [ +  -  +  - ]:          1 :         if (stats2.ipackets != 2 || stats2.opackets != 2 ||
     409   [ +  -  +  - ]:          1 :                         stats2.ibytes != 0 || stats2.obytes != 0 ||
     410   [ +  -  -  + ]:          1 :                         stats2.ierrors != 0 || stats2.oerrors != 0) {
     411                 :          0 :                 printf("Error: port %d stats are not as expected\n",
     412                 :            :                                 rxtx_porte);
     413                 :          0 :                 return TEST_FAILED;
     414                 :            :         }
     415                 :            : 
     416                 :          1 :         ret = rte_eth_dev_stop(rxtx_portd);
     417         [ -  + ]:          1 :         if (ret != 0)
     418                 :          0 :                 printf("Error: failed to stop port %u: %s\n",
     419                 :            :                        rxtx_portd, rte_strerror(-ret));
     420                 :          1 :         ret = rte_eth_dev_stop(rxtx_porte);
     421         [ -  + ]:          1 :         if (ret != 0)
     422                 :          0 :                 printf("Error: failed to stop port %u: %s\n",
     423                 :            :                        rxtx_porte, rte_strerror(-ret));
     424                 :            : 
     425                 :            :         return TEST_SUCCESS;
     426                 :            : }
     427                 :            : 
     428                 :            : static void
     429                 :          1 : test_cleanup_resources(void)
     430                 :            : {
     431                 :            :         int itr, ret;
     432         [ +  + ]:          3 :         for (itr = 0; itr < NUM_RINGS; itr++)
     433                 :          2 :                 rte_ring_free(rxtx[itr]);
     434                 :            : 
     435                 :          1 :         ret = rte_eth_dev_stop(tx_porta);
     436         [ -  + ]:          1 :         if (ret != 0)
     437                 :          0 :                 printf("Error: failed to stop port %u: %s\n",
     438                 :            :                        tx_porta, rte_strerror(-ret));
     439                 :          1 :         ret = rte_eth_dev_stop(rx_portb);
     440         [ -  + ]:          1 :         if (ret != 0)
     441                 :          0 :                 printf("Error: failed to stop port %u: %s\n",
     442                 :            :                        rx_portb, rte_strerror(-ret));
     443                 :          1 :         ret = rte_eth_dev_stop(rxtx_portc);
     444         [ -  + ]:          1 :         if (ret != 0)
     445                 :          0 :                 printf("Error: failed to stop port %u: %s\n",
     446                 :            :                        rxtx_portc, rte_strerror(-ret));
     447                 :            : 
     448                 :          1 :         rte_mempool_free(mp);
     449                 :          1 :         rte_vdev_uninit("net_ring_net_ringa");
     450                 :          1 :         rte_vdev_uninit("net_ring_net_ringb");
     451                 :          1 :         rte_vdev_uninit("net_ring_net_ringc");
     452                 :          1 :         rte_vdev_uninit("net_ring_net_ringd");
     453                 :          1 :         rte_vdev_uninit("net_ring_net_ringe");
     454                 :          1 : }
     455                 :            : 
     456                 :            : static int
     457                 :          1 : test_pmd_ringcreate_setup(void)
     458                 :            : {
     459                 :            :         uint8_t nb_ports;
     460                 :            : 
     461                 :          1 :         nb_ports = rte_eth_dev_count_avail();
     462                 :          1 :         printf("nb_ports=%d\n", (int)nb_ports);
     463                 :            : 
     464                 :            :         /*  create the rings and eth_rings in the test code.
     465                 :            :          *  This does not test the rte_pmd_ring_devinit function.
     466                 :            :          *
     467                 :            :          *  Test with the command line option --vdev=net_ring0 to test rte_pmd_ring_devinit.
     468                 :            :          */
     469                 :          1 :         rxtx[0] = rte_ring_create("R0", RING_SIZE, SOCKET0, RING_F_SP_ENQ|RING_F_SC_DEQ);
     470         [ -  + ]:          1 :         if (rxtx[0] == NULL) {
     471                 :            :                 printf("rte_ring_create R0 failed");
     472                 :          0 :                 return -1;
     473                 :            :         }
     474                 :            : 
     475                 :          1 :         rxtx[1] = rte_ring_create("R1", RING_SIZE, SOCKET0, RING_F_SP_ENQ|RING_F_SC_DEQ);
     476         [ -  + ]:          1 :         if (rxtx[1] == NULL) {
     477                 :            :                 printf("rte_ring_create R1 failed");
     478                 :          0 :                 return -1;
     479                 :            :         }
     480                 :            : 
     481                 :          1 :         tx_porta = rte_eth_from_rings("net_ringa", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
     482                 :          1 :         rx_portb = rte_eth_from_rings("net_ringb", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
     483                 :          1 :         rxtx_portc = rte_eth_from_rings("net_ringc", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
     484                 :          1 :         rxtx_portd = rte_eth_from_rings("net_ringd", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
     485                 :          1 :         rxtx_porte = rte_eth_from_rings("net_ringe", rxtx, NUM_RINGS, rxtx, NUM_RINGS, SOCKET0);
     486                 :            : 
     487                 :          1 :         printf("tx_porta=%d rx_portb=%d rxtx_portc=%d rxtx_portd=%d rxtx_porte=%d\n",
     488                 :            :                         tx_porta, rx_portb, rxtx_portc, rxtx_portd, rxtx_porte);
     489                 :            : 
     490   [ +  -  +  -  :          1 :         if ((tx_porta == -1) || (rx_portb == -1) || (rxtx_portc == -1)
                   +  - ]
     491   [ +  -  -  + ]:          1 :                         || (rxtx_portd == -1) || (rxtx_porte == -1)) {
     492                 :            :                 printf("rte_eth_from rings failed\n");
     493                 :          0 :                 return -1;
     494                 :            :         }
     495                 :            : 
     496                 :          1 :         mp = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 32,
     497                 :          1 :                         0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
     498         [ +  - ]:          1 :         if (mp == NULL)
     499                 :            :                 return -1;
     500                 :            : 
     501   [ +  -  +  - ]:          1 :         if ((tx_porta >= RTE_MAX_ETHPORTS) || (rx_portb >= RTE_MAX_ETHPORTS)
     502         [ +  - ]:          1 :                         || (rxtx_portc >= RTE_MAX_ETHPORTS)
     503         [ +  - ]:          1 :                         || (rxtx_portd >= RTE_MAX_ETHPORTS)
     504         [ -  + ]:          1 :                         || (rxtx_porte >= RTE_MAX_ETHPORTS)) {
     505                 :            :                 printf(" port exceed max eth ports\n");
     506                 :          0 :                 return -1;
     507                 :            :         }
     508                 :            :         return 0;
     509                 :            : }
     510                 :            : 
     511                 :            : static int
     512                 :          1 : test_command_line_ring_port(void)
     513                 :            : {
     514                 :            :         int port, cmdl_port0 = -1;
     515                 :            :         int ret;
     516                 :            : 
     517                 :            :         /* find a port created with the --vdev=net_ring0 command line option */
     518         [ +  + ]:          6 :         RTE_ETH_FOREACH_DEV(port) {
     519                 :            :                 struct rte_eth_dev_info dev_info;
     520                 :            : 
     521                 :          5 :                 ret = rte_eth_dev_info_get(port, &dev_info);
     522         [ -  + ]:          5 :                 TEST_ASSERT((ret == 0),
     523                 :            :                                 "Error during getting device (port %d) info: %s\n",
     524                 :            :                                 port, strerror(-ret));
     525                 :            : 
     526         [ -  + ]:          5 :                 if (!strcmp(dev_info.driver_name, "Rings PMD")) {
     527                 :            :                         printf("found a command line ring port=%d\n", port);
     528                 :            :                         cmdl_port0 = port;
     529                 :          0 :                         break;
     530                 :            :                 }
     531                 :            :         }
     532         [ -  + ]:          1 :         if (cmdl_port0 != -1) {
     533         [ #  # ]:          0 :                 TEST_ASSERT((test_ethdev_configure_port(cmdl_port0) < 0),
     534                 :            :                                 "test ethdev configure port cmdl_port0 is failed");
     535         [ #  # ]:          0 :                 TEST_ASSERT((test_send_basic_packets_port(cmdl_port0) < 0),
     536                 :            :                                 "test send basic packets port cmdl_port0 is failed");
     537         [ #  # ]:          0 :                 TEST_ASSERT((test_stats_reset(cmdl_port0) < 0),
     538                 :            :                                 "test stats reset cmdl_port0 is failed");
     539         [ #  # ]:          0 :                 TEST_ASSERT((test_get_stats(cmdl_port0) < 0),
     540                 :            :                                 "test get stats cmdl_port0 is failed");
     541         [ #  # ]:          0 :                 TEST_ASSERT((rte_eth_dev_stop(cmdl_port0) == 0),
     542                 :            :                                 "test stop cmdl_port0 is failed");
     543                 :            :         }
     544                 :            :         return TEST_SUCCESS;
     545                 :            : }
     546                 :            : 
     547                 :            : static int
     548                 :          1 : test_ethdev_configure_ports(void)
     549                 :            : {
     550         [ -  + ]:          1 :         TEST_ASSERT((test_ethdev_configure_port(tx_porta) == 0),
     551                 :            :                         "test ethdev configure ports tx_porta is failed");
     552         [ -  + ]:          1 :         TEST_ASSERT((test_ethdev_configure_port(rx_portb) == 0),
     553                 :            :                         "test ethdev configure ports rx_portb is failed");
     554         [ -  + ]:          1 :         TEST_ASSERT((test_ethdev_configure_port(rxtx_portc) == 0),
     555                 :            :                         "test ethdev configure ports rxtx_portc is failed");
     556                 :            : 
     557                 :            :         return TEST_SUCCESS;
     558                 :            : }
     559                 :            : 
     560                 :            : static int
     561                 :          1 : test_get_stats_for_port(void)
     562                 :            : {
     563         [ -  + ]:          1 :         TEST_ASSERT(test_get_stats(rxtx_portc) == 0, "test get stats failed");
     564                 :            :         return TEST_SUCCESS;
     565                 :            : }
     566                 :            : 
     567                 :            : static int
     568                 :          1 : test_stats_reset_for_port(void)
     569                 :            : {
     570         [ -  + ]:          1 :         TEST_ASSERT(test_stats_reset(rxtx_portc) == 0, "test stats reset failed");
     571                 :            :         return TEST_SUCCESS;
     572                 :            : }
     573                 :            : 
     574                 :            : static struct
     575                 :            : unit_test_suite test_pmd_ring_suite  = {
     576                 :            :         .setup = test_pmd_ringcreate_setup,
     577                 :            :         .teardown = test_cleanup_resources,
     578                 :            :         .suite_name = "Test Pmd Ring Unit Test Suite",
     579                 :            :         .unit_test_cases = {
     580                 :            :                 TEST_CASE(test_ethdev_configure_ports),
     581                 :            :                 TEST_CASE(test_send_basic_packets),
     582                 :            :                 TEST_CASE(test_get_stats_for_port),
     583                 :            :                 TEST_CASE(test_stats_reset_for_port),
     584                 :            :                 TEST_CASE(test_pmd_ring_pair_create_attach),
     585                 :            :                 TEST_CASE(test_command_line_ring_port),
     586                 :            :                 TEST_CASES_END()
     587                 :            :         }
     588                 :            : };
     589                 :            : 
     590                 :            : static int
     591                 :          1 : test_pmd_ring(void)
     592                 :            : {
     593                 :          1 :         return unit_test_suite_runner(&test_pmd_ring_suite);
     594                 :            : }
     595                 :            : 
     596                 :        251 : REGISTER_FAST_TEST(ring_pmd_autotest, true, true, test_pmd_ring);

Generated by: LCOV version 1.14