4 * Copyright (C) Cavium, Inc. 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium, Inc nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <rte_common.h>
37 #include <rte_bitmap.h>
38 #include <rte_malloc.h>
45 test_bitmap_scan_operations(struct rte_bitmap *bmp)
48 uint64_t slab1_magic = 0xBADC0FFEEBADF00D;
49 uint64_t slab2_magic = 0xFEEDDEADDEADF00D;
50 uint64_t out_slab = 0;
52 rte_bitmap_reset(bmp);
54 rte_bitmap_set_slab(bmp, pos, slab1_magic);
55 rte_bitmap_set_slab(bmp, pos + RTE_BITMAP_SLAB_BIT_SIZE, slab2_magic);
57 if (!rte_bitmap_scan(bmp, &pos, &out_slab)) {
58 printf("Failed to get slab from bitmap.\n");
62 if (slab1_magic != out_slab) {
63 printf("Scan operation sanity failed.\n");
67 if (!rte_bitmap_scan(bmp, &pos, &out_slab)) {
68 printf("Failed to get slab from bitmap.\n");
72 if (slab2_magic != out_slab) {
73 printf("Scan operation sanity failed.\n");
78 if (!rte_bitmap_scan(bmp, &pos, &out_slab)) {
79 printf("Failed to get slab from bitmap.\n");
83 if (slab1_magic != out_slab) {
84 printf("Scan operation wrap around failed.\n");
88 /* Scan reset check. */
89 __rte_bitmap_scan_init(bmp);
91 if (!rte_bitmap_scan(bmp, &pos, &out_slab)) {
92 printf("Failed to get slab from bitmap.\n");
96 if (slab1_magic != out_slab) {
97 printf("Scan reset operation failed.\n");
105 test_bitmap_slab_set_get(struct rte_bitmap *bmp)
108 uint64_t slab_magic = 0xBADC0FFEEBADF00D;
109 uint64_t out_slab = 0;
111 rte_bitmap_reset(bmp);
112 rte_bitmap_set_slab(bmp, pos, slab_magic);
114 if (!rte_bitmap_scan(bmp, &pos, &out_slab)) {
115 printf("Failed to get slab from bitmap.\n");
120 if (slab_magic != out_slab) {
121 printf("Invalid slab in bitmap.\n");
130 test_bitmap_set_get_clear(struct rte_bitmap *bmp)
134 rte_bitmap_reset(bmp);
135 for (i = 0; i < MAX_BITS; i++)
136 rte_bitmap_set(bmp, i);
138 for (i = 0; i < MAX_BITS; i++) {
139 if (!rte_bitmap_get(bmp, i)) {
140 printf("Failed to get set bit.\n");
145 for (i = 0; i < MAX_BITS; i++)
146 rte_bitmap_clear(bmp, i);
148 for (i = 0; i < MAX_BITS; i++) {
149 if (rte_bitmap_get(bmp, i)) {
150 printf("Failed to clear set bit.\n");
163 struct rte_bitmap *bmp;
166 rte_bitmap_get_memory_footprint(MAX_BITS);
168 mem = rte_zmalloc("test_bmap", bmp_size, RTE_CACHE_LINE_SIZE);
170 printf("Failed to allocate memory for bitmap\n");
174 bmp = rte_bitmap_init(MAX_BITS, mem, bmp_size);
176 printf("Failed to init bitmap\n");
180 if (test_bitmap_set_get_clear(bmp) < 0)
183 if (test_bitmap_slab_set_get(bmp) < 0)
186 if (test_bitmap_scan_operations(bmp) < 0)
192 REGISTER_TEST_COMMAND(bitmap_test, test_bitmap);