async def run_stress_test(dut, idle_inserter=None, backpressure_inserter=None):

    tb = TB(dut)

    byte_lanes = tb.source[0].byte_lanes
    id_count = 2**len(tb.source[0].bus.tid)

    cur_id = 1

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_frames = [[list() for y in tb.sink] for x in tb.source]

    for p in range(len(tb.source)):
        for k in range(128):
            length = random.randint(1, byte_lanes * 16)
            test_data = bytearray(
                itertools.islice(itertools.cycle(range(256)), length))
            test_frame = AxiStreamFrame(test_data)
            test_frame.tid = cur_id
            test_frame.tdest = random.randrange(len(tb.sink))

            test_frames[p][test_frame.tdest].append(test_frame)
            await tb.source[p].send(test_frame)

            cur_id = (cur_id + 1) % id_count

    for lst in test_frames:
        while any(lst):
            rx_frame = await tb.sink[[x for x in lst if x][0][0].tdest].recv()

            test_frame = None

            for lst_a in test_frames:
                for lst_b in lst_a:
                    if lst_b and lst_b[0].tid == rx_frame.tid:
                        test_frame = lst_b.pop(0)
                        break

            assert test_frame is not None

            assert rx_frame.tdata == test_frame.tdata
            assert rx_frame.tid == test_frame.tid
            assert rx_frame.tdest == test_frame.tdest
            assert not rx_frame.tuser

    assert all(s.empty() for s in tb.sink)

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #2
0
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None,
                   s=0,
                   m=0):

    tb = TB(dut)

    id_width = len(tb.source[0].bus.tid)
    id_count = 2**id_width
    id_mask = id_count - 1

    src_width = (len(tb.source) - 1).bit_length()
    src_mask = 2**src_width - 1 if src_width else 0
    src_shift = id_width - src_width
    max_count = 2**src_shift
    count_mask = max_count - 1

    cur_id = 1

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_frames = []

    for test_data in [payload_data(x) for x in payload_lengths()]:
        test_frame = AxiStreamFrame(test_data)
        test_frame.tid = cur_id | (s << src_shift)
        test_frame.tdest = m

        test_frames.append(test_frame)
        await tb.source[s].send(test_frame)

        cur_id = (cur_id + 1) % max_count

    for test_frame in test_frames:
        rx_frame = await tb.sink[m].recv()

        assert rx_frame.tdata == test_frame.tdata
        assert (rx_frame.tid & id_mask) == test_frame.tid
        assert ((rx_frame.tid >> src_shift) & src_mask) == s
        assert (rx_frame.tid >> id_width) == s
        assert rx_frame.tdest == test_frame.tdest
        assert not rx_frame.tuser

    assert all(s.empty() for s in tb.sink)

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_arb_test(dut):

    tb = TB(dut)

    byte_lanes = tb.source[0].byte_lanes
    id_count = 2**len(tb.source[0].bus.tid)

    cur_id = 1

    await tb.reset()

    test_frames = []

    length = byte_lanes * 16
    test_data = bytearray(itertools.islice(itertools.cycle(range(256)),
                                           length))

    for k in range(5):
        test_frame = AxiStreamFrame(test_data, tx_complete=Event())
        test_frame.tid = cur_id
        test_frame.tdest = 0

        src_ind = 0

        if k == 0:
            src_ind = 0
        elif k == 4:
            await test_frames[1].tx_complete.wait()
            for j in range(8):
                await RisingEdge(dut.clk)
            src_ind = 0
        else:
            src_ind = 1

        test_frames.append(test_frame)
        await tb.source[src_ind].send(test_frame)

        cur_id = (cur_id + 1) % id_count

    for k in [0, 1, 2, 4, 3]:
        test_frame = test_frames[k]
        rx_frame = await tb.sink[0].recv()

        assert rx_frame.tdata == test_frame.tdata
        assert rx_frame.tid == test_frame.tid
        assert rx_frame.tdest == test_frame.tdest
        assert not rx_frame.tuser

    assert all(s.empty() for s in tb.sink)

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #4
0
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None,
                   port=0):

    tb = TB(dut)

    id_width = len(tb.source.bus.tid)
    id_count = 2**id_width
    id_mask = id_count - 1

    dest_width = len(tb.sink[0].bus.tid)
    dest_count = 2**dest_width
    dest_mask = dest_count - 1

    cur_id = 1

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_frames = []

    dut.enable.setimmediatevalue(1)
    dut.drop.setimmediatevalue(0)
    dut.select.setimmediatevalue(port)

    for test_data in [payload_data(x) for x in payload_lengths()]:
        test_frame = AxiStreamFrame(test_data)
        test_frame.tid = cur_id
        test_frame.tdest = cur_id | (port << dest_width)

        test_frames.append(test_frame)
        await tb.source.send(test_frame)

        cur_id = (cur_id + 1) % id_count

    for test_frame in test_frames:
        rx_frame = await tb.sink[port].recv()

        assert rx_frame.tdata == test_frame.tdata
        assert rx_frame.tid == test_frame.tid
        assert rx_frame.tdest == (test_frame.tdest & dest_mask)
        assert not rx_frame.tuser

    assert tb.sink[port].empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #5
