mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-25 03:29:58 -07:00
unit tests: test aligment by 8
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user