[PATCH] memblock_tests: move variable declarations to single block

From: Rebecca Mckeever
Date: Sun Sep 04 2022 - 00:24:23 EST


Move variable declarations to a single block at the beginning of each
testing function.

Signed-off-by: Rebecca Mckeever <remckee0@xxxxxxxxx>
---
tools/testing/memblock/tests/alloc_api.c | 57 ++++---------
.../memblock/tests/alloc_helpers_api.c | 32 ++------
tools/testing/memblock/tests/alloc_nid_api.c | 80 +++++--------------
3 files changed, 42 insertions(+), 127 deletions(-)

diff --git a/tools/testing/memblock/tests/alloc_api.c b/tools/testing/memblock/tests/alloc_api.c
index 36dd7e254cce..68f1a75cd72c 100644
--- a/tools/testing/memblock/tests/alloc_api.c
+++ b/tools/testing/memblock/tests/alloc_api.c
@@ -25,12 +25,10 @@ static int alloc_top_down_simple_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_2;
phys_addr_t expected_start;

+ PREFIX_PUSH();
setup_memblock();

expected_start = memblock_end_of_DRAM() - SMP_CACHE_BYTES;
@@ -76,15 +74,13 @@ static int alloc_top_down_disjoint_check(void)
struct memblock_region *rgn2 = &memblock.reserved.regions[0];
struct region r1;
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r2_size = SZ_16;
/* Use custom alignment */
phys_addr_t alignment = SMP_CACHE_BYTES * 2;
phys_addr_t total_size;
phys_addr_t expected_start;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_end_of_DRAM() - SZ_2;
@@ -128,9 +124,6 @@ static int alloc_top_down_before_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
/*
* The first region ends at the aligned address to test region merging
*/
@@ -138,6 +131,7 @@ static int alloc_top_down_before_check(void)
phys_addr_t r2_size = SZ_512;
phys_addr_t total_size = r1_size + r2_size;

+ PREFIX_PUSH();
setup_memblock();

memblock_reserve(memblock_end_of_DRAM() - total_size, r1_size);
@@ -174,12 +168,10 @@ static int alloc_top_down_after_check(void)
struct memblock_region *rgn = &memblock.reserved.regions[0];
struct region r1;
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r2_size = SZ_512;
phys_addr_t total_size;

+ PREFIX_PUSH();
setup_memblock();