0
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None):

    tb = TB(dut)

    id_count = 2**len(tb.source.bus.tid)

    cur_id = 1

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_frames = []

    for test_data in [payload_data(x) for x in payload_lengths()]:
        test_frame = AxiStreamFrame(test_data)
        test_frame.tid = cur_id
        test_frame.tdest = cur_id
        await tb.source.send(test_frame)

        test_frames.append(test_frame)

        cur_id = (cur_id + 1) % id_count

    for test_frame in test_frames:
        rx_frame = await tb.sink.recv()

        assert rx_frame.tdata == test_frame.tdata
        assert rx_frame.tid == test_frame.tid
        assert rx_frame.tdest == test_frame.tdest
        assert not rx_frame.tuser

        mon_rx_frame = await tb.monitor.recv()

        assert mon_rx_frame.tdata == test_frame.tdata
        assert mon_rx_frame.tid == test_frame.tid
        assert mon_rx_frame.tdest == test_frame.tdest
        assert not mon_rx_frame.tuser

        assert rx_frame.sim_time_start == mon_rx_frame.sim_time_start
        assert rx_frame.sim_time_end == mon_rx_frame.sim_time_end

    assert tb.sink.empty()
    assert tb.monitor.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_test(dut, payload_lengths=None, payload_data=None, idle_inserter=None):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)

    test_pkts = []
    test_frames = []

    for payload in [payload_data(x) for x in payload_lengths()]:
        test_pkt = bytearray(payload)

        test_pkts.append(test_pkt)
        test_frame = AxiStreamFrame(test_pkt)
        test_frames.append(test_frame)

        await tb.source.send(test_frame)

    for test_pkt, test_frame in zip(test_pkts, test_frames):
        rx_frame = await tb.sink.recv()

        rx_pkt = bytes(rx_frame)

        tb.log.info("RX packet: %s", repr(rx_pkt))

        # padded to 60 if the packet size is less than 60
        padded_pkt = test_pkt.ljust(60, b'\x00')
        assert rx_frame.tdata == padded_pkt

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_test_overflow(dut):

    tb = TB(dut)

    await tb.reset()

    tb.sink.pause = True

    test_data = bytearray(itertools.islice(itertools.cycle(range(256)), 2048))
    test_frame = AxiStreamFrame(test_data)
    await tb.source.send(test_frame)

    for k in range(2048):
        await RisingEdge(dut.clk)

    tb.sink.pause = False

    if int(os.getenv("PARAM_FRAME_FIFO")):
        for k in range(2048):
            await RisingEdge(dut.clk)

    else:
        rx_frame = await tb.sink.recv()

        assert rx_frame.tdata == test_data
        assert not rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_test_shift_out_source_reset(dut):

    tb = TB(dut)

    await tb.reset()

    test_data = bytearray(itertools.islice(itertools.cycle(range(256)), 256))
    test_frame = AxiStreamFrame(test_data)
    await tb.source.send(test_frame)

    await RisingEdge(dut.m_axis_tvalid)

    for k in range(8):
        await RisingEdge(dut.s_clk)

    await tb.reset_source()

    for k in range(64):
        await RisingEdge(dut.s_clk)

    rx_frame = await tb.sink.recv()

    assert rx_frame.tuser

    assert tb.sink.idle()

    await RisingEdge(dut.s_clk)
    await RisingEdge(dut.s_clk)
