diff mbox series

[v2,1/8] memblock tests: reserve the 129th memory block at all possible position

Message ID 20240425071929.18004-2-richard.weiyang@gmail.com (mailing list archive)
State New
Headers show
Series memblock: clenup | expand

Commit Message

Wei Yang April 25, 2024, 7:19 a.m. UTC
In stead of add 129th memory block at the last position, let's try all
possible position.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 tools/testing/memblock/tests/basic_api.c | 121 ++++++++++++-----------
 1 file changed, 65 insertions(+), 56 deletions(-)

Comments

Mike Rapoport April 28, 2024, 6:35 a.m. UTC | #1
On Thu, Apr 25, 2024 at 07:19:22AM +0000, Wei Yang wrote:
> In stead of add 129th memory block at the last position, let's try all
> possible position.

Why do you insist on changing the existing test rather than adding a new
one?
 
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> ---
>  tools/testing/memblock/tests/basic_api.c | 121 ++++++++++++-----------
>  1 file changed, 65 insertions(+), 56 deletions(-)
Wei Yang April 28, 2024, 12:22 p.m. UTC | #2
On Sun, Apr 28, 2024 at 09:35:25AM +0300, Mike Rapoport wrote:
>On Thu, Apr 25, 2024 at 07:19:22AM +0000, Wei Yang wrote:
>> In stead of add 129th memory block at the last position, let's try all
>> possible position.
>
>Why do you insist on changing the existing test rather than adding a new
>one?
> 

Sounds there is some misunderstanding between us.

I am not sure about your idea at first, so I sent a draft to confirm with you.
Then I came up with another version which could trigger the overlap bug.

You mentioned to keep both and not objection to the first draft, which is the
same as this one, I thought this is what you expect.

Well, I will add a new one next round. Do you have some suggestion on the
function name? memblock_reserve_many_all_position_check ?

>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> ---
>>  tools/testing/memblock/tests/basic_api.c | 121 ++++++++++++-----------
>>  1 file changed, 65 insertions(+), 56 deletions(-)
> 
>
>-- 
>Sincerely yours,
>Mike.
Mike Rapoport April 29, 2024, 2:17 p.m. UTC | #3
On Sun, Apr 28, 2024 at 12:22:04PM +0000, Wei Yang wrote:
> On Sun, Apr 28, 2024 at 09:35:25AM +0300, Mike Rapoport wrote:
> >On Thu, Apr 25, 2024 at 07:19:22AM +0000, Wei Yang wrote:
> >> In stead of add 129th memory block at the last position, let's try all
> >> possible position.
> >
> >Why do you insist on changing the existing test rather than adding a new
> >one?
> > 
> 
> Sounds there is some misunderstanding between us.
> 
> I am not sure about your idea at first, so I sent a draft to confirm with you.
> Then I came up with another version which could trigger the overlap bug.
> 
> You mentioned to keep both and not objection to the first draft, which is the
> same as this one, I thought this is what you expect.

Sorry if I wasn't clear. My intention was to keep the existing test and add
a new one rather than update the old test.
 
> Well, I will add a new one next round. Do you have some suggestion on the
> function name? memblock_reserve_many_all_position_check ?

How about memblock_reserve_all_locations_check?
 
