All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Song Chen <chensong_2000@189.cn>
Cc: karolinadrobnik@gmail.com, david@redhat.com, remckee0@gmail.com,
	shaoqin.huang@intel.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH] tools/testing/memblock: add double array test
Date: Tue, 6 Sep 2022 15:58:47 +0300	[thread overview]
Message-ID: <YxdEB+5f1wvbfjdY@kernel.org> (raw)
In-Reply-To: <1662102645-8272-1-git-send-email-chensong_2000@189.cn>

Hi Song,

On Fri, Sep 02, 2022 at 03:10:45PM +0800, Song Chen wrote:
> By default, there are 128 memblock_regions in memblock.memory.regions.
> This test is trying to add the 129th region by calling memblock_add,
> expects to trigger memblock_double_array.
> 
> The test will pass if
>     memblock.memory.cnt == 129 and
>     memblock.memory.max == 256
> 
> Below is the output:
> 
> ./main -v
> Running memblock_double_array tests...
> memblock_add: [0x7fffdccdf0a0a-0x7fffdccdf080a] 0x5616cca50dc4S
> .....
> memblock_add: [0x7fffdccdf0a0a-0x7fffdccdf080a] 0x5616cca50de4S
> memblock: memory is doubled to 256 at [0x7fffdccdeeb0a-0x7fffdccdeed0a]
> ok 25 : memblock_double_array: passed

Your patch largely duplicates work by Shaoqin:

https://lore.kernel.org/all/20220902024007.58041-1-shaoqin.huang@intel.com

> Signed-off-by: Song Chen <chensong_2000@189.cn>
> ---
>  tools/testing/memblock/tests/basic_api.c | 42 ++++++++++++++++++++++++
>  tools/testing/memblock/tests/common.c    |  5 ---
>  tools/testing/memblock/tests/common.h    |  4 +++
>  3 files changed, 46 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c
> index 66f46f261e66..e668ceff2f10 100644
> --- a/tools/testing/memblock/tests/basic_api.c
> +++ b/tools/testing/memblock/tests/basic_api.c
> @@ -8,6 +8,7 @@
>  #define FUNC_RESERVE					"memblock_reserve"
>  #define FUNC_REMOVE					"memblock_remove"
>  #define FUNC_FREE					"memblock_free"
> +#define FUNC_DOUBLE_ARRAY			"memblock_double_array"
>  
>  static int memblock_initialization_check(void)
>  {
> @@ -1180,6 +1181,46 @@ static int memblock_free_checks(void)
>  	return 0;
>  }
>  
> +/*
> + * A simple test that adds to 129 memory blocks.
> + * Expect the region max doubled.
> + */
> +static int memblock_double_array_check(void)
> +{
> +	int i;
> +	struct memblock_region *regions = memblock.memory.regions;
> +	struct region r = {
> +		.base = 0,
> +		.size = SZ_512,
> +	};
> +
> +	prefix_reset();
> +	prefix_push(FUNC_DOUBLE_ARRAY);
> +	test_print("Running %s tests...\n", FUNC_DOUBLE_ARRAY);
> +
> +	dummy_physical_memory_init();
> +	reset_memblock_attributes();
> +	setup_memblock();
> +	memblock_allow_resize();
> +
> +	for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) {
> +		r.base += SZ_1K;
> +		memblock_add(r.base, r.size);
> +	}
> +
> +	ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 1);
> +	ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2);
> +
> +	memblock.memory.regions = regions;
> +	memblock.memory.cnt = INIT_MEMBLOCK_REGIONS;
> +	dummy_physical_memory_cleanup();
> +
> +	test_pass_pop();
> +
> +	return 0;
> +}
> +
> +
>  int memblock_basic_checks(void)
>  {
>  	memblock_initialization_check();
> @@ -1187,6 +1228,7 @@ int memblock_basic_checks(void)
>  	memblock_reserve_checks();
>  	memblock_remove_checks();
>  	memblock_free_checks();
> +	memblock_double_array_check();
>  
>  	return 0;
>  }
> diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c
> index e43b2676af81..1d295a71ad44 100644
> --- a/tools/testing/memblock/tests/common.c
> +++ b/tools/testing/memblock/tests/common.c
> @@ -5,11 +5,6 @@
>  #include <linux/memory_hotplug.h>
>  #include <linux/build_bug.h>
>  
> -#define INIT_MEMBLOCK_REGIONS			128
> -#define INIT_MEMBLOCK_RESERVED_REGIONS		INIT_MEMBLOCK_REGIONS
> -#define PREFIXES_MAX				15
> -#define DELIM					": "
> -
>  static struct test_memory memory_block;
>  static const char __maybe_unused *prefixes[PREFIXES_MAX];
>  static int __maybe_unused nr_prefixes;
> diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h
> index 3e7f23d341d7..13559825ddca 100644
> --- a/tools/testing/memblock/tests/common.h
> +++ b/tools/testing/memblock/tests/common.h
> @@ -11,6 +11,10 @@
>  #include <../selftests/kselftest.h>
>  
>  #define MEM_SIZE SZ_16K
> +#define INIT_MEMBLOCK_REGIONS			128
> +#define INIT_MEMBLOCK_RESERVED_REGIONS		INIT_MEMBLOCK_REGIONS
> +#define PREFIXES_MAX				15
> +#define DELIM					": "
>  
>  /**
>   * ASSERT_EQ():
> -- 
> 2.25.1
> 
> 

-- 
Sincerely yours,
Mike.


      reply	other threads:[~2022-09-06 12:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-02  7:10 [PATCH] tools/testing/memblock: add double array test Song Chen
2022-09-06 12:58 ` Mike Rapoport [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YxdEB+5f1wvbfjdY@kernel.org \
    --to=rppt@kernel.org \
    --cc=chensong_2000@189.cn \
    --cc=david@redhat.com \
    --cc=karolinadrobnik@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=remckee0@gmail.com \
    --cc=shaoqin.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.