test/test_axi: add bursts to axi2native

This commit is contained in:
Florent Kermarrec 2018-11-12 17:16:27 +01:00
parent e27fbc2430
commit 93e8510f55
1 changed files with 48 additions and 33 deletions

View File

@ -112,30 +112,35 @@ class TestAXI(unittest.TestCase):
run_simulation(dut, generators, vcd_name="burst2beat.vcd")
self.assertEqual(self.errors, 0)
def test_axi2native(self):
def test_axi2native(self, with_random=True):
def writes_cmd_generator(axi_port, writes):
for write in writes:
# send command
yield axi_port.aw.valid.eq(1)
yield axi_port.aw.addr.eq(write.addr<<2)
yield axi_port.aw.burst.eq(write.type)
yield axi_port.aw.len.eq(write.len)
yield axi_port.aw.size.eq(write.size)
yield axi_port.aw.id.eq(write.id)
yield
while (yield axi_port.aw.ready) == 0:
yield
yield
yield axi_port.aw.valid.eq(0)
yield
def writes_data_generator(axi_port, writes):
for write in writes:
for i, data in enumerate(write.data):
# send data
yield axi_port.w.valid.eq(1)
if (i == (len(write.data) - 1)):
yield axi_port.w.last.eq(1)
yield axi_port.w.data.eq(write.data)
else:
yield axi_port.w.last.eq(0)
yield axi_port.w.data.eq(data)
yield
while (yield axi_port.w.ready) == 0:
yield
yield
yield axi_port.w.valid.eq(0)
yield
def writes_response_generator(axi_port, writes):
self.writes_id_errors = 0
@ -153,28 +158,36 @@ class TestAXI(unittest.TestCase):
# send command
yield axi_port.ar.valid.eq(1)
yield axi_port.ar.addr.eq(read.addr<<2)
yield axi_port.ar.burst.eq(read.type)
yield axi_port.ar.len.eq(read.len)
yield axi_port.ar.size.eq(read.size)
yield axi_port.ar.id.eq(read.id)
yield
while (yield axi_port.ar.ready) == 0:
yield
yield axi_port.ar.valid.eq(0)
yield
def reads_response_data_generator(axi_port, reads):
self.reads_data_errors = 0
self.reads_id_errors = 0
self.reads_last_errors = 0
yield axi_port.r.ready.eq(1) # always accepting read response
yield
for read in reads:
for i, data in enumerate(read.data):
# wait data / response
while (yield axi_port.r.valid) == 0:
yield
if (yield axi_port.r.data) != read.data:
if (yield axi_port.r.data) != data:
self.reads_data_errors += 1
if (yield axi_port.r.id) != read.id:
self.reads_id_errors += 1
if i == (len(read.data) - 1):
if (yield axi_port.r.last) != 1:
self.reads_last_errors += 1
else:
if (yield axi_port.r.last) != 0:
self.reads_last_errors += 1
yield
# dut
@ -186,19 +199,21 @@ class TestAXI(unittest.TestCase):
# generate writes/reads
prng = random.Random(42)
writes = []
for i in range(64):
for i in range(16):
if with_random:
# incrementing addr, random data &id
writes.append(Write(i, prng.randrange(2**32), prng.randrange(2**8)))
writes.append(Write(i, [prng.randrange(2**32) for _ in range(i+1)], prng.randrange(2**8), type=0b00, len=i))
else:
# incrementing addr, data & id (debug)
#writes.append(Write(i, i, i))
writes.append(Write(i, [i for _ in range(i+1)], i, type=0b00, len=i))
reads = []
for i in range(64): # dummy reads while content not yet written
reads.append(Read(64, 0x00000000, 0x00))
for i in range(64):
for i in range(16):
if with_random:
# incrementing addr, written data, random id
reads.append(Read(i, writes[i].data, prng.randrange(2**8)))
reads.append(Read(i, writes[i].data, prng.randrange(2**8), type=0b00, len=len(writes[i].data)-1))
else:
# incrementing addr, written data, incrementing id (debug)
#reads.append(Read(i, writes[i].data, i))
reads.append(Read(i, writes[i].data, i, type=0b00, len=len(writes[i].data)-1))
# simulation
generators = [