From 68596ec7173a059478eb2e13d908fd2e2cb06f35 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 2 Apr 2020 20:48:58 -0700 Subject: [PATCH] tests pass --- src/nmutil/test/__init__.py | 16 + src/nmutil/test/test_buf_pipe.py | 459 ++++++++++++-------- src/nmutil/test/test_inout_feedback_pipe.py | 89 ++-- src/nmutil/test/test_prioritymux_pipe.py | 60 +-- 4 files changed, 376 insertions(+), 248 deletions(-) diff --git a/src/nmutil/test/__init__.py b/src/nmutil/test/__init__.py index e69de29..0a3071d 100644 --- a/src/nmutil/test/__init__.py +++ b/src/nmutil/test/__init__.py @@ -0,0 +1,16 @@ +class StepLimiter: + def __init__(self, limit=100000): + self.limit = limit + self.step_count = 0 + assert self.step_count < self.limit, "step count limit reached" + + def step(self): + self.step_count += 1 + assert self.step_count < self.limit, "step count limit reached" + + def __iter__(self): + return self + + def __next__(self): + self.step() + return None diff --git a/src/nmutil/test/test_buf_pipe.py b/src/nmutil/test/test_buf_pipe.py index f0bacbb..54e5b8e 100644 --- a/src/nmutil/test/test_buf_pipe.py +++ b/src/nmutil/test/test_buf_pipe.py @@ -36,38 +36,42 @@ from nmutil.singlepipe import MaskCancellable from random import randint, seed -#seed(4) +import unittest + +# seed(4) def check_o_n_valid(dut, val): o_n_valid = yield dut.n.valid_o assert o_n_valid == val + def check_o_n_valid2(dut, val): o_n_valid = yield dut.n.valid_o assert o_n_valid == val def tbench(dut): - #yield dut.i_p_rst.eq(1) + # yield dut.i_p_rst.eq(1) yield dut.n.ready_i.eq(0) - #yield dut.p.ready_o.eq(0) + # yield dut.p.ready_o.eq(0) yield yield - #yield dut.i_p_rst.eq(0) + # yield dut.i_p_rst.eq(0) yield dut.n.ready_i.eq(1) yield dut.p.data_i.eq(5) yield dut.p.valid_i.eq(1) yield yield dut.p.data_i.eq(7) - yield from check_o_n_valid(dut, 0) # effects of i_p_valid delayed + yield from check_o_n_valid(dut, 0) # effects of i_p_valid delayed yield - yield from check_o_n_valid(dut, 1) # ok *now* i_p_valid effect is felt + yield from check_o_n_valid(dut, 1) # ok *now* i_p_valid effect is felt yield dut.p.data_i.eq(2) yield - yield dut.n.ready_i.eq(0) # begin going into "stall" (next stage says ready) + # begin going into "stall" (next stage says ready) + yield dut.n.ready_i.eq(0) yield dut.p.data_i.eq(9) yield yield dut.p.valid_i.eq(0) @@ -76,35 +80,38 @@ def tbench(dut): yield dut.p.data_i.eq(32) yield dut.n.ready_i.eq(1) yield - yield from check_o_n_valid(dut, 1) # buffer still needs to output + yield from check_o_n_valid(dut, 1) # buffer still needs to output yield - yield from check_o_n_valid(dut, 1) # buffer still needs to output + yield from check_o_n_valid(dut, 1) # buffer still needs to output yield - yield from check_o_n_valid(dut, 0) # buffer outputted, *now* we're done. + yield from check_o_n_valid(dut, 0) # buffer outputted, *now* we're done. yield def tbench2(dut): - #yield dut.p.i_rst.eq(1) + # yield dut.p.i_rst.eq(1) yield dut.n.ready_i.eq(0) - #yield dut.p.ready_o.eq(0) + # yield dut.p.ready_o.eq(0) yield yield - #yield dut.p.i_rst.eq(0) + # yield dut.p.i_rst.eq(0) yield dut.n.ready_i.eq(1) yield dut.p.data_i.eq(5) yield dut.p.valid_i.eq(1) yield yield dut.p.data_i.eq(7) - yield from check_o_n_valid2(dut, 0) # effects of i_p_valid delayed 2 clocks + # effects of i_p_valid delayed 2 clocks + yield from check_o_n_valid2(dut, 0) yield - yield from check_o_n_valid2(dut, 0) # effects of i_p_valid delayed 2 clocks + # effects of i_p_valid delayed 2 clocks + yield from check_o_n_valid2(dut, 0) yield dut.p.data_i.eq(2) yield - yield from check_o_n_valid2(dut, 1) # ok *now* i_p_valid effect is felt - yield dut.n.ready_i.eq(0) # begin going into "stall" (next stage says ready) + yield from check_o_n_valid2(dut, 1) # ok *now* i_p_valid effect is felt + # begin going into "stall" (next stage says ready) + yield dut.n.ready_i.eq(0) yield dut.p.data_i.eq(9) yield yield dut.p.valid_i.eq(0) @@ -113,13 +120,13 @@ def tbench2(dut): yield dut.p.data_i.eq(32) yield dut.n.ready_i.eq(1) yield - yield from check_o_n_valid2(dut, 1) # buffer still needs to output + yield from check_o_n_valid2(dut, 1) # buffer still needs to output yield - yield from check_o_n_valid2(dut, 1) # buffer still needs to output + yield from check_o_n_valid2(dut, 1) # buffer still needs to output yield - yield from check_o_n_valid2(dut, 1) # buffer still needs to output + yield from check_o_n_valid2(dut, 1) # buffer still needs to output yield - yield from check_o_n_valid2(dut, 0) # buffer outputted, *now* we're done. + yield from check_o_n_valid2(dut, 0) # buffer outputted, *now* we're done. yield yield yield @@ -139,7 +146,7 @@ class Test3: def send(self): while self.o != len(self.data): send_range = randint(0, 3) - for j in range(randint(1,10)): + for j in range(randint(1, 10)): if send_range == 0: send = True else: @@ -159,7 +166,7 @@ class Test3: def rcv(self): while self.o != len(self.data): stall_range = randint(0, 3) - for j in range(randint(1,10)): + for j in range(randint(1, 10)): stall = randint(0, stall_range) != 0 yield self.dut.n.ready_i.eq(stall) yield @@ -173,26 +180,29 @@ class Test3: if self.o == len(self.data): break + def resultfn_3(data_o, expected, i, o): assert data_o == expected + 1, \ - "%d-%d data %x not match %x\n" \ - % (i, o, data_o, expected) + "%d-%d data %x not match %x\n" \ + % (i, o, data_o, expected) + def data_placeholder(): - data = [] - for i in range(num_tests): - d = PlaceHolder() - d.src1 = randint(0, 1<<16-1) - d.src2 = randint(0, 1<<16-1) - data.append(d) - return data + data = [] + for i in range(num_tests): + d = PlaceHolder() + d.src1 = randint(0, 1 << 16-1) + d.src2 = randint(0, 1 << 16-1) + data.append(d) + return data + def data_dict(): - data = [] - for i in range(num_tests): - data.append({'src1': randint(0, 1<<16-1), - 'src2': randint(0, 1<<16-1)}) - return data + data = [] + for i in range(num_tests): + data.append({'src1': randint(0, 1 << 16-1), + 'src2': randint(0, 1 << 16-1)}) + return data class Test5: @@ -205,14 +215,15 @@ class Test5: else: self.data = [] for i in range(num_tests): - self.data.append((randint(0, 1<<16-1), randint(0, 1<<16-1))) + self.data.append( + (randint(0, 1 << 16-1), randint(0, 1 << 16-1))) self.i = 0 self.o = 0 def send(self): while self.o != len(self.data): send_range = randint(0, 3) - for j in range(randint(1,10)): + for j in range(randint(1, 10)): if send_range == 0: send = True else: @@ -234,7 +245,7 @@ class Test5: def rcv(self): while self.o != len(self.data): stall_range = randint(0, 3) - for j in range(randint(1,10)): + for j in range(randint(1, 10)): ready = randint(0, stall_range) != 0 #ready = True yield self.dut.n.ready_i.eq(ready) @@ -255,9 +266,10 @@ class Test5: if self.o == len(self.data): break + class TestMask: def __init__(self, dut, resultfn, maskwid, data=None, stage_ctl=False, - latching=False): + latching=False): self.dut = dut self.resultfn = resultfn self.stage_ctl = stage_ctl @@ -269,14 +281,15 @@ class TestMask: else: self.data = [] for i in range(num_tests): - self.data.append((randint(0, 1<<16-1), randint(0, 1<<16-1))) + self.data.append( + (randint(0, 1 << 16-1), randint(0, 1 << 16-1))) self.i = 0 self.o = 0 def send(self): while self.o != len(self.data): send_range = randint(0, 3) - for j in range(randint(1,10)): + for j in range(randint(1, 10)): if send_range == 0: send = True else: @@ -298,24 +311,24 @@ class TestMask: self.latchmode = 1 - self.latchmode yield self.dut.latchmode.eq(self.latchmode) mode = yield self.dut.latchmode - print ("latching", mode) + print("latching", mode) if send and self.i != len(self.data): - print ("send", self.i, self.data[self.i]) + print("send", self.i, self.data[self.i]) yield self.dut.p.valid_i.eq(1) - yield self.dut.p.mask_i.eq(1<