summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-07-15 09:51:25 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-07-15 09:51:25 +0200
commit62906512c5938bff7f23e3abfd515c589c228d12 (patch)
tree75839baa3c148a972d5dc9013405e7539f82b169
parent5956699139b783c13869a1097bfb5dba8e867b0f (diff)
downloadabaos-62906512c5938bff7f23e3abfd515c589c228d12.tar.gz
abaos-62906512c5938bff7f23e3abfd515c589c228d12.tar.bz2
added a better malloc test
-rw-r--r--tests/libc/test_malloc.c19
1 files changed, 19 insertions, 0 deletions
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 );
}