LCOV - code coverage report
Current view: top level - plugins/unittest - sparse_vec_test.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 17 20 85.0 %
Date: 2023-07-05 22:20:52 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2018 Cisco and/or its affiliates.
       3             :  * Licensed under the Apache License, Version 2.0 (the "License");
       4             :  * you may not use this file except in compliance with the License.
       5             :  * You may obtain a copy of the License at:
       6             :  *
       7             :  *     http://www.apache.org/licenses/LICENSE-2.0
       8             :  *
       9             :  * Unless required by applicable law or agreed to in writing, software
      10             :  * distributed under the License is distributed on an "AS IS" BASIS,
      11             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             :  * See the License for the specific language governing permissions and
      13             :  * limitations under the License.
      14             :  */
      15             : 
      16             : #include <vlib/vlib.h>
      17             : #include <vppinfra/sparse_vec.h>
      18             : 
      19             : static clib_error_t *
      20           1 : test_sparse_vec_command_fn (vlib_main_t * vm,
      21             :                             unformat_input_t * input,
      22             :                             vlib_cli_command_t * cmd)
      23             : {
      24             :   /* A sparse vector ... */
      25           1 :   int *spv = 0;
      26             :   int i, c0, c1;
      27             :   u32 i0, i1;
      28             : 
      29             :   /* set one member */
      30           1 :   sparse_vec_validate (spv, 42)[0] = 0x4242;
      31             :   /* count how many times we can find it */
      32           1 :   c0 = 0;
      33       65537 :   for (i = 0; i <= 0xffff; i++)
      34             :     {
      35       65536 :       c0 += (sparse_vec_index (spv, i) != 0);
      36             :     }
      37             : 
      38           1 :   if (c0 != 1)
      39           0 :     vlib_cli_output (vm, "sparse_vec_index failed: c0 is %d != 1", c0);
      40             : 
      41           1 :   c0 = 0;
      42           1 :   c1 = 0;
      43       65537 :   for (i = 0; i <= 0xffff; i++)
      44             :     {
      45       65536 :       sparse_vec_index2 (spv, i, 0xffff ^ i, &i0, &i1);
      46       65536 :       c0 += (i0 != 0);
      47       65536 :       c1 += (i1 != 0);
      48             :     }
      49             : 
      50           1 :   if (c0 != 1)
      51           0 :     vlib_cli_output (vm, "sparse_vec_index2 failed: c0 is %d != 1", c0);
      52           1 :   if (c1 != 1)
      53           0 :     vlib_cli_output (vm, "sparse_vec_index2 failed: c1 is %d != 1", c1);
      54             : 
      55           1 :   return 0;
      56             : }
      57             : 
      58             : /* *INDENT-OFF* */
      59       16239 : VLIB_CLI_COMMAND (test_sparse_vec_command, static) =
      60             : {
      61             :   .path = "test sparse_vec",
      62             :   .short_help = "test sparse_vec",
      63             :   .function = test_sparse_vec_command_fn,
      64             : };
      65             : /* *INDENT-ON* */
      66             : 
      67             : /*
      68             :  * fd.io coding-style-patch-verification: ON
      69             :  *
      70             :  * Local Variables:
      71             :  * eval: (c-set-style "gnu")
      72             :  * End:
      73             :  */

Generated by: LCOV version 1.14