From 62906512c5938bff7f23e3abfd515c589c228d12 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 15 Jul 2017 09:51:25 +0200 Subject: added a better malloc test --- tests/libc/test_malloc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/libc/test_malloc.c b/tests/libc/test_malloc.c index aaff2da..b20ee62 100644 --- a/tests/libc/test_malloc.c +++ b/tests/libc/test_malloc.c @@ -19,6 +19,25 @@ int main( void ) 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 ); + + char *v[120]; + for( int i = 0; i < 120; i++ ) { + v[i] = (char *)malloc( i ); + if( v[i] == NULL ) exit( 1 ); + } + + for( int i = 119; i >= 0; i-- ) { + 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 ); exit( 0 ); } -- cgit v1.2.3-54-g00ecf