example_test.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from __future__ import unicode_literals
  2. import re
  3. import time
  4. import ttfw_idf
  5. from tiny_test_fw import Utility
  6. @ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32'])
  7. def test_examples_ulp(env, extra_data):
  8. dut = env.get_dut('ulp', 'examples/system/ulp_fsm/ulp')
  9. dut.start_app()
  10. dut.expect_all('Not ULP wakeup, initializing ULP',
  11. 'Entering deep sleep',
  12. timeout=30)
  13. def generate_gpio0_events():
  14. for _ in range(5):
  15. dut.port_inst.setDTR(True) # Pulling GPIO0 low using DTR
  16. time.sleep(0.25)
  17. dut.port_inst.setDTR(False)
  18. time.sleep(0.25)
  19. nvs_value = None
  20. for _ in range(5):
  21. generate_gpio0_events()
  22. dut.expect('ULP wakeup, saving pulse count', timeout=5)
  23. Utility.console_log('Woke up...')
  24. init_count = int(dut.expect(re.compile(r'Read pulse count from NVS:\s+(\d+)'), timeout=5)[0], 10)
  25. assert nvs_value in (init_count, None), ('Read count is {} and previously written value is {}'
  26. ''.format(init_count, nvs_value))
  27. inc = int(dut.expect(re.compile(r'Pulse count from ULP:\s+(\d+)'), timeout=5)[0], 10)
  28. assert inc in (5, 6), 'pulse count is {}'.format(inc)
  29. new_count = int(dut.expect(re.compile(r'Wrote updated pulse count to NVS:\s+(\d+)'), timeout=5)[0], 10)
  30. assert init_count + inc == new_count, '{} + {} != {}'.format(init_count, inc, new_count)
  31. nvs_value = new_count
  32. Utility.console_log('Pulse count written to NVS: {}. Entering deep sleep...'.format(nvs_value))
  33. dut.expect('Entering deep sleep', timeout=5)
  34. if __name__ == '__main__':
  35. test_examples_ulp()