[PATCH v2 3/3] drm/buddy: Add a new unit test case for buffer clearance issue
Arunpravin Paneer Selvam
Arunpravin.PaneerSelvam at amd.com
Tue Jul 1 19:08:22 UTC 2025
Add a new unit test case for buffer clearance issue during
resume.
Using a non-power-of-two mm size, allocate alternating blocks of
4KiB in an even sequence and free them as cleared. All alternate
blocks should be marked as dirty and the split blocks should be
merged back to their original size when the blocks clear reset
function is called.
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam at amd.com>
---
drivers/gpu/drm/tests/drm_buddy_test.c | 41 ++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c
index 7a0e523651f0..e23922a21c77 100644
--- a/drivers/gpu/drm/tests/drm_buddy_test.c
+++ b/drivers/gpu/drm/tests/drm_buddy_test.c
@@ -408,6 +408,47 @@ static void drm_test_buddy_alloc_clear(struct kunit *test)
"buddy_alloc hit an error size=%lu\n", ps);
drm_buddy_free_list(&mm, &allocated, DRM_BUDDY_CLEARED);
drm_buddy_fini(&mm);
+
+ /*
+ * Using a non-power-of-two mm size, allocate alternating blocks of 4KiB in an
+ * even sequence and free them as cleared. All blocks should be marked as
+ * dirty and the split blocks should be merged back to their original
+ * size when the blocks clear reset function is called.
+ */
+ KUNIT_EXPECT_FALSE(test, drm_buddy_init(&mm, mm_size, ps));
+ KUNIT_EXPECT_EQ(test, mm.max_order, max_order);
+
+ i = 0;
+ n_pages = mm_size / ps;
+ do {
+ if (i % 2 == 0)
+ KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
+ ps, ps, &allocated, 0),
+ "buddy_alloc hit an error size=%lu\n", ps);
+ } while (++i < n_pages);
+
+ drm_buddy_free_list(&mm, &allocated, DRM_BUDDY_CLEARED);
+ drm_buddy_reset_clear_state(&mm, false);
+ KUNIT_EXPECT_EQ(test, mm.clear_avail, 0);
+
+ /*
+ * Using a non-power-of-two mm size, allocate alternating blocks of 4KiB in an
+ * odd sequence and free them as cleared. All blocks should be marked as
+ * cleared and the split blocks should be merged back to their original
+ * size when the blocks clear reset function is called.
+ */
+ i = 0;
+ do {
+ if (i % 2 != 0)
+ KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
+ ps, ps, &allocated, 0),
+ "buddy_alloc hit an error size=%lu\n", ps);
+ } while (++i < n_pages);
+
+ drm_buddy_free_list(&mm, &allocated, DRM_BUDDY_CLEARED);
+ drm_buddy_reset_clear_state(&mm, true);
+ KUNIT_EXPECT_EQ(test, mm.clear_avail, mm_size);
+ drm_buddy_fini(&mm);
}
static void drm_test_buddy_alloc_contiguous(struct kunit *test)
--
2.43.0
More information about the amd-gfx
mailing list