LCOV - code coverage report
Current view: top level - app/test - test_vdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 32 46 69.6 %
Date: 2026-10-01 18:19:24 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 20 32 62.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2021 6WIND S.A.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <string.h>
       7                 :            : 
       8                 :            : #include <rte_dev.h>
       9                 :            : #include <rte_bus.h>
      10                 :            : #include <rte_bus_vdev.h>
      11                 :            : 
      12                 :            : #include "test.h"
      13                 :            : 
      14                 :            : static struct rte_device *
      15                 :          5 : find_vdev_by_name(const char *name)
      16                 :            : {
      17                 :          5 :         struct rte_dev_iterator it = { 0 };
      18                 :            :         struct rte_device *dev;
      19                 :            : 
      20         [ +  + ]:          9 :         RTE_DEV_FOREACH(dev, "bus=vdev", &it) {
      21         [ +  + ]:          8 :                 if (strcmp(rte_dev_name(dev), name) == 0)
      22                 :          4 :                         return dev;
      23                 :            :         }
      24                 :            :         return NULL;
      25                 :            : }
      26                 :            : 
      27                 :            : static int
      28                 :          1 : test_vdev_bus(void)
      29                 :            : {
      30                 :          1 :         struct rte_bus *vdev_bus = rte_bus_find_by_name("vdev");
      31                 :          1 :         struct rte_dev_iterator dev_iter = { 0 };
      32                 :            :         struct rte_device *dev, *dev0, *dev1;
      33                 :            : 
      34                 :            :         /* not supported */
      35         [ +  - ]:          1 :         if (vdev_bus == NULL)
      36                 :            :                 return 0;
      37                 :            : 
      38                 :            :         /* create first vdev */
      39         [ -  + ]:          1 :         if (rte_vdev_init("net_null_test0", "") < 0) {
      40                 :            :                 printf("Failed to create vdev net_null_test0\n");
      41                 :          0 :                 goto fail;
      42                 :            :         }
      43                 :          1 :         dev0 = find_vdev_by_name("net_null_test0");
      44         [ -  + ]:          1 :         if (dev0 == NULL) {
      45                 :            :                 printf("Cannot find net_null_test0 vdev\n");
      46                 :          0 :                 goto fail;
      47                 :            :         }
      48                 :            : 
      49                 :            :         /* create second vdev */
      50         [ -  + ]:          1 :         if (rte_vdev_init("net_null_test1", "") < 0) {
      51                 :            :                 printf("Failed to create vdev net_null_test1\n");
      52                 :          0 :                 goto fail;
      53                 :            :         }
      54                 :          1 :         dev1 = find_vdev_by_name("net_null_test1");
      55         [ -  + ]:          1 :         if (dev1 == NULL) {
      56                 :            :                 printf("Cannot find net_null_test1 vdev\n");
      57                 :          0 :                 goto fail;
      58                 :            :         }
      59                 :            : 
      60                 :            :         /* try to find vdevs */
      61                 :          1 :         dev = find_vdev_by_name("net_null_test0");
      62         [ -  + ]:          1 :         if (dev != dev0) {
      63                 :            :                 printf("Cannot match net_null_test0 vdev\n");
      64                 :          0 :                 goto fail;
      65                 :            :         }
      66                 :            : 
      67                 :          1 :         dev = find_vdev_by_name("net_null_test1");
      68         [ -  + ]:          1 :         if (dev != dev1) {
      69                 :            :                 printf("Cannot match net_null_test1 vdev\n");
      70                 :          0 :                 goto fail;
      71                 :            :         }
      72                 :            : 
      73                 :          1 :         dev = find_vdev_by_name("nonexistent");
      74         [ -  + ]:          1 :         if (dev != NULL) {
      75                 :            :                 printf("Nonexistent vdev should not match\n");
      76                 :          0 :                 goto fail;
      77                 :            :         }
      78                 :            : 
      79                 :            :         /* iterate all vdevs, and ensure we find dev0 and dev1 */
      80         [ +  + ]:          3 :         RTE_DEV_FOREACH(dev, "bus=vdev", &dev_iter) {
      81         [ +  + ]:          2 :                 if (dev == dev0)
      82                 :            :                         dev0 = NULL;
      83         [ +  - ]:          1 :                 else if (dev == dev1)
      84                 :            :                         dev1 = NULL;
      85                 :            :         }
      86         [ -  + ]:          1 :         if (dev0 != NULL) {
      87                 :            :                 printf("dev0 was not iterated\n");
      88                 :          0 :                 goto fail;
      89                 :            :         }
      90         [ -  + ]:          1 :         if (dev1 != NULL) {
      91                 :            :                 printf("dev1 was not iterated\n");
      92                 :          0 :                 goto fail;
      93                 :            :         }
      94                 :            : 
      95                 :          1 :         rte_vdev_uninit("net_null_test0");
      96                 :          1 :         rte_vdev_uninit("net_null_test1");
      97                 :            : 
      98                 :          1 :         return 0;
      99                 :            : 
     100                 :          0 : fail:
     101                 :          0 :         rte_vdev_uninit("net_null_test0");
     102                 :          0 :         rte_vdev_uninit("net_null_test1");
     103                 :          0 :         return -1;
     104                 :            : }
     105                 :            : 
     106                 :            : static int
     107                 :          1 : test_vdev(void)
     108                 :            : {
     109                 :            :         printf("== test vdev bus ==\n");
     110         [ -  + ]:          1 :         if (test_vdev_bus() < 0)
     111                 :          0 :                 return -1;
     112                 :            :         return 0;
     113                 :            : }
     114                 :            : 
     115                 :        302 : REGISTER_FAST_TEST(vdev_autotest, NOHUGE_OK, ASAN_OK, test_vdev);

Generated by: LCOV version 1.14