pytest_deep_sleep.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # SPDX-FileCopyrightText: 2022 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]),
  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. 'Entering deep sleep']
  27. for exp in expect_items:
  28. dut.expect(exp, timeout=10)
  29. def expect_enable_deep_sleep_no_touch() -> None:
  30. dut.expect_exact('Enabling timer wakeup, 20s', timeout=10)
  31. dut.expect_exact('Entering deep sleep', timeout=10)
  32. if dut.target in touch_wake_up_support:
  33. expect_enable_deep_sleep = expect_enable_deep_sleep_touch
  34. else:
  35. expect_enable_deep_sleep = expect_enable_deep_sleep_no_touch
  36. dut.expect_exact('Not a deep sleep reset')
  37. expect_enable_deep_sleep()
  38. start_sleep = time.time()
  39. logging.info('Waiting for wakeup...')
  40. dut.expect_exact('boot: ESP-IDF') # first output that's the same on all chips
  41. sleep_time = time.time() - start_sleep
  42. logging.info('Host measured sleep time at {:.2f}s'.format(sleep_time))
  43. assert 18 < sleep_time < 22 # note: high tolerance as measuring time on the host may have some timing skew
  44. # This line indicates that the CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP option set in sdkconfig.defaults
  45. # has correctly allowed skipping verification on wakeup
  46. dut.expect_exact('boot: Fast booting app from partition', timeout=2)
  47. # Check that it measured 2xxxxms in deep sleep, i.e at least 20 seconds:
  48. dut.expect(r'Wake up from timer. Time spent in deep sleep: 2\d{4}ms', timeout=2)
  49. expect_enable_deep_sleep()