svm: minimal initial fifo
[vpp.git] / src / plugins / unittest / sparse_vec_test.c
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 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   int *spv = 0;
26   int i, c0, c1;
27   u32 i0, i1;
28
29   /* set one member */
30   sparse_vec_validate (spv, 42)[0] = 0x4242;
31   /* count how many times we can find it */
32   c0 = 0;
33   for (i = 0; i <= 0xffff; i++)
34     {
35       c0 += (sparse_vec_index (spv, i) != 0);
36     }
37
38   if (c0 != 1)
39     vlib_cli_output (vm, "sparse_vec_index failed: c0 is %d != 1", c0);
40
41   c0 = 0;
42   c1 = 0;
43   for (i = 0; i <= 0xffff; i++)
44     {
45       sparse_vec_index2 (spv, i, 0xffff ^ i, &i0, &i1);
46       c0 += (i0 != 0);
47       c1 += (i1 != 0);
48     }
49
50   if (c0 != 1)
51     vlib_cli_output (vm, "sparse_vec_index2 failed: c0 is %d != 1", c0);
52   if (c1 != 1)
53     vlib_cli_output (vm, "sparse_vec_index2 failed: c1 is %d != 1", c1);
54
55   return 0;
56 }
57
58 /* *INDENT-OFF* */
59 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  */