mirror of
https://github.com/enjoy-digital/litedram.git
synced 2025-01-04 09:52:25 -05:00
test: remove use of rand_wait, rename rand_level to random
This commit is contained in:
parent
0eef5d4d55
commit
9584c2fe88
2 changed files with 45 additions and 40 deletions
|
@ -6,13 +6,6 @@ import random
|
|||
|
||||
from migen import *
|
||||
|
||||
|
||||
def rand_wait(level):
|
||||
prng = random.Random(42)
|
||||
while prng.randrange(100) < level:
|
||||
yield
|
||||
|
||||
|
||||
def seed_to_data(seed, random=True, nbits=32):
|
||||
if nbits == 32:
|
||||
if random:
|
||||
|
@ -43,7 +36,7 @@ class DRAMMemory:
|
|||
print("0x{:08x}: 0x{:08x}".format(addr, self.mem[addr]))
|
||||
|
||||
@passive
|
||||
def read_handler(self, dram_port, rdata_valid_rand_level=0):
|
||||
def read_handler(self, dram_port, rdata_valid_random=0):
|
||||
address = 0
|
||||
pending = 0
|
||||
prng = random.Random(42)
|
||||
|
@ -51,7 +44,8 @@ class DRAMMemory:
|
|||
while True:
|
||||
yield dram_port.rdata.valid.eq(0)
|
||||
if pending:
|
||||
yield from rand_wait(rdata_valid_rand_level)
|
||||
while prng.randrange(100) < rdata_valid_random:
|
||||
yield
|
||||
yield dram_port.rdata.valid.eq(1)
|
||||
yield dram_port.rdata.data.eq(self.mem[address%self.depth])
|
||||
yield
|
||||
|
@ -68,7 +62,7 @@ class DRAMMemory:
|
|||
yield
|
||||
|
||||
@passive
|
||||
def write_handler(self, dram_port, wdata_ready_rand_level=0):
|
||||
def write_handler(self, dram_port, wdata_ready_random=0):
|
||||
address = 0
|
||||
pending = 0
|
||||
prng = random.Random(42)
|
||||
|
@ -78,7 +72,8 @@ class DRAMMemory:
|
|||
if pending:
|
||||
while (yield dram_port.wdata.valid) == 0:
|
||||
yield
|
||||
yield from rand_wait(wdata_ready_rand_level)
|
||||
while prng.randrange(100) < wdata_ready_random:
|
||||
yield
|
||||
yield dram_port.wdata.ready.eq(1)
|
||||
yield
|
||||
self.mem[address%self.depth] = (yield dram_port.wdata.data) # TODO manage we
|
||||
|
|
|
@ -58,25 +58,27 @@ class Read(Access):
|
|||
class TestAXI(unittest.TestCase):
|
||||
def _test_axi2native(self,
|
||||
naccesses=16, simultaneous_writes_reads=False,
|
||||
# rand_level: 0: min (no random), 100: max.
|
||||
# random: 0: min (no random), 100: max.
|
||||
# burst randomness
|
||||
id_rand_enable = False,
|
||||
len_rand_enable = False,
|
||||
data_rand_enable = False,
|
||||
# flow valid randomness
|
||||
aw_valid_rand_level = 0,
|
||||
w_valid_rand_level = 0,
|
||||
ar_valid_rand_level = 0,
|
||||
r_valid_rand_level = 0,
|
||||
aw_valid_random = 0,
|
||||
w_valid_random = 0,
|
||||
ar_valid_random = 0,
|
||||
r_valid_random = 0,
|
||||
# flow ready randomness
|
||||
w_ready_rand_level = 0,
|
||||
b_ready_rand_level = 0,
|
||||
r_ready_rand_level = 0
|
||||
w_ready_random = 0,
|
||||
b_ready_random = 0,
|
||||
r_ready_random = 0
|
||||
):
|
||||
|
||||
def writes_cmd_generator(axi_port, writes):
|
||||
prng = random.Random(42)
|
||||
for write in writes:
|
||||
yield from rand_wait(aw_valid_rand_level)
|
||||
while prng.randrange(100) < aw_valid_random:
|
||||
yield
|
||||
# send command
|
||||
yield axi_port.aw.valid.eq(1)
|
||||
yield axi_port.aw.addr.eq(write.addr<<2)
|
||||
|
@ -90,9 +92,11 @@ class TestAXI(unittest.TestCase):
|
|||
yield axi_port.aw.valid.eq(0)
|
||||
|
||||
def writes_data_generator(axi_port, writes):
|
||||
prng = random.Random(42)
|
||||
for write in writes:
|
||||
for i, data in enumerate(write.data):
|
||||
yield from rand_wait(w_valid_rand_level)
|
||||
while prng.randrange(100) < w_valid_random:
|
||||
yield
|
||||
# send data
|
||||
yield axi_port.w.valid.eq(1)
|
||||
if (i == (len(write.data) - 1)):
|
||||
|
@ -107,6 +111,7 @@ class TestAXI(unittest.TestCase):
|
|||
axi_port.reads_enable = True
|
||||
|
||||
def writes_response_generator(axi_port, writes):
|
||||
prng = random.Random(42)
|
||||
self.writes_id_errors = 0
|
||||
for write in writes:
|
||||
# wait response
|
||||
|
@ -114,17 +119,20 @@ class TestAXI(unittest.TestCase):
|
|||
yield
|
||||
while (yield axi_port.b.valid) == 0:
|
||||
yield
|
||||
yield from rand_wait(b_ready_rand_level)
|
||||
while prng.randrange(100) < b_ready_random:
|
||||
yield
|
||||
yield axi_port.b.ready.eq(1)
|
||||
yield
|
||||
if (yield axi_port.b.id) != write.id:
|
||||
self.writes_id_errors += 1
|
||||
|
||||
def reads_cmd_generator(axi_port, reads):
|
||||
prng = random.Random(42)
|
||||
while not axi_port.reads_enable:
|
||||
yield
|
||||
for read in reads:
|
||||
yield from rand_wait(ar_valid_rand_level)
|
||||
while prng.randrange(100) < ar_valid_random:
|
||||
yield
|
||||
# send command
|
||||
yield axi_port.ar.valid.eq(1)
|
||||
yield axi_port.ar.addr.eq(read.addr<<2)
|
||||
|
@ -138,6 +146,7 @@ class TestAXI(unittest.TestCase):
|
|||
yield axi_port.ar.valid.eq(0)
|
||||
|
||||
def reads_response_data_generator(axi_port, reads):
|
||||
prng = random.Random(42)
|
||||
self.reads_data_errors = 0
|
||||
self.reads_id_errors = 0
|
||||
self.reads_last_errors = 0
|
||||
|
@ -150,7 +159,8 @@ class TestAXI(unittest.TestCase):
|
|||
yield
|
||||
while (yield axi_port.r.valid) == 0:
|
||||
yield
|
||||
yield from rand_wait(r_ready_rand_level)
|
||||
while prng.randrange(100) < r_ready_random:
|
||||
yield
|
||||
yield axi_port.r.ready.eq(1)
|
||||
yield
|
||||
if (yield axi_port.r.data) != data:
|
||||
|
@ -195,8 +205,8 @@ class TestAXI(unittest.TestCase):
|
|||
writes_response_generator(axi_port, writes),
|
||||
reads_cmd_generator(axi_port, reads),
|
||||
reads_response_data_generator(axi_port, reads),
|
||||
mem.read_handler(dram_port, rdata_valid_rand_level=r_valid_rand_level),
|
||||
mem.write_handler(dram_port, wdata_ready_rand_level=w_ready_rand_level)
|
||||
mem.read_handler(dram_port, rdata_valid_random=r_valid_random),
|
||||
mem.write_handler(dram_port, wdata_ready_random=w_ready_random)
|
||||
]
|
||||
run_simulation(dut, generators)
|
||||
#mem.show_content()
|
||||
|
@ -228,25 +238,25 @@ class TestAXI(unittest.TestCase):
|
|||
data_rand_enable=True)
|
||||
|
||||
def test_axi2native_random_w_ready(self):
|
||||
self._test_axi2native(w_ready_rand_level=90)
|
||||
self._test_axi2native(w_ready_random=90)
|
||||
|
||||
def test_axi2native_random_b_ready(self):
|
||||
self._test_axi2native(b_ready_rand_level=90)
|
||||
self._test_axi2native(b_ready_random=90)
|
||||
|
||||
def test_axi2native_random_r_ready(self):
|
||||
self._test_axi2native(r_ready_rand_level=90)
|
||||
self._test_axi2native(r_ready_random=90)
|
||||
|
||||
def test_axi2native_random_aw_valid(self):
|
||||
self._test_axi2native(aw_valid_rand_level=90)
|
||||
self._test_axi2native(aw_valid_random=90)
|
||||
|
||||
def test_axi2native_random_w_valid(self):
|
||||
self._test_axi2native(w_valid_rand_level=90)
|
||||
self._test_axi2native(w_valid_random=90)
|
||||
|
||||
def test_axi2native_random_ar_valid(self):
|
||||
self._test_axi2native(ar_valid_rand_level=90)
|
||||
self._test_axi2native(ar_valid_random=90)
|
||||
|
||||
def test_axi2native_random_r_valid(self):
|
||||
self._test_axi2native(r_valid_rand_level=90)
|
||||
self._test_axi2native(r_valid_random=90)
|
||||
|
||||
# now let's stress things a bit... :)
|
||||
def test_axi2native_random_all(self):
|
||||
|
@ -254,11 +264,11 @@ class TestAXI(unittest.TestCase):
|
|||
simultaneous_writes_reads=True,
|
||||
id_rand_enable=True,
|
||||
len_rand_enable=True,
|
||||
aw_valid_rand_level=50,
|
||||
w_ready_rand_level=50,
|
||||
b_ready_rand_level=50,
|
||||
w_valid_rand_level=50,
|
||||
ar_valid_rand_level=90,
|
||||
r_valid_rand_level=90,
|
||||
r_ready_rand_level=90
|
||||
aw_valid_random=50,
|
||||
w_ready_random=50,
|
||||
b_ready_random=50,
|
||||
w_valid_random=50,
|
||||
ar_valid_random=90,
|
||||
r_valid_random=90,
|
||||
r_ready_random=90
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue