mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	drm/buddy: Add a testcase to verify the multiroot fini
- Added a testcase to verify the multiroot force merge fini. - Added a new field in_use to track the mm freed status. v2:(Matthew) - Add kunit_fail_current_test() when WARN_ON is true. Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> Signed-off-by: Lin.Cao <lincao12@amd.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20241226070116.309290-2-Arunpravin.PaneerSelvam@amd.com
This commit is contained in:
		
							parent
							
								
									467dce3817
								
							
						
					
					
						commit
						8cb3a1e2b3
					
				
					 2 changed files with 25 additions and 10 deletions
				
			
		|  | @ -3,6 +3,8 @@ | ||||||
|  * Copyright © 2021 Intel Corporation |  * Copyright © 2021 Intel Corporation | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | #include <kunit/test-bug.h> | ||||||
|  | 
 | ||||||
| #include <linux/kmemleak.h> | #include <linux/kmemleak.h> | ||||||
| #include <linux/module.h> | #include <linux/module.h> | ||||||
| #include <linux/sizes.h> | #include <linux/sizes.h> | ||||||
|  | @ -335,7 +337,9 @@ void drm_buddy_fini(struct drm_buddy *mm) | ||||||
| 		start = drm_buddy_block_offset(mm->roots[i]); | 		start = drm_buddy_block_offset(mm->roots[i]); | ||||||
| 		__force_merge(mm, start, start + size, order); | 		__force_merge(mm, start, start + size, order); | ||||||
| 
 | 
 | ||||||
| 		WARN_ON(!drm_buddy_block_is_free(mm->roots[i])); | 		if (WARN_ON(!drm_buddy_block_is_free(mm->roots[i]))) | ||||||
|  | 			kunit_fail_current_test("buddy_fini() root"); | ||||||
|  | 
 | ||||||
| 		drm_block_free(mm, mm->roots[i]); | 		drm_block_free(mm, mm->roots[i]); | ||||||
| 
 | 
 | ||||||
| 		root_size = mm->chunk_size << order; | 		root_size = mm->chunk_size << order; | ||||||
|  |  | ||||||
|  | @ -385,17 +385,28 @@ static void drm_test_buddy_alloc_clear(struct kunit *test) | ||||||
| 	drm_buddy_fini(&mm); | 	drm_buddy_fini(&mm); | ||||||
| 
 | 
 | ||||||
| 	/*
 | 	/*
 | ||||||
| 	 * Create a new mm with a non power-of-two size. Allocate a random size, free as | 	 * Create a new mm with a non power-of-two size. Allocate a random size from each | ||||||
| 	 * cleared and then call fini. This will ensure the multi-root force merge during | 	 * root, free as cleared and then call fini. This will ensure the multi-root | ||||||
| 	 * fini. | 	 * force merge during fini. | ||||||
| 	 */ | 	 */ | ||||||
| 	mm_size = 12 * SZ_4K; | 	mm_size = (SZ_4K << max_order) + (SZ_4K << (max_order - 2)); | ||||||
| 	size = max(round_up(prandom_u32_state(&prng) % mm_size, ps), ps); | 
 | ||||||
| 	KUNIT_EXPECT_FALSE(test, drm_buddy_init(&mm, mm_size, ps)); | 	KUNIT_EXPECT_FALSE(test, drm_buddy_init(&mm, mm_size, ps)); | ||||||
| 	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size, | 	KUNIT_EXPECT_EQ(test, mm.max_order, max_order); | ||||||
| 							    size, ps, &allocated, | 	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, SZ_4K << max_order, | ||||||
| 							    DRM_BUDDY_TOPDOWN_ALLOCATION), | 							    4 * ps, ps, &allocated, | ||||||
| 				"buddy_alloc hit an error size=%u\n", size); | 							    DRM_BUDDY_RANGE_ALLOCATION), | ||||||
|  | 				"buddy_alloc hit an error size=%lu\n", 4 * ps); | ||||||
|  | 	drm_buddy_free_list(&mm, &allocated, DRM_BUDDY_CLEARED); | ||||||
|  | 	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, SZ_4K << max_order, | ||||||
|  | 							    2 * ps, ps, &allocated, | ||||||
|  | 							    DRM_BUDDY_CLEAR_ALLOCATION), | ||||||
|  | 				"buddy_alloc hit an error size=%lu\n", 2 * ps); | ||||||
|  | 	drm_buddy_free_list(&mm, &allocated, DRM_BUDDY_CLEARED); | ||||||
|  | 	KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, SZ_4K << max_order, mm_size, | ||||||
|  | 							    ps, ps, &allocated, | ||||||
|  | 							    DRM_BUDDY_RANGE_ALLOCATION), | ||||||
|  | 				"buddy_alloc hit an error size=%lu\n", ps); | ||||||
| 	drm_buddy_free_list(&mm, &allocated, DRM_BUDDY_CLEARED); | 	drm_buddy_free_list(&mm, &allocated, DRM_BUDDY_CLEARED); | ||||||
| 	drm_buddy_fini(&mm); | 	drm_buddy_fini(&mm); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Arunpravin Paneer Selvam
						Arunpravin Paneer Selvam