Skip to contentSkip to conversation

lib: tests: add bitmap set and clear tests

PATCH Applied Michael Estner 2 participants 2 messages Sep 28 – Nov 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: tests: add bitmap set and clear tests

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.

---
 lib/sbi/tests/sbi_bitmap_test.c | 34 +++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
lib/sbi/tests/sbi_bitmap_test.c +34 -0
index b6586fe1..96165b7e 100644
@@ -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,
 };
 
Signature · 7 lines
2.34.1


-- 
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Reviewed-by on v1 1/1 Applied
#1 lore raw
Quoted 7 lines · Michael Estner

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.

LGTM.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 62 lines
---
 lib/sbi/tests/sbi_bitmap_test.c | 34 +++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
lib/sbi/tests/sbi_bitmap_test.c +34 -1
index b6586fe1..96165b7e 100644
@@ -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
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi