2025-01-08 12:59:03 +08:00
|
|
|
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
2022-03-08 11:15:37 +08:00
|
|
|
# SPDX-License-Identifier: CC0-1.0
|
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from pytest_embedded import Dut
|
2025-02-24 10:18:03 +08:00
|
|
|
from pytest_embedded_idf.utils import idf_parametrize
|
2022-03-08 11:15:37 +08:00
|
|
|
|
2022-06-23 17:26:51 +08:00
|
|
|
|
|
|
|
@pytest.mark.generic
|
2025-02-24 10:18:03 +08:00
|
|
|
@idf_parametrize(
|
|
|
|
'config,target', [('esp32_singlecore', 'esp32'), ('basic', 'supported_targets')], indirect=['config', 'target']
|
|
|
|
)
|
2022-06-23 17:26:51 +08:00
|
|
|
def test_deep_sleep(dut: Dut) -> None:
|
2025-04-23 18:24:28 +08:00
|
|
|
dut.expect_exact('Enabling timer wakeup, 20s', timeout=10)
|
2023-03-02 20:49:14 +08:00
|
|
|
dut.expect_exact('Not a deep sleep reset')
|
|
|
|
dut.expect_exact('Entering deep sleep')
|
2022-03-08 11:15:37 +08:00
|
|
|
|
|
|
|
start_sleep = time.time()
|
|
|
|
logging.info('Waiting for wakeup...')
|
|
|
|
dut.expect_exact('boot: ESP-IDF') # first output that's the same on all chips
|
|
|
|
|
|
|
|
sleep_time = time.time() - start_sleep
|
|
|
|
logging.info('Host measured sleep time at {:.2f}s'.format(sleep_time))
|
2022-03-16 11:23:32 +08:00
|
|
|
assert 18 < sleep_time < 22 # note: high tolerance as measuring time on the host may have some timing skew
|
2022-03-08 11:15:37 +08:00
|
|
|
|
2024-06-14 15:39:42 +03:00
|
|
|
dut.expect_exact('boot: Fast booting app from partition', timeout=2)
|
2022-03-08 11:15:37 +08:00
|
|
|
|
|
|
|
# Check that it measured 2xxxxms in deep sleep, i.e at least 20 seconds:
|
2025-04-23 18:24:28 +08:00
|
|
|
dut.expect_exact('Enabling timer wakeup, 20s', timeout=10)
|
2023-03-02 20:49:14 +08:00
|
|
|
dut.expect(r'Wake up from timer. Time spent in deep sleep: 2\d{4}ms', timeout=2)
|
|
|
|
dut.expect_exact('Entering deep sleep')
|