Skip to content

Commit b765f50

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

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

tests/test_mctpd.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,123 @@ async def test_assign_endpoint_static_varies(dbus, mctpd):
431431
assert str(ex.value) == "Already assigned a different EID"
432432

433433

434+
async def test_assign_bridge_static(dbus, mctpd):
435+
"""Test that AssignBridgeStatic assigns the requested EID and pool to a
436+
bridge endpoint, and marks it as new on first call.
437+
"""
438+
iface = mctpd.system.interfaces[0]
439+
dev = mctpd.network.endpoints[0]
440+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
441+
static_eid = 12
442+
pool_size = 3
443+
pool_start = static_eid + 1
444+
445+
for _ in range(pool_size):
446+
dev.add_bridged_ep(Endpoint(iface, bytes()))
447+
448+
(eid, pool_start_out, _, _, new) = await mctp.call_assign_bridge_static(
449+
dev.lladdr, static_eid, pool_start, pool_size
450+
)
451+
452+
assert eid == static_eid
453+
assert pool_start_out == pool_start
454+
assert new
455+
456+
457+
async def test_assign_bridge_static_zero_start(dbus, mctpd):
458+
"""Test that AssignBridgeStatic sets pool start EID to bridge-eid+1
459+
when pool_start is passed as zero.
460+
"""
461+
iface = mctpd.system.interfaces[0]
462+
dev = mctpd.network.endpoints[0]
463+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
464+
static_eid = 12
465+
pool_size = 3
466+
pool_start = 0
467+
expected_pool_start = static_eid + 1
468+
469+
for _ in range(pool_size):
470+
dev.add_bridged_ep(Endpoint(iface, bytes()))
471+
472+
(eid, pool_start_out, _, _, new) = await mctp.call_assign_bridge_static(
473+
dev.lladdr, static_eid, pool_start, pool_size
474+
)
475+
476+
assert eid == static_eid
477+
assert pool_start_out == expected_pool_start
478+
assert new
479+
480+
481+
async def test_assign_bridge_static_conflict(dbus, mctpd):
482+
"""Test that AssignBridgeStatic rejects an EID that is already in use by
483+
a different endpoint.
484+
"""
485+
iface = mctpd.system.interfaces[0]
486+
dev1 = mctpd.network.endpoints[0]
487+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
488+
489+
dev2 = Endpoint(iface, bytes([0x1E]))
490+
mctpd.network.add_endpoint(dev2)
491+
492+
static_eid = 12
493+
pool_size = 3
494+
pool_start = static_eid + 1
495+
496+
for _ in range(pool_size):
497+
dev2.add_bridged_ep(Endpoint(iface, bytes()))
498+
499+
(eid, _, _, new) = await mctp.call_assign_endpoint_static(
500+
dev1.lladdr, static_eid
501+
)
502+
assert eid == static_eid
503+
assert new
504+
505+
# try to assign dev2 the same EID — must fail
506+
with pytest.raises(asyncdbus.errors.DBusError) as ex:
507+
await mctp.call_assign_bridge_static(
508+
dev2.lladdr, static_eid, pool_start, pool_size
509+
)
510+
511+
assert str(ex.value) == "Address in use"
512+
513+
514+
async def test_assign_bridge_static_pool_conflict(dbus, mctpd):
515+
"""Test that AssignBridgeStatic rejects assigning a pool range that
516+
conflicts with an existing endpoint's EID, even if the bridge EID itself
517+
does not conflict.
518+
"""
519+
iface = mctpd.system.interfaces[0]
520+
dev1 = mctpd.network.endpoints[0]
521+
mctp = await mctpd_mctp_iface_obj(dbus, iface)
522+
523+
dev2 = Endpoint(iface, bytes([0x1E]))
524+
mctpd.network.add_endpoint(dev2)
525+
526+
# dev1 is a single endpoint assigned EID 13
527+
dev1_eid = 13
528+
(eid1, _, _, new1) = await mctp.call_assign_endpoint_static(
529+
dev1.lladdr, dev1_eid
530+
)
531+
assert eid1 == dev1_eid
532+
assert new1
533+
534+
# dev2 is a bridge endpoint with EID 11, pool size 3 (pool start 12, range 12-14)
535+
dev2_eid = 11
536+
pool_size = 3
537+
pool_start = dev2_eid + 1
538+
539+
for _ in range(pool_size):
540+
dev2.add_bridged_ep(Endpoint(iface, bytes()))
541+
542+
# try to assign dev2 — must fail due to pool conflict at EID 13
543+
with pytest.raises(asyncdbus.errors.DBusError) as ex:
544+
await mctp.call_assign_bridge_static(
545+
dev2.lladdr, dev2_eid, pool_start, pool_size
546+
)
547+
548+
assert str(ex.value) == "Ran out of EIDs"
549+
550+
434551
async def test_get_endpoint_id(dbus, mctpd, routed_ep):
435552
"""Test that the mctpd control protocol responder support has support for a
436553
basic Get Endpoint ID command

0 commit comments

Comments
 (0)