def __init__(self, dut, init_val): """ Setup the testbench. *init_val* signifies the ``BinaryValue`` which must be captured by the output monitor with the first rising clock edge. This must match the initial state of the D flip-flop in RTL. """ # Some internal state self.dut = dut self.stopped = False # Create input driver and output monitor self.input_drv = BitDriver(signal=dut.d, clk=dut.c, generator=input_gen()) self.output_mon = BitMonitor(name="output", signal=dut.q, clk=dut.c) # Create a scoreboard on the outputs self.expected_output = [init_val ] # a list with init_val as the first element self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.output_mon, self.expected_output) # Use the input monitor to reconstruct the transactions from the pins # and send them to our 'model' of the design. self.input_mon = BitMonitor(name="input", signal=dut.d, clk=dut.c, callback=self.model)
class DFF_TB(object): def __init__(self, dut, init_val): """ Setup the testbench. *init_val* signifies the ``BinaryValue`` which must be captured by the output monitor with the first rising clock edge. This must match the initial state of the D flip-flop in RTL. """ # Some internal state self.dut = dut self.stopped = False # Create input driver and output monitor self.input_drv = BitDriver(signal=dut.d, clk=dut.c, generator=input_gen()) self.output_mon = BitMonitor(name="output", signal=dut.q, clk=dut.c) # Create a scoreboard on the outputs self.expected_output = [init_val ] # a list with init_val as the first element with warnings.catch_warnings(): warnings.simplefilter("ignore") self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.output_mon, self.expected_output) # Use the input monitor to reconstruct the transactions from the pins # and send them to our 'model' of the design. self.input_mon = BitMonitor(name="input", signal=dut.d, clk=dut.c, callback=self.model) def model(self, transaction): """Model the DUT based on the input *transaction*. For a D flip-flop, what goes in at ``d`` comes out on ``q``, so the value on ``d`` (put into *transaction* by our ``input_mon``) can be used as expected output without change. Thus we can directly append *transaction* to the ``expected_output`` list, except for the very last clock cycle of the simulation (that is, after ``stop()`` has been called). """ if not self.stopped: self.expected_output.append(transaction) def start(self): """Start generating input data.""" self.input_drv.start() def stop(self): """Stop generating input data. Also stop generation of expected output transactions. One more clock cycle must be executed afterwards so that the output of the D flip-flop can be checked. """ self.input_drv.stop() self.stopped = True
def __init__(self, dut, init_val): """ Setup testbench. init_val signifies the BinaryValue which must be captured by the output monitor with the first risign edge. This is actually the initial state of the flip-flop. """ # Some internal state self.dut = dut self.stopped = False # Create input driver and output monitor self.input_drv = BitDriver(dut.d, dut.c, input_gen()) self.output_mon = BitMonitor("output", dut.q, dut.c) # Create a scoreboard on the outputs self.expected_output = [ init_val ] self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.output_mon, self.expected_output) # Reconstruct the input transactions from the pins # and send them to our 'model' self.input_mon = BitMonitor("input", dut.d, dut.c, callback=self.model)
def __init__(self, dut): """ Setup testbench. """ # Some internal state self.dut = dut self.stopped = False # Create input driver and output monitor self.input_drv = BitDriver(dut.enable, dut.clk, input_gen()) dut.enable <= 0 self.output_mon = BitMonitor("output", dut.impulse, dut.clk) # Create a scoreboard on the outputs self.expected_output = [BinaryValue(0, 1)] self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.output_mon, self.expected_output) # Reconstruct the input transactions from the pins # and send them to our 'model' self.input_mon = BitMonitor("input", dut.enable, dut.clk, callback=self.model) # Model variables self.triggered = False self.counter = 0
class TB(object): def __init__(self, dut): # Some internal state self.dut = dut self.stopped = False # Use the input monitor to reconstruct the transactions from the pins # and send them to our 'model' of the design. self.input_mon = BitMonitor(name="input", signal=dut.Zybo_Example_sw_in, clk=dut.clk, callback=self.model) # Create input driver and output monitor self.input_drv = BitDriver(signal=dut.Zybo_Example_sw_in, clk=dut.clk, generator=input_gen()) self.output_mon = BitMonitor(name="output", signal=dut.Zybo_Example_leds_out, clk=dut.clk) # Create a scoreboard on the outputs self.expected_output = [] self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.output_mon, self.expected_output) def model(self, transaction): if not self.stopped: self.expected_output.append(transaction) def start(self): self.input_drv.start() def stop(self): self.input_drv.stop() self.stopped = True
def __init__(self, dut, debug=False): self.dut = dut self.stream_in = AvalonSTDriver(dut, "stream_in", dut.clk) self.backpressure = BitDriver(self.dut.stream_out_ready, self.dut.clk) self.stream_out = AvalonSTMonitor( dut, "stream_out", dut.clk, config={'firstSymbolInHighOrderBits': True}) self.csr = AvalonMaster(dut, "csr", dut.clk) cocotb.fork( stream_out_config_setter(dut, self.stream_out, self.stream_in)) # Create a scoreboard on the stream_out bus self.pkts_sent = 0 self.expected_output = [] with warnings.catch_warnings(): warnings.simplefilter("ignore") self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.stream_out, self.expected_output) # Reconstruct the input transactions from the pins # and send them to our 'model' self.stream_in_recovered = AvalonSTMonitor(dut, "stream_in", dut.clk, callback=self.model) # Set verbosity on our various interfaces level = logging.DEBUG if debug else logging.WARNING self.stream_in.log.setLevel(level) self.stream_in_recovered.log.setLevel(level)
def __init__(self, dut, codec, debug=False): dut._log.info("Preparing tb for padder, codec={codec}") self.dut = dut self.codec = codec # sha_type_actual self.sha = Sha.get_method(codec=codec) self.s_axis = AXIS_Driver(dut, "s_axis", dut.axis_aclk) self.backpressure = BitDriver(dut.m_axis_tready, dut.axis_aclk) self.m_axis = AXIS_Monitor(dut, "m_axis", dut.axis_aclk) self.expected_output = [] # Create a scoreboard on the m_axis bus with warnings.catch_warnings(): warnings.simplefilter("ignore") self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.m_axis, self.expected_output) # Reconstrut the input transactions self.s_axis_recovered = AXIS_Monitor(dut, "s_axis", dut.axis_aclk, callback=self.model) level = logging.DEBUG if debug else logging.WARNING self.s_axis.log.setLevel(level) self.s_axis_recovered.log.setLevel(level)
class DFF_TB(object): def __init__(self, dut, init_val): """ Setup testbench. init_val signifies the BinaryValue which must be captured by the output monitor with the first risign edge. This is actually the initial state of the flip-flop. """ # Some internal state self.dut = dut self.stopped = False # Create input driver and output monitor self.input_drv = BitDriver(dut.d, dut.c, input_gen()) self.output_mon = BitMonitor("output", dut.q, dut.c) # Create a scoreboard on the outputs self.expected_output = [ init_val ] self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.output_mon, self.expected_output) # Reconstruct the input transactions from the pins # and send them to our 'model' self.input_mon = BitMonitor("input", dut.d, dut.c, callback=self.model) def model(self, transaction): """Model the DUT based on the input transaction.""" # Do not append an output transaction for the last clock cycle of the # simulation, that is, after stop() has been called. if not self.stopped: self.expected_output.append(transaction) def start(self): """Start generation of input data.""" self.input_drv.start() def stop(self): """ Stop generation of input data. Also stop generation of expected output transactions. One more clock cycle must be executed afterwards, so that, output of D-FF can be checked. """ self.input_drv.stop() self.stopped = True
def __init__(self, dut, debug: bool = False): self._dut = dut self._fft_in = DecoupledDriver(self._dut, "in", self._dut.clock) self._fft_mon = FFTMonitor(self._dut, self._dut.clock) self._backpressure = BitDriver(self._dut.out_ready, self._dut.clock) self._scoreboard = Scoreboard(self._dut) self._scoreboard.add_interface(self._fft_mon._mon_out, self._fft_mon._expected_output)
def __init__(self, dut): self.dut = dut self.clkedge = RisingEdge(dut.clk) self.stream_in = AvalonSTDriver(self.dut, "asi", dut.clk) self.stream_out = AvalonSTMonitor(self.dut, "aso", dut.clk) self.scoreboard = Scoreboard(self.dut, fail_immediately=True) self.expected_output = [] self.scoreboard.add_interface(self.stream_out, self.expected_output) self.backpressure = BitDriver(self.dut.aso_ready, self.dut.clk)
def __init__(self, dut, debug=False): self.dut = dut self.stream_in = STDriver(dut, "ValNamein_0", dut.clock, name_map=axi4stream_chisel_name_map) self.backpressure = BitDriver(self.dut.out_0_ready, self.dut.clock) self.stream_out = STMonitor(dut, "out_0", dut.clock, name_map=axi4stream_chisel_name_map) self.csr = MemMaster(dut, "ValNameioMem_0", dut.clock, name_map=axi4_chisel_name_map) self.set_rotation(0) # Reconstruct the input transactions from the pins # and send them to our 'model' self.stream_in_recovered = STMonitor( dut, "ValNamein_0", dut.clock, callback=self.model, name_map=axi4stream_chisel_name_map) # Create a scoreboard on the stream_out bus self.pkts_sent = 0 self.expected_output = [] self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.stream_out, self.expected_output) # Set verbosity on our various interfaces level = logging.DEBUG if debug else logging.WARNING self.stream_in.log.setLevel(level) self.stream_in_recovered.log.setLevel(level)
class ImpulseGeneratorTB(object): def __init__(self, dut): """ Setup testbench. """ # Some internal state self.dut = dut self.stopped = False # Create input driver and output monitor self.input_drv = BitDriver(dut.enable, dut.clk, input_gen()) dut.enable <= 0 self.output_mon = BitMonitor("output", dut.impulse, dut.clk) # Create a scoreboard on the outputs self.expected_output = [BinaryValue(0, 1)] self.scoreboard = Scoreboard(dut) self.scoreboard.add_interface(self.output_mon, self.expected_output) # Reconstruct the input transactions from the pins # and send them to our 'model' self.input_mon = BitMonitor("input", dut.enable, dut.clk, callback=self.model) # Model variables self.triggered = False self.counter = 0 @cocotb.coroutine def reset(self, duration=100000): self.dut._log.debug("Resetting DUT") self.dut.rst <= 1 yield Timer(duration) yield RisingEdge(self.dut.clk) self.dut.rst <= 0 self.dut._log.debug("Out of reset") def model(self, transaction): """ Model the DUT based on the input transaction. """ # Do not append an output transaction for the last clock cycle of the # simulation, that is, after stop() has been called. if not self.stopped: print "--- PING" print(type(transaction)) print(transaction.integer) if self.triggered: print "Appending 1" self.expected_output.append(BinaryValue(1, 1)) self.counter = self.counter + 1 if self.counter == 21 - 1: self.triggered = False else: print "Appending 0" if transaction.integer == 0: self.expected_output.append(BinaryValue(0, 1)) if transaction.integer == 1: self.expected_output.append(BinaryValue(1, 1)) self.counter = self.counter = 0 self.triggered = True # self.expected_output.append(transaction) def start(self): """Start generation of input data.""" self.input_drv.start() def stop(self): """ Stop generation of input data. Also stop generation of expected output transactions. """ self.input_drv.stop() self.stopped = True