All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Estner <michaelestner@web.de>
To: opensbi@lists.infradead.org
Cc: Michael Estner <michaelestner@web.de>
Subject: [PATCH] lib: tests: add bitmap set and clear tests
Date: Mon, 28 Sep 2026 13:14:42 +0200	[thread overview]
Message-ID: <20260928111442.289267-1-michaelestner@web.de> (raw)

Add SBIUnit word-boundary coverage for bitmap_set() and bitmap_clear().

Derive the base bit index from BITS_PER_LONG so that the tested range
crosses the 31/32 boundary on RV32 and the 63/64 boundary on RV64.

Signed-off-by: Michael Estner <michaelestner@web.de>
---
 lib/sbi/tests/sbi_bitmap_test.c | 34 +++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/lib/sbi/tests/sbi_bitmap_test.c b/lib/sbi/tests/sbi_bitmap_test.c
index b6586fe1..96165b7e 100644
--- a/lib/sbi/tests/sbi_bitmap_test.c
+++ b/lib/sbi/tests/sbi_bitmap_test.c
@@ -120,11 +120,45 @@ static void bitmap_empty_test(struct sbiunit_test_case *test)
 	SBIUNIT_EXPECT_EQ(test, bitmap_empty(data_a, 0), true);
 }
 
+static void bitmap_set_clear_test(struct sbiunit_test_case *test)
+{
+	unsigned long res[DATA_SIZE];
+	int start = BITS_PER_LONG - 2;
+
+	/* Set across a word boundary */
+	bitmap_zero(res, DATA_BIT_SIZE);
+	bitmap_set(res, start, 4);
+
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start), true);
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start + 1), true);
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start + 2), true);
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start + 3), true);
+
+	/* Adjacent bits untouched */
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start - 1), false);
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start + 4), false);
+
+	/* Clear across the same boundary */
+	bitmap_clear(res, start + 1, 2);
+
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start), true);
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start + 1), false);
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start + 2), false);
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start + 3), true);
+
+	/* Clearing 0 bits is a no-op */
+	bitmap_clear(res, start, 0);
+
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start), true);
+	SBIUNIT_EXPECT_EQ(test, bitmap_test(res, start + 3), 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_TEST_CASE(bitmap_set_clear_test),
 	SBIUNIT_END_CASE,
 };
 
-- 
2.34.1


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

                 reply	other threads:[~2026-09-28 11:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260928111442.289267-1-michaelestner@web.de \
    --to=michaelestner@web.de \
    --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.