2022-07-17 09:21:56 +00:00
|
|
|
#include "../minunit.h"
|
2020-10-15 17:36:15 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
2022-02-18 19:53:46 +00:00
|
|
|
|
2020-10-15 17:36:15 +00:00
|
|
|
void test_furi_memmgr() {
|
2022-12-24 14:13:21 +00:00
|
|
|
void* ptr;
|
2020-10-15 17:36:15 +00:00
|
|
|
|
|
|
|
// allocate memory case
|
2022-12-24 14:13:21 +00:00
|
|
|
ptr = malloc(100);
|
|
|
|
mu_check(ptr != NULL);
|
|
|
|
// test that memory is zero-initialized after allocation
|
|
|
|
for(int i = 0; i < 100; i++) {
|
|
|
|
mu_assert_int_eq(0, ((uint8_t*)ptr)[i]);
|
|
|
|
}
|
2020-10-15 17:36:15 +00:00
|
|
|
free(ptr);
|
|
|
|
|
|
|
|
// reallocate memory case
|
2022-12-24 14:13:21 +00:00
|
|
|
ptr = malloc(100);
|
|
|
|
memset(ptr, 66, 100);
|
|
|
|
ptr = realloc(ptr, 200);
|
|
|
|
mu_check(ptr != NULL);
|
|
|
|
|
|
|
|
// test that memory is really reallocated
|
|
|
|
for(int i = 0; i < 100; i++) {
|
|
|
|
mu_assert_int_eq(66, ((uint8_t*)ptr)[i]);
|
2020-10-15 17:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(ptr);
|
|
|
|
|
|
|
|
// allocate and zero-initialize array (calloc)
|
2022-12-24 14:13:21 +00:00
|
|
|
ptr = calloc(100, 2);
|
|
|
|
mu_check(ptr != NULL);
|
|
|
|
for(int i = 0; i < 100 * 2; i++) {
|
|
|
|
mu_assert_int_eq(0, ((uint8_t*)ptr)[i]);
|
2020-10-15 17:36:15 +00:00
|
|
|
}
|
|
|
|
free(ptr);
|
2022-02-18 19:53:46 +00:00
|
|
|
}
|