example_test.py 2.1 KB

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