mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
fix(rom): fixed systimer always using ROM implementation
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# This is the project CMakeLists.txt file for the test subproject
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
#"Trim" the build. Include the minimal set of components, main, and anything it depends on.
|
||||
set(COMPONENTS main)
|
||||
|
||||
project(esp_rom_impl_components)
|
||||
@@ -0,0 +1,2 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
@@ -0,0 +1,7 @@
|
||||
set(srcs "test_app_main.c")
|
||||
|
||||
# In order for the cases defined by `TEST_CASE` to be linked into the final elf,
|
||||
# the component can be registered as WHOLE_ARCHIVE
|
||||
idf_component_register(SRCS ${srcs}
|
||||
PRIV_REQUIRES unity
|
||||
WHOLE_ARCHIVE)
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include "unity.h"
|
||||
#include "unity_test_runner.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/wdt_hal.h"
|
||||
#include "hal/systimer_hal.h"
|
||||
|
||||
static bool fn_in_rom(void *fn)
|
||||
{
|
||||
const int fnaddr = (int)fn;
|
||||
return (fnaddr >= SOC_IROM_MASK_LOW && fnaddr < SOC_IROM_MASK_HIGH);
|
||||
}
|
||||
|
||||
#if CONFIG_HAL_WDT_USE_ROM_IMPL
|
||||
TEST_CASE("Test that WDT implementation from ROM is used", "[rom-impl-components]")
|
||||
{
|
||||
TEST_ASSERT_TRUE(fn_in_rom(wdt_hal_feed));
|
||||
}
|
||||
|
||||
#else
|
||||
TEST_CASE("Test that WDT implementation from ROM is NOT used", "[rom-impl-components]")
|
||||
{
|
||||
TEST_ASSERT_FALSE(fn_in_rom(wdt_hal_feed));
|
||||
}
|
||||
#endif // CONFIG_HAL_WDT_USE_ROM_IMPL
|
||||
|
||||
|
||||
#if CONFIG_HAL_SYSTIMER_USE_ROM_IMPL
|
||||
TEST_CASE("Test that systimer implementation from ROM is used", "[rom-impl-components]")
|
||||
{
|
||||
TEST_ASSERT_TRUE(fn_in_rom(systimer_hal_get_counter_value));
|
||||
}
|
||||
|
||||
#else
|
||||
TEST_CASE("Test that systimer implementation from ROM is NOT used", "[rom-impl-components]")
|
||||
{
|
||||
TEST_ASSERT_FALSE(fn_in_rom(systimer_hal_get_counter_value));
|
||||
}
|
||||
#endif // CONFIG_HAL_SYSTIMER_USE_ROM_IMPL
|
||||
|
||||
extern uint32_t tlsf_create;
|
||||
#if CONFIG_HEAP_TLSF_USE_ROM_IMPL
|
||||
TEST_CASE("Test that HEAP implementation from ROM is used", "[rom-impl-components]")
|
||||
{
|
||||
TEST_ASSERT_TRUE(fn_in_rom((&tlsf_create)));
|
||||
}
|
||||
|
||||
#else
|
||||
TEST_CASE("Test that HEAP implementation from ROM is NOT used", "[rom-impl-components]")
|
||||
{
|
||||
TEST_ASSERT_FALSE(fn_in_rom(&tlsf_create));
|
||||
}
|
||||
#endif // CONFIG_HEAP_TLSF_USE_ROM_IMPL
|
||||
|
||||
|
||||
extern uint32_t spi_flash_chip_generic_probe;
|
||||
#if CONFIG_SPI_FLASH_ROM_IMPL
|
||||
TEST_CASE("Test that SPI flash implementation from ROM is used", "[rom-impl-components]")
|
||||
{
|
||||
TEST_ASSERT_TRUE(fn_in_rom(&spi_flash_chip_generic_probe));
|
||||
}
|
||||
|
||||
#else
|
||||
TEST_CASE("Test that SPI flash implementation from ROM is NOT used", "[rom-impl-components]")
|
||||
{
|
||||
TEST_ASSERT_FALSE(fn_in_rom(&spi_flash_chip_generic_probe));
|
||||
}
|
||||
#endif // CONFIG_SPI_FLASH_ROM_IMPL
|
||||
|
||||
|
||||
#define TEST_MEMORY_LEAK_THRESHOLD (-100)
|
||||
|
||||
static size_t before_free_8bit;
|
||||
static size_t before_free_32bit;
|
||||
|
||||
static void check_leak(size_t before_free, size_t after_free, const char *type)
|
||||
{
|
||||
ssize_t delta = after_free - before_free;
|
||||
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta);
|
||||
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak");
|
||||
}
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
|
||||
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
|
||||
check_leak(before_free_8bit, after_free_8bit, "8BIT");
|
||||
check_leak(before_free_32bit, after_free_32bit, "32BIT");
|
||||
}
|
||||
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
unity_run_menu();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.supported_targets
|
||||
@pytest.mark.generic
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'no_rom_impl_components',
|
||||
'rom_impl_components',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
def test_esp_rom_impl_components(dut: Dut) -> None:
|
||||
dut.run_all_single_board_cases()
|
||||
@@ -0,0 +1,6 @@
|
||||
CONFIG_HAL_WDT_USE_ROM_IMPL=n
|
||||
CONFIG_HAL_SYSTIMER_USE_ROM_IMPL=n
|
||||
CONFIG_HEAP_TLSF_USE_ROM_IMPL=n
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=n
|
||||
|
||||
# update tools/test_apps/.build-test-rules.yml if adding more ROM options above!
|
||||
@@ -0,0 +1,6 @@
|
||||
CONFIG_HAL_WDT_USE_ROM_IMPL=y
|
||||
CONFIG_HAL_SYSTIMER_USE_ROM_IMPL=y
|
||||
CONFIG_HEAP_TLSF_USE_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
|
||||
# update tools/test_apps/.build-test-rules.yml if adding more ROM options above!
|
||||
@@ -0,0 +1 @@
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
Reference in New Issue
Block a user