Re: [PATCH v2 1/8] memblock tests: update tests to check if memblock_alloc zeroed memory

From: Mike Rapoport
Date: Tue Aug 23 2022 - 12:56:31 EST


On Fri, Aug 19, 2022 at 01:34:49AM -0700, Rebecca Mckeever wrote:
> Add an assert in memblock_alloc() tests where allocation is expected to
> occur. The assert checks whether the entire chunk of allocated memory is
> cleared.
>
> The current memblock_alloc() tests do not check whether the allocated
> memory was zeroed. memblock_alloc() should zero the allocated memory since
> it is a wrapper for memblock_alloc_try_nid().
>
> Reviewed-by: Shaoqin Huang <shaoqin.huang@xxxxxxxxx>
> Signed-off-by: Rebecca Mckeever <remckee0@xxxxxxxxx>
> ---
> tools/testing/memblock/tests/alloc_api.c | 23 +++++++++++++++++++++++
> tools/testing/memblock/tests/common.c | 7 +++++++
> tools/testing/memblock/tests/common.h | 12 ++++++++++++
> 3 files changed, 42 insertions(+)
>
> diff --git a/tools/testing/memblock/tests/alloc_api.c b/tools/testing/memblock/tests/alloc_api.c
> index a14f38eb8a89..aefb67557de9 100644
> --- a/tools/testing/memblock/tests/alloc_api.c
> +++ b/tools/testing/memblock/tests/alloc_api.c
> @@ -22,6 +22,8 @@ static int alloc_top_down_simple_check(void)
> allocated_ptr = memblock_alloc(size, SMP_CACHE_BYTES);
>
> ASSERT_NE(allocated_ptr, NULL);
> + ASSERT_MEM_EQ((char *)allocated_ptr, 0, size);
> +

Can we please hide the casting inside ASSERT_MEM_EQ()?

Like if ASSERT_MEM_EQ() were a function its declaration would be

bool ASSERT_MEM_EQ(void *mem, char val, size_t size);

> ASSERT_EQ(rgn->size, size);
> ASSERT_EQ(rgn->base, expected_start);
>

--
Sincerely yours,
Mike.