mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-12 10:44:06 -04:00
gpu/tests/gpu_buddy: Add KUnit test for gpu_buddy_allocated_addr_to_block
Add a new KUnit test gpu_test_buddy_addr_to_block() that validates the gpu_buddy_allocated_addr_to_block() helper which traces a address back to its allocated buddy block. The test covers: - Exact address matching returns the correct allocated block - An unallocated address inside the manager should return NULL - An address outside the manager should return -ENXIO v4(MattA): - Add test for unaligned address v3(Sashiko): - remove unused target_addr variable v2(Sashiko): - Drop the mutex and lockdep annotation; standalone KUnit tests do not register a driver lock. Signed-off-by: Tejas Upadhyay <tejas.upadhyay@intel.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> Link: https://patch.msgid.link/20260806053624.3215216-6-tejas.upadhyay@intel.com
This commit is contained in:
committed by
Arunpravin Paneer Selvam
parent
151ebbc20a
commit
3de014f7de
@@ -1422,6 +1422,50 @@ static void gpu_test_buddy_alloc_exceeds_max_order(struct kunit *test)
|
||||
gpu_buddy_fini(&mm);
|
||||
}
|
||||
|
||||
static void gpu_test_buddy_addr_to_block(struct kunit *test)
|
||||
{
|
||||
struct gpu_buddy_block *allocated_block, *found_block;
|
||||
LIST_HEAD(allocated_list);
|
||||
const u64 test_size = SZ_4M + SZ_2M;
|
||||
const u64 alloc_start = SZ_4M;
|
||||
const u64 alloc_size = SZ_4K;
|
||||
const u64 chunk_size = SZ_4K;
|
||||
struct gpu_buddy mm;
|
||||
|
||||
KUNIT_ASSERT_FALSE_MSG(test, gpu_buddy_init(&mm, test_size, chunk_size),
|
||||
"buddy_init failed\n");
|
||||
|
||||
KUNIT_ASSERT_FALSE_MSG(test, gpu_buddy_alloc_blocks(&mm, alloc_start,
|
||||
alloc_start + alloc_size,
|
||||
alloc_size, chunk_size,
|
||||
&allocated_list, 0),
|
||||
"buddy_alloc failed\n");
|
||||
|
||||
allocated_block = list_first_entry(&allocated_list, struct gpu_buddy_block, link);
|
||||
KUNIT_EXPECT_EQ(test, gpu_buddy_block_offset(allocated_block), alloc_start);
|
||||
KUNIT_EXPECT_EQ(test, gpu_buddy_block_size(&mm, allocated_block), alloc_size);
|
||||
|
||||
found_block = gpu_buddy_allocated_addr_to_block(&mm, alloc_start);
|
||||
KUNIT_EXPECT_PTR_EQ(test, found_block, allocated_block);
|
||||
|
||||
/* Unaligned address inside the allocated block (should resolve to the same block) */
|
||||
found_block = gpu_buddy_allocated_addr_to_block(&mm, alloc_start + 16);
|
||||
KUNIT_EXPECT_PTR_EQ(test, found_block, allocated_block);
|
||||
|
||||
/* An unallocated address inside the manager should return NULL. */
|
||||
found_block = gpu_buddy_allocated_addr_to_block(&mm,
|
||||
alloc_start - chunk_size);
|
||||
KUNIT_EXPECT_NULL(test, found_block);
|
||||
|
||||
/* An address outside the manager should return -ENXIO. */
|
||||
found_block = gpu_buddy_allocated_addr_to_block(&mm, test_size);
|
||||
KUNIT_EXPECT_EQ(test, PTR_ERR(found_block), -ENXIO);
|
||||
|
||||
/* 3. Standard inline cleanup flow */
|
||||
gpu_buddy_free_list(&mm, &allocated_list, 0);
|
||||
gpu_buddy_fini(&mm);
|
||||
}
|
||||
|
||||
static int gpu_buddy_suite_init(struct kunit_suite *suite)
|
||||
{
|
||||
while (!random_seed)
|
||||
@@ -1446,6 +1490,7 @@ static struct kunit_case gpu_buddy_tests[] = {
|
||||
KUNIT_CASE(gpu_test_buddy_alloc_exceeds_max_order),
|
||||
KUNIT_CASE(gpu_test_buddy_offset_aligned_allocation),
|
||||
KUNIT_CASE(gpu_test_buddy_subtree_offset_alignment_stress),
|
||||
KUNIT_CASE(gpu_test_buddy_addr_to_block),
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user