pytest_ulp_fsm.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. @pytest.mark.esp32
  8. @pytest.mark.generic
  9. def test_ulp_fsm(dut: Dut) -> None:
  10. dut.expect_exact('Not ULP wakeup')
  11. dut.expect_exact('Entering deep sleep')
  12. def generate_gpio0_events() -> None:
  13. for _ in range(5):
  14. dut.serial.proc.setDTR(True) # Pulling GPIO0 low using DTR
  15. time.sleep(0.25)
  16. dut.serial.proc.setDTR(False)
  17. time.sleep(0.25)
  18. nvs_value = None
  19. for _ in range(5):
  20. generate_gpio0_events()
  21. dut.expect_exact('ULP wakeup, saving pulse count', timeout=5)
  22. logging.info('Woke up...')
  23. init_count = int(dut.expect(r'Read pulse count from NVS:\s+(\d+)', timeout=5).group(1), 10)
  24. assert nvs_value in (init_count, None), ('Read count is {} and previously written value is {}'
  25. ''.format(init_count, nvs_value))
  26. inc = int(dut.expect(r'Pulse count from ULP:\s+(\d+)', timeout=5).group(1), 10)
  27. assert inc in (5, 6), 'pulse count is {}'.format(inc)
  28. new_count = int(dut.expect(r'Wrote updated pulse count to NVS:\s+(\d+)', timeout=5).group(1), 10)
  29. assert init_count + inc == new_count, '{} + {} != {}'.format(init_count, inc, new_count)
  30. nvs_value = new_count
  31. logging.info('Pulse count written to NVS: {}. Entering deep sleep...'.format(nvs_value))
  32. dut.expect_exact('Entering deep sleep', timeout=5)