LCOV - code coverage report
Current view: top level - libbpfilter - verdict.c (source / functions) Coverage Total Hit
Test: coverage.lcov Lines: 100.0 % 8 8
Test Date: 2025-11-24 12:34:34 Functions: 100.0 % 2 2
Branches: 100.0 % 6 6

             Branch data     Line data    Source code
       1                 :             : /* SPDX-License-Identifier: GPL-2.0-only */
       2                 :             : /*
       3                 :             :  * Copyright (c) 2022 Meta Platforms, Inc. and affiliates.
       4                 :             :  */
       5                 :             : 
       6                 :             : #include "bpfilter/verdict.h"
       7                 :             : 
       8                 :             : #include <errno.h>
       9                 :             : #include <stddef.h>
      10                 :             : 
      11                 :             : #include "bpfilter/helper.h"
      12                 :             : 
      13                 :             : static const char *_bf_verdict_strs[] = {
      14                 :             :     [BF_VERDICT_ACCEPT] = "ACCEPT",
      15                 :             :     [BF_VERDICT_DROP] = "DROP",
      16                 :             :     [BF_VERDICT_CONTINUE] = "CONTINUE",
      17                 :             : };
      18                 :             : static_assert(ARRAY_SIZE(_bf_verdict_strs) == _BF_VERDICT_MAX,
      19                 :             :               "missing entries in the verdict array");
      20                 :             : 
      21                 :          43 : const char *bf_verdict_to_str(enum bf_verdict verdict)
      22                 :             : {
      23         [ +  + ]:          43 :     if (verdict < 0 || verdict >= _BF_VERDICT_MAX)
      24                 :             :         return "<bf_verdict unknown>";
      25                 :             : 
      26                 :          41 :     return _bf_verdict_strs[verdict];
      27                 :             : }
      28                 :             : 
      29                 :        1551 : int bf_verdict_from_str(const char *str, enum bf_verdict *verdict)
      30                 :             : {
      31                 :             :     bf_assert(verdict);
      32                 :             : 
      33         [ +  + ]:        2026 :     for (size_t i = 0; i < _BF_VERDICT_MAX; ++i) {
      34         [ +  + ]:        2023 :         if (bf_streq(_bf_verdict_strs[i], str)) {
      35                 :        1548 :             *verdict = i;
      36                 :        1548 :             return 0;
      37                 :             :         }
      38                 :             :     }
      39                 :             : 
      40                 :             :     return -EINVAL;
      41                 :             : }
        

Generated by: LCOV version 2.0-1