summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-08-02 19:44:13 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-08-02 19:44:13 +0200
commitc6e06f58e4d0b8bc40c8482728357cbd3be5d6b3 (patch)
treebcd01050c963cc3a48eb3e3643d3aa6b9aef7a3e
parent53821f9c9e1eba16cd369b1f7e1c051f8935a2e2 (diff)
downloadabaos-c6e06f58e4d0b8bc40c8482728357cbd3be5d6b3.tar.gz
abaos-c6e06f58e4d0b8bc40c8482728357cbd3be5d6b3.tar.bz2
simplified malloc test, see if we are leaking memory, the exact
size can differ due to alignment now
-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 );
}