pytest_deep_sleep.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: CC0-1.0
  3. import logging
  4. import time
  5. import pytest
  6. from pytest_embedded import Dut
  7. touch_wake_up_support = ['esp32', 'esp32s2']
  8. CONFIGS = [
  9. pytest.param('esp32_singlecore', marks=[pytest.mark.esp32]),
  10. pytest.param('basic', marks=[pytest.mark.esp32, pytest.mark.esp32s2, pytest.mark.esp32s3, pytest.mark.esp32c3, pytest.mark.esp32c6, pytest.mark.esp32c2]),
  11. ]
  12. @pytest.mark.parametrize('config', CONFIGS, indirect=True)
  13. @pytest.mark.generic
  14. def test_deep_sleep(dut: Dut) -> None:
  15. def expect_enable_deep_sleep_touch() -> None:
  16. # different targets configure different wake pin(s)
  17. wake_pads = {
  18. 'esp32': [8,9],
  19. 'esp32s2': [9],
  20. }[dut.target]
  21. logging.info('Expecting to see wakeup configured on pad(s): {}'.format(wake_pads))
  22. expect_items = ['Enabling timer wakeup, 20s']
  23. for pad in wake_pads:
  24. expect_items += [r'Touch pad #{} average: \d+, wakeup threshold set to \d+.'.format(pad)]
  25. expect_items += ['Enabling touch pad wakeup']
  26. for exp in expect_items:
  27. dut.expect(exp, timeout=10)
  28. def expect_enable_deep_sleep_no_touch() -> None:
  29. dut.expect_exact('Enabling timer wakeup, 20s', timeout=10)
  30. if dut.target in touch_wake_up_support:
  31. expect_enable_deep_sleep = expect_enable_deep_sleep_touch
  32. else:
  33. expect_enable_deep_sleep = expect_enable_deep_sleep_no_touch
  34. expect_enable_deep_sleep()
  35. dut.expect_exact('Not a deep sleep reset')
  36. dut.expect_exact('Entering deep sleep')
  37. start_sleep = time.time()
  38. logging.info('Waiting for wakeup...')
  39. dut.expect_exact('boot: ESP-IDF') # first output that's the same on all chips
  40. sleep_time = time.time() - start_sleep
  41. logging.info('Host measured sleep time at {:.2f}s'.format(sleep_time))
  42. assert 18 < sleep_time < 22 # note: high tolerance as measuring time on the host may have some timing skew
  43. # This line indicates that the CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP option set in sdkconfig.defaults
  44. # has correctly allowed skipping verification on wakeup
  45. # Note: this feature depends on rtc mem
  46. if dut.app.sdkconfig.get('SOC_RTC_MEM_SUPPORTED') is True:
  47. dut.expect_exact('boot: Fast booting app from partition', timeout=2)
  48. # Check that it measured 2xxxxms in deep sleep, i.e at least 20 seconds:
  49. expect_enable_deep_sleep()
  50. dut.expect(r'Wake up from timer. Time spent in deep sleep: 2\d{4}ms', timeout=2)
  51. dut.expect_exact('Entering deep sleep')