Skip to content

Commit 47b4df9

Browse files
robertszczepanskitmichalak
authored andcommitted
Add test for AXI burst
1 parent 9950392 commit 47b4df9

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

verification/cocotb/block/axi_adapter/test_bus_stress.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from cocotb.triggers import ClockCycles, Combine, Event, RisingEdge, Timer, with_timeout
1919
from cocotb_helpers import reset_n
2020

21+
from cocotbext.axi.constants import AxiBurstType
22+
2123

2224
async def timeout_task(timeout):
2325
await Timer(timeout, "us")
@@ -69,6 +71,8 @@ async def initialize(dut, timeout=50):
6971
data_len = random.randint(10, 100)
7072
test_data = [random.randint(0, 2**32 - 1) for _ in range(data_len)]
7173

74+
tb.log.info(f"Generated {data_len} dwords to transfer.")
75+
7276
return tb, data_len, test_data
7377

7478

@@ -78,12 +82,12 @@ async def test_collision_with_write(dut):
7882

7983
fifo_addr = tb.reg_map.I3C_EC.SECFWRECOVERYIF.INDIRECT_FIFO_DATA.base_addr
8084

81-
tb.log.info(f"Generated {data_len} dwords to transfer.")
82-
8385
async def writer():
8486
# Write sequence should just write data
8587
for d in test_data:
8688
await tb.write_csr(fifo_addr, int2bytes(d))
89+
# Wait for read to finish to avoid multiple writes per read
90+
await tb.axi_m.wait_read()
8791

8892
async def reader(return_data):
8993
# Wait until there is data in FIFO
@@ -104,7 +108,7 @@ async def reader(return_data):
104108

105109
await Combine(w, r)
106110

107-
assert received_data == test_data, "Recieved data does not match sent data!"
111+
assert received_data == test_data, "Received data does not match sent data!"
108112

109113
tb.log.info("Test finished!")
110114

@@ -115,16 +119,16 @@ async def test_collision_with_read(dut):
115119

116120
fifo_addr = tb.reg_map.I3C_EC.SECFWRECOVERYIF.INDIRECT_FIFO_DATA.base_addr
117121

118-
tb.log.info(f"Generated {data_len} dwords to transfer.")
119-
120122
async def writer():
121123
# Write sequence should write data on each read data
122124
for i, d in enumerate(test_data):
123125
# Awaiting read request causes writing simultaneously with read data channel activity
124126
if i > 2:
125127
await RisingEdge(dut.s_cpuif_req)
126128
assert not dut.s_cpuif_req_is_wr.value
127-
await tb.write_csr(fifo_addr, int2bytes(d))
129+
# Wait additional cycle to line up write with FIFO read delay
130+
await RisingEdge(tb.clk)
131+
await tb.write_csr(fifo_addr, int2dword(d))
128132

129133
async def reader(return_data):
130134
# Wait until there is data in FIFO
@@ -134,6 +138,8 @@ async def reader(return_data):
134138

135139
# Read sequence should just read data
136140
for _ in range(data_len):
141+
# Wait for write to finish to avoid multiple reads per write
142+
await tb.axi_m.wait_write()
137143
return_data.append(dword2int(await tb.read_csr(fifo_addr)))
138144
await RisingEdge(tb.clk)
139145

@@ -143,26 +149,32 @@ async def reader(return_data):
143149

144150
await Combine(w, r)
145151

146-
assert received_data == test_data, "Recieved data does not match sent data!"
152+
assert received_data == test_data, "Received data does not match sent data!"
147153

148154
tb.log.info("Test finished!")
149155

150156

151-
@cocotb.test(skip=True)
152-
async def test_write_burst(dut):
153-
tb = await initialize(dut)
157+
@cocotb.test()
158+
async def test_write_read_burst(dut):
159+
tb, data_len, test_data = await initialize(dut)
154160

161+
fifo_addr = tb.reg_map.I3C_EC.SECFWRECOVERYIF.INDIRECT_FIFO_DATA.base_addr
155162

156-
@cocotb.test(skip=True)
157-
async def test_read_burst(dut):
158-
tb = await initialize(dut)
163+
await with_timeout(tb.axi_m.write_dwords(fifo_addr, test_data, burst=AxiBurstType.FIXED), 1, "us")
164+
received_data = await with_timeout(tb.axi_m.read_dwords(fifo_addr, count=data_len, burst=AxiBurstType.FIXED), 1, "us")
165+
166+
assert received_data == test_data, "Received data does not match sent data!"
159167

160168

161169
@cocotb.test(skip=True)
162170
async def test_read_burst_collision_with_write(dut):
163-
tb = await initialize(dut)
171+
tb, data_len, test_data = await initialize(dut)
172+
173+
fifo_addr = tb.reg_map.I3C_EC.SECFWRECOVERYIF.INDIRECT_FIFO_DATA.base_addr
164174

165175

166176
@cocotb.test(skip=True)
167177
async def test_write_burst_collision_with_read(dut):
168-
tb = await initialize(dut)
178+
tb, data_len, test_data = await initialize(dut)
179+
180+
fifo_addr = tb.reg_map.I3C_EC.SECFWRECOVERYIF.INDIRECT_FIFO_DATA.base_addr

0 commit comments

Comments
 (0)