example_test.py 937 B

12345678910111213141516171819202122232425262728293031
  1. from __future__ import unicode_literals
  2. import re
  3. import ttfw_idf
  4. import os
  5. @ttfw_idf.idf_example_test(env_tag='Example_WIFI')
  6. def test_examples_icmp_echo(env, extra_data):
  7. dut = env.get_dut('icmp_echo', 'examples/protocols/icmp_echo')
  8. dut.start_app()
  9. dut.expect('example_connect: Connected to')
  10. dut.expect('esp>')
  11. ping_dest = os.getenv('EXAMPLE_ICMP_SERVER', 'www.espressif.com')
  12. dut.write('ping {}'.format(ping_dest))
  13. ip_re = r'\.'.join((r'\d{1,3}',) * 4)
  14. ip = dut.expect(re.compile(r'64 bytes from ({}) icmp_seq=1 ttl=\d+ time=\d+ ms'.format(ip_re)))[0]
  15. # expect at least one more (there could be lost packets)
  16. dut.expect(re.compile(r'64 bytes from {} icmp_seq=[2-5] ttl=\d+ time='.format(ip)))
  17. dut.expect(re.compile(r'5 packets transmitted, [2-5] received, \d{1,3}% packet loss'))
  18. dut.write('')
  19. dut.expect('esp>')
  20. if __name__ == '__main__':
  21. test_examples_icmp_echo()