async def run_test_pad(dut, payload_data=None, idle_inserter=None):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)

    test_pkt = bytearray(payload_data(60))

    for k in range(1, 60):
        test_frame = AxiStreamFrame(tdata=test_pkt, tkeep=[1 if i < k else 0 for i in range(60)])

        await tb.source.send(test_frame)

    for k in range(1, 60):
        rx_frame = await tb.sink.recv()

        rx_pkt = bytes(rx_frame)

        tb.log.info("RX packet: %s", repr(rx_pkt))

        # padded to 60 if the packet size is less than 60
        padded_pkt = test_pkt[:k].ljust(60, b'\x00')

        assert len(rx_frame.tdata) == 60
        assert rx_frame.tdata == padded_pkt

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_test_shift_in_source_reset(dut):

    tb = TB(dut)

    await tb.reset()

    test_data = bytearray(itertools.islice(itertools.cycle(range(256)), 256))
    test_frame = AxiStreamFrame(test_data)
    await tb.source.send(test_frame)

    for k in range(8):
        await RisingEdge(dut.s_clk)

    await tb.reset_source()

    for k in range(64):
        await RisingEdge(dut.s_clk)

    if int(os.getenv("PARAM_FRAME_FIFO")):
        assert tb.sink.empty()
    else:
        rx_frame = await tb.sink.recv()

        assert rx_frame.tuser

        assert tb.sink.empty()
    assert tb.sink.idle()

    await RisingEdge(dut.s_clk)
    await RisingEdge(dut.s_clk)
async def run_test_init_sink_pause_reset(dut):

    tb = TB(dut)

    await tb.reset()

    tb.sink.pause = True

    test_data = bytearray(itertools.islice(itertools.cycle(range(256)), 32))
    test_frame = AxiStreamFrame(test_data)
    await tb.source.send(test_frame)

    for k in range(64):
        await RisingEdge(dut.clk)

    await tb.reset()

    tb.sink.pause = False

    for k in range(64):
        await RisingEdge(dut.clk)

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #12
0
async def run_test(dut, payload_lengths=None, payload_data=None, idle_inserter=None, backpressure_inserter=None):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_frames = [payload_data(x) for x in payload_lengths()]

    for test_data in test_frames:
        enc = cobs_encode(test_data)
        test_frame = AxiStreamFrame(enc)
        await tb.source.send(test_frame)

    for test_data in test_frames:
        rx_frame = await tb.sink.recv()

        assert rx_frame.tdata == test_data
        assert not rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #13
