pytest_deep_sleep.py 2.7 KB

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