2022-07-17 12:21:56 +03:00
|
|
|
#include "../minunit.h"
|
2020-10-15 20:36:15 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
2022-02-18 22:53:46 +03:00
|
|
|
|
2020-10-15 20:36:15 +03:00
|
|
|
void test_furi_memmgr() {
|
2022-12-24 17:13:21 +03:00
|
|
|
void* ptr;
|
2020-10-15 20:36:15 +03:00
|
|
|
|
|
|
|
// allocate memory case
|
2022-12-24 17:13:21 +03: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 20:36:15 +03:00
|
|
|
free(ptr);
|
|
|
|
|
|
|
|
// reallocate memory case
|
2022-12-24 17:13:21 +03: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 20:36:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
free(ptr);
|
|
|
|
|
|
|
|
// allocate and zero-initialize array (calloc)
|
2022-12-24 17:13:21 +03: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 20:36:15 +03:00
|
|
|
}
|
|
|
|
free(ptr);
|
2022-02-18 22:53:46 +03:00
|
|
|
}
|