0
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None,
                   rate=(1, 1)):

    tb = TB(dut)

    id_count = 2**len(tb.source.bus.tid)

    cur_id = 1

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    dut.rate_num.value = rate[0]
    dut.rate_denom.value = rate[1]
    await RisingEdge(dut.clk)

    test_frames = []

    for test_data in [payload_data(x) for x in payload_lengths()]:
        test_frame = AxiStreamFrame(test_data)
        test_frame.tid = cur_id
        test_frame.tdest = cur_id

        test_frames.append(test_frame)
        await tb.source.send(test_frame)

        cur_id = (cur_id + 1) % id_count

    for test_frame in test_frames:
        rx_frame = await tb.sink.recv()

        assert rx_frame.tdata == test_frame.tdata
        assert rx_frame.tid == test_frame.tid
        assert rx_frame.tdest == test_frame.tdest
        assert not rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None,
                   s=0,
                   m=0):

    tb = TB(dut)

    id_count = 2**len(tb.source[s].bus.tid)

    cur_id = 1

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_frames = []

    for test_data in [payload_data(x) for x in payload_lengths()]:
        test_frame = AxiStreamFrame(test_data)
        test_frame.tid = cur_id
        test_frame.tdest = m

        test_frames.append(test_frame)
        await tb.source[s].send(test_frame)

        cur_id = (cur_id + 1) % id_count

    for test_frame in test_frames:
        rx_frame = await tb.sink[m].recv()

        assert rx_frame.tdata == test_frame.tdata
        assert rx_frame.tid == test_frame.tid
        assert rx_frame.tdest == test_frame.tdest
        assert not rx_frame.tuser

    assert all(s.empty() for s in tb.sink)

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #15
0
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   pkt_type=Ether):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)

    test_pkts = []
    test_frames = []

    ip_id = 0

    for payload in [payload_data(x) for x in payload_lengths()]:
        eth = Ether(src='5A:51:52:53:54:55', dst='DA:D1:D2:D3:D4:D5')
        if pkt_type == Ether:
            test_pkt = eth / payload
        else:
            ip = IP(src=f'10.1.0.{ip_id}', dst=f'10.2.0.{ip_id}', id=ip_id)
            if pkt_type == IP:
                test_pkt = eth / ip / payload
            elif pkt_type == UDP:
                udp = UDP(sport=ip_id, dport=0x1000 + ip_id)
                test_pkt = eth / ip / udp / payload
            elif pkt_type == TCP:
                tcp = TCP(sport=ip_id, dport=0x1000 + ip_id)
                test_pkt = eth / ip / tcp / payload

        test_pkts.append(test_pkt)

        test_frame = AxiStreamFrame(test_pkt.build())
        test_frames.append(test_frame)
        await tb.source.send(test_frame)

        ip_id = (ip_id + 1) & 0xffff

    for test_pkt, test_frame in zip(test_pkts, test_frames):
        rx_csum = await tb.sink.recv()

        csum = ~scapy.utils.checksum(bytes(test_pkt.payload)) & 0xffff

        tb.log.info("Output checksum: 0x%04x (expected 0x%04x)",
                    rx_csum.csum.integer, csum)

        assert rx_csum.csum == csum

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #16
0
async def run_test_write(dut, data_in=None, idle_inserter=None, backpressure_inserter=None):

    tb = TB(dut)

    byte_lanes = tb.axi_ram.byte_lanes
    step_size = 1 if int(os.getenv("PARAM_ENABLE_UNALIGNED")) else byte_lanes
    tag_count = 2**len(tb.write_desc_source.bus.tag)

    cur_tag = 1

    await tb.cycle_reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    dut.enable.value = 1

    for length in list(range(1, byte_lanes*4+1))+[128]:
        for offset in list(range(0, byte_lanes*2, step_size))+list(range(4096-byte_lanes*2, 4096, step_size)):
            for diff in [-8, -2, -1, 0, 1, 2, 8]:
                if length+diff < 1:
                    continue

                tb.log.info("length %d, offset %d, diff %d", length, offset, diff)
                addr = offset+0x1000
                test_data = bytearray([x % 256 for x in range(length)])
                test_data2 = bytearray([x % 256 for x in range(length+diff)])

                tb.axi_ram.write(addr-128, b'\xaa'*(len(test_data)+256))

                desc = DescTransaction(addr=addr, len=len(test_data), tag=cur_tag)
                await tb.write_desc_source.send(desc)

                await tb.write_data_source.send(AxiStreamFrame(test_data2, tid=cur_tag))

                status = await tb.write_desc_status_sink.recv()

                tb.log.info("status: %s", status)
                assert int(status.len) == min(len(test_data), len(test_data2))
                assert int(status.tag) == cur_tag
                assert int(status.id) == cur_tag
                assert int(status.error) == 0

                tb.log.debug("%s", tb.axi_ram.hexdump_str((addr & ~0xf)-16, (((addr & 0xf)+length-1) & ~0xf)+48))

                if len(test_data) <= len(test_data2):
                    assert tb.axi_ram.read(addr-8, len(test_data)+16) == b'\xaa'*8+test_data+b'\xaa'*8
                else:
                    assert tb.axi_ram.read(addr-8, len(test_data2)+16) == b'\xaa'*8+test_data2+b'\xaa'*8

                cur_tag = (cur_tag + 1) % tag_count

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #17
0
async def run_stress_test(dut, idle_inserter=None, backpressure_inserter=None):

    tb = TB(dut)

    byte_lanes = tb.source.byte_lanes
    id_count = 2**len(tb.source.bus.tid)

    cur_id = 1

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_frames = []

    for k in range(128):
        length = random.randint(1, byte_lanes * 16)
        test_data = bytearray(
            itertools.islice(itertools.cycle(range(256)), length))
        test_frame = AxiStreamFrame(test_data)
        test_frame.tid = cur_id
        test_frame.tdest = cur_id

        test_frames.append(test_frame)
        await tb.source.send(test_frame)

        cur_id = (cur_id + 1) % id_count

    for test_frame in test_frames:
        rx_frame = await tb.sink.recv()

        assert rx_frame.tdata == test_frame.tdata
        assert rx_frame.tid == test_frame.tid
        assert rx_frame.tdest == test_frame.tdest
        assert not rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #18
