/* * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include "sdkconfig.h" #include #include #include "inttypes.h" #include "esp_log.h" #include "esp_attr.h" #include "unity.h" #include "esp_private/esp_cache_private.h" #include "esp_memory_utils.h" #include "hal/cache_ll.h" #include "hal/cache_hal.h" TEST_CASE("test heap_caps_malloc_prefer for dma memory", "[hw-align]") { void *ptr = NULL; ptr = heap_caps_malloc_prefer(40, 1, MALLOC_CAP_DMA); TEST_ASSERT_NOT_NULL(ptr); TEST_ASSERT(esp_ptr_dma_capable(ptr)); free(ptr); } TEST_CASE("test heap_caps_calloc_prefer for dma memory", "[hw-align]") { void *ptr = NULL; ptr = heap_caps_calloc_prefer(40, 1, 1, MALLOC_CAP_DMA); TEST_ASSERT_NOT_NULL(ptr); TEST_ASSERT(esp_ptr_dma_capable(ptr)); free(ptr); } #include "esp_private/heap_align_hw.h" #define TEST_ALLOC_COUNT 100 static bool test_alignment(uint32_t caps, int expected_alignment) { bool ret=true; void *mem[TEST_ALLOC_COUNT]; size_t size[TEST_ALLOC_COUNT]; //First, check if we can allocate memory with these caps anyway. void *tst=heap_caps_malloc(1, caps); if (!tst) return true; free(tst); //Step 1: generate sizes and allocate memory. for (int i=0; i8?int_cache_size:8); test_alignment(MALLOC_CAP_DMA|MALLOC_CAP_SPIRAM, ext_cache_size); }