- yield from check_o_n_stb(dut, 1) # buffer still needs to output
- yield
- yield from check_o_n_stb(dut, 1) # buffer still needs to output
- yield
- yield from check_o_n_stb(dut, 1) # buffer still needs to output
- yield
- yield from check_o_n_stb(dut, 0) # buffer outputted, *now* we're done.
- yield
- yield
- yield
-
-
-def testbench3(dut):
- data = []
- for i in range(1000):
- #data.append(randint(0, 1<<16-1))
- data.append(i+1)
- i = 0
- o = 0
- while True:
- stall = randint(0, 3) == 0
- send = randint(0, 5) != 0
- yield dut.i_n_busy.eq(stall)
- o_p_busy = yield dut.o_p_busy
- if not o_p_busy:
- if send and i != len(data):
- yield dut.i_p_stb.eq(1)
- yield dut.stage.i_data.eq(data[i])
- i += 1
- else:
- yield dut.i_p_stb.eq(0)
- yield
- o_n_stb = yield dut.o_n_stb
- i_n_busy = yield dut.i_n_busy
- if o_n_stb and not i_n_busy:
- o_data = yield dut.stage.o_data
- assert o_data == data[o] + 1, "%d-%d data %x not match %x\n" \
- % (i, o, o_data, data[o])
- o += 1
- if o == len(data):
- break
+ yield from check_o_n_stb2(dut, 1) # buffer still needs to output
+ yield
+ yield from check_o_n_stb2(dut, 1) # buffer still needs to output
+ yield
+ yield from check_o_n_stb2(dut, 1) # buffer still needs to output
+ yield
+ yield from check_o_n_stb2(dut, 0) # buffer outputted, *now* we're done.
+ yield
+ yield
+ yield
+
+
+class Test3:
+ def __init__(self, dut):
+ self.dut = dut
+ self.data = []
+ for i in range(10000):
+ #data.append(randint(0, 1<<16-1))
+ self.data.append(i+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)):
+ if send_range == 0:
+ send = True
+ else:
+ send = randint(0, send_range) != 0
+ o_p_busy = yield self.dut.o.p_busy
+ if o_p_busy:
+ yield
+ continue
+ if send and self.i != len(self.data):
+ yield self.dut.i.p_stb.eq(1)
+ yield self.dut.stage.i_data.eq(self.data[self.i])
+ self.i += 1
+ else:
+ yield self.dut.i.p_stb.eq(0)
+ yield
+
+ def rcv(self):
+ while self.o != len(self.data):
+ stall_range = randint(0, 3)
+ for j in range(randint(1,10)):
+ stall = randint(0, stall_range) == 0
+ yield self.dut.i.n_busy.eq(stall)
+ yield
+ o_n_stb = yield self.dut.o.n_stb
+ i_n_busy = yield self.dut.i.n_busy
+ if not o_n_stb or i_n_busy:
+ continue
+ o_data = yield self.dut.stage.o_data
+ assert o_data == self.data[self.o] + 1, \
+ "%d-%d data %x not match %x\n" \
+ % (self.i, self.o, o_data, self.data[self.o])
+ self.o += 1
+ if self.o == len(self.data):
+ break