diff options
| author | Rebecca Mckeever <remckee0@gmail.com> | 2022-08-27 08:42:46 +0300 |
|---|---|---|
| committer | Mike Rapoport <rppt@linux.ibm.com> | 2022-08-30 13:12:00 +0300 |
| commit | 21a233f68afe55aafa8b79705c97f7a1d37be3e1 (patch) | |
| tree | c935caf32f9e6e542433405fb02782c91bd0da5f /tools/testing/memblock/tests/alloc_api.c | |
| parent | fb2e97fe853ff515df473d4acec6707816e05d87 (diff) | |
| download | linux-21a233f68afe55aafa8b79705c97f7a1d37be3e1.tar.xz | |
memblock tests: add additional tests for basic api and memblock_alloc
Add tests for memblock_add(), memblock_reserve(), memblock_remove(),
memblock_free(), and memblock_alloc() for the following test scenarios.
memblock_add() and memblock_reserve():
- add/reserve a memory block in the gap between two existing memory
blocks, and check that the blocks are merged into one region
- try to add/reserve memblock regions that extend past PHYS_ADDR_MAX
memblock_remove() and memblock_free():
- remove/free a region when it is the only available region
+ These tests ensure that the first region is overwritten with a
"dummy" region when the last remaining region of that type is
removed or freed.
- remove/free() a region that overlaps with two existing regions of the
relevant type
- try to remove/free memblock regions that extend past PHYS_ADDR_MAX
memblock_alloc():
- try to allocate a region that is larger than the total size of available
memory (memblock.memory)
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Shaoqin Huang <shaoqin.huang@intel.com>
Signed-off-by: Rebecca Mckeever <remckee0@gmail.com>
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Link: https://lore.kernel.org/r/c23c0393c5b9a53fe7f676996913c629495e9727.1661578349.git.remckee0@gmail.com
Diffstat (limited to 'tools/testing/memblock/tests/alloc_api.c')
| -rw-r--r-- | tools/testing/memblock/tests/alloc_api.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/testing/memblock/tests/alloc_api.c b/tools/testing/memblock/tests/alloc_api.c index de3405634f8a..e20e326d636f 100644 --- a/tools/testing/memblock/tests/alloc_api.c +++ b/tools/testing/memblock/tests/alloc_api.c @@ -470,6 +470,40 @@ static int alloc_no_memory_generic_check(void) } /* + * A test that tries to allocate a region that is larger than the total size of + * available memory (memblock.memory): + * + * +-----------------------------------+ + * | new | + * +-----------------------------------+ + * | | + * | | + * +---------------------------------+ + * + * Expect no allocation to happen. + */ +static int alloc_too_large_generic_check(void) +{ + struct memblock_region *rgn = &memblock.reserved.regions[0]; + void *allocated_ptr = NULL; + + PREFIX_PUSH(); + + setup_memblock(); + + allocated_ptr = memblock_alloc(MEM_SIZE + SZ_2, SMP_CACHE_BYTES); + + ASSERT_EQ(allocated_ptr, NULL); + ASSERT_EQ(rgn->size, 0); + ASSERT_EQ(rgn->base, 0); + ASSERT_EQ(memblock.reserved.total_size, 0); + + test_pass_pop(); + + return 0; +} + +/* * A simple test that tries to allocate a small memory region. * Expect to allocate an aligned region at the beginning of the available * memory. @@ -813,6 +847,15 @@ static int alloc_no_memory_check(void) return 0; } +static int alloc_too_large_check(void) +{ + test_print("\tRunning %s...\n", __func__); + run_top_down(alloc_too_large_generic_check); + run_bottom_up(alloc_too_large_generic_check); + + return 0; +} + int memblock_alloc_checks(void) { const char *func_testing = "memblock_alloc"; @@ -835,6 +878,7 @@ int memblock_alloc_checks(void) alloc_no_space_check(); alloc_limited_space_check(); alloc_no_memory_check(); + alloc_too_large_check(); dummy_physical_memory_cleanup(); |
