LCOV - code coverage report
Current view: top level - app/test - test_pdump.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 42 84 50.0 %
Date: 2025-03-01 20:23:48 Functions: 6 7 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 48 25.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Intel Corporation
       3                 :            :  */
       4                 :            : #include <stdio.h>
       5                 :            : #include <unistd.h>
       6                 :            : #include <stdint.h>
       7                 :            : #include <limits.h>
       8                 :            : 
       9                 :            : #include <ethdev_driver.h>
      10                 :            : #include <rte_pdump.h>
      11                 :            : #include "rte_eal.h"
      12                 :            : #include "rte_lcore.h"
      13                 :            : #include "rte_mempool.h"
      14                 :            : #include "rte_ring.h"
      15                 :            : 
      16                 :            : #include "sample_packet_forward.h"
      17                 :            : #include "test.h"
      18                 :            : #include "process.h"
      19                 :            : #include "test_pdump.h"
      20                 :            : 
      21                 :            : #define launch_p(ARGV) process_dup(ARGV, RTE_DIM(ARGV), __func__)
      22                 :            : 
      23                 :            : struct rte_ring *ring_server;
      24                 :            : uint16_t portid;
      25                 :            : uint16_t flag_for_send_pkts = 1;
      26                 :            : 
      27                 :            : int
      28                 :          1 : test_pdump_init(void)
      29                 :            : {
      30                 :            :         int ret = 0;
      31                 :            : 
      32                 :          1 :         ret = rte_pdump_init();
      33         [ -  + ]:          1 :         if (ret < 0) {
      34                 :            :                 printf("rte_pdump_init failed\n");
      35                 :          0 :                 return -1;
      36                 :            :         }
      37                 :          1 :         ret = test_ring_setup(&ring_server, &portid);
      38         [ -  + ]:          1 :         if (ret < 0) {
      39                 :            :                 printf("test_ring_setup failed\n");
      40                 :          0 :                 return -1;
      41                 :            :         }
      42                 :            :         printf("pdump_init success\n");
      43                 :          1 :         return ret;
      44                 :            : }
      45                 :            : 
      46                 :            : int
      47                 :          0 : run_pdump_client_tests(void)
      48                 :            : {
      49                 :            :         int flags = RTE_PDUMP_FLAG_TX, ret = 0, itr;
      50                 :          0 :         char deviceid[] = "net_ring_net_ringa";
      51                 :            :         struct rte_ring *ring_client;
      52                 :          0 :         struct rte_mempool *mp = NULL;
      53                 :            :         struct rte_eth_dev *eth_dev = NULL;
      54                 :          0 :         char poolname[] = "mbuf_pool_client";
      55                 :            : 
      56                 :          0 :         ret = test_get_mempool(&mp, poolname);
      57         [ #  # ]:          0 :         if (ret < 0)
      58                 :            :                 return -1;
      59                 :          0 :         mp->flags = 0x0000;
      60                 :          0 :         ring_client = rte_ring_create("SR0", RING_SIZE, rte_socket_id(), 0);
      61         [ #  # ]:          0 :         if (ring_client == NULL) {
      62                 :            :                 printf("rte_ring_create SR0 failed");
      63                 :          0 :                 return -1;
      64                 :            :         }
      65                 :            : 
      66                 :          0 :         eth_dev = rte_eth_dev_attach_secondary(deviceid);
      67         [ #  # ]:          0 :         if (!eth_dev) {
      68                 :            :                 printf("Failed to probe %s", deviceid);
      69                 :          0 :                 return -1;
      70                 :            :         }
      71                 :          0 :         rte_eth_dev_probing_finish(eth_dev);
      72                 :            : 
      73                 :            :         printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n");
      74                 :            : 
      75         [ #  # ]:          0 :         for (itr = 0; itr < NUM_ITR; itr++) {
      76                 :          0 :                 ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client,
      77                 :            :                                        mp, NULL);
      78         [ #  # ]:          0 :                 if (ret < 0) {
      79                 :            :                         printf("rte_pdump_enable failed\n");
      80                 :          0 :                         return -1;
      81                 :            :                 }
      82                 :            :                 printf("pdump_enable success\n");
      83                 :            : 
      84                 :          0 :                 ret = rte_pdump_disable(portid, QUEUE_ID, flags);
      85         [ #  # ]:          0 :                 if (ret < 0) {
      86                 :            :                         printf("rte_pdump_disable failed\n");
      87                 :          0 :                         return -1;
      88                 :            :                 }
      89                 :            :                 printf("pdump_disable success\n");
      90                 :            : 
      91                 :          0 :                 ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags,
      92                 :            :                                                    ring_client, mp, NULL);
      93         [ #  # ]:          0 :                 if (ret < 0) {
      94                 :            :                         printf("rte_pdump_enable_by_deviceid failed\n");
      95                 :          0 :                         return -1;
      96                 :            :                 }
      97                 :            :                 printf("pdump_enable_by_deviceid success\n");
      98                 :            : 
      99                 :          0 :                 ret = rte_pdump_disable_by_deviceid(deviceid, QUEUE_ID, flags);
     100         [ #  # ]:          0 :                 if (ret < 0) {
     101                 :            :                         printf("rte_pdump_disable_by_deviceid failed\n");
     102                 :          0 :                         return -1;
     103                 :            :                 }
     104                 :            :                 printf("pdump_disable_by_deviceid success\n");
     105                 :            : 
     106         [ #  # ]:          0 :                 if (itr == 0) {
     107                 :            :                         flags = RTE_PDUMP_FLAG_RX;
     108                 :            :                         printf("\n***** flags = RTE_PDUMP_FLAG_RX *****\n");
     109         [ #  # ]:          0 :                 } else if (itr == 1) {
     110                 :            :                         flags = RTE_PDUMP_FLAG_RXTX;
     111                 :            :                         printf("\n***** flags = RTE_PDUMP_FLAG_RXTX *****\n");
     112                 :            :                 }
     113                 :            :         }
     114                 :            :         if (ring_client != NULL)
     115                 :          0 :                 test_ring_free(ring_client);
     116         [ #  # ]:          0 :         if (mp != NULL)
     117                 :          0 :                 test_mp_free(mp);
     118                 :            : 
     119                 :            :         return ret;
     120                 :            : }
     121                 :            : 
     122                 :            : int
     123                 :          1 : test_pdump_uninit(void)
     124                 :            : {
     125                 :            :         int ret = 0;
     126                 :            : 
     127                 :          1 :         ret = rte_pdump_uninit();
     128         [ -  + ]:          1 :         if (ret < 0) {
     129                 :            :                 printf("rte_pdump_uninit failed\n");
     130                 :          0 :                 return -1;
     131                 :            :         }
     132         [ +  - ]:          1 :         if (ring_server != NULL)
     133                 :          1 :                 test_ring_free(ring_server);
     134                 :            :         printf("pdump_uninit success\n");
     135                 :          1 :         test_vdev_uninit("net_ring_net_ringa");
     136                 :          1 :         return ret;
     137                 :            : }
     138                 :            : 
     139                 :            : uint32_t
     140                 :          1 : send_pkts(void *empty __rte_unused)
     141                 :            : {
     142                 :            :         int ret = 0;
     143                 :          1 :         struct rte_mbuf *pbuf[NUM_PACKETS] = { };
     144                 :            :         struct rte_mempool *mp;
     145                 :          1 :         char poolname[] = "mbuf_pool_server";
     146                 :            : 
     147                 :          1 :         ret = test_get_mbuf_from_pool(&mp, pbuf, poolname);
     148         [ -  + ]:          1 :         if (ret < 0)
     149                 :            :                 printf("get_mbuf_from_pool failed\n");
     150                 :            : 
     151                 :          1 :         ret = test_dev_start(portid, mp);
     152         [ -  + ]:          1 :         if (ret < 0)
     153                 :          0 :                 printf("test_dev_start(%hu, %p) failed, error code: %d\n",
     154                 :            :                         portid, mp, ret);
     155                 :            : 
     156   [ +  -  +  + ]:    3903069 :         while (ret >= 0 && flag_for_send_pkts) {
     157                 :    3903068 :                 ret = test_packet_forward(pbuf, portid, QUEUE_ID);
     158         [ -  + ]:    3903068 :                 if (ret < 0)
     159                 :            :                         printf("send pkts Failed\n");
     160                 :            :         };
     161                 :            : 
     162                 :          1 :         rte_eth_dev_stop(portid);
     163                 :          1 :         test_put_mbuf_to_pool(mp, pbuf);
     164                 :          1 :         return 0;
     165                 :            : }
     166                 :            : 
     167                 :            : /*
     168                 :            :  * This function is called in the primary i.e. main test, to spawn off secondary
     169                 :            :  * processes to run actual mp tests. Uses fork() and exec pair
     170                 :            :  */
     171                 :            : 
     172                 :            : int
     173                 :          1 : run_pdump_server_tests(void)
     174                 :            : {
     175                 :            :         int ret = 0;
     176                 :            :         char coremask[10];
     177                 :            : 
     178                 :            : #ifdef RTE_EXEC_ENV_LINUX
     179                 :          1 :         char tmp[PATH_MAX] = { 0 };
     180                 :          1 :         char prefix[PATH_MAX] = { 0 };
     181                 :            : 
     182                 :          1 :         get_current_prefix(tmp, sizeof(tmp));
     183                 :            :         snprintf(prefix, sizeof(prefix), "--file-prefix=%s", tmp);
     184                 :            : #else
     185                 :            :         const char *prefix = "";
     186                 :            : #endif
     187                 :            : 
     188                 :            :         /* good case, using secondary */
     189                 :          1 :         const char *const argv1[] = {
     190                 :            :                 prgname, "-c", coremask, "--proc-type=secondary",
     191                 :            :                 prefix
     192                 :            :         };
     193                 :            : 
     194                 :          1 :         snprintf(coremask, sizeof(coremask), "%x",
     195                 :          1 :                  (1 << rte_get_main_lcore()));
     196                 :            : 
     197                 :          1 :         ret = test_pdump_init();
     198                 :          1 :         ret |= launch_p(argv1);
     199                 :          1 :         ret |= test_pdump_uninit();
     200                 :          1 :         return ret;
     201                 :            : }
     202                 :            : 
     203                 :            : int
     204                 :          1 : test_pdump(void)
     205                 :            : {
     206                 :            :         int ret = 0;
     207         [ +  - ]:          1 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
     208                 :            :                 printf("IN PRIMARY PROCESS\n");
     209                 :          1 :                 ret = run_pdump_server_tests();
     210         [ -  + ]:          1 :                 if (ret < 0)
     211                 :          0 :                         return TEST_FAILED;
     212         [ #  # ]:          0 :         } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
     213                 :            :                 printf("IN SECONDARY PROCESS\n");
     214                 :          0 :                 sleep(5);
     215                 :          0 :                 ret = run_pdump_client_tests();
     216         [ #  # ]:          0 :                 if (ret < 0)
     217                 :          0 :                         return TEST_FAILED;
     218                 :            :         }
     219                 :            :         return TEST_SUCCESS;
     220                 :            : }
     221                 :            : 
     222                 :        252 : REGISTER_FAST_TEST(pdump_autotest, true, false, test_pdump);

Generated by: LCOV version 1.14