Merge branch 'zlo/tlsf-and-a-temple-of-memcorrupt' of https://github.com/flipperdevices/flipperzero-firmware into mntm-dev

This commit is contained in:
Willy-JL
2024-06-11 23:24:35 +02:00
9 changed files with 1388 additions and 14 deletions

View File

@@ -1,5 +1,8 @@
#include "../test.h" // IWYU pragma: keep
#include <furi.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
void test_furi_memmgr(void) {
void* ptr;
@@ -48,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) {
@@ -99,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) {
@@ -124,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++) {
@@ -290,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

@@ -8,6 +8,7 @@ void test_furi_concurrent_access(void);
void test_furi_pubsub(void);
void test_furi_memmgr(void);
void test_furi_memmgr_advanced(void);
void test_furi_memmgr_aligned8(void);
void test_furi_event_loop(void);
static int foo = 0;
@@ -38,6 +39,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(mu_test_furi_event_loop) {