pytest_ulp_riscv_gpio.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: CC0-1.0
  3. import time
  4. import pexpect
  5. import pytest
  6. from pytest_embedded import Dut
  7. @pytest.mark.esp32s2
  8. @pytest.mark.esp32s3
  9. @pytest.mark.generic
  10. def test_ulp_riscv_gpio(dut: Dut) -> None:
  11. dut.expect_exact('Not a ULP-RISC-V wakeup, initializing it!')
  12. dut.expect_exact('Entering in deep sleep')
  13. # Give the chip time to enter deepsleep
  14. time.sleep(1)
  15. # Run two times to make sure device sleep
  16. # and wake up properly
  17. for i in range(0, 2):
  18. # Set GPIO0 using DTR
  19. dut.serial.proc.setDTR(i % 2 == 0)
  20. dut.expect_exact('ULP-RISC-V woke up the main CPU!', timeout=5)
  21. # Check GPIO state
  22. state = 'Low' if i % 2 == 0 else 'High'
  23. dut.expect(r'ULP-RISC-V read changes in GPIO_0 current is: %s' % state, timeout=5)
  24. # Go back to sleep
  25. dut.expect_exact('Entering in deep sleep', timeout=5)
  26. try:
  27. # We expect a timeout here, otherwise it means that
  28. # the main CPU woke up unexpectedly!
  29. dut.expect('ULP-RISC-V woke up the main CPU!', timeout=20)
  30. raise Exception('Main CPU woke up unexpectedly!')
  31. except pexpect.exceptions.TIMEOUT:
  32. pass