From a0127919bcdad884160a9534590096894a6ecf62 Mon Sep 17 00:00:00 2001 From: stijn Date: Tue, 24 Oct 2023 17:08:43 +0200 Subject: [PATCH] tests: Make socket tests compatible with CPython on windows. Note these are mostly the 'bare' socket tests, not the ssl/tls ones for instance: most of these don't run on CPython because of incompatible wrap_socket() arguments. The change mostly consists of checking the WSA error codes next to the errno ones and these are written as numeric values because the names (like WSAEAGAIN) are only available in CPython and not in micropython. Signed-off-by: stijn --- tests/extmod/socket_tcp_basic.py | 2 +- tests/extmod/socket_udp_nonblock.py | 2 +- tests/multi_net/asyncio_tcp_client_rst.py | 2 +- tests/multi_net/asyncio_tcp_client_rst.py.exp | 2 +- tests/multi_net/tcp_accept_recv.py | 2 +- tests/net_hosted/accept_nonblock.py | 2 +- tests/net_hosted/accept_timeout.py | 4 +++- tests/net_hosted/connect_nonblock.py | 2 +- tests/net_inet/ssl_errors.py | 2 +- 9 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/extmod/socket_tcp_basic.py b/tests/extmod/socket_tcp_basic.py index ebd30f7862..30d7dbd44e 100644 --- a/tests/extmod/socket_tcp_basic.py +++ b/tests/extmod/socket_tcp_basic.py @@ -11,4 +11,4 @@ s = socket.socket() try: s.recv(1) except OSError as er: - print("ENOTCONN:", er.errno == errno.ENOTCONN) + print("ENOTCONN:", er.errno in (errno.ENOTCONN, 10057)) diff --git a/tests/extmod/socket_udp_nonblock.py b/tests/extmod/socket_udp_nonblock.py index 1e74e2917d..dae2be2e52 100644 --- a/tests/extmod/socket_udp_nonblock.py +++ b/tests/extmod/socket_udp_nonblock.py @@ -18,4 +18,4 @@ s.settimeout(0) try: s.recv(1) except OSError as er: - print("EAGAIN:", er.errno == errno.EAGAIN) + print("EAGAIN:", er.errno in (errno.EAGAIN, 10035)) diff --git a/tests/multi_net/asyncio_tcp_client_rst.py b/tests/multi_net/asyncio_tcp_client_rst.py index af70c2e22e..f2d18ed0b0 100644 --- a/tests/multi_net/asyncio_tcp_client_rst.py +++ b/tests/multi_net/asyncio_tcp_client_rst.py @@ -21,7 +21,7 @@ async def handle_connection(reader, writer): writer.close() await writer.wait_closed() except OSError as er: - print("OSError", er.errno) + print("OSError", er.errno in (22, 104)) ev.set() diff --git a/tests/multi_net/asyncio_tcp_client_rst.py.exp b/tests/multi_net/asyncio_tcp_client_rst.py.exp index 920d1bb8d7..8dee3c14a3 100644 --- a/tests/multi_net/asyncio_tcp_client_rst.py.exp +++ b/tests/multi_net/asyncio_tcp_client_rst.py.exp @@ -1,5 +1,5 @@ --- instance0 --- b'GET / HTTP' -OSError 104 +OSError True --- instance1 --- diff --git a/tests/multi_net/tcp_accept_recv.py b/tests/multi_net/tcp_accept_recv.py index dee14e3b97..d9b700fb62 100644 --- a/tests/multi_net/tcp_accept_recv.py +++ b/tests/multi_net/tcp_accept_recv.py @@ -17,7 +17,7 @@ def instance0(): try: print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN except OSError as er: - print(er.errno in (107, 128)) + print(er.errno in (107, 128, 10057)) s.close() diff --git a/tests/net_hosted/accept_nonblock.py b/tests/net_hosted/accept_nonblock.py index 30d2033e65..915174a808 100644 --- a/tests/net_hosted/accept_nonblock.py +++ b/tests/net_hosted/accept_nonblock.py @@ -9,5 +9,5 @@ s.listen(1) try: s.accept() except OSError as er: - print(er.errno == 11) # 11 is EAGAIN + print(er.errno in (11, 10035)) # 11 is EAGAIN s.close() diff --git a/tests/net_hosted/accept_timeout.py b/tests/net_hosted/accept_timeout.py index 865d2aad26..2f047ee843 100644 --- a/tests/net_hosted/accept_timeout.py +++ b/tests/net_hosted/accept_timeout.py @@ -15,5 +15,7 @@ s.listen(1) try: s.accept() except OSError as er: - print(er.errno in (errno.ETIMEDOUT, "timed out")) # CPython uses a string instead of errno + print( + er.errno == errno.ETIMEDOUT or str(er) == "timed out" + ) # CPython uses a string instead of errno s.close() diff --git a/tests/net_hosted/connect_nonblock.py b/tests/net_hosted/connect_nonblock.py index 781f1a4ee2..4640dd5808 100644 --- a/tests/net_hosted/connect_nonblock.py +++ b/tests/net_hosted/connect_nonblock.py @@ -9,7 +9,7 @@ def test(peer_addr): try: s.connect(peer_addr) except OSError as er: - print(er.errno == errno.EINPROGRESS) + print(er.errno in (errno.EINPROGRESS, 10035)) s.close() diff --git a/tests/net_inet/ssl_errors.py b/tests/net_inet/ssl_errors.py index bc4e5910bc..5798a62f46 100644 --- a/tests/net_inet/ssl_errors.py +++ b/tests/net_inet/ssl_errors.py @@ -12,7 +12,7 @@ def test(addr, hostname, block=True): s.connect(addr) print("connected") except OSError as e: - if e.errno != errno.EINPROGRESS: + if e.errno not in (errno.EINPROGRESS, 10035): raise print("EINPROGRESS")