Skip to content

Commit 35d5993

Browse files
committed
tests: use a fixture for setting up a routed endpoint
We have a few cases of boilerplate in the test code, where we're setting up an endpoint to communicate with mctpd. Use a fixure - routed_ep - for this pattern, and replace the boilerplate. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
1 parent 16f617f commit 35d5993

File tree

2 files changed

+31
-59
lines changed

2 files changed

+31
-59
lines changed

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,20 @@ def autojump_clock():
4343
Custom autojump clock with a reasonable threshold for non-time I/O waits
4444
"""
4545
return trio.testing.MockClock(autojump_threshold=0.01)
46+
47+
@pytest.fixture
48+
async def routed_ep(mctpd):
49+
"""
50+
Return a routable endpoint (using the default sysnet ep that already
51+
exists), with routing established, but no mctpd registration.
52+
"""
53+
ep = mctpd.network.endpoints[0]
54+
iface = mctpd.system.interfaces[0]
55+
56+
ep.eid = 9
57+
route = mctpd.system.Route(ep.eid, 1, iface = iface)
58+
neigh = mctpd.system.Neighbour(iface, ep.lladdr, ep.eid)
59+
await mctpd.system.add_route(route)
60+
await mctpd.system.add_neighbour(neigh)
61+
62+
return ep

tests/test_mctpd.py

Lines changed: 14 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -406,19 +406,13 @@ async def test_assign_endpoint_static_varies(dbus, mctpd):
406406

407407
""" Test that the mctpd control protocol responder support has support
408408
for a basic Get Endpoint ID command"""
409-
async def test_get_endpoint_id(dbus, mctpd):
409+
async def test_get_endpoint_id(dbus, mctpd, routed_ep):
410+
ep = routed_ep
410411
iface = mctpd.system.interfaces[0]
411-
dev = mctpd.network.endpoints[0]
412412
mctp = await mctpd_mctp_iface_obj(dbus, iface)
413-
dev.eid = 12
414-
415-
await mctpd.system.add_route(mctpd.system.Route(dev.eid, 0, iface = iface))
416-
await mctpd.system.add_neighbour(
417-
mctpd.system.Neighbour(iface, dev.lladdr, dev.eid)
418-
)
419413

420414
cmd = MCTPControlCommand(True, 0, 0x02)
421-
rsp = await dev.send_control(mctpd.network.mctp_socket, cmd)
415+
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
422416

423417
# command code
424418
assert rsp[1] == 0x02
@@ -1263,14 +1257,8 @@ async def test_bridge_pool_range_limited(dbus, sysnet, nursery):
12631257
res = await mctpd.stop_mctpd()
12641258
assert res == 0
12651259

1266-
async def test_get_message_types(dbus, mctpd):
1267-
ep = mctpd.network.endpoints[0]
1268-
ep.eid = 12
1269-
iface = mctpd.system.interfaces[0]
1270-
await mctpd.system.add_route(mctpd.system.Route(ep.eid, 1, iface = iface))
1271-
await mctpd.system.add_neighbour(
1272-
mctpd.system.Neighbour(iface, ep.lladdr, ep.eid)
1273-
)
1260+
async def test_get_message_types(dbus, mctpd, routed_ep):
1261+
ep = routed_ep
12741262

12751263
# Check default response when no responder registered
12761264
cmd = MCTPControlCommand(True, 0, 0x05, bytes([0x00]))
@@ -1292,30 +1280,17 @@ async def test_get_message_types(dbus, mctpd):
12921280
assert rsp.hex(' ') == '00 04 00 01 f4 f3 f2 f1'
12931281

12941282
""" Test RegisterVDMTypeSupport when no responders are registered """
1295-
async def test_register_vdm_type_support_empty(mctpd):
1296-
ep = mctpd.network.endpoints[0]
1297-
ep.eid = 12
1298-
iface = mctpd.system.interfaces[0]
1299-
await mctpd.system.add_route(mctpd.system.Route(ep.eid, 1, iface=iface))
1300-
await mctpd.system.add_neighbour(
1301-
mctpd.system.Neighbour(iface, ep.lladdr, ep.eid)
1302-
)
1283+
async def test_register_vdm_type_support_empty(mctpd, routed_ep):
1284+
ep = routed_ep
13031285

13041286
# Verify error response when no VDM is registered
13051287
cmd = MCTPControlCommand(True, 0, 0x06, bytes([0x00]))
13061288
rsp = await ep.send_control(mctpd.network.mctp_socket, cmd)
13071289
assert rsp.hex(' ') == '00 06 02'
13081290

13091291
""" Test RegisterVDMTypeSupport when a single PCIe VDM is registered """
1310-
async def test_register_vdm_type_support_pcie_only(dbus, mctpd):
1311-
ep = mctpd.network.endpoints[0]
1312-
ep.eid = 12
1313-
iface = mctpd.system.interfaces[0]
1314-
await mctpd.system.add_route(mctpd.system.Route(ep.eid, 1, iface=iface))
1315-
await mctpd.system.add_neighbour(
1316-
mctpd.system.Neighbour(iface, ep.lladdr, ep.eid)
1317-
)
1318-
1292+
async def test_register_vdm_type_support_pcie_only(dbus, mctpd, routed_ep):
1293+
ep = routed_ep
13191294
mctp = await mctpd_mctp_base_iface_obj(dbus)
13201295

13211296
# Register PCIe VDM: format=0x00, VID=0xABCD, command_set=0x0001
@@ -1333,15 +1308,8 @@ async def test_register_vdm_type_support_pcie_only(dbus, mctpd):
13331308
assert rsp.hex(' ') == '00 06 02'
13341309

13351310
""" Test RegisterVDMTypeSupport when a single IANA VDM is registered """
1336-
async def test_register_vdm_type_support_iana_only(dbus, mctpd):
1337-
ep = mctpd.network.endpoints[0]
1338-
ep.eid = 12
1339-
iface = mctpd.system.interfaces[0]
1340-
await mctpd.system.add_route(mctpd.system.Route(ep.eid, 1, iface=iface))
1341-
await mctpd.system.add_neighbour(
1342-
mctpd.system.Neighbour(iface, ep.lladdr, ep.eid)
1343-
)
1344-
1311+
async def test_register_vdm_type_support_iana_only(dbus, mctpd, routed_ep):
1312+
ep = routed_ep
13451313
mctp = await mctpd_mctp_base_iface_obj(dbus)
13461314

13471315
# Register IANA VDM: format=0x01, VID=0x1234ABCD, command_set=0x5678
@@ -1354,14 +1322,8 @@ async def test_register_vdm_type_support_iana_only(dbus, mctpd):
13541322
assert rsp.hex(' ') == '00 06 00 ff 01 12 34 ab cd 56 78'
13551323

13561324
""" Test RegisterVDMTypeSupport with dbus disconnect """
1357-
async def test_register_vdm_type_support_dbus_disconnect(mctpd):
1358-
ep = mctpd.network.endpoints[0]
1359-
ep.eid = 12
1360-
iface = mctpd.system.interfaces[0]
1361-
await mctpd.system.add_route(mctpd.system.Route(ep.eid, 1, iface=iface))
1362-
await mctpd.system.add_neighbour(
1363-
mctpd.system.Neighbour(iface, ep.lladdr, ep.eid)
1364-
)
1325+
async def test_register_vdm_type_support_dbus_disconnect(mctpd, routed_ep):
1326+
ep = routed_ep
13651327

13661328
# Verify error response when no VDM is registered
13671329
cmd = MCTPControlCommand(True, 0, 0x06, bytes([0x00]))
@@ -1390,15 +1352,8 @@ async def test_register_vdm_type_support_dbus_disconnect(mctpd):
13901352

13911353
""" Test RegisterVDMTypeSupport error handling """
13921354
async def test_register_vdm_type_support_errors(dbus, mctpd):
1393-
ep = mctpd.network.endpoints[0]
1394-
ep.eid = 12
1395-
iface = mctpd.system.interfaces[0]
1396-
await mctpd.system.add_route(mctpd.system.Route(ep.eid, 1, iface=iface))
1397-
await mctpd.system.add_neighbour(
1398-
mctpd.system.Neighbour(iface, ep.lladdr, ep.eid)
1399-
)
1400-
14011355
mctp = await mctpd_mctp_base_iface_obj(dbus)
1356+
14021357
# Verify DBus call fails with invalid format 0x02
14031358
v_type = asyncdbus.Variant('q', 0xABCD)
14041359
with pytest.raises(asyncdbus.errors.DBusError) as ex:

0 commit comments

Comments
 (0)