> >> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> >> ---
> >>  tools/testing/memblock/tests/basic_api.c | 121 ++++++++++++-----------
> >>  1 file changed, 65 insertions(+), 56 deletions(-)
> > 
> >
> >-- 
> >Sincerely yours,
> >Mike.
> 
> -- 
> Wei Yang
> Help you, Help me
Wei Yang April 30, 2024, 12:12 a.m. UTC | #4
On Mon, Apr 29, 2024 at 05:17:19PM +0300, Mike Rapoport wrote:
>On Sun, Apr 28, 2024 at 12:22:04PM +0000, Wei Yang wrote:
>> On Sun, Apr 28, 2024 at 09:35:25AM +0300, Mike Rapoport wrote:
>> >On Thu, Apr 25, 2024 at 07:19:22AM +0000, Wei Yang wrote:
>> >> In stead of add 129th memory block at the last position, let's try all
>> >> possible position.
>> >
>> >Why do you insist on changing the existing test rather than adding a new
>> >one?
>> > 
>> 
>> Sounds there is some misunderstanding between us.
>> 
>> I am not sure about your idea at first, so I sent a draft to confirm with you.
>> Then I came up with another version which could trigger the overlap bug.
>> 
>> You mentioned to keep both and not objection to the first draft, which is the
>> same as this one, I thought this is what you expect.
>
>Sorry if I wasn't clear. My intention was to keep the existing test and add
>a new one rather than update the old test.
> 

You are so kind. Nice to work with you. 

>> Well, I will add a new one next round. Do you have some suggestion on the
>> function name? memblock_reserve_many_all_position_check ?
>
>How about memblock_reserve_all_locations_check?
> 

Yep, sounds good :-)

>> >> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> >> ---
>> >>  tools/testing/memblock/tests/basic_api.c | 121 ++++++++++++-----------
>> >>  1 file changed, 65 insertions(+), 56 deletions(-)
>> > 
>> >
>> >-- 
>> >Sincerely yours,
>> >Mike.
>> 
>> -- 
>> Wei Yang
>> Help you, Help me
>
>-- 
>Sincerely yours,
>Mike.
diff mbox series

Patch

diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c
index f317fe691fc4..1ae62272867a 100644
--- a/tools/testing/memblock/tests/basic_api.c
+++ b/tools/testing/memblock/tests/basic_api.c
@@ -898,84 +898,93 @@  static int memblock_reserve_near_max_check(void)
  * memblock.memory.max, find a new valid memory as
  * reserved.regions.
  */
+/* Keep the gap so these memory region will not be merged. */
+#define MEMORY_BASE(idx) (SZ_128K + (MEM_SIZE * 2) * (idx))
 static int memblock_reserve_many_check(void)
 {
-	int i;
+	int i, skip;
 	void *orig_region;
 	struct region r = {
 		.base = SZ_16K,
 		.size = SZ_16K,
 	};
-	phys_addr_t memory_base = SZ_128K;
 	phys_addr_t new_reserved_regions_size;
 
 	PREFIX_PUSH();
 
-	reset_memblock_regions();
-	memblock_allow_resize();
+	/* Reserve the 129th memory block for all possible positions*/
+	for (skip = 0; skip < INIT_MEMBLOCK_REGIONS + 1; skip++) {
+		reset_memblock_regions();
+		memblock_allow_resize();
 
-	/* Add a valid memory region used by double_array(). */
-	dummy_physical_memory_init();
-	memblock_add(dummy_physical_memory_base(), MEM_SIZE);
+		/* Add a valid memory region used by double_array(). */
+		dummy_physical_memory_init();
+		memblock_add(dummy_physical_memory_base(), MEM_SIZE);
 
-	for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) {
-		/* Reserve some fakes memory region to fulfill the memblock. */
-		memblock_reserve(memory_base, MEM_SIZE);
+		for (i = 0; i < INIT_MEMBLOCK_REGIONS + 1; i++) {
+			if (i == skip)
+				continue;
 
-		ASSERT_EQ(memblock.reserved.cnt, i + 1);
-		ASSERT_EQ(memblock.reserved.total_size, (i + 1) * MEM_SIZE);
+			/* Reserve some fakes memory region to fulfill the memblock. */
+			memblock_reserve(MEMORY_BASE(i), MEM_SIZE);
 
-		/* Keep the gap so these memory region will not be merged. */
-		memory_base += MEM_SIZE * 2;
-	}
+			if (i < skip) {
+				ASSERT_EQ(memblock.reserved.cnt, i + 1);
+				ASSERT_EQ(memblock.reserved.total_size, (i + 1) * MEM_SIZE);
+			} else {
+				ASSERT_EQ(memblock.reserved.cnt, i);
+				ASSERT_EQ(memblock.reserved.total_size, i * MEM_SIZE);
+			}
+		}
 
-	orig_region = memblock.reserved.regions;
+		orig_region = memblock.reserved.regions;
 
-	/* This reserve the 129 memory_region, and makes it double array. */
-	memblock_reserve(memory_base, MEM_SIZE);
+		/* This reserve the 129 memory_region, and makes it double array. */
+		memblock_reserve(MEMORY_BASE(skip), MEM_SIZE);
 
-	/*
-	 * This is the memory region size used by the doubled reserved.regions,
-	 * and it has been reserved due to it has been used. The size is used to
-	 * calculate the total_size that the memblock.reserved have now.
-	 */
-	new_reserved_regions_size = PAGE_ALIGN((INIT_MEMBLOCK_REGIONS * 2) *
-					sizeof(struct memblock_region));
-	/*
-	 * The double_array() will find a free memory region as the new
-	 * reserved.regions, and the used memory region will be reserved, so
-	 * there will be one more region exist in the reserved memblock. And the
-	 * one more reserved region's size is new_reserved_regions_size.
-	 */
-	ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 2);
-	ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
-						new_reserved_regions_size);
-	ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
+		/*
+		 * This is the memory region size used by the doubled reserved.regions,
+		 * and it has been reserved due to it has been used. The size is used to
+		 * calculate the total_size that the memblock.reserved have now.
+		 */
+		new_reserved_regions_size = PAGE_ALIGN((INIT_MEMBLOCK_REGIONS * 2) *
+						sizeof(struct memblock_region));
+		/*
+		 * The double_array() will find a free memory region as the new
+		 * reserved.regions, and the used memory region will be reserved, so
+		 * there will be one more region exist in the reserved memblock. And the
+		 * one more reserved region's size is new_reserved_regions_size.
+		 */
+		ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 2);
+		ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
+							new_reserved_regions_size);
+		ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
 
