[PATCH v2 0/8] memblock tests: update and extend memblock simulator

From: Rebecca Mckeever
Date: Fri Aug 19 2022 - 04:38:30 EST


These patches update existing tests in memblock simulator, add
additional tests for memblock functions that are already being tested,
and add test coverage for additional memblock functions.

Updated tests for:
- memblock_alloc()
- memblock_alloc_try_nid()
- memblock_alloc_from()

The updates to memblock_alloc() tests include the addition of an assert
that checks whether the entire chunk of allocated memory is cleared. For
memblock_alloc_try_nid() and memblock_alloc_from(), the assert that checks
whether the allocated memory is cleared now checks the entire chunk of
allocated memory instead of just the first byte. To make this more robust,
setup_memblock() and dummy_physical_memory_init() fill the entire MEM_SIZE
simulated physical memory with nonzero values by calling fill_memblock().
setup_memblock() is called at the beginning of most tests for
memblock_alloc() functions.

Additional tests for:
- memblock_add()
- memblock_reserve()
- memblock_remove()
- memblock_free()
- memblock_alloc()

Introducing test coverage for:
- memblock_alloc_raw()
- memblock_alloc_try_nid_raw()
- memblock_set_bottom_up()
- memblock_bottom_up()
- memblock_trim_memory()

The tests for the memblock_alloc_*raw() functions test both top-down and
bottom-up allocation directions. To add coverage for memblock_alloc_raw(),
the alloc_api was updated so that it runs through all the existing tests
twice: once for memblock_alloc() and once for memblock_alloc_raw(). When
the tests run memblock_alloc_raw(), they test that the entire memory
region is nonzero instead of testing that it is zero.

Similarly, the alloc_nid_api was updated to run through its tests twice:
once for memblock_alloc_try_nid() and once for
memblock_alloc_try_nid_raw(). When the tests run
memblock_alloc_try_nid_raw(), they test that the entire memory region is
nonzero instead of testing that it is zero.

The patch set also adds labels to verbose output for generic
memblock_alloc*() tests that indicate which allocation direction is set.
The function names of those tests do not include this information.

---
Changelog

v1 -> v2
Updates based on feedback from Shaoqin Huang:
PATCH 1:
- tests/alloc_api.c:
- Remove fill_memblock() from alloc_no_memory_generic_check().
- tests/common.c, tests/common.h:
- Change fill_memblock() to file static.
PATCH 3:
- Shaoqin Huang and I discussed using run_top_down() and run_bottom_up()
even for functions with `top_down` and `bottom_up` in the name to
maintain a consistent output style. However, this would make the
output more redundant, so no changes were made.
PATCH 4:
- tests/basic_api.c:
- Rename instances of r1_size and r2_size to
new_r1_size and new_r2_size.
PATCH 6:
- tests/alloc_api.c, tests/alloc_nid_api.c, tests/common.h:
- Change verify_mem_content() to a common function defined in
common.h.
PATCH 8:
- tests/basic_api.c:
- Rename instances of r2_base and r2_size to
new_r2_base and new_r2_size.
---

Rebecca Mckeever (8):
memblock tests: update tests to check if memblock_alloc zeroed memory
memblock tests: update zeroed memory check for memblock_alloc_* tests
memblock tests: add labels to verbose output for generic alloc tests
memblock tests: add additional tests for basic api and memblock_alloc
memblock tests: update alloc_api to test memblock_alloc_raw
memblock tests: update alloc_nid_api to test
memblock_alloc_try_nid_raw
memblock tests: add tests for memblock_*bottom_up functions
memblock tests: add tests for memblock_trim_memory

tools/testing/memblock/tests/alloc_api.c | 175 +++-
.../memblock/tests/alloc_helpers_api.c | 20 +-
tools/testing/memblock/tests/alloc_nid_api.c | 260 +++---
tools/testing/memblock/tests/basic_api.c | 767 ++++++++++++++++++
tools/testing/memblock/tests/common.c | 7 +
tools/testing/memblock/tests/common.h | 53 ++
6 files changed, 1095 insertions(+), 187 deletions(-)

--
2.25.1