diff options
| author | Yu-Chien Peter Lin <peter.lin@sifive.com> | 2026-03-11 20:51:16 +0800 |
|---|---|---|
| committer | Anup Patel <anup@brainfault.org> | 2026-04-08 17:58:06 +0530 |
| commit | 2257e9957103aac7df8089a59b9d4bdda7c592ce (patch) | |
| tree | eaa7d764db68e5ce43bad271f75448d903ba2232 | |
| parent | ff7d245b86daa36aa36147022fa583e79ffe25cc (diff) | |
| download | opensbi-master.tar.gz opensbi-master.tar.bz2 opensbi-master.zip | |
Add tests for bitmap_empty(), covers empty/non-empty bitmaps and
edge case nbits=0.
Signed-off-by: Yu-Chien Peter Lin <peter.lin@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260311125116.1401002-2-peter.lin@sifive.com
Signed-off-by: Anup Patel <anup@brainfault.org>
| -rw-r--r-- | lib/sbi/tests/sbi_bitmap_test.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/sbi/tests/sbi_bitmap_test.c b/lib/sbi/tests/sbi_bitmap_test.c index d2c35996..b6586fe1 100644 --- a/lib/sbi/tests/sbi_bitmap_test.c +++ b/lib/sbi/tests/sbi_bitmap_test.c @@ -92,10 +92,39 @@ static void bitmap_xor_test(struct sbiunit_test_case *test) SBIUNIT_EXPECT_MEMEQ(test, res, data_zero, DATA_SIZE); } +static void bitmap_empty_test(struct sbiunit_test_case *test) +{ + unsigned long res[DATA_SIZE]; + + /* All zeros = empty */ + SBIUNIT_EXPECT_EQ(test, bitmap_empty(data_zero, DATA_BIT_SIZE), true); + + /* Non-zero data = not empty */ + SBIUNIT_EXPECT_EQ(test, bitmap_empty(data_a, DATA_BIT_SIZE), false); + SBIUNIT_EXPECT_EQ(test, bitmap_empty(data_b, DATA_BIT_SIZE), false); + + /* bitmap_zero creates empty bitmap */ + bitmap_zero(res, DATA_BIT_SIZE); + SBIUNIT_EXPECT_EQ(test, bitmap_empty(res, DATA_BIT_SIZE), true); + + /* bitmap_fill creates non-empty bitmap */ + bitmap_fill(res, DATA_BIT_SIZE); + SBIUNIT_EXPECT_EQ(test, bitmap_empty(res, DATA_BIT_SIZE), false); + + /* Single bit set = not empty */ + bitmap_zero(res, DATA_BIT_SIZE); + bitmap_set(res, 0, 1); + SBIUNIT_EXPECT_EQ(test, bitmap_empty(res, DATA_BIT_SIZE), false); + + /* Zero nbits = empty */ + SBIUNIT_EXPECT_EQ(test, bitmap_empty(data_a, 0), true); +} + static struct sbiunit_test_case bitmap_test_cases[] = { SBIUNIT_TEST_CASE(bitmap_and_test), SBIUNIT_TEST_CASE(bitmap_or_test), SBIUNIT_TEST_CASE(bitmap_xor_test), + SBIUNIT_TEST_CASE(bitmap_empty_test), SBIUNIT_END_CASE, }; |
