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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vlib/vlib.h>
17 #include <vppinfra/sparse_vec.h>
20 test_sparse_vec_command_fn (vlib_main_t * vm,
21 unformat_input_t * input,
22 vlib_cli_command_t * cmd)
24 /* A sparse vector ... */
30 sparse_vec_validate (spv, 42)[0] = 0x4242;
31 /* count how many times we can find it */
33 for (i = 0; i <= 0xffff; i++)
35 c0 += (sparse_vec_index (spv, i) != 0);
39 vlib_cli_output (vm, "sparse_vec_index failed: c0 is %d != 1", c0);
43 for (i = 0; i <= 0xffff; i++)
45 sparse_vec_index2 (spv, i, 0xffff ^ i, &i0, &i1);
51 vlib_cli_output (vm, "sparse_vec_index2 failed: c0 is %d != 1", c0);
53 vlib_cli_output (vm, "sparse_vec_index2 failed: c1 is %d != 1", c1);
59 VLIB_CLI_COMMAND (test_sparse_vec_command, static) =
61 .path = "test sparse_vec",
62 .short_help = "test sparse_vec",
63 .function = test_sparse_vec_command_fn,
68 * fd.io coding-style-patch-verification: ON
71 * eval: (c-set-style "gnu")