[PATCH 2/2] lib: sbi_bitmap_test: add tests for bitmap_empty()

Anup Patel anup at brainfault.org
Wed Apr 8 05:37:59 PDT 2026


On Wed, Mar 11, 2026 at 6:21 PM Yu-Chien Peter Lin <peter.lin at sifive.com> wrote:
>
> Add tests for bitmap_empty(), covers empty/non-empty bitmaps and
> edge case nbits=0.
>
> Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>

LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>  lib/sbi/tests/sbi_bitmap_test.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
>
> 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,
>  };
>
> --
> 2.53.0
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



More information about the opensbi mailing list