From 901ba0b3d84c58b2ec1491a09729687e56e1bc74 Mon Sep 17 00:00:00 2001 From: Nils Weiss Date: Thu, 11 Jun 2026 22:15:55 +0200 Subject: [PATCH 1/2] Enhance CoAP socket tests: add interoperability and stress testing with libcoap AI-Assisted: no --- test/contrib/coap_socket.uts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/contrib/coap_socket.uts b/test/contrib/coap_socket.uts index fbd857b2765..751c81c0334 100644 --- a/test/contrib/coap_socket.uts +++ b/test/contrib/coap_socket.uts @@ -21,10 +21,6 @@ handler = logging.StreamHandler(log_stream) log_runtime.addHandler(handler) log_coap_sock.addHandler(handler) -coap_client_bin = shutil.which("coap-client") -coap_server_bin = shutil.which("coap-server") -libcoap_available = coap_client_bin is not None and coap_server_bin is not None - def _pick_port(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) @@ -223,6 +219,13 @@ with CoAPSocket("127.0.0.1", 5683, lst_resources=lst_resources) as coap_server, assert rcv.token == pkt.token + Testing interoperability with libcoap +~ linux + += prepare coap-client and coap-server binaries + +coap_client_bin = shutil.which("coap-client") +coap_server_bin = shutil.which("coap-server") +libcoap_available = coap_client_bin is not None and coap_server_bin is not None = libcoap client -> CoAPSocket server @@ -261,6 +264,7 @@ else: _cleanup_process(libcoap_server) + Stress tests +~ linux = Stress: libcoap client -> CoAPSocket server From 2a7b5efcd608671350d1ce945c95d95dab54d3be Mon Sep 17 00:00:00 2001 From: Nils Weiss Date: Thu, 11 Jun 2026 22:23:57 +0200 Subject: [PATCH 2/2] Fix windows unit tests AI-Assisted: no --- scapy/contrib/coap_socket.py | 4 +++- test/contrib/coap_socket.uts | 12 ++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/scapy/contrib/coap_socket.py b/scapy/contrib/coap_socket.py index 2c1cbd665b0..465b04e80a2 100644 --- a/scapy/contrib/coap_socket.py +++ b/scapy/contrib/coap_socket.py @@ -20,6 +20,7 @@ Type ) +from scapy.consts import LINUX from scapy.error import Scapy_Exception from scapy.packet import Packet from scapy.contrib.coap import CoAP, coap_options, coap_codes, EMPTY_MESSAGE, GET, \ @@ -444,7 +445,8 @@ def __init__(self, if sock is None: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) + if LINUX: + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) s.bind((self.ip, self.port)) self.sock = SimpleSocket(s) else: diff --git a/test/contrib/coap_socket.uts b/test/contrib/coap_socket.uts index 751c81c0334..fbd857b2765 100644 --- a/test/contrib/coap_socket.uts +++ b/test/contrib/coap_socket.uts @@ -21,6 +21,10 @@ handler = logging.StreamHandler(log_stream) log_runtime.addHandler(handler) log_coap_sock.addHandler(handler) +coap_client_bin = shutil.which("coap-client") +coap_server_bin = shutil.which("coap-server") +libcoap_available = coap_client_bin is not None and coap_server_bin is not None + def _pick_port(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) @@ -219,13 +223,6 @@ with CoAPSocket("127.0.0.1", 5683, lst_resources=lst_resources) as coap_server, assert rcv.token == pkt.token + Testing interoperability with libcoap -~ linux - -= prepare coap-client and coap-server binaries - -coap_client_bin = shutil.which("coap-client") -coap_server_bin = shutil.which("coap-server") -libcoap_available = coap_client_bin is not None and coap_server_bin is not None = libcoap client -> CoAPSocket server @@ -264,7 +261,6 @@ else: _cleanup_process(libcoap_server) + Stress tests -~ linux = Stress: libcoap client -> CoAPSocket server