unit tests: test aligment by 8

This commit is contained in:
SG
2024-06-03 14:35:51 +01:00
parent 500afc67ba
commit 32a55f2575
3 changed files with 36 additions and 7 deletions
@@ -51,6 +51,11 @@ static void test_memmgr_malloc(const size_t allocation_size) {
error_message = "malloc failed";
}
// test that memory is aligned by 8 bytes
if(((uintptr_t)ptr % 8) != 0) {
error_message = "memory is not aligned by 8 bytes after malloc";
}
// test that memory is zero-initialized after allocation
for(size_t i = 0; i < allocation_size; i++) {
if(ptr[i] != 0) {
@@ -102,6 +107,11 @@ static void test_memmgr_realloc(const size_t allocation_size) {
error_message = "realloc(NULL) failed";
}
// test that memory is aligned by 8 bytes
if(((uintptr_t)ptr % 8) != 0) {
error_message = "memory is not aligned by 8 bytes after realloc";
}
// test that memory is zero-initialized after allocation
for(size_t i = 0; i < allocation_size; i++) {
if(ptr[i] != 0) {
@@ -127,6 +137,11 @@ static void test_memmgr_realloc(const size_t allocation_size) {
}
}
// test that memory is aligned by 8 bytes
if(((uintptr_t)ptr % 8) != 0) {
error_message = "memory is not aligned by 8 bytes after realloc";
}
// test that remaining memory is zero-initialized
size_t non_zero_count = 0;
for(size_t i = allocation_size; i < allocation_size * 2; i++) {
@@ -293,4 +308,18 @@ void test_furi_memmgr_advanced(void) {
free(guards[i]);
}
}
}
void test_furi_memmgr_aligned8(void) {
const size_t repeat_count = 100;
for(size_t i = 0; i < repeat_count; i++) {
uintptr_t ptr = (uintptr_t)malloc(10);
mu_assert_int_eq(0, ptr % 8);
ptr = (uintptr_t)realloc((void*)ptr, 20);
mu_assert_int_eq(0, ptr % 8);
ptr = (uintptr_t)realloc((void*)ptr, 30);
mu_assert_int_eq(0, ptr % 8);
free((void*)ptr);
}
}
@@ -10,6 +10,7 @@ void test_furi_pubsub(void);
void test_furi_memmgr(void);
void test_furi_memmgr_advanced(void);
void test_furi_memmgr_aligned8(void);
static int foo = 0;
@@ -39,6 +40,7 @@ MU_TEST(mu_test_furi_memmgr) {
// that memory management is working fine
test_furi_memmgr();
test_furi_memmgr_advanced();
test_furi_memmgr_aligned8();
}
MU_TEST_SUITE(test_suite) {
+5 -7
View File
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,63.0,,
Version,+,64.0,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
@@ -593,9 +593,7 @@ Function,-,acosh,double,double
Function,-,acoshf,float,float
Function,-,acoshl,long double,long double
Function,-,acosl,long double,long double
Function,-,aligned_alloc,void*,"size_t, size_t"
Function,+,aligned_free,void,void*
Function,+,aligned_malloc,void*,"size_t, size_t"
Function,+,aligned_alloc,void*,"size_t, size_t"
Function,-,arc4random,__uint32_t,
Function,-,arc4random_buf,void,"void*, size_t"
Function,-,arc4random_uniform,__uint32_t,__uint32_t
@@ -2412,7 +2410,8 @@ Function,+,memchr,void*,"const void*, int, size_t"
Function,+,memcmp,int,"const void*, const void*, size_t"
Function,+,memcpy,void*,"void*, const void*, size_t"
Function,-,memmem,void*,"const void*, size_t, const void*, size_t"
Function,-,memmgr_alloc_from_pool,void*,size_t
Function,+,memmgr_aux_pool_alloc,void*,size_t
Function,+,memmgr_aux_pool_get_free,size_t,
Function,+,memmgr_get_free_heap,size_t,
Function,+,memmgr_get_minimum_free_heap,size_t,
Function,+,memmgr_get_total_heap,size_t,
@@ -2420,8 +2419,7 @@ Function,+,memmgr_heap_disable_thread_trace,void,FuriThreadId
Function,+,memmgr_heap_enable_thread_trace,void,FuriThreadId
Function,+,memmgr_heap_get_max_free_block,size_t,
Function,+,memmgr_heap_get_thread_memory,size_t,FuriThreadId
Function,+,memmgr_heap_printf_free_blocks,void,
Function,-,memmgr_pool_get_free,size_t,
Function,+,memmgr_heap_walk_blocks,void,"BlockWalker, void*"
Function,-,memmgr_pool_get_max_block,size_t,
Function,+,memmove,void*,"void*, const void*, size_t"
Function,-,mempcpy,void*,"void*, const void*, size_t"
1 entry status name type params
2 Version + 63.0 64.0
3 Header + applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h
4 Header + applications/services/bt/bt_service/bt.h
5 Header + applications/services/bt/bt_service/bt_keys_storage.h
593 Function - acoshf float float
594 Function - acoshl long double long double
595 Function - acosl long double long double
596 Function - + aligned_alloc void* size_t, size_t
Function + aligned_free void void*
Function + aligned_malloc void* size_t, size_t
597 Function - arc4random __uint32_t
598 Function - arc4random_buf void void*, size_t
599 Function - arc4random_uniform __uint32_t __uint32_t
2410 Function + memcmp int const void*, const void*, size_t
2411 Function + memcpy void* void*, const void*, size_t
2412 Function - memmem void* const void*, size_t, const void*, size_t
2413 Function - + memmgr_alloc_from_pool memmgr_aux_pool_alloc void* size_t
2414 Function + memmgr_aux_pool_get_free size_t
2415 Function + memmgr_get_free_heap size_t
2416 Function + memmgr_get_minimum_free_heap size_t
2417 Function + memmgr_get_total_heap size_t
2419 Function + memmgr_heap_enable_thread_trace void FuriThreadId
2420 Function + memmgr_heap_get_max_free_block size_t
2421 Function + memmgr_heap_get_thread_memory size_t FuriThreadId
2422 Function + memmgr_heap_printf_free_blocks memmgr_heap_walk_blocks void BlockWalker, void*
Function - memmgr_pool_get_free size_t
2423 Function - memmgr_pool_get_max_block size_t
2424 Function + memmove void* void*, const void*, size_t
2425 Function - mempcpy void* void*, const void*, size_t