Skip to content

Commit a91c997

Browse files
FreddieJheng-quantapotinlai
authored andcommitted
tests: mctpd: Add tests for AssignBridgeStatic method
Add test cases to verify successful static EID and pool assignment, and rejection on conflict with an existing EID allocation. Signed-off-by: Freddie Jheng <Freddie.Jheng@quantatw.com>
1 parent da464ea commit a91c997

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/test_mctpd.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,62 @@ async def test_assign_endpoint_static_varies(dbus, mctpd):
429429
assert str(ex.value) == "Already assigned a different EID"
430430

431431

432+
async def test_assign_bridge_static(dbus, mctpd):
433+
"""Test that AssignBridgeStatic assigns the requested EID and pool to a
434+
bridge endpoint, and marks it as new on first call.
435+
"""
436+
iface = mctpd.system.interfaces[0]
437+
dev = mctpd.network.endpoints[0]
438+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
439+
static_eid = 12
440+
pool_size = 3
441+
pool_start = static_eid + 1
442+
443+
for _ in range(pool_size):
444+
dev.add_bridged_ep(Endpoint(iface, bytes()))
445+
446+
(eid, _, _, new) = await mctp.call_assign_bridge_static(
447+
dev.lladdr, static_eid, pool_start, pool_size
448+
)
449+
450+
assert eid == static_eid
451+
assert new
452+
453+
454+
async def test_assign_bridge_static_conflict(dbus, mctpd):
455+
"""Test that AssignBridgeStatic rejects an EID that is already in use by
456+
a different endpoint.
457+
"""
458+
iface = mctpd.system.interfaces[0]
459+
dev1 = mctpd.network.endpoints[0]
460+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
461+
462+
dev2 = Endpoint(iface, bytes([0x1E]))
463+
mctpd.network.add_endpoint(dev2)
464+
465+
static_eid = 12
466+
pool_size = 3
467+
pool_start = static_eid + 1
468+
469+
for _ in range(pool_size):
470+
dev1.add_bridged_ep(Endpoint(iface, bytes()))
471+
472+
(eid, _, _, new) = await mctp.call_assign_bridge_static(
473+
dev1.lladdr, static_eid, pool_start, pool_size
474+
)
475+
print(f"dev1 assigned: eid={eid}, new={new}")
476+
assert new
477+
478+
# try to assign dev2 the same EID — must fail
479+
with pytest.raises(asyncdbus.errors.DBusError) as ex:
480+
await mctp.call_assign_bridge_static(
481+
dev2.lladdr, static_eid, pool_start, pool_size
482+
)
483+
484+
print(f"dev2 conflict error: {ex.value}")
485+
assert str(ex.value) == "Address in use"
486+
487+
432488
async def test_get_endpoint_id(dbus, mctpd, routed_ep):
433489
"""Test that the mctpd control protocol responder support has support for a
434490
basic Get Endpoint ID command

0 commit comments

Comments
 (0)