From: Karolina Drobnik Date: Mon, 28 Feb 2022 14:46:44 +0000 (+0100) Subject: memblock tests: Add simulation of physical memory X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=284d950dd6b0ea699608455e443341e82f9719c8;p=linux.git memblock tests: Add simulation of physical memory Allocation functions that return virtual addresses (with an exception of _raw variant) clear the allocated memory after reserving it. This requires valid memory ranges in memblock.memory. Introduce memory_block variable to store memory that can be registered with memblock data structure. Move assert.h and size.h includes to common.h to share them between the test files. Signed-off-by: Karolina Drobnik Signed-off-by: Mike Rapoport Link: https://lore.kernel.org/r/dce115503c74a6936c44694b00014658a1bb6522.1646055639.git.karolinadrobnik@gmail.com --- diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index d5035a3dcce88..fbc1ce1603037 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include #include -#include #include "basic_api.h" #define EXPECTED_MEMBLOCK_REGIONS 128 diff --git a/tools/testing/memblock/tests/basic_api.h b/tools/testing/memblock/tests/basic_api.h index 1ceecfca1f47c..1873faa54754b 100644 --- a/tools/testing/memblock/tests/basic_api.h +++ b/tools/testing/memblock/tests/basic_api.h @@ -2,7 +2,6 @@ #ifndef _MEMBLOCK_BASIC_H #define _MEMBLOCK_BASIC_H -#include #include "common.h" int memblock_basic_checks(void); diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c index dd7e87c589fe3..62d3191f7c9a5 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -5,6 +5,8 @@ #define INIT_MEMBLOCK_REGIONS 128 #define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS +static struct test_memory memory_block; + void reset_memblock_regions(void) { memset(memblock.memory.regions, 0, @@ -27,3 +29,20 @@ void reset_memblock_attributes(void) memblock.bottom_up = false; memblock.current_limit = MEMBLOCK_ALLOC_ANYWHERE; } + +void setup_memblock(void) +{ + reset_memblock_regions(); + memblock_add((phys_addr_t)memory_block.base, MEM_SIZE); +} + +void dummy_physical_memory_init(void) +{ + memory_block.base = malloc(MEM_SIZE); + assert(memory_block.base); +} + +void dummy_physical_memory_cleanup(void) +{ + free(memory_block.base); +} diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index b864c64fb60f5..619054d032196 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -2,8 +2,23 @@ #ifndef _MEMBLOCK_TEST_H #define _MEMBLOCK_TEST_H +#include +#include #include #include +#include + +#define MEM_SIZE SZ_16K + +/* + * Available memory registered with memblock needs to be valid for allocs + * test to run. This is a convenience wrapper for memory allocated in + * dummy_physical_memory_init() that is later registered with memblock + * in setup_memblock(). + */ +struct test_memory { + void *base; +}; struct region { phys_addr_t base; @@ -12,5 +27,8 @@ struct region { void reset_memblock_regions(void); void reset_memblock_attributes(void); +void setup_memblock(void); +void dummy_physical_memory_init(void); +void dummy_physical_memory_cleanup(void); #endif