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

View File

@@ -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);
}
}

View File

@@ -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) {