Skip to content

Commit 6d5d3a0

Browse files
committed
bitmap: add test for bitmap_*_region() functions
Test basic functionality of bitmap_{allocate,release,find_free}_region() functions. CC: Rasmus Villemoes <linux@rasmusvillemoes.dk> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Yury Norov <yury.norov@gmail.com>
1 parent 82bf9bd commit 6d5d3a0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/test_bitmap.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,29 @@ static void __init test_copy(void)
330330
expect_eq_pbl("0-108,128-1023", bmap2, 1024);
331331
}
332332

333+
static void __init test_bitmap_region(void)
334+
{
335+
int pos, order;
336+
337+
DECLARE_BITMAP(bmap, 1000);
338+
339+
bitmap_zero(bmap, 1000);
340+
341+
for (order = 0; order < 10; order++) {
342+
pos = bitmap_find_free_region(bmap, 1000, order);
343+
if (order == 0)
344+
expect_eq_uint(pos, 0);
345+
else
346+
expect_eq_uint(pos, order < 9 ? BIT(order) : -ENOMEM);
347+
}
348+
349+
bitmap_release_region(bmap, 0, 0);
350+
for (order = 1; order < 9; order++)
351+
bitmap_release_region(bmap, BIT(order), order);
352+
353+
expect_eq_uint(bitmap_weight(bmap, 1000), 0);
354+
}
355+
333356
#define EXP2_IN_BITS (sizeof(exp2) * 8)
334357

335358
static void __init test_replace(void)
@@ -1227,6 +1250,7 @@ static void __init selftest(void)
12271250
test_zero_clear();
12281251
test_fill_set();
12291252
test_copy();
1253+
test_bitmap_region();
12301254
test_replace();
12311255
test_bitmap_arr32();
12321256
test_bitmap_arr64();

0 commit comments

Comments
 (0)