-	/*
-	 * Now memblock_double_array() works fine. Let's check after the
-	 * double_array(), the memblock_reserve() still works as normal.
-	 */
-	memblock_reserve(r.base, r.size);
-	ASSERT_EQ(memblock.reserved.regions[0].base, r.base);
-	ASSERT_EQ(memblock.reserved.regions[0].size, r.size);
+		/*
+		 * Now memblock_double_array() works fine. Let's check after the
+		 * double_array(), the memblock_reserve() still works as normal.
+		 */
+		memblock_reserve(r.base, r.size);
+		ASSERT_EQ(memblock.reserved.regions[0].base, r.base);
+		ASSERT_EQ(memblock.reserved.regions[0].size, r.size);
 
-	ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 3);
-	ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
-						new_reserved_regions_size +
-						r.size);
-	ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
+		ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 3);
+		ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
+							new_reserved_regions_size +
+							r.size);
+		ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
 
-	dummy_physical_memory_cleanup();
+		dummy_physical_memory_cleanup();
 
-	/*
-	 * The current reserved.regions is occupying a range of memory that
-	 * allocated from dummy_physical_memory_init(). After free the memory,
-	 * we must not use it. So restore the origin memory region to make sure
-	 * the tests can run as normal and not affected by the double array.
-	 */
-	memblock.reserved.regions = orig_region;
-	memblock.reserved.cnt = INIT_MEMBLOCK_RESERVED_REGIONS;
+		/*
+		 * The current reserved.regions is occupying a range of memory that
+		 * allocated from dummy_physical_memory_init(). After free the memory,
+		 * we must not use it. So restore the origin memory region to make sure
+		 * the tests can run as normal and not affected by the double array.
+		 */
+		memblock.reserved.regions = orig_region;
+		memblock.reserved.cnt = INIT_MEMBLOCK_RESERVED_REGIONS;
+	}
 
 	test_pass_pop();