From 5f4e2cf39113541f4b0a7dc34502d394309fd483 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 11 May 2020 08:20:43 +0200 Subject: [PATCH] socket examples: fix random ci failure on reading ipv6 address dut.expect() returns groups of a matching regex, but could be truncated upon reading/buffering. fixed by forcing expect to acquire exactly 8 octets of IPv6 address, i.e. not supporting short-handed entries such as fe80::0000.. --- examples/protocols/sockets/tcp_server/example_test.py | 3 ++- examples/protocols/sockets/udp_server/example_test.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/protocols/sockets/tcp_server/example_test.py b/examples/protocols/sockets/tcp_server/example_test.py index db6cece26e..11b631bd92 100644 --- a/examples/protocols/sockets/tcp_server/example_test.py +++ b/examples/protocols/sockets/tcp_server/example_test.py @@ -65,7 +65,8 @@ def test_examples_protocol_socket(env, extra_data): dut1.start_app() ipv4 = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)[0] - ipv6 = dut1.expect(re.compile(r" IPv6 address: ([0-9A-Fa-f\:]+)"), timeout=30)[0] + ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) # expect all 8 octets from IPv6 (assumes it's printed in the long form) + ipv6 = dut1.expect(re.compile(r' IPv6 address: ({})'.format(ipv6_r)), timeout=30)[0] print("Connected with IPv4={} and IPv6={}".format(ipv4, ipv6)) # test IPv4 diff --git a/examples/protocols/sockets/udp_server/example_test.py b/examples/protocols/sockets/udp_server/example_test.py index d78358ef94..0173c8c37e 100644 --- a/examples/protocols/sockets/udp_server/example_test.py +++ b/examples/protocols/sockets/udp_server/example_test.py @@ -63,7 +63,8 @@ def test_examples_protocol_socket(env, extra_data): dut1.start_app() ipv4 = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)[0] - ipv6 = dut1.expect(re.compile(r" IPv6 address: ([0-9A-Fa-f\:]+)"), timeout=30)[0] + ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) # expect all 8 octets from IPv6 (assumes it's printed in the long form) + ipv6 = dut1.expect(re.compile(r' IPv6 address: ({})'.format(ipv6_r)), timeout=30)[0] print("Connected with IPv4={} and IPv6={}".format(ipv4, ipv6)) # test IPv4