Skip to content

Commit 5607051

Browse files
committed
tests: move lossy endpoint implementation to a separate class
Rather than adding test-specific behaviour to the base Endpoint object, move the control-protocol-drop implementation to a new LossyEndpoint object, internal to the retry_timeout test. We may want to move this to mctpenv later, but it's only used by the one test currently, and we don't have enough of an API definition to make that common. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
1 parent 2df7f51 commit 5607051

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

tests/mctpenv/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,14 @@ def to_buf(self):
318318
return bytes([flags, self.cmd]) + self.data
319319

320320
class Endpoint:
321-
def __init__(self, iface, lladdr, ep_uuid = None, eid = 0, types = None, timeout_opcodes = set(), timeout_count = 0):
321+
def __init__(self, iface, lladdr, ep_uuid = None, eid = 0, types = None):
322322
self.iface = iface
323323
self.lladdr = lladdr
324324
self.uuid = ep_uuid or uuid.uuid1()
325325
self.eid = eid
326326
self.types = types or [0]
327327
self.bridged_eps = []
328328
self.allocated_pool = None # or (start, size)
329-
self.timeout_opcodes = timeout_opcodes
330-
self.timeout_count = timeout_count
331329

332330
# keyed by (type, type-specific-instance)
333331
self.commands = {}
@@ -370,11 +368,6 @@ async def handle_mctp_control(self, sock, addr, data):
370368
# Use IID from request, zero Rq and D bits
371369
hdr = [iid, opcode]
372370

373-
if opcode in self.timeout_opcodes:
374-
if self.timeout_count > 0:
375-
self.timeout_count -= 1
376-
return
377-
378371
if opcode == 1:
379372
# Set Endpoint ID
380373
(op, eid) = data[2:]

tests/test_mctpd.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,22 @@ async def test_register_vdm_type_support_errors(dbus, mctpd):
13781378
assert str(ex.value) == "VDM type already registered"
13791379

13801380
async def test_query_peer_properties_retry_timeout(nursery, dbus, sysnet):
1381+
class LossyEndpoint(Endpoint):
1382+
"""An endpoint object that may drop a specific number (timeout_count)
1383+
of MCTP Control Protocol requests.
1384+
"""
1385+
def __init__(self, *args, **kwargs):
1386+
super().__init__(*args, **kwargs)
1387+
self.timeout_count = 0
1388+
self.timeout_opcode = 0x05 # Get Message Type Support
1389+
1390+
async def handle_mctp_control(self, sock, addr, data):
1391+
rq = data[0] & 0x80
1392+
opcode = data[1]
1393+
if rq and opcode == self.timeout_opcode and self.timeout_count:
1394+
self.timeout_count -= 1
1395+
return
1396+
return await super().handle_mctp_control(sock, addr, data)
13811397

13821398
# activate mctpd
13831399
mctpd = MctpdWrapper(dbus, sysnet)
@@ -1389,7 +1405,7 @@ async def test_query_peer_properties_retry_timeout(nursery, dbus, sysnet):
13891405
# define expected message types
13901406
# add a normal endpoint to network
13911407
expected_types = [0, 1, 2]
1392-
ep = Endpoint(iface, bytes([0x1a]), eid=15, types=expected_types)
1408+
ep = LossyEndpoint(iface, bytes([0x1a]), eid=15, types=expected_types)
13931409
mctpd.network.add_endpoint(ep)
13941410

13951411
# call setup_endpoint on ep, which will allocate a object path for it
@@ -1401,7 +1417,6 @@ async def test_query_peer_properties_retry_timeout(nursery, dbus, sysnet):
14011417
assert objtypes == expected_types
14021418

14031419
ep.lladdr = bytes([0x1b]) # change lladdr to force retry
1404-
ep.timeout_opcodes.add(0x05) # set Message Type Support would timeout
14051420
ep.timeout_count = 2 # timeout twice before responding
14061421

14071422
# call setup_endpoint again, which will trigger query of peer properties

0 commit comments

Comments
 (0)