0
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_pkts = []
    test_frames = []

    for payload in [payload_data(x) for x in payload_lengths()]:
        eth = Ether(src='5A:51:52:53:54:55',
                    dst='DA:D1:D2:D3:D4:D5',
                    type=0x8000)
        test_pkt = eth / payload

        test_pkts.append(test_pkt.copy())
        test_frame = AxiStreamFrame(test_pkt.build())
        test_frames.append(test_frame)

        await tb.source.send(test_frame)

    for test_pkt, test_frame in zip(test_pkts, test_frames):
        rx_header = await tb.header_sink.recv()
        rx_payload = await tb.payload_sink.recv()

        eth = Ether()
        eth.dst = rx_header.dest_mac.integer.to_bytes(6, 'big')
        eth.src = rx_header.src_mac.integer.to_bytes(6, 'big')
        eth.type = rx_header.type.integer
        rx_pkt = eth / bytes(rx_payload.tdata)

        tb.log.info("RX packet: %s", repr(rx_pkt))

        assert rx_pkt.build() == test_pkt.build()
        assert not rx_payload.tuser

    assert tb.header_sink.empty()
    assert tb.payload_sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_pkts = []

    for payload in [payload_data(x) for x in payload_lengths()]:
        eth = Ether(src='5A:51:52:53:54:55',
                    dst='DA:D1:D2:D3:D4:D5',
                    type=0x8000)
        test_pkt = eth / payload
        test_pkts.append(test_pkt.copy())

        test_frame = test_pkt.build()

        hdr = EthHdrTransaction()
        hdr.dest_mac = int.from_bytes(test_frame[0:6], "big")
        hdr.src_mac = int.from_bytes(test_frame[6:12], "big")
        hdr.type = int.from_bytes(test_frame[12:14], "big")

        await tb.header_source.send(hdr)
        await tb.payload_source.send(AxiStreamFrame(payload))

    for test_pkt in test_pkts:
        rx_frame = await tb.sink.recv()

        rx_pkt = Ether(bytes(rx_frame))

        tb.log.info("RX packet: %s", repr(rx_pkt))

        assert rx_pkt.build() == test_pkt.build()
        assert not rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #20
0
async def run_test_tuser_assert(dut, port=0):

    tb = TB(dut)

    await tb.reset()

    test_data = bytearray(itertools.islice(itertools.cycle(range(256)), 32))
    test_frame = AxiStreamFrame(test_data, tuser=1)
    await tb.source[port].send(test_frame)

    rx_frame = await tb.sink.recv()

    assert rx_frame.tdata == test_data
    assert rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #21
0
async def run_test_tuser_assert(dut, s=0, m=0):

    tb = TB(dut)

    await tb.reset()

    test_data = bytearray(itertools.islice(itertools.cycle(range(256)), 32))
    test_frame = AxiStreamFrame(test_data, tuser=1, tdest=m)
    await tb.source[s].send(test_frame)

    rx_frame = await tb.sink[m].recv()

    assert rx_frame.tdata == test_data
    assert rx_frame.tuser

    assert all(s.empty() for s in tb.sink)

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_test_shift_in_sink_reset(dut):

    tb = TB(dut)

    await tb.reset()

    test_data = bytearray(itertools.islice(itertools.cycle(range(256)), 256))
    test_frame = AxiStreamFrame(test_data)
    await tb.source.send(test_frame)

    for k in range(8):
        await RisingEdge(dut.s_clk)

    await tb.reset_sink()

    for k in range(64):
        await RisingEdge(dut.s_clk)

    assert tb.sink.idle()

    await RisingEdge(dut.s_clk)
    await RisingEdge(dut.s_clk)
