LCOV - code coverage report
Current view: top level - lib/cmdline - cmdline_parse_bool.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 14 0.0 %
Date: 2026-06-01 18:36:17 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 16 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2023 NVIDIA Corporation & Affiliates
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <stdint.h>
       7                 :            : #include <inttypes.h>
       8                 :            : #include <string.h>
       9                 :            : #include <eal_export.h>
      10                 :            : #include <rte_string_fns.h>
      11                 :            : #include <stdlib.h>
      12                 :            : 
      13                 :            : #include "cmdline_parse.h"
      14                 :            : #include "cmdline_parse_bool.h"
      15                 :            : 
      16                 :            : static int
      17                 :            : cmdline_get_help_bool(cmdline_parse_token_hdr_t *tk, char *dstbuf,
      18                 :            :                 unsigned int size);
      19                 :            : 
      20                 :            : 
      21                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(cmdline_token_bool_ops, 25.03)
      22                 :            : struct cmdline_token_ops cmdline_token_bool_ops = {
      23                 :            :         .parse = cmdline_parse_bool,
      24                 :            :         .complete_get_nb = NULL,
      25                 :            :         .complete_get_elt = NULL,
      26                 :            :         .get_help = cmdline_get_help_bool,
      27                 :            : };
      28                 :            : 
      29                 :            : static cmdline_parse_token_string_t cmd_parse_token_bool = {
      30                 :            :         {
      31                 :            :                 &cmdline_token_string_ops,
      32                 :            :                 0
      33                 :            :         },
      34                 :            :         {
      35                 :            :                 "on#off"
      36                 :            :         }
      37                 :            : };
      38                 :            : 
      39                 :            : /* get help for bool token */
      40                 :            : static int
      41                 :          0 : cmdline_get_help_bool(__rte_unused cmdline_parse_token_hdr_t *tk,
      42                 :            :                 char *dstbuf, unsigned int size)
      43                 :            : {
      44         [ #  # ]:          0 :         if (dstbuf == NULL || size == 0)
      45                 :            :                 return -1;
      46                 :            : 
      47                 :          0 :         strlcpy(dstbuf, "on|off", size);
      48                 :          0 :         return 0;
      49                 :            : }
      50                 :            : 
      51                 :            : /* parse string to bool */
      52                 :            : int
      53                 :          0 : cmdline_parse_bool(__rte_unused cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res,
      54                 :            :         unsigned int ressize)
      55                 :            : {
      56                 :          0 :         cmdline_fixed_string_t on_off = {0};
      57                 :            :         uint8_t val;
      58                 :            : 
      59   [ #  #  #  # ]:          0 :         if (!srcbuf || !*srcbuf)
      60                 :            :                 return -1;
      61                 :            : 
      62         [ #  # ]:          0 :         if (res != NULL && ressize < sizeof(uint8_t))
      63                 :            :                 return -1;
      64                 :            : 
      65         [ #  # ]:          0 :         if (cmdline_token_string_ops.parse
      66                 :            :                         (&cmd_parse_token_bool.hdr, srcbuf, on_off, sizeof(on_off)) < 0)
      67                 :            :                 return -1;
      68                 :            : 
      69         [ #  # ]:          0 :         if (strcmp((char *)on_off, "on") == 0)
      70                 :            :                 val = 1;
      71         [ #  # ]:          0 :         else if (strcmp((char *)on_off, "off") == 0)
      72                 :            :                 val = 0;
      73                 :            :         else
      74                 :            :                 return -1;
      75                 :            : 
      76         [ #  # ]:          0 :         if (res != NULL)
      77                 :          0 :                 *(uint8_t *)res = val;
      78                 :            : 
      79                 :          0 :         return strlen(on_off);
      80                 :            : }

Generated by: LCOV version 1.14