/*
@@ -225,12 +217,10 @@ static int alloc_top_down_second_fit_check(void)
struct memblock_region *rgn = &memblock.reserved.regions[0];
struct region r1, r2;
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r3_size = SZ_1K;
phys_addr_t total_size;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_end_of_DRAM() - SZ_512;
@@ -276,9 +266,6 @@ static int alloc_in_between_generic_check(void)
struct memblock_region *rgn = &memblock.reserved.regions[0];
struct region r1, r2;
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t gap_size = SMP_CACHE_BYTES;
phys_addr_t r3_size = SZ_64;
/*
@@ -287,6 +274,7 @@ static int alloc_in_between_generic_check(void)
phys_addr_t rgn_size = (MEM_SIZE - (2 * gap_size + r3_size)) / 2;
phys_addr_t total_size;

+ PREFIX_PUSH();
setup_memblock();

r1.size = rgn_size;
@@ -332,13 +320,11 @@ static int alloc_in_between_generic_check(void)
static int alloc_small_gaps_generic_check(void)
{
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t region_size = SZ_1K;
phys_addr_t gap_size = SZ_256;
phys_addr_t region_end;

+ PREFIX_PUSH();
setup_memblock();

region_end = memblock_start_of_DRAM();
@@ -366,7 +352,6 @@ static int alloc_all_reserved_generic_check(void)
void *allocated_ptr = NULL;

PREFIX_PUSH();
-
setup_memblock();

/* Simulate full memory */
@@ -397,14 +382,12 @@ static int alloc_all_reserved_generic_check(void)
static int alloc_no_space_generic_check(void)
{
void *allocated_ptr = NULL;
+ phys_addr_t available_size = SZ_256;
+ phys_addr_t reserved_size = MEM_SIZE - available_size;

PREFIX_PUSH();
-
setup_memblock();

- phys_addr_t available_size = SZ_256;
- phys_addr_t reserved_size = MEM_SIZE - available_size;
-
/* Simulate almost-full memory */
memblock_reserve(memblock_start_of_DRAM(), reserved_size);

@@ -432,12 +415,10 @@ static int alloc_limited_space_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t available_size = SZ_256;
phys_addr_t reserved_size = MEM_SIZE - available_size;

+ PREFIX_PUSH();
setup_memblock();

/* Simulate almost-full memory */
@@ -504,7 +485,6 @@ static int alloc_too_large_generic_check(void)
void *allocated_ptr = NULL;

PREFIX_PUSH();
-
setup_memblock();

allocated_ptr = run_memblock_alloc(MEM_SIZE + SZ_2, SMP_CACHE_BYTES);
@@ -530,7 +510,6 @@ static int alloc_bottom_up_simple_check(void)
void *allocated_ptr = NULL;

PREFIX_PUSH();
-
setup_memblock();

allocated_ptr = run_memblock_alloc(SZ_2, SMP_CACHE_BYTES);
@@ -572,15 +551,13 @@ static int alloc_bottom_up_disjoint_check(void)
struct memblock_region *rgn2 = &memblock.reserved.regions[1];
struct region r1;
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r2_size = SZ_16;
/* Use custom alignment */
phys_addr_t alignment = SMP_CACHE_BYTES * 2;
phys_addr_t total_size;
phys_addr_t expected_start;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_start_of_DRAM() + SZ_2;
@@ -624,13 +601,11 @@ static int alloc_bottom_up_before_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r1_size = SZ_512;
phys_addr_t r2_size = SZ_128;
phys_addr_t total_size = r1_size + r2_size;

+ PREFIX_PUSH();
setup_memblock();

memblock_reserve(memblock_start_of_DRAM() + r1_size, r2_size);
@@ -666,12 +641,10 @@ static int alloc_bottom_up_after_check(void)
struct memblock_region *rgn = &memblock.reserved.regions[0];
struct region r1;
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r2_size = SZ_512;
phys_addr_t total_size;

+ PREFIX_PUSH();
setup_memblock();

/*
@@ -718,12 +691,10 @@ static int alloc_bottom_up_second_fit_check(void)
struct memblock_region *rgn = &memblock.reserved.regions[1];
struct region r1, r2;
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r3_size = SZ_1K;
phys_addr_t total_size;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_start_of_DRAM();
diff --git a/tools/testing/memblock/tests/alloc_helpers_api.c b/tools/testing/memblock/tests/alloc_helpers_api.c
index 06577bd0e349..3ef9486da8a0 100644
--- a/tools/testing/memblock/tests/alloc_helpers_api.c
+++ b/tools/testing/memblock/tests/alloc_helpers_api.c
@@ -19,12 +19,10 @@ static int alloc_from_simple_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_16;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_end_of_DRAM() - SMP_CACHE_BYTES;
@@ -64,12 +62,10 @@ static int alloc_from_misaligned_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_32;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

/* A misaligned address */
@@ -113,12 +109,10 @@ static int alloc_from_top_down_high_addr_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_32;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

/* The address is too close to the end of the memory */
@@ -158,14 +152,12 @@ static int alloc_from_top_down_no_space_above_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r1_size = SZ_64;
phys_addr_t r2_size = SZ_2;
phys_addr_t total_size = r1_size + r2_size;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_end_of_DRAM() - SMP_CACHE_BYTES * 2;
@@ -197,13 +189,11 @@ static int alloc_from_top_down_min_addr_cap_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r1_size = SZ_64;
phys_addr_t min_addr;
phys_addr_t start_addr;

+ PREFIX_PUSH();
setup_memblock();

start_addr = (phys_addr_t)memblock_start_of_DRAM();
@@ -245,12 +235,10 @@ static int alloc_from_bottom_up_high_addr_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_32;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

/* The address is too close to the end of the memory */
@@ -289,13 +277,11 @@ static int alloc_from_bottom_up_no_space_above_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r1_size = SZ_64;
phys_addr_t min_addr;
phys_addr_t r2_size;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() + SZ_128;
@@ -327,13 +313,11 @@ static int alloc_from_bottom_up_min_addr_cap_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r1_size = SZ_64;
phys_addr_t min_addr;
phys_addr_t start_addr;

+ PREFIX_PUSH();
setup_memblock();

start_addr = (phys_addr_t)memblock_start_of_DRAM();
diff --git a/tools/testing/memblock/tests/alloc_nid_api.c b/tools/testing/memblock/tests/alloc_nid_api.c
index 77f83f31c835..5789379ad9da 100644
--- a/tools/testing/memblock/tests/alloc_nid_api.c
+++ b/tools/testing/memblock/tests/alloc_nid_api.c
@@ -47,14 +47,12 @@ static int alloc_try_nid_top_down_simple_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_128;
phys_addr_t min_addr;
phys_addr_t max_addr;
phys_addr_t rgn_end;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
@@ -101,15 +99,13 @@ static int alloc_try_nid_top_down_end_misaligned_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_128;
phys_addr_t misalign = SZ_2;
phys_addr_t min_addr;
phys_addr_t max_addr;
phys_addr_t rgn_end;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
@@ -154,14 +150,12 @@ static int alloc_try_nid_exact_address_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_1K;
phys_addr_t min_addr;
phys_addr_t max_addr;
phys_addr_t rgn_end;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES;
@@ -208,13 +202,11 @@ static int alloc_try_nid_top_down_narrow_range_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_256;
phys_addr_t min_addr;
phys_addr_t max_addr;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() + SZ_512;
@@ -261,13 +253,11 @@ static int alloc_try_nid_top_down_narrow_range_check(void)
static int alloc_try_nid_low_max_generic_check(void)
{
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_1K;
phys_addr_t min_addr;
phys_addr_t max_addr;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM();
@@ -302,9 +292,6 @@ static int alloc_try_nid_min_reserved_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r1_size = SZ_128;
phys_addr_t r2_size = SZ_64;
phys_addr_t total_size = r1_size + r2_size;
@@ -312,6 +299,7 @@ static int alloc_try_nid_min_reserved_generic_check(void)
phys_addr_t max_addr;
phys_addr_t reserved_base;

+ PREFIX_PUSH();
setup_memblock();

max_addr = memblock_end_of_DRAM();
@@ -356,15 +344,13 @@ static int alloc_try_nid_max_reserved_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t r1_size = SZ_64;
phys_addr_t r2_size = SZ_128;
phys_addr_t total_size = r1_size + r2_size;
phys_addr_t min_addr;
phys_addr_t max_addr;

+ PREFIX_PUSH();
setup_memblock();

max_addr = memblock_end_of_DRAM() - r1_size;
@@ -413,15 +399,13 @@ static int alloc_try_nid_top_down_reserved_with_space_check(void)
struct memblock_region *rgn2 = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
struct region r1, r2;
-
- PREFIX_PUSH();
-
phys_addr_t r3_size = SZ_64;
phys_addr_t gap_size = SMP_CACHE_BYTES;
phys_addr_t total_size;
phys_addr_t max_addr;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_end_of_DRAM() - SMP_CACHE_BYTES * 2;
@@ -479,14 +463,12 @@ static int alloc_try_nid_reserved_full_merge_generic_check(void)
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
struct region r1, r2;
-
- PREFIX_PUSH();
-
phys_addr_t r3_size = SZ_64;
phys_addr_t total_size;
phys_addr_t max_addr;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_end_of_DRAM() - SMP_CACHE_BYTES * 2;
@@ -544,15 +526,13 @@ static int alloc_try_nid_top_down_reserved_no_space_check(void)
struct memblock_region *rgn2 = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
struct region r1, r2;
-
- PREFIX_PUSH();
-
phys_addr_t r3_size = SZ_256;
phys_addr_t gap_size = SMP_CACHE_BYTES;
phys_addr_t total_size;
phys_addr_t max_addr;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_end_of_DRAM() - SMP_CACHE_BYTES * 2;
@@ -613,14 +593,12 @@ static int alloc_try_nid_reserved_all_generic_check(void)
{
void *allocated_ptr = NULL;
struct region r1, r2;
-
- PREFIX_PUSH();
-
phys_addr_t r3_size = SZ_256;
phys_addr_t gap_size = SMP_CACHE_BYTES;
phys_addr_t max_addr;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_end_of_DRAM() - SMP_CACHE_BYTES;
@@ -655,13 +633,11 @@ static int alloc_try_nid_top_down_cap_max_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_256;
phys_addr_t min_addr;
phys_addr_t max_addr;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_end_of_DRAM() - SZ_1K;
@@ -694,13 +670,11 @@ static int alloc_try_nid_top_down_cap_min_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_1K;
phys_addr_t min_addr;
phys_addr_t max_addr;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() - SZ_256;
@@ -742,14 +716,12 @@ static int alloc_try_nid_bottom_up_simple_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_128;
phys_addr_t min_addr;
phys_addr_t max_addr;
phys_addr_t rgn_end;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
@@ -796,15 +768,13 @@ static int alloc_try_nid_bottom_up_start_misaligned_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_128;
phys_addr_t misalign = SZ_2;
phys_addr_t min_addr;
phys_addr_t max_addr;
phys_addr_t rgn_end;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() + misalign;
@@ -851,13 +821,11 @@ static int alloc_try_nid_bottom_up_narrow_range_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_256;
phys_addr_t min_addr;
phys_addr_t max_addr;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() + SZ_512;
@@ -904,15 +872,13 @@ static int alloc_try_nid_bottom_up_reserved_with_space_check(void)
struct memblock_region *rgn2 = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
struct region r1, r2;
-
- PREFIX_PUSH();
-
phys_addr_t r3_size = SZ_64;
phys_addr_t gap_size = SMP_CACHE_BYTES;
phys_addr_t total_size;
phys_addr_t max_addr;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_end_of_DRAM() - SMP_CACHE_BYTES * 2;
@@ -976,15 +942,13 @@ static int alloc_try_nid_bottom_up_reserved_no_space_check(void)
struct memblock_region *rgn3 = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
struct region r1, r2;
-
- PREFIX_PUSH();
-
phys_addr_t r3_size = SZ_256;
phys_addr_t gap_size = SMP_CACHE_BYTES;
phys_addr_t total_size;
phys_addr_t max_addr;
phys_addr_t min_addr;

+ PREFIX_PUSH();
setup_memblock();

r1.base = memblock_end_of_DRAM() - SMP_CACHE_BYTES * 2;
@@ -1033,13 +997,11 @@ static int alloc_try_nid_bottom_up_cap_max_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_256;
phys_addr_t min_addr;
phys_addr_t max_addr;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM() + SZ_1K;
@@ -1072,13 +1034,11 @@ static int alloc_try_nid_bottom_up_cap_min_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
-
- PREFIX_PUSH();
-
phys_addr_t size = SZ_1K;
phys_addr_t min_addr;
phys_addr_t max_addr;

+ PREFIX_PUSH();
setup_memblock();

min_addr = memblock_start_of_DRAM();
--
2.25.1