From: Yu-Chien Peter Lin <peter.lin@sifive.com>
To: opensbi@lists.infradead.org
Cc: Yu-Chien Peter Lin <peter.lin@sifive.com>
Subject: [PATCH 2/2] lib: sbi_bitmap_test: add tests for bitmap_empty()
Date: Wed, 11 Mar 2026 20:51:16 +0800 [thread overview]
Message-ID: <20260311125116.1401002-2-peter.lin@sifive.com> (raw)
In-Reply-To: <20260311125116.1401002-1-peter.lin@sifive.com>
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>
---
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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2026-03-11 12:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 12:51 [PATCH 1/2] include: sbi_bitmap: add bitmap_empty() function Yu-Chien Peter Lin
2026-03-11 12:51 ` Yu-Chien Peter Lin [this message]
2026-04-08 12:37 ` [PATCH 2/2] lib: sbi_bitmap_test: add tests for bitmap_empty() Anup Patel
2026-04-08 12:37 ` [PATCH 1/2] include: sbi_bitmap: add bitmap_empty() function Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260311125116.1401002-2-peter.lin@sifive.com \
--to=peter.lin@sifive.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.