example_test.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from __future__ import print_function
  2. import re
  3. import time
  4. import ttfw_idf
  5. ENTERING_SLEEP_STR = 'Entering light sleep'
  6. EXIT_SLEEP_REGEX = re.compile(r'Returned from light sleep, reason: (\w+), t=(\d+) ms, slept for (\d+) ms')
  7. WAITING_FOR_GPIO_STR = re.compile(r'Waiting for GPIO\d to go high...')
  8. WAKEUP_INTERVAL_MS = 2000
  9. @ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
  10. def test_examples_system_light_sleep(env, extra_data):
  11. dut = env.get_dut('light_sleep_example', 'examples/system/light_sleep')
  12. dut.start_app()
  13. # Ensure DTR and RTS are de-asserted for proper control of GPIO0
  14. dut.port_inst.setDTR(False)
  15. dut.port_inst.setRTS(False)
  16. # enter sleep first time
  17. dut.expect(ENTERING_SLEEP_STR, timeout=30)
  18. # don't check timing here, might be cache dependent
  19. dut.expect(EXIT_SLEEP_REGEX)
  20. print('Got first sleep period')
  21. # enter sleep second time
  22. dut.expect(ENTERING_SLEEP_STR)
  23. groups = dut.expect(EXIT_SLEEP_REGEX)
  24. print('Got second sleep period, wakeup from {}, slept for {}'.format(groups[0], groups[2]))
  25. # sleep time error should be less than 1ms
  26. assert(groups[0] == 'timer' and int(groups[2]) == WAKEUP_INTERVAL_MS)
  27. # this time we'll test gpio wakeup
  28. dut.expect(ENTERING_SLEEP_STR)
  29. print('Pulling GPIO0 low using DTR')
  30. dut.port_inst.setDTR(True)
  31. time.sleep(1)
  32. groups = dut.expect(EXIT_SLEEP_REGEX)
  33. print('Got third sleep period, wakeup from {}, slept for {}'.format(groups[0], groups[2]))
  34. assert(groups[0] == 'pin' and int(groups[2]) < WAKEUP_INTERVAL_MS)
  35. dut.expect(WAITING_FOR_GPIO_STR)
  36. print('Is waiting for GPIO...')
  37. dut.port_inst.setDTR(False)
  38. dut.expect(ENTERING_SLEEP_STR)
  39. print('Went to sleep again')
  40. groups = dut.expect(EXIT_SLEEP_REGEX)
  41. assert(groups[0] == 'timer' and int(groups[2]) == WAKEUP_INTERVAL_MS)
  42. print('Woke up from timer again')
  43. if __name__ == '__main__':
  44. test_examples_system_light_sleep()