[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <YxdEB+5f1wvbfjdY@kernel.org>
Date: Tue, 6 Sep 2022 15:58:47 +0300
From: Mike Rapoport <rppt@...nel.org>
To: Song Chen <chensong_2000@....cn>
Cc: karolinadrobnik@...il.com, david@...hat.com, remckee0@...il.com,
shaoqin.huang@...el.com, linux-kernel@...r.kernel.org,
linux-mm@...ck.org
Subject: Re: [PATCH] tools/testing/memblock: add double array test
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@....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.
Powered by blists - more mailing lists