예제 #23
0
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None):

    tb = TB(dut)

    append_zero = int(os.getenv("PARAM_APPEND_ZERO"))

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_frames = [payload_data(x) for x in payload_lengths()]

    for test_data in test_frames:
        test_frame = AxiStreamFrame(test_data)
        await tb.source.send(test_frame)

    for test_data in test_frames:
        rx_frame = await tb.sink.recv()

        if append_zero:
            assert rx_frame.tdata == cobs_encode(test_data) + b'\x00'
            assert cobs_decode(rx_frame.tdata[:-1]) == test_data
        else:
            assert rx_frame.tdata == cobs_encode(test_data)
            assert cobs_decode(rx_frame.tdata) == test_data
        assert not rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_test_tuser_assert(dut):

    tb = TB(dut)

    await tb.reset()

    test_data = bytearray(itertools.islice(itertools.cycle(range(256)), 32))
    test_frame = AxiStreamFrame(test_data, tuser=1)
    await tb.source.send(test_frame)

    if int(os.getenv("PARAM_FRAME_FIFO")):
        for k in range(64):
            await RisingEdge(dut.clk)

    else:
        rx_frame = await tb.sink.recv()

        assert rx_frame.tdata == test_data
        assert rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #25
0
async def run_test_offsets(dut,
                           payload_lengths=None,
                           payload_data=None,
                           idle_inserter=None,
                           backpressure_inserter=None):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_pkts = []
    test_frames = []
    check_frames = []

    ip_id = 1

    for payload in [payload_data(x) for x in payload_lengths()]:
        eth = Ether(src='5A:51:52:53:54:55', dst='DA:D1:D2:D3:D4:D5')
        test_pkt = eth / payload

        ip_id = (ip_id + 1) & 0xffff

        for start in range(0, min(len(payload) + 14, 32)):
            offset = 0
            test_pkts.append(test_pkt.copy())
            test_frame = AxiStreamFrame(test_pkt.build())
            test_frames.append(test_frame)

            await tb.source.send(test_frame)
            await tb.cmd_source.send(
                CsumCmdTransaction(csum_enable=1,
                                   csum_start=start,
                                   csum_offset=offset,
                                   csum_init=0))

            csum = scapy.utils.checksum(bytes(test_pkt)[start:])

            check_frame = bytearray(test_frame.tdata)
            struct.pack_into('>H', check_frame, offset, csum)

            check_frames.append(check_frame)

        for offset in range(0, min(len(payload) + 14, 32) - 1):
            start = 0
            test_pkts.append(test_pkt.copy())
            test_frame = AxiStreamFrame(test_pkt.build())
            test_frames.append(test_frame)

            await tb.source.send(test_frame)
            await tb.cmd_source.send(
                CsumCmdTransaction(csum_enable=1,
                                   csum_start=start,
                                   csum_offset=offset,
                                   csum_init=0))

            csum = scapy.utils.checksum(bytes(test_pkt)[start:])

            check_frame = bytearray(test_frame.tdata)
            struct.pack_into('>H', check_frame, offset, csum)

            check_frames.append(check_frame)

    for test_pkt, test_frame, check_frame in zip(test_pkts, test_frames,
                                                 check_frames):
        rx_frame = await tb.sink.recv()

        rx_pkt = Ether(bytes(rx_frame))

        tb.log.info("RX packet: %s", repr(rx_pkt))

        assert rx_frame.tdata == check_frame

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #26
0
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   pkt_type=Ether):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)

    test_pkts = []
    hash_info = []
    test_frames = []

    ip_id = 1

    for payload in [payload_data(x) for x in payload_lengths()]:
        eth = Ether(src='5A:51:52:53:54:55', dst='DA:D1:D2:D3:D4:D5')
        if pkt_type == Ether:
            test_pkt = eth / payload
            hash_type = HashType(0)
            hash_val = 0
        else:
            ip = IP(src=f'10.1.0.{ip_id}', dst=f'10.2.0.{ip_id}', id=ip_id)
            if pkt_type == IP:
                test_pkt = eth / ip / payload
                hash_type = HashType.IPV4
                hash_val = hash_toep(tuple_pack(ip.src, ip.dst), tb.hash_key)
            elif pkt_type == UDP:
                udp = UDP(sport=ip_id, dport=0x1000 + ip_id)
                test_pkt = eth / ip / udp / payload
                hash_type = HashType.IPV4 | HashType.UDP
                hash_val = hash_toep(
                    tuple_pack(ip.src, ip.dst, udp.sport, udp.dport),
                    tb.hash_key)
            elif pkt_type == TCP:
                tcp = TCP(sport=ip_id, dport=0x1000 + ip_id)
                test_pkt = eth / ip / tcp / payload
                hash_type = HashType.IPV4 | HashType.TCP
                hash_val = hash_toep(
                    tuple_pack(ip.src, ip.dst, tcp.sport, tcp.dport),
                    tb.hash_key)

        test_pkts.append(test_pkt)
        hash_info.append((hash_type, hash_val))

        test_frame = AxiStreamFrame(test_pkt.build())
        test_frames.append(test_frame)
        await tb.source.send(test_frame)

        ip_id = (ip_id + 1) & 0xffff

    for test_pkt, info, test_frame in zip(test_pkts, hash_info, test_frames):
        hash_type, hash_val = info

        rx_hash = await tb.sink.recv()

        tb.log.info(
            "RX hash: 0x%08x (expected: 0x%08x) type: %s (expected: %s)",
            rx_hash.hash, hash_val, HashType(rx_hash.hash_type.integer),
            hash_type)

        assert rx_hash.hash_type == hash_type
        assert rx_hash.hash == hash_val

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #27
0
async def run_test(dut,
                   payload_lengths=None,
                   payload_data=None,
                   idle_inserter=None,
                   backpressure_inserter=None):

    tb = TB(dut)

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_pkts = []
    test_frames = []

    ip_id = 1

    for payload in [payload_data(x) for x in payload_lengths()]:
        eth = Ether(src='5A:51:52:53:54:55', dst='DA:D1:D2:D3:D4:D5')
        ip = IP(src='192.168.1.100', dst='192.168.1.101', id=ip_id)
        udp = UDP(sport=1234, dport=4321)
        test_pkt = eth / ip / udp / payload

        ip_id = (ip_id + 1) & 0xffff

        # don't compute checksum
        test_pkts.append(test_pkt.copy())
        test_frame = AxiStreamFrame(test_pkt.build())
        test_frames.append(test_frame)

        await tb.source.send(test_frame)
        await tb.cmd_source.send(
            CsumCmdTransaction(csum_enable=0,
                               csum_start=34,
                               csum_offset=40,
                               csum_init=0))

        # inline partial checksum
        test_pkts.append(test_pkt.copy())

        pkt = test_pkt.copy()
        partial_csum = scapy.utils.checksum(bytes(pkt[UDP]))
        pkt[UDP].chksum = partial_csum

        test_frame = AxiStreamFrame(pkt.build())
        test_frames.append(test_frame)

        await tb.source.send(test_frame)
        await tb.cmd_source.send(
            CsumCmdTransaction(csum_enable=1,
                               csum_start=34,
                               csum_offset=40,
                               csum_init=0))

        # partial checksum in command
        test_pkts.append(test_pkt.copy())

        pkt = test_pkt.copy()
        partial_csum = scapy.utils.checksum(bytes(pkt[UDP]))
        pkt[UDP].chksum = 0

        test_frame = AxiStreamFrame(pkt.build())
        test_frames.append(test_frame)

        await tb.source.send(test_frame)
        await tb.cmd_source.send(
            CsumCmdTransaction(csum_enable=1,
                               csum_start=34,
                               csum_offset=40,
                               csum_init=partial_csum))

    for test_pkt, test_frame in zip(test_pkts, test_frames):
        rx_frame = await tb.sink.recv()

        rx_pkt = Ether(bytes(rx_frame))

        tb.log.info("RX packet: %s", repr(rx_pkt))

        check_pkt = Ether(test_pkt.build())

        tb.log.info("RX packet UDP checksum: 0x%04x (expected 0x%04x)",
                    rx_pkt[UDP].chksum, check_pkt[UDP].chksum)

        assert check_pkt == rx_pkt

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #28
0
async def run_stress_test(dut, idle_inserter=None, backpressure_inserter=None):

    tb = TB(dut)

    byte_lanes = tb.source[0].byte_lanes
    id_width = len(tb.source[0].bus.tid)
    id_count = 2**id_width
    id_mask = id_count - 1

    src_width = (len(tb.source) - 1).bit_length()
    src_mask = 2**src_width - 1 if src_width else 0
    src_shift = id_width - src_width
    max_count = 2**src_shift
    count_mask = max_count - 1

    cur_id = 1

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    test_frames = [list() for x in tb.source]

    for p in range(len(tb.source)):
        for k in range(128):
            length = random.randint(1, byte_lanes * 16)
            test_data = bytearray(
                itertools.islice(itertools.cycle(range(256)), length))
            test_frame = AxiStreamFrame(test_data)
            test_frame.tid = cur_id | (p << src_shift)
            test_frame.tdest = cur_id

            test_frames[p].append(test_frame)
            await tb.source[p].send(test_frame)

            cur_id = (cur_id + 1) % max_count

    while any(test_frames):
        rx_frame = await tb.sink.recv()

        test_frame = None

        for lst in test_frames:
            if lst and lst[0].tid == (rx_frame.tid & id_mask):
                test_frame = lst.pop(0)
                break

        assert test_frame is not None

        assert rx_frame.tdata == test_frame.tdata
        assert (rx_frame.tid & id_mask) == test_frame.tid
        assert ((rx_frame.tid >> src_shift)
                & src_mask) == (rx_frame.tid >> id_width)
        assert rx_frame.tdest == test_frame.tdest
        assert not rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
