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