example_test.py 2.1 KB

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