예제 #29
0
async def run_arb_test(dut):

    tb = TB(dut)

    byte_lanes = tb.source[0].byte_lanes
    id_width = len(tb.source[0].bus.tid)
    id_count = 2**id_width
    id_mask = id_count - 1

    src_width = (len(tb.source) - 1).bit_length()
    src_mask = 2**src_width - 1 if src_width else 0
    src_shift = id_width - src_width
    max_count = 2**src_shift
    count_mask = max_count - 1

    cur_id = 1

    await tb.reset()

    test_frames = []

    length = byte_lanes * 16
    test_data = bytearray(itertools.islice(itertools.cycle(range(256)),
                                           length))

    for k in range(5):
        test_frame = AxiStreamFrame(test_data, tx_complete=Event())

        src_ind = 0

        if k == 0:
            src_ind = 0
        elif k == 4:
            await test_frames[1].tx_complete.wait()
            for j in range(8):
                await RisingEdge(dut.clk)
            src_ind = 0
        else:
            src_ind = 1

        test_frame.tid = cur_id | (src_ind << src_shift)
        test_frame.tdest = 0

        test_frames.append(test_frame)
        await tb.source[src_ind].send(test_frame)

        cur_id = (cur_id + 1) % max_count

    for k in [0, 1, 2, 4, 3]:
        test_frame = test_frames[k]
        rx_frame = await tb.sink.recv()

        assert rx_frame.tdata == test_frame.tdata
        assert (rx_frame.tid & id_mask) == test_frame.tid
        assert ((rx_frame.tid >> src_shift)
                & src_mask) == (rx_frame.tid >> id_width)
        assert rx_frame.tdest == test_frame.tdest
        assert not rx_frame.tuser

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
async def run_test(dut, payload_lengths=None, payload_data=None, idle_inserter=None, backpressure_inserter=None):

    tb = TB(dut)

    data_width = len(tb.source.bus.tkeep)
    byte_width = data_width // 8
    id_count = 2**len(tb.source.bus.tid)

    cur_id = 1

    await tb.reset()

    tb.set_idle_generator(idle_inserter)
    tb.set_backpressure_generator(backpressure_inserter)

    for length_max in range(1, byte_width*2+2):
        for length_min in range(0, length_max+1):
            tb.log.info("length_min %d, length_max %d", length_min, length_max)

            await RisingEdge(dut.clk)
            tb.dut.length_min <= length_min
            tb.dut.length_max <= length_max
            await RisingEdge(dut.clk)

            test_frames = []

            for test_data in [payload_data(x) for x in payload_lengths()]:
                test_frame = AxiStreamFrame(test_data, tid=cur_id, tdest=cur_id)

                test_frames.append(test_frame)
                await tb.source.send(test_frame)

                cur_id = (cur_id + 1) % id_count

            for test_frame in test_frames:
                rx_frame = await tb.sink.recv()

                len_rx = len(rx_frame.tdata)
                len_test = len(test_frame.tdata)
                len_min = min(len_rx, len_test)

                assert len_rx >= length_min
                assert len_rx <= length_max
                assert rx_frame.tdata[:len_min] == test_frame.tdata[:len_min]
                assert rx_frame.tid == test_frame.tid
                assert rx_frame.tdest == test_frame.tdest
                assert not rx_frame.tuser

                status = await tb.status_sink.recv()

                tb.log.info("Status: %s", status)

                assert status.frame_pad == int(len_test < length_min)
                assert status.frame_truncate == int(len_test > length_max)
                assert status.frame_length == len_rx
                assert status.frame_original_length == len_test

    assert tb.sink.empty()

    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)