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)
Exemple #2
0
def tun_tap_example_test(dut):
    """Example of a test using TUN/TAP.

    Creates an interface (192.168.255.1) and any packets received are sent
    into the DUT.  The response output by the DUT is then sent back out on
    this interface.

    Note to create the TUN interface this test must be run as root or the user
    must have CAP_NET_ADMIN capability.
    """

    cocotb.fork(Clock(dut.clk, 5000).start())

    stream_in = AvalonSTDriver(dut, "stream_in", dut.clk)
    stream_out = AvalonSTMonitor(dut, "stream_out", dut.clk)

    # Enable verbose logging so we can see what's going on
    stream_in.log.setLevel(logging.DEBUG)
    stream_out.log.setLevel(logging.DEBUG)

    # Reset the DUT
    dut._log.debug("Resetting DUT")
    dut.reset_n <= 0
    stream_in.bus.valid <= 0
    yield Timer(10000)
    yield RisingEdge(dut.clk)
    dut.reset_n <= 1
    dut.stream_out_ready <= 1
    dut._log.debug("Out of reset")

    # Create our interface (destroyed at the end of the test)
    tun = create_tun()
    fd = tun.fileno()

    # Kick off a ping...
    subprocess.check_call('ping -c 5 192.168.255.2 &', shell=True)

    # Respond to 5 pings, then quit
    pingcounter = 0
    while True:
        cocotb.log.info("Waiting for packets on tun interface")
        packet = os.read(fd, 2048)
        cocotb.log.info("Received a packet!")

        if packet[9] == '\x01' and packet[20] == '\x08':
            cocotb.log.debug("Packet is an ICMP echo request")
            pingcounter += 1
        else:
            cocotb.log.info(
                "Packet is no ICMP echo request, throwing away packet")
            continue

        stream_in.append(packet)
        result = yield stream_out.wait_for_recv()

        cocotb.log.info("Rtl replied!")
        os.write(fd, str(result))

        if pingcounter == 5:
            break
Exemple #3
0
 def __init__(self, dut):
     self.dut = dut
     self.st_in = AvalonSTDriver(dut, 'st_in', dut.clk)
     self.st_out = AvalonSTMonitor(dut, 'st_out', dut.clk)
     self.csr = AvalonMaster(dut, 'csr', dut.clk)
     self.st_in_recovered = AvalonSTMonitor(dut,
                                            'st_in',
                                            dut.clk,
                                            callback=self.model)
     self.expected_output = []
     self.scoreboard = Scoreboard(dut)
     self.scoreboard.add_interface(self.st_out, self.expected_output)
Exemple #4
0
    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)
Exemple #5
0
 def __init__(self, dut):
     super().__init__(dut)
     self.data_tx = AvalonSTDriver(dut, 'data_tx', dut.clk)
Exemple #6
0
 def __init__(self, dut):
     super().__init__(dut)
     self.tlp_rx_st = AvalonSTDriver(dut, 'tlp_rx_st', dut.clk)
     self.tlp_rx_recovered = AvalonSTMonitor(dut, 'tlp_rx_st', dut.clk,
             callback=self.rx_model)