vppinfra: improve test coverage
[vpp.git] / src / plugins / unittest / bitmap_test.c
1 /*
2  * Copyright (c) 2020 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 #include <vlib/vlib.h>
16 #include <vppinfra/bitmap.h>
17
18 static clib_error_t *
19 test_bitmap_command_fn (vlib_main_t * vm,
20                         unformat_input_t * input, vlib_cli_command_t * cmd)
21 {
22   u64 *bm = 0;
23   u64 *bm2 = 0;
24   u64 *dup;
25   uword junk;
26
27   bm = clib_bitmap_set_multiple (bm, 2, ~0ULL, BITS (uword));
28
29   junk = clib_bitmap_next_clear (bm, 3);
30   junk = clib_bitmap_next_clear (bm, 65);
31
32   bm2 = clib_bitmap_set_multiple (bm2, 0, ~0ULL, BITS (uword));
33   _vec_len (bm2) = 1;
34   junk = clib_bitmap_next_clear (bm2, 0);
35
36
37   bm = clib_bitmap_set_multiple (bm, 2, ~0ULL, BITS (uword) - 3);
38   junk = clib_bitmap_get_multiple (bm, 2, BITS (uword));
39   junk = clib_bitmap_first_set (bm);
40   junk = 1 << 3;
41   bm = clib_bitmap_xori (bm, junk);
42   bm = clib_bitmap_andi (bm, junk);
43   bm = clib_bitmap_xori_notrim (bm, junk);
44   bm = clib_bitmap_andi_notrim (bm, junk);
45
46   bm = clib_bitmap_set_multiple (bm, 2, ~0ULL, BITS (uword) - 3);
47   bm2 = clib_bitmap_set_multiple (bm2, 2, ~0ULL, BITS (uword) - 3);
48
49   dup = clib_bitmap_dup_and (bm, bm2);
50   vec_free (dup);
51   dup = clib_bitmap_dup_andnot (bm, bm2);
52   vec_free (dup);
53   vec_free (bm);
54   vec_free (bm2);
55
56   return 0;
57 }
58
59
60
61 /* *INDENT-OFF* */
62 VLIB_CLI_COMMAND (test_bihash_command, static) =
63 {
64   .path = "test bitmap",
65   .short_help = "Coverage test for bitmap.h",
66   .function = test_bitmap_command_fn,
67 };
68 /* *INDENT-ON* */
69
70 /*
71  * fd.io coding-style-patch-verification: ON
72  *
73  * Local Variables:
74  * eval: (c-set-style "gnu")
75  * End:
76  */