Skip to content

Commit 97a3407

Browse files
robertszczepanskitmichalak
authored andcommitted
Improve RSTACT CCC tests
1 parent 615af4f commit 97a3407

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

verification/cocotb/top/lib_i3c_top/test_ccc.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import cocotb
1313
from cocotb.triggers import ClockCycles
14+
from cocotb.regression import TestFactory
1415

1516
TGT_ADR = 0x5A
1617

@@ -645,21 +646,32 @@ async def test_ccc_setmrl_bcast(dut):
645646
assert mrl == int(sig)
646647

647648

648-
@cocotb.test()
649-
async def test_ccc_rstact_direct(dut):
650-
command = CCC.DIRECT.RSTACT
651-
649+
SUPPORTED_RESET_ACTIONS = [
650+
I3cTargetResetAction.NO_RESET,
651+
I3cTargetResetAction.RESET_PERIPHERAL_ONLY,
652+
I3cTargetResetAction.RESET_WHOLE_TARGET,
653+
]
654+
async def test_ccc_rstact(dut, type, rstact):
652655
i3c_controller, _, tb = await test_setup(dut)
653656
await ClockCycles(tb.clk, 50)
654657

658+
if type == "broadcast":
659+
command = CCC.BCAST.RSTACT
660+
directed_data = None
661+
reset_actions = rstact
662+
elif type == "direct":
663+
command = CCC.DIRECT.RSTACT
664+
directed_data = [(TGT_ADR, [])]
665+
reset_actions = [(TGT_ADR, rstact)]
666+
else:
667+
assert False, "Unsupported RSTACT type, must be 'broadcast' or 'direct'"
668+
655669
# Send directed RSTACT
656670
rst_action = 0xAA
657671
await i3c_controller.i3c_ccc_write(
658672
ccc=command,
659673
defining_byte=rst_action,
660-
directed_data=[
661-
(TGT_ADR, []),
662-
],
674+
directed_data=directed_data,
663675
stop=False,
664676
)
665677

@@ -671,35 +683,24 @@ async def test_ccc_rstact_direct(dut):
671683
await i3c_controller.send_stop()
672684

673685
# Start new frame and reset target with reset action set to peripheral reset
674-
await i3c_controller.target_reset(I3cTargetResetAction.RESET_PERIPHERAL_ONLY)
675-
assert dut.peripheral_reset_o == 1
676-
assert dut.escalated_reset_o == 0
677-
await ClockCycles(tb.clk, 50)
678-
679-
680-
@cocotb.test()
681-
async def test_ccc_rstact_bcast(dut):
682-
command = CCC.BCAST.RSTACT
683-
684-
i3c_controller, _, tb = await test_setup(dut)
686+
await i3c_controller.target_reset(reset_actions)
687+
if rstact == I3cTargetResetAction.NO_RESET:
688+
assert dut.peripheral_reset_o == 0
689+
assert dut.escalated_reset_o == 0
690+
elif rstact == I3cTargetResetAction.RESET_PERIPHERAL_ONLY:
691+
assert dut.peripheral_reset_o == 1
692+
assert dut.escalated_reset_o == 0
693+
elif rstact == I3cTargetResetAction.RESET_WHOLE_TARGET:
694+
assert dut.peripheral_reset_o == 0
695+
assert dut.escalated_reset_o == 1
696+
else:
697+
assert False, f"Unsupported reset action ({rstact}), must be one of {SUPPORTED_RESET_ACTIONS}"
685698
await ClockCycles(tb.clk, 50)
686699

687-
# Send broadcast RSTACT
688-
rst_action = 0xAA
689-
await i3c_controller.i3c_ccc_write(ccc=command, defining_byte=rst_action, stop=False)
690-
691-
# Check if reset action got stored correctly in the logic after Target Reset Pattern
692-
sig = dut.xi3c_wrapper.i3c.xcontroller.xcontroller_standby.xcontroller_standby_i3c.rst_action_o
693-
assert int(sig) == 0
694-
await i3c_controller.send_target_reset_pattern()
695-
assert rst_action == int(sig)
696-
await i3c_controller.send_stop()
697-
698-
# Start new frame and reset target with reset action set to peripheral reset
699-
await i3c_controller.target_reset(I3cTargetResetAction.RESET_WHOLE_TARGET)
700-
assert dut.peripheral_reset_o == 0
701-
assert dut.escalated_reset_o == 1
702-
await ClockCycles(tb.clk, 50)
700+
rstact_tf = TestFactory(test_function=test_ccc_rstact)
701+
rstact_tf.add_option(name="rstact", optionlist=SUPPORTED_RESET_ACTIONS)
702+
rstact_tf.add_option(name="type", optionlist=["broadcast", "direct"])
703+
rstact_tf.generate_tests()
703704

704705

705706
@cocotb.test()

0 commit comments

Comments
 (0)