summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/libc/test_malloc.c19
1 files 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 );
}