mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 11:17:20 +02:00
UT/esp32c2: reenable pm and sleep related UT
This commit is contained in:
@@ -268,8 +268,6 @@ TEST_CASE("Can wake up from automatic light sleep by GPIO", "[pm][ignore]")
|
|||||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3)
|
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32S3)
|
||||||
#endif //CONFIG_ULP_COPROC_TYPE_FSM
|
#endif //CONFIG_ULP_COPROC_TYPE_FSM
|
||||||
|
|
||||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
//IDF-5053
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int delay_us;
|
int delay_us;
|
||||||
int result;
|
int result;
|
||||||
@@ -390,7 +388,6 @@ TEST_CASE("esp_timer produces correct delays with light sleep", "[pm]")
|
|||||||
|
|
||||||
#undef NUM_INTERVALS
|
#undef NUM_INTERVALS
|
||||||
}
|
}
|
||||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
|
|
||||||
static void timer_cb1(void *arg)
|
static void timer_cb1(void *arg)
|
||||||
{
|
{
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
set(requires "unity"
|
set(requires "unity"
|
||||||
"test_utils"
|
"test_utils"
|
||||||
"driver"
|
"driver"
|
||||||
"esp_timer")
|
"esp_timer"
|
||||||
|
"nvs_flash")
|
||||||
|
|
||||||
set(excludes "test_ipc_isr.c"
|
set(excludes "test_ipc_isr.c"
|
||||||
"test_ipc_isr.S"
|
"test_ipc_isr.S"
|
||||||
|
@@ -28,6 +28,8 @@
|
|||||||
#include "esp_timer.h"
|
#include "esp_timer.h"
|
||||||
#include "esp_private/esp_clk.h"
|
#include "esp_private/esp_clk.h"
|
||||||
#include "esp_random.h"
|
#include "esp_random.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "nvs.h"
|
||||||
|
|
||||||
#define ESP_EXT0_WAKEUP_LEVEL_LOW 0
|
#define ESP_EXT0_WAKEUP_LEVEL_LOW 0
|
||||||
#define ESP_EXT0_WAKEUP_LEVEL_HIGH 1
|
#define ESP_EXT0_WAKEUP_LEVEL_HIGH 1
|
||||||
@@ -64,8 +66,6 @@ TEST_CASE("enter deep sleep on APP CPU and wake up using timer", "[deepsleep][re
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
//IDF-5131
|
|
||||||
TEST_CASE("wake up from deep sleep using timer", "[deepsleep][reset=DEEPSLEEP_RESET]")
|
TEST_CASE("wake up from deep sleep using timer", "[deepsleep][reset=DEEPSLEEP_RESET]")
|
||||||
{
|
{
|
||||||
esp_sleep_enable_timer_wakeup(2000000);
|
esp_sleep_enable_timer_wakeup(2000000);
|
||||||
@@ -79,7 +79,6 @@ TEST_CASE("light sleep followed by deep sleep", "[deepsleep][reset=DEEPSLEEP_RES
|
|||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
//IDF-5053
|
|
||||||
TEST_CASE("wake up from light sleep using timer", "[deepsleep]")
|
TEST_CASE("wake up from light sleep using timer", "[deepsleep]")
|
||||||
{
|
{
|
||||||
esp_sleep_enable_timer_wakeup(2000000);
|
esp_sleep_enable_timer_wakeup(2000000);
|
||||||
@@ -91,7 +90,6 @@ TEST_CASE("wake up from light sleep using timer", "[deepsleep]")
|
|||||||
(tv_stop.tv_usec - tv_start.tv_usec) * 1e-3f;
|
(tv_stop.tv_usec - tv_start.tv_usec) * 1e-3f;
|
||||||
TEST_ASSERT_INT32_WITHIN(500, 2000, (int) dt);
|
TEST_ASSERT_INT32_WITHIN(500, 2000, (int) dt);
|
||||||
}
|
}
|
||||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
|
|
||||||
//NOTE: Explained in IDF-1445 | MR !14996
|
//NOTE: Explained in IDF-1445 | MR !14996
|
||||||
#if !(CONFIG_SPIRAM) || (CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL >= 16384)
|
#if !(CONFIG_SPIRAM) || (CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL >= 16384)
|
||||||
@@ -232,8 +230,6 @@ TEST_CASE("light sleep and frequency switching", "[deepsleep]")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
//IDF-5131
|
|
||||||
static void do_deep_sleep(void)
|
static void do_deep_sleep(void)
|
||||||
{
|
{
|
||||||
esp_sleep_enable_timer_wakeup(100000);
|
esp_sleep_enable_timer_wakeup(100000);
|
||||||
@@ -275,6 +271,7 @@ TEST_CASE_MULTIPLE_STAGES("enter deep sleep after abort", "[deepsleep][reset=abo
|
|||||||
check_abort_reset_and_sleep,
|
check_abort_reset_and_sleep,
|
||||||
check_sleep_reset);
|
check_sleep_reset);
|
||||||
|
|
||||||
|
#if SOC_RTC_FAST_MEM_SUPPORTED
|
||||||
static RTC_DATA_ATTR uint32_t s_wake_stub_var;
|
static RTC_DATA_ATTR uint32_t s_wake_stub_var;
|
||||||
|
|
||||||
static RTC_IRAM_ATTR void wake_stub(void)
|
static RTC_IRAM_ATTR void wake_stub(void)
|
||||||
@@ -300,12 +297,10 @@ static void check_wake_stub(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE_MULTIPLE_STAGES("can set sleep wake stub", "[deepsleep][reset=DEEPSLEEP_RESET]",
|
TEST_CASE_MULTIPLE_STAGES("can set sleep wake stub", "[deepsleep][reset=DEEPSLEEP_RESET]",
|
||||||
prepare_wake_stub,
|
prepare_wake_stub,
|
||||||
check_wake_stub);
|
check_wake_stub);
|
||||||
|
#endif // SOC_RTC_FAST_MEM_SUPPORTED
|
||||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
|
|
||||||
|
|
||||||
#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
|
#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
|
||||||
@@ -374,9 +369,7 @@ TEST_CASE_MULTIPLE_STAGES("can set sleep wake stub from stack in RTC RAM", "[dee
|
|||||||
|
|
||||||
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||||
|
|
||||||
|
#if SOC_PM_SUPPORT_EXT_WAKEUP
|
||||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
//IDF-5131
|
|
||||||
TEST_CASE("wake up using ext0 (13 high)", "[deepsleep][ignore]")
|
TEST_CASE("wake up using ext0 (13 high)", "[deepsleep][ignore]")
|
||||||
{
|
{
|
||||||
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
|
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_13));
|
||||||
@@ -430,8 +423,7 @@ TEST_CASE("wake up using ext1 when RTC_PERIPH is on (13 low)", "[deepsleep][igno
|
|||||||
ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW));
|
ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(BIT(GPIO_NUM_13), ESP_EXT1_WAKEUP_ALL_LOW));
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
|
#endif // SOC_PM_SUPPORT_EXT_WAKEUP
|
||||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
|
|
||||||
__attribute__((unused)) static float get_time_ms(void)
|
__attribute__((unused)) static float get_time_ms(void)
|
||||||
{
|
{
|
||||||
@@ -528,11 +520,30 @@ TEST_CASE("disable source trigger behavior", "[deepsleep]")
|
|||||||
|
|
||||||
#endif //SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
#endif //SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
|
||||||
|
|
||||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
//IDF-5131
|
|
||||||
static RTC_DATA_ATTR struct timeval start;
|
|
||||||
static void trigger_deepsleep(void)
|
static void trigger_deepsleep(void)
|
||||||
{
|
{
|
||||||
|
struct timeval start;
|
||||||
|
|
||||||
|
// Use NVS instead of RTC mem to store the start time of deep sleep
|
||||||
|
// Beacuse not all esp chips support RTC mem(such as esp32c2)
|
||||||
|
// Initialize NVS
|
||||||
|
esp_err_t err = nvs_flash_init();
|
||||||
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
// NVS partition was truncated and needs to be erased
|
||||||
|
// Retry nvs_flash_init
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
err = nvs_flash_init();
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
|
||||||
|
nvs_handle_t nvs_handle;
|
||||||
|
err = nvs_open("storage", NVS_READWRITE, &nvs_handle);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err));
|
||||||
|
} else {
|
||||||
|
printf("Done\n");
|
||||||
|
}
|
||||||
|
|
||||||
printf("Trigger deep sleep. Waiting for 10 sec ...\n");
|
printf("Trigger deep sleep. Waiting for 10 sec ...\n");
|
||||||
|
|
||||||
// Simulate the dispersion of the calibration coefficients at start-up.
|
// Simulate the dispersion of the calibration coefficients at start-up.
|
||||||
@@ -545,6 +556,14 @@ static void trigger_deepsleep(void)
|
|||||||
|
|
||||||
// Save start time. Deep sleep.
|
// Save start time. Deep sleep.
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(nvs_set_i32(nvs_handle, "start_sec", start.tv_sec));
|
||||||
|
ESP_ERROR_CHECK(nvs_set_i32(nvs_handle, "start_usec", start.tv_usec));
|
||||||
|
ESP_ERROR_CHECK(nvs_commit(nvs_handle));
|
||||||
|
nvs_close(nvs_handle);
|
||||||
|
// Deinit NVS to prevent Unity from complaining "The test leaked too much memory"
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_deinit());
|
||||||
|
|
||||||
esp_sleep_enable_timer_wakeup(1000);
|
esp_sleep_enable_timer_wakeup(1000);
|
||||||
// In function esp_deep_sleep_start() uses function esp_sync_timekeeping_timers()
|
// In function esp_deep_sleep_start() uses function esp_sync_timekeeping_timers()
|
||||||
// to prevent a negative time after wake up.
|
// to prevent a negative time after wake up.
|
||||||
@@ -553,11 +572,39 @@ static void trigger_deepsleep(void)
|
|||||||
|
|
||||||
static void check_time_deepsleep(void)
|
static void check_time_deepsleep(void)
|
||||||
{
|
{
|
||||||
struct timeval stop;
|
struct timeval start, stop;
|
||||||
|
|
||||||
|
// Initialize NVS
|
||||||
|
esp_err_t err = nvs_flash_init();
|
||||||
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
// NVS partition was truncated and needs to be erased
|
||||||
|
// Retry nvs_flash_init
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
err = nvs_flash_init();
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
|
||||||
|
nvs_handle_t nvs_handle;
|
||||||
|
err = nvs_open("storage", NVS_READWRITE, &nvs_handle);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err));
|
||||||
|
} else {
|
||||||
|
printf("Done\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get start time of deep sleep
|
||||||
|
ESP_ERROR_CHECK(nvs_get_i32(nvs_handle, "start_sec", (int32_t *)&start.tv_sec));
|
||||||
|
ESP_ERROR_CHECK(nvs_get_i32(nvs_handle, "start_usec", (int32_t *)&start.tv_usec));
|
||||||
|
nvs_close(nvs_handle);
|
||||||
|
// Deinit NVS to prevent Unity from complaining "The test leaked too much memory"
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_deinit());
|
||||||
|
|
||||||
|
// Reset must be caused by deep sleep
|
||||||
soc_reset_reason_t reason = esp_rom_get_reset_reason(0);
|
soc_reset_reason_t reason = esp_rom_get_reset_reason(0);
|
||||||
TEST_ASSERT(reason == RESET_REASON_CORE_DEEP_SLEEP);
|
TEST_ASSERT(reason == RESET_REASON_CORE_DEEP_SLEEP);
|
||||||
gettimeofday(&stop, NULL);
|
|
||||||
// Time dt_ms must in any case be positive.
|
// Time dt_ms must in any case be positive.
|
||||||
|
gettimeofday(&stop, NULL);
|
||||||
int dt_ms = (stop.tv_sec - start.tv_sec) * 1000 + (stop.tv_usec - start.tv_usec) / 1000;
|
int dt_ms = (stop.tv_sec - start.tv_sec) * 1000 + (stop.tv_usec - start.tv_usec) / 1000;
|
||||||
printf("delta time = %d \n", dt_ms);
|
printf("delta time = %d \n", dt_ms);
|
||||||
TEST_ASSERT_MESSAGE(dt_ms > 0, "Time in deep sleep is negative");
|
TEST_ASSERT_MESSAGE(dt_ms > 0, "Time in deep sleep is negative");
|
||||||
@@ -589,4 +636,3 @@ TEST_CASE("wake up using GPIO (2 or 4 low)", "[deepsleep][ignore]")
|
|||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
#endif // SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
|
#endif // SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
|
||||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
|
@@ -16,9 +16,6 @@
|
|||||||
#include "soc/soc_caps.h"
|
#include "soc/soc_caps.h"
|
||||||
|
|
||||||
|
|
||||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
//IDF-5131
|
|
||||||
|
|
||||||
static const char TAG[] = "rtc_8m";
|
static const char TAG[] = "rtc_8m";
|
||||||
|
|
||||||
static void test_deepsleep(bool force_rtc_periph)
|
static void test_deepsleep(bool force_rtc_periph)
|
||||||
@@ -40,7 +37,6 @@ TEST_CASE("Can use 8MD256 as RTC clock source in deepsleep", "[pm]")
|
|||||||
{
|
{
|
||||||
test_deepsleep(false);
|
test_deepsleep(false);
|
||||||
}
|
}
|
||||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
||||||
|
|
||||||
static void test_lightsleep(bool force_rtc_periph)
|
static void test_lightsleep(bool force_rtc_periph)
|
||||||
{
|
{
|
||||||
|
@@ -19,11 +19,11 @@ def deepsleep_test(dut: Dut, case_name: str) -> None:
|
|||||||
dut.expect(r'rst:.*\(%s\)' % reset_reason, timeout=10)
|
dut.expect(r'rst:.*\(%s\)' % reset_reason, timeout=10)
|
||||||
|
|
||||||
|
|
||||||
# IDF-5131
|
|
||||||
@pytest.mark.esp32
|
@pytest.mark.esp32
|
||||||
@pytest.mark.esp32s2
|
@pytest.mark.esp32s2
|
||||||
@pytest.mark.esp32s3
|
@pytest.mark.esp32s3
|
||||||
@pytest.mark.esp32c3
|
@pytest.mark.esp32c3
|
||||||
|
@pytest.mark.esp32c2
|
||||||
@pytest.mark.generic
|
@pytest.mark.generic
|
||||||
def test_rtc_8md256_deepsleep(dut: Dut) -> None:
|
def test_rtc_8md256_deepsleep(dut: Dut) -> None:
|
||||||
deepsleep_test(dut, '"Can use 8MD256 as RTC clock source in deepsleep"')
|
deepsleep_test(dut, '"Can use 8MD256 as RTC clock source in deepsleep"')
|
||||||
|
@@ -90,12 +90,6 @@ examples/system/ipc/ipc_isr:
|
|||||||
temporary: true
|
temporary: true
|
||||||
reason: the other targets are not tested yet
|
reason: the other targets are not tested yet
|
||||||
|
|
||||||
examples/system/light_sleep:
|
|
||||||
disable:
|
|
||||||
- if: IDF_TARGET == "esp32c2"
|
|
||||||
temporary: true
|
|
||||||
reason: target esp32c2 is not supported yet
|
|
||||||
|
|
||||||
examples/system/ota/advanced_https_ota:
|
examples/system/ota/advanced_https_ota:
|
||||||
disable_test:
|
disable_test:
|
||||||
- if: IDF_TARGET == "esp32c2"
|
- if: IDF_TARGET == "esp32c2"
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
| Supported Targets | ESP32 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
|
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
|
||||||
| ----------------- | ----- | -------- | -------- | -------- |
|
| ----------------- | ----- | -------- | -------- | -------- | -------- |
|
||||||
|
|
||||||
# Light Sleep Example
|
# Light Sleep Example
|
||||||
|
|
||||||
|
@@ -54,8 +54,14 @@ static void light_sleep_task(void *args)
|
|||||||
wakeup_reason = "other";
|
wakeup_reason = "other";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#if CONFIG_NEWLIB_NANO_FORMAT
|
||||||
|
/* printf in newlib-nano does not support %ll format, causing example test fail */
|
||||||
|
printf("Returned from light sleep, reason: %s, t=%d ms, slept for %d ms\n",
|
||||||
|
wakeup_reason, (int) (t_after_us / 1000), (int) ((t_after_us - t_before_us) / 1000));
|
||||||
|
#else
|
||||||
printf("Returned from light sleep, reason: %s, t=%lld ms, slept for %lld ms\n",
|
printf("Returned from light sleep, reason: %s, t=%lld ms, slept for %lld ms\n",
|
||||||
wakeup_reason, t_after_us / 1000, (t_after_us - t_before_us) / 1000);
|
wakeup_reason, t_after_us / 1000, (t_after_us - t_before_us) / 1000);
|
||||||
|
#endif
|
||||||
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) {
|
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) {
|
||||||
/* Waiting for the gpio inactive, or the chip will continously trigger wakeup*/
|
/* Waiting for the gpio inactive, or the chip will continously trigger wakeup*/
|
||||||
example_wait_gpio_inactive();
|
example_wait_gpio_inactive();
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: CC0-1.0
|
# SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@@ -8,11 +8,11 @@ import pytest
|
|||||||
from pytest_embedded import Dut
|
from pytest_embedded import Dut
|
||||||
|
|
||||||
|
|
||||||
# IDF-5053
|
|
||||||
@pytest.mark.esp32
|
@pytest.mark.esp32
|
||||||
@pytest.mark.esp32s2
|
@pytest.mark.esp32s2
|
||||||
@pytest.mark.esp32s3
|
@pytest.mark.esp32s3
|
||||||
@pytest.mark.esp32c3
|
@pytest.mark.esp32c3
|
||||||
|
@pytest.mark.esp32c2
|
||||||
@pytest.mark.generic
|
@pytest.mark.generic
|
||||||
def test_light_sleep(dut: Dut) -> None:
|
def test_light_sleep(dut: Dut) -> None:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user