From c6e06f58e4d0b8bc40c8482728357cbd3be5d6b3 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 2 Aug 2017 19:44:13 +0200 Subject: simplified malloc test, see if we are leaking memory, the exact size can differ due to alignment now --- tests/libc/test_malloc.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/libc/test_malloc.c b/tests/libc/test_malloc.c index b20ee62..e523de9 100644 --- a/tests/libc/test_malloc.c +++ b/tests/libc/test_malloc.c @@ -14,17 +14,17 @@ int main( void ) char *s; char *s1 = "test_string"; - + + // simple test if malloced string can be used s = (char *)malloc( strlen( s1 ) + 1 ); size_t n = strlcpy( s, s1, strlen( s1 ) + 1 ); if( n != 11 ) exit( 1 ); if( strcmp( s, s1 ) != 0 ) exit( 1 ); free( s ); - - if( memory_manager.size != heap_size - sizeof( memory_chunk_t ) ) exit( 1 ); - if( memory_manager.offset != (uint32_t)&buf ) exit( 1 ); - if( memory_manager_stats_used( &memory_manager ) != 0 ) exit( 1 ); - if( memory_manager_stats_free( &memory_manager ) != heap_size - sizeof( memory_chunk_t ) ) exit( 1 ); + + // test if we are freing all memory and are not leaking + + size_t memory_used_before = memory_manager_stats_used( &memory_manager ); char *v[120]; for( int i = 0; i < 120; i++ ) { @@ -36,8 +36,9 @@ int main( void ) free( v[i] ); } - if( memory_manager_stats_used( &memory_manager ) != 0 ) exit( 1 ); - if( memory_manager_stats_free( &memory_manager ) != heap_size - sizeof( memory_chunk_t ) ) exit( 1 ); - + size_t memory_used_after = memory_manager_stats_used( &memory_manager ); + + if( memory_used_before != memory_used_after ) exit( 1 ); + exit( 0 ); } -- cgit v1.2.3-54-g00ecf