unity_utils_memory_esp.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "esp_heap_caps.h"
  7. #include "unity_test_utils.h"
  8. #ifdef CONFIG_HEAP_TRACING
  9. #include "esp_heap_trace.h"
  10. #endif
  11. static size_t s_before_free_8bit;
  12. static size_t s_before_free_32bit;
  13. void unity_utils_record_free_mem(void)
  14. {
  15. s_before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
  16. s_before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
  17. }
  18. void unity_utils_setup_heap_record(size_t num_heap_records)
  19. {
  20. #ifdef CONFIG_HEAP_TRACING
  21. static heap_trace_record_t *record_buffer;
  22. if (!record_buffer) {
  23. record_buffer = malloc(sizeof(heap_trace_record_t) * num_heap_records);
  24. assert(record_buffer);
  25. heap_trace_init_standalone(record_buffer, num_heap_records);
  26. }
  27. #endif
  28. }
  29. void unity_utils_evaluate_leaks_direct(size_t threshold)
  30. {
  31. size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
  32. size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
  33. unity_utils_check_leak(s_before_free_8bit, after_free_8bit, "8BIT", threshold);
  34. unity_utils_check_leak(s_before_free_32bit, after_free_32bit, "32BIT", threshold);
  35. }