From 7c6d343a605eede50e8b0241c926b965b4c79ad8 Mon Sep 17 00:00:00 2001 From: Laukik Hase Date: Thu, 27 Jan 2022 17:29:19 +0530 Subject: [PATCH 1/4] ci: Add unit test configs for aggressive SPIRAM allocations - CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0 Everything will be allocated from the SPIRAM (except DMA and FreeRTOS task resources) - CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y Allow external memory as an argument to xTaskCreateStatic - CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=default Reserved memory for crucial internal functions (DMA, FreeRTOS) - Increase parallel job count --- .gitlab/ci/target-test.yml | 2 +- tools/unit-test-app/configs/psram_all_ext_1 | 8 ++++++++ tools/unit-test-app/configs/psram_all_ext_2 | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tools/unit-test-app/configs/psram_all_ext_1 create mode 100644 tools/unit-test-app/configs/psram_all_ext_2 diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 216be7f9ee..2a61af58d9 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -645,7 +645,7 @@ UT_001: UT_002: extends: .unit_test_esp32_template - parallel: 15 + parallel: 21 tags: - ESP32_IDF - UT_T1_1 diff --git a/tools/unit-test-app/configs/psram_all_ext_1 b/tools/unit-test-app/configs/psram_all_ext_1 new file mode 100644 index 0000000000..fed757531a --- /dev/null +++ b/tools/unit-test-app/configs/psram_all_ext_1 @@ -0,0 +1,8 @@ +CONFIG_IDF_TARGET="esp32" +TEST_COMPONENTS=driver esp_hw_support esp_system esp_timer +CONFIG_ESP32_SPIRAM_SUPPORT=y +CONFIG_ESP_INT_WDT_TIMEOUT_MS=800 +CONFIG_SPIRAM_OCCUPY_NO_HOST=y +CONFIG_ESP32_WIFI_RX_IRAM_OPT=n +CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y +CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0 diff --git a/tools/unit-test-app/configs/psram_all_ext_2 b/tools/unit-test-app/configs/psram_all_ext_2 new file mode 100644 index 0000000000..b7ebb27f49 --- /dev/null +++ b/tools/unit-test-app/configs/psram_all_ext_2 @@ -0,0 +1,8 @@ +CONFIG_IDF_TARGET="esp32" +TEST_COMPONENTS=heap mbedtls soc spi_flash +CONFIG_ESP32_SPIRAM_SUPPORT=y +CONFIG_ESP_INT_WDT_TIMEOUT_MS=800 +CONFIG_SPIRAM_OCCUPY_NO_HOST=y +CONFIG_ESP32_WIFI_RX_IRAM_OPT=n +CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y +CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0 From 6f9fc0ba8e49f0355583da8f208c2a1590819d1d Mon Sep 17 00:00:00 2001 From: Laukik Hase Date: Mon, 13 Dec 2021 15:49:06 +0530 Subject: [PATCH 2/4] esp_system: Place ipc_task semaphores on DRAM - For CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL < 92, the ipc_task semaphores were allocated on SPIRAM rather than internal RAM - SemaphoreHandle_t has a size of 92, thus the failure --- components/esp_system/esp_ipc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/esp_system/esp_ipc.c b/components/esp_system/esp_ipc.c index 68a8dd0d3d..71ca5cc164 100644 --- a/components/esp_system/esp_ipc.c +++ b/components/esp_system/esp_ipc.c @@ -19,6 +19,10 @@ #if !defined(CONFIG_FREERTOS_UNICORE) || defined(CONFIG_APPTRACE_GCOV_ENABLE) +static DRAM_ATTR StaticSemaphore_t s_ipc_mutex_buffer[portNUM_PROCESSORS]; +static DRAM_ATTR StaticSemaphore_t s_ipc_sem_buffer[portNUM_PROCESSORS]; +static DRAM_ATTR StaticSemaphore_t s_ipc_ack_buffer[portNUM_PROCESSORS]; + static TaskHandle_t s_ipc_task_handle[portNUM_PROCESSORS]; static SemaphoreHandle_t s_ipc_mutex[portNUM_PROCESSORS]; // This mutex is used as a global lock for esp_ipc_* APIs static SemaphoreHandle_t s_ipc_sem[portNUM_PROCESSORS]; // Two semaphores used to wake each of ipc tasks @@ -104,9 +108,9 @@ static void esp_ipc_init(void) for (int i = 0; i < portNUM_PROCESSORS; ++i) { snprintf(task_name, sizeof(task_name), "ipc%d", i); - s_ipc_mutex[i] = xSemaphoreCreateMutex(); - s_ipc_ack[i] = xSemaphoreCreateBinary(); - s_ipc_sem[i] = xSemaphoreCreateBinary(); + s_ipc_mutex[i] = xSemaphoreCreateMutexStatic(&s_ipc_mutex_buffer[i]); + s_ipc_ack[i] = xSemaphoreCreateBinaryStatic(&s_ipc_ack_buffer[i]); + s_ipc_sem[i] = xSemaphoreCreateBinaryStatic(&s_ipc_sem_buffer[i]); portBASE_TYPE res = xTaskCreatePinnedToCore(ipc_task, task_name, CONFIG_ESP_IPC_TASK_STACK_SIZE, (void*) i, configMAX_PRIORITIES - 1, &s_ipc_task_handle[i], i); assert(res == pdTRUE); From c5decf291e0c5513ba1fb24bf9e8c2c514bbfbfa Mon Sep 17 00:00:00 2001 From: Laukik Hase Date: Mon, 3 Jan 2022 18:17:43 +0530 Subject: [PATCH 3/4] ci: Fix for `ETSTimers arm & disarm run from IRAM` UT - For ESP32 | SPIRAM_MALLOC_ALWAYSINTERNAL=0 - Forced `esp_timer_create` to allocate resource from the internal memory - WiFi/BT coexistence will sometimes arm/disarm timers from an ISR where flash may be disabled. This can lead to a cache-based exception as the timer instance will be located in the PSRAM. --- components/esp_timer/src/esp_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_timer/src/esp_timer.c b/components/esp_timer/src/esp_timer.c index 2ea8409ebb..ff2e6bd322 100644 --- a/components/esp_timer/src/esp_timer.c +++ b/components/esp_timer/src/esp_timer.c @@ -122,7 +122,7 @@ esp_err_t esp_timer_create(const esp_timer_create_args_t* args, args->dispatch_method < 0 || args->dispatch_method >= ESP_TIMER_MAX) { return ESP_ERR_INVALID_ARG; } - esp_timer_handle_t result = (esp_timer_handle_t) calloc(1, sizeof(*result)); + esp_timer_handle_t result = (esp_timer_handle_t) heap_caps_calloc(1, sizeof(*result), MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); if (result == NULL) { return ESP_ERR_NO_MEM; } From 3b3b6682565aefca75acabd642c91b07acc4d4b4 Mon Sep 17 00:00:00 2001 From: Laukik Hase Date: Thu, 3 Mar 2022 11:31:03 +0530 Subject: [PATCH 4/4] ci: Disable failing UTs - For ESP32 | SPIRAM_MALLOC_ALWAYSINTERNAL=0 --- components/driver/test/test_spi_master.c | 3 +++ components/esp_system/test/test_sleep.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/driver/test/test_spi_master.c b/components/driver/test/test_spi_master.c index c3dcde6ba0..5a0b6d8ea1 100644 --- a/components/driver/test/test_spi_master.c +++ b/components/driver/test/test_spi_master.c @@ -1299,6 +1299,8 @@ static void fd_slave(void) TEST_CASE_MULTIPLE_DEVICES("SPI Master: FD, DMA, Master Single Direction Test", "[spi_ms][test_env=Example_SPI_Multi_device]", fd_master, fd_slave); #endif //#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32) //TODO: IDF-3494 +//NOTE: Explained in IDF-1445 | MR !14996 +#if !(CONFIG_SPIRAM_SUPPORT) || (CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL >= 16384) /******************************************************************************** * Test SPI transaction interval ********************************************************************************/ @@ -1455,3 +1457,4 @@ TEST_CASE("spi_speed", "[spi]") master_free_device_bus(spi); } #endif // CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE +#endif // !(CONFIG_SPIRAM_SUPPORT) || (CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL >= 16384) diff --git a/components/esp_system/test/test_sleep.c b/components/esp_system/test/test_sleep.c index 473e79c942..f7cbdea4c4 100644 --- a/components/esp_system/test/test_sleep.c +++ b/components/esp_system/test/test_sleep.c @@ -82,6 +82,8 @@ TEST_CASE("wake up from light sleep using timer", "[deepsleep]") TEST_ASSERT_INT32_WITHIN(500, 2000, (int) dt); } +//NOTE: Explained in IDF-1445 | MR !14996 +#if !(CONFIG_SPIRAM_SUPPORT) || (CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL >= 16384) static void test_light_sleep(void* arg) { vTaskDelay(2); @@ -137,7 +139,7 @@ TEST_CASE("light sleep stress test with periodic esp_timer", "[deepsleep]") esp_timer_stop(timer); esp_timer_delete(timer); } - +#endif // !(CONFIG_SPIRAM_SUPPORT) || (CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL >= 16384) #if defined(CONFIG_ESP_SYSTEM_RTC_EXT_XTAL) #define MAX_SLEEP_TIME_ERROR_US 200