serdes-transceiver/test_buffer.py

47 lines
1.1 KiB
Python

from migen import *
from buffer import Buffer
BUFFER_DEPTH=8
full_test_bytes = [0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xD0, 0xCA, 0xFE, 0x15, 0x77]
def testbench(dut, length=10):
# dut = Buffer(8, BUFFER_DEPTH)
# full_test_bytes = [0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xD0, 0xCA, 0xFE, 0x15, 0x77]
test_data = full_test_bytes[:min(BUFFER_DEPTH, length)]
# Initial condition, stb low
yield dut.i_stb.eq(0)
yield
# Append bytes one-by-one
for number in test_data:
yield dut.din.eq(number)
yield dut.i_stb.eq(1)
yield
# Deassert input strobe to buffers
yield dut.i_stb.eq(0)
yield
# Receive bytes on-by-one
for number in test_data:
assert (yield dut.o_stb) == 1
assert (yield dut.dout) == number
yield dut.o_ack.eq(1)
yield
yield dut.o_ack.eq(0)
yield
yield
yield
yield
assert (yield dut.o_stb) == 0
for buffer_len in range(len(full_test_bytes)):
dut = Buffer(8, BUFFER_DEPTH)
run_simulation(dut, testbench(dut, length=buffer_len), vcd_name="buffer.vcd")