memblock tests: add VERBOSE and MEMBLOCK_DEBUG Makefile options
Mike Rapoport
maintainerRe: [PATCH v3 2/4] memblock tests: add verbose output to memblock tests
In reply to Rebecca MckeeverQuoted 53 lines · Rebecca Mckeever
Quoted 52 lines · Mike Rapoport
Quoted 51 lines · Rebecca Mckeever
Quoted 29 lines · Mike Rapoport
Quoted 20 lines · Shaoqin
Quoted 11 lines · Rebecca Mckeever
Quoted 10 lines · Shaoqin
Just test it and everything works fine. And I think there are some thing can improve:
The
prefix_push()andprefix_pop()are used in so many functions and
almost of them just put theprefix_push(__func__)begin in the head and theprefix_pop()in the end.
May be you can define some macro that when you output something and
automatically push the__func__as prefix. And when leave the function, automatically pop it. And only in some special place, you call it manually.Quoted 5 lines
Thank you for your review. I'm not sure how you would automatically push
__func__since you have to be inside the function to access that variable. Let me know if you have any suggestions. I am thinking about adding another function incommon.cthat just callstest_pass()followed byprefix_pop()since those are called together so often.Quoted 7 lines
Just like:
#define test_pass_macro() \ do { \ prefix_push(__func__); \ test_pass(); \ prefix_pop(); \ } while (0)Quoted 8 lines
This will not print the name of the failing test, e.g. instead of
not ok 28 :
memblock_alloc:alloc_bottom_up_disjoint_check: failedwith Rebecca's implementation it'll print
not ok 28 :
memblock_alloc: failedOh yeah,
prefix_push()needs to be called before the asserts.Quoted 4 lines
How about
#define
PREFIX_PUSH()prefix_push(__func__)?Good idea. What about
#define TEST_PASS() do { \ test_pass(); \ prefix_pop(); \ } while (0)
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
? Or would it be better to make a function?
static inline function would be better.
Would there be any advantage to defining a different version for each side of #ifdef VERBOSE?
No, a single version will do. For !VERBOSE builds it will be optimized out anyway.
Quoted 3 lines
Thanks,
Rebecca
Signature · 2 lines
Sincerely yours, Mike.
Mike Rapoport
maintainerRe: [PATCH v3 2/4] memblock tests: add verbose output to memblock tests
In reply to Rebecca MckeeverQuoted 53 lines · Rebecca Mckeever
Quoted 52 lines · Mike Rapoport
Quoted 34 lines · Rebecca Mckeever
Add and use functions for printing verbose testing output.
If the Memblock simulator was compiled with VERBOSE=1:
prefix_push()appends the given string to a prefix string that will be
printed in the test functions.
prefix_pop()removes the last prefix from the prefix string.prefix_reset()clears the prefix string.
test_fail()prints a message after a test fails containing the test
number of the failing test and the prefix.
test_pass()prints a message after a test passes containing its test
number and the prefix.
test_print()prints the given formatted output string.If the Memblock simulator was not compiled with VERBOSE=1, these functions do nothing.
Add the assert wrapper macros
ASSERT_EQ(),ASSERT_NE(), andASSERT_LT(). If the assert condition fails, these macros calltest_fail()before executingassert().Signed-off-by Rebecca Mckeever <[email protected]>--- tools/testing/memblock/tests/alloc_api.c | 241 ++++++++---- .../memblock/tests/alloc_helpers_api.c | 135 +++++-- tools/testing/memblock/tests/alloc_nid_api.c | 371 ++++++++++++------ tools/testing/memblock/tests/basic_api.c | 365 ++++++++++++----- tools/testing/memblock/tests/common.c | 58 +++ tools/testing/memblock/tests/common.h | 54 +++ 6 files changed, 880 insertions(+), 344 deletions(-)tools/testing/memblock/tests/alloc_api.c +0
-0...
tools/testing/memblock/tests/alloc_api.c static int alloc_no_memory_check(void) · line 827
Quoted 9 lines
tools/testing/memblock/tests/alloc_api.c +5
-0@@ -729,6 +820,12 @@ static int alloc_no_memory_check(void)int memblock_alloc_checks (void ) { +static const char func_testing[] ="memblock_alloc" ; + +prefix_reset (); +prefix_push (func_testing); +test_print ("Running %s tests...\n" , func_testing);Why not
test_print("Running memblock_alloc tests...\n");
Quoted 7 lines
Quoted 3 lines
?
(applies to other cases below)
Both
prefix_push()andtest_print()are using that string, and I thought it made sense to use a constant instead of hard coding the string in both places. Is it better to hard code the string in this case?
Oh, missed that.
I'd drop static, it doesn't really matter here.
Quoted 175 lines
Quoted 134 lines
Quoted 3 lines
tools/testing/memblock/tests/alloc_api.c +1
-0+reset_memblock_attributes ();dummy_physical_memory_init ();...
Quoted 4 lines
tools/testing/memblock/tests/alloc_helpers_api.c +0
-0...
Quoted 17 lines
tools/testing/memblock/tests/alloc_helpers_api.c +6
-0@@ -378,6 +423,12 @@ static int alloc_from_min_addr_cap_check(void)int memblock_alloc_helpers_checks (void ) { +static const char func_testing[] ="memblock_alloc_from" ; + +prefix_reset (); +prefix_push (func_testing); +test_print ("Running %s tests...\n" , func_testing); +reset_memblock_attributes ();dummy_physical_memory_init ();tools/testing/memblock/tests/alloc_nid_api.c +0
-0...
Quoted 91 lines
tools/testing/memblock/tests/alloc_nid_api.c +8
-0@@ -1150,6 +1263,12 @@ static int alloc_try_nid_low_max_check(void)int memblock_alloc_nid_checks (void ) { +static const char func_testing[] ="memblock_alloc_try_nid" ; + +prefix_reset (); +prefix_push (func_testing); +test_print ("Running %s tests...\n" , func_testing); +reset_memblock_attributes ();dummy_physical_memory_init ();@@ -1170,5 +1289,7 @@ int memblock_alloc_nid_checks(void)dummy_physical_memory_cleanup (); +prefix_pop (); +return 0 ; }tools/testing/memblock/tests/basic_api.c +28
-14@@ -4,21 +4,30 @@#include "basic_api.h" #define EXPECTED_MEMBLOCK_REGIONS 128 +#define FUNC_ADD "memblock_add" +#define FUNC_RESERVE "memblock_reserve" +#define FUNC_REMOVE "memblock_remove" +#define FUNC_FREE "memblock_free"static int memblock_initialization_check (void ) { -assert (memblock.memory.regions); -assert (memblock.memory.cnt ==1 ); -assert (memblock.memory.max ==EXPECTED_MEMBLOCK_REGIONS ); -assert (strcmp (memblock.memory.name,"memory" ) ==0 ); +prefix_push (__func__); -assert (memblock.reserved.regions); -assert (memblock.reserved.cnt ==1 ); -assert (memblock.memory.max ==EXPECTED_MEMBLOCK_REGIONS ); -assert (strcmp (memblock.reserved.name,"reserved" ) ==0 ); +ASSERT_NE (memblock.memory.regions,NULL ); +ASSERT_EQ (memblock.memory.cnt,1 ); +ASSERT_EQ (memblock.memory.max,EXPECTED_MEMBLOCK_REGIONS ); +ASSERT_EQ (strcmp (memblock.memory.name,"memory" ),0 ); -assert (!memblock.bottom_up); -assert (memblock.current_limit ==MEMBLOCK_ALLOC_ANYWHERE ); +ASSERT_NE (memblock.reserved.regions,NULL ); +ASSERT_EQ (memblock.reserved.cnt,1 ); +ASSERT_EQ (memblock.memory.max,EXPECTED_MEMBLOCK_REGIONS ); +ASSERT_EQ (strcmp (memblock.reserved.name,"reserved" ),0 ); + +ASSERT_EQ (memblock.bottom_up, false); +ASSERT_EQ (memblock.current_limit,MEMBLOCK_ALLOC_ANYWHERE ); + +test_pass (); +prefix_pop ();return 0 ; }@@ -40,14 +49,19 @@ static int memblock_add_simple_check(void) .size = SZ_4M }; +prefix_push (__func__); +reset_memblock_regions ();memblock_add (r.base, r.size); -assert (rgn->base == r.base); -assert (rgn->size == r.size); +ASSERT_EQ (rgn->base, r.base); +ASSERT_EQ (rgn->size, r.size); + +ASSERT_EQ (memblock.memory.cnt,1 ); +ASSERT_EQ (memblock.memory.total_size, r.size); -assert (memblock.memory.cnt ==1 ); -assert (memblock.memory.total_size == r.size); +test_pass (); +prefix_pop ();return 0 ; }tools/testing/memblock/tests/basic_api.c static int memblock_add_node_simple_check(void) · line 88
Quoted 6 lines
tools/testing/memblock/tests/basic_api.c +3
-0@@ -69,18 +83,27 @@ static int memblock_add_node_simple_check(void) .size = SZ_16M }; +prefix_pop (); +prefix_push ("memblock_add_node" ); +prefix_push (__func__);I think there is no need to change the prefix from
memblock_addtomemblock_add_nodehere.Quoted 4 lines
ok 3 :
memblock_add:memblock_add_node_simple_check: passedprovides enough information.
Will do.
Quoted 25 lines
Quoted 25 lines
tools/testing/memblock/tests/basic_api.c +12
-6+reset_memblock_regions ();memblock_add_node (r.base, r.size,1 ,MEMBLOCK_HOTPLUG ); -assert (rgn->base == r.base); -assert (rgn->size == r.size); +ASSERT_EQ (rgn->base, r.base); +ASSERT_EQ (rgn->size, r.size);#ifdef CONFIG_NUMA -assert (rgn->nid ==1 ); +ASSERT_EQ (rgn->nid,1 );#endif -assert (rgn->flags ==MEMBLOCK_HOTPLUG ); +ASSERT_EQ (rgn->flags,MEMBLOCK_HOTPLUG ); + +ASSERT_EQ (memblock.memory.cnt,1 ); +ASSERT_EQ (memblock.memory.total_size, r.size); -assert (memblock.memory.cnt ==1 ); -assert (memblock.memory.total_size == r.size); +test_pass (); +prefix_pop (); +prefix_pop (); +prefix_push (FUNC_ADD );Quoted 6 lines
Quoted 2 lines
tools/testing/memblock/tests/basic_api.c +0
-0return 0 ; }Signature · 2 lines
Sincerely yours, Mike.Thanks,
Rebecca
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH v3 2/4] memblock tests: add verbose output to memblock tests
Quoted 56 lines · Mike Rapoport
Quoted 55 lines · Rebecca Mckeever
Quoted 54 lines · Mike Rapoport
Quoted 34 lines · Rebecca Mckeever
Add and use functions for printing verbose testing output.
If the Memblock simulator was compiled with VERBOSE=1:
prefix_push()appends the given string to a prefix string that will be
printed in the test functions.
prefix_pop()removes the last prefix from the prefix string.prefix_reset()clears the prefix string.
test_fail()prints a message after a test fails containing the test
number of the failing test and the prefix.
test_pass()prints a message after a test passes containing its test
number and the prefix.
test_print()prints the given formatted output string.If the Memblock simulator was not compiled with VERBOSE=1, these functions do nothing.
Add the assert wrapper macros
ASSERT_EQ(),ASSERT_NE(), andASSERT_LT(). If the assert condition fails, these macros calltest_fail()before executingassert().Signed-off-by Rebecca Mckeever <[email protected]>--- tools/testing/memblock/tests/alloc_api.c | 241 ++++++++---- .../memblock/tests/alloc_helpers_api.c | 135 +++++-- tools/testing/memblock/tests/alloc_nid_api.c | 371 ++++++++++++------ tools/testing/memblock/tests/basic_api.c | 365 ++++++++++++----- tools/testing/memblock/tests/common.c | 58 +++ tools/testing/memblock/tests/common.h | 54 +++ 6 files changed, 880 insertions(+), 344 deletions(-)tools/testing/memblock/tests/alloc_api.c +0
-0...
tools/testing/memblock/tests/alloc_api.c static int alloc_no_memory_check(void) · line 827
Quoted 9 lines
tools/testing/memblock/tests/alloc_api.c +5
-0@@ -729,6 +820,12 @@ static int alloc_no_memory_check(void)int memblock_alloc_checks (void ) { +static const char func_testing[] ="memblock_alloc" ; + +prefix_reset (); +prefix_push (func_testing); +test_print ("Running %s tests...\n" , func_testing);Why not
test_print("Running memblock_alloc tests...\n");?
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
(applies to other cases below)
Both
prefix_push()andtest_print()are using that string, and I thought it made sense to use a constant instead of hard coding the string in both places. Is it better to hard code the string in this case?Oh, missed that.
I'd drop static, it doesn't really matter here.
Will do.
Quoted 179 lines
Quoted 175 lines
Quoted 134 lines
Quoted 3 lines
tools/testing/memblock/tests/alloc_api.c +1
-0+reset_memblock_attributes ();dummy_physical_memory_init ();...
Quoted 4 lines
tools/testing/memblock/tests/alloc_helpers_api.c +0
-0...
Quoted 17 lines
tools/testing/memblock/tests/alloc_helpers_api.c +6
-0@@ -378,6 +423,12 @@ static int alloc_from_min_addr_cap_check(void)int memblock_alloc_helpers_checks (void ) { +static const char func_testing[] ="memblock_alloc_from" ; + +prefix_reset (); +prefix_push (func_testing); +test_print ("Running %s tests...\n" , func_testing); +reset_memblock_attributes ();dummy_physical_memory_init ();tools/testing/memblock/tests/alloc_nid_api.c +0
-0...
Quoted 91 lines
tools/testing/memblock/tests/alloc_nid_api.c +8
-0@@ -1150,6 +1263,12 @@ static int alloc_try_nid_low_max_check(void)int memblock_alloc_nid_checks (void ) { +static const char func_testing[] ="memblock_alloc_try_nid" ; + +prefix_reset (); +prefix_push (func_testing); +test_print ("Running %s tests...\n" , func_testing); +reset_memblock_attributes ();dummy_physical_memory_init ();@@ -1170,5 +1289,7 @@ int memblock_alloc_nid_checks(void)dummy_physical_memory_cleanup (); +prefix_pop (); +return 0 ; }tools/testing/memblock/tests/basic_api.c +28
-14@@ -4,21 +4,30 @@#include "basic_api.h" #define EXPECTED_MEMBLOCK_REGIONS 128 +#define FUNC_ADD "memblock_add" +#define FUNC_RESERVE "memblock_reserve" +#define FUNC_REMOVE "memblock_remove" +#define FUNC_FREE "memblock_free"static int memblock_initialization_check (void ) { -assert (memblock.memory.regions); -assert (memblock.memory.cnt ==1 ); -assert (memblock.memory.max ==EXPECTED_MEMBLOCK_REGIONS ); -assert (strcmp (memblock.memory.name,"memory" ) ==0 ); +prefix_push (__func__); -assert (memblock.reserved.regions); -assert (memblock.reserved.cnt ==1 ); -assert (memblock.memory.max ==EXPECTED_MEMBLOCK_REGIONS ); -assert (strcmp (memblock.reserved.name,"reserved" ) ==0 ); +ASSERT_NE (memblock.memory.regions,NULL ); +ASSERT_EQ (memblock.memory.cnt,1 ); +ASSERT_EQ (memblock.memory.max,EXPECTED_MEMBLOCK_REGIONS ); +ASSERT_EQ (strcmp (memblock.memory.name,"memory" ),0 ); -assert (!memblock.bottom_up); -assert (memblock.current_limit ==MEMBLOCK_ALLOC_ANYWHERE ); +ASSERT_NE (memblock.reserved.regions,NULL ); +ASSERT_EQ (memblock.reserved.cnt,1 ); +ASSERT_EQ (memblock.memory.max,EXPECTED_MEMBLOCK_REGIONS ); +ASSERT_EQ (strcmp (memblock.reserved.name,"reserved" ),0 ); + +ASSERT_EQ (memblock.bottom_up, false); +ASSERT_EQ (memblock.current_limit,MEMBLOCK_ALLOC_ANYWHERE ); + +test_pass (); +prefix_pop ();return 0 ; }@@ -40,14 +49,19 @@ static int memblock_add_simple_check(void) .size = SZ_4M }; +prefix_push (__func__); +reset_memblock_regions ();memblock_add (r.base, r.size); -assert (rgn->base == r.base); -assert (rgn->size == r.size); +ASSERT_EQ (rgn->base, r.base); +ASSERT_EQ (rgn->size, r.size); + +ASSERT_EQ (memblock.memory.cnt,1 ); +ASSERT_EQ (memblock.memory.total_size, r.size); -assert (memblock.memory.cnt ==1 ); -assert (memblock.memory.total_size == r.size); +test_pass (); +prefix_pop ();return 0 ; }tools/testing/memblock/tests/basic_api.c static int memblock_add_node_simple_check(void) · line 88
Quoted 6 lines
tools/testing/memblock/tests/basic_api.c +3
-0@@ -69,18 +83,27 @@ static int memblock_add_node_simple_check(void) .size = SZ_16M }; +prefix_pop (); +prefix_push ("memblock_add_node" ); +prefix_push (__func__);I think there is no need to change the prefix from
memblock_addtomemblock_add_nodehere.Quoted 4 lines
ok 3 :
memblock_add:memblock_add_node_simple_check: passedprovides enough information.
Will do.
Quoted 25 lines
Quoted 25 lines
tools/testing/memblock/tests/basic_api.c +12
-6+reset_memblock_regions ();memblock_add_node (r.base, r.size,1 ,MEMBLOCK_HOTPLUG ); -assert (rgn->base == r.base); -assert (rgn->size == r.size); +ASSERT_EQ (rgn->base, r.base); +ASSERT_EQ (rgn->size, r.size);#ifdef CONFIG_NUMA -assert (rgn->nid ==1 ); +ASSERT_EQ (rgn->nid,1 );#endif -assert (rgn->flags ==MEMBLOCK_HOTPLUG ); +ASSERT_EQ (rgn->flags,MEMBLOCK_HOTPLUG ); + +ASSERT_EQ (memblock.memory.cnt,1 ); +ASSERT_EQ (memblock.memory.total_size, r.size); -assert (memblock.memory.cnt ==1 ); -assert (memblock.memory.total_size == r.size); +test_pass (); +prefix_pop (); +prefix_pop (); +prefix_push (FUNC_ADD );Quoted 6 lines
Quoted 2 lines
tools/testing/memblock/tests/basic_api.c +0
-0return 0 ; }Signature · 2 lines
Sincerely yours, Mike.Thanks,
RebeccaSignature · 2 lines
Sincerely yours, Mike.