async def run_test(dut, data_in=None, codec=None, backpressure_inserter=None): dut.m_axis_tready <= 0 #dut.log.setLevel(logging.DEBUG) """ Setup testbench and run a test. """ clock = Clock(dut.axis_aclk, 10, units="ns") # Create a 10ns period clock on port clk cocotb.fork(clock.start()) # Start the clock tb = PadderTB(dut, codec, False) # Debug=False await tb.reset() dut.m_axis_tready <= 1 if backpressure_inserter is not None: tb.backpressure.start(backpressure_inserter()) # Send in the packets for transaction in data_in(): tb.s_axis.bus.tuser <= BinaryValue(80 * '0' + little_endian_codec(codec) + 32 * '0') await tb.s_axis.send(transaction, tuser=get_bytes(16, random_data())) # Wait for last transmission await RisingEdge(dut.axis_aclk) while not (dut.m_axis_tlast.value and dut.m_axis_tvalid.value and dut.m_axis_tready.value): await RisingEdge(dut.axis_aclk) for _ in range(3): await RisingEdge(dut.axis_aclk) dut._log.info("DUT testbench finished!") raise tb.scoreboard.result
def udp_random_sizes(npackets=100, payload=_default_payload()): """UDP packets with random sizes""" header = Ether() / IP() / UDP() max_size = 1500 - len(header) for pkt in range(npackets): yield header / get_bytes(random.randint(0, max_size), payload)
def ipv4_small_packets(npackets=100, payload=_default_payload()): """ Small (<100bytes payload) IPV4 packets .. deprecated:: 1.4.1 """ for pkt in range(npackets): yield Ether() / IP() / get_bytes(random.randint(0, 100), payload)
def udp_all_sizes(max_size=1500, payload=_default_payload()): """ UDP packets of every supported size .. deprecated:: 1.4.1 """ header = Ether() / IP() / UDP() for size in range(0, max_size - len(header)): yield header / get_bytes(size, payload)
def random_message(blocks512 ,min_blocks=1, max_blocks=4, npackets=4): """random string data of a random length""" if blocks512>>1: max_blocks = int(max_blocks/2) if(max_blocks == 0): max_blocks = 1 mult_blocks = 2 else: mult_blocks = 1 for _ in range(npackets): yield get_bytes(BLOCK_BYTE_WIDTH*mult_blocks*random.randint(min_blocks, max_blocks), random_data())
def random_packet_sizes(min_size=1, max_size=150, npackets=10): """random string data of a random length""" for i in range(npackets): yield get_bytes(random.randint(min_size, max_size), random_data())
def format_wt(codec, min_blocks=1, max_blocks=4, npackets=4): dumy_sha_instance = Sha.get_method(codec) virtual_bytes_per_block = BYTE_WIDTH_WORDS*dumy_sha_instance.wt_iters gen = random_wt(dumy_sha_instance.word_size) for _ in range(npackets): yield get_bytes(virtual_bytes_per_block*random.randint(min_blocks,max_blocks),gen)
def ipv4_small_packets(npackets=100, payload=_default_payload()): """Small (<100bytes payload) IPV4 packets""" for pkt in range(npackets): yield Ether() / IP() / get_bytes(random.randint(0, 100), payload)
def udp_all_sizes(max_size=1500, payload=_default_payload()): """UDP packets of every supported size""" header = Ether() / IP() / UDP() for size in range(0, max_size - len(header)): yield header / get_bytes(size, payload)
def simple_input(): words = iter(map(chr, range(100 * 64))) for i in range(100): yield get_bytes(2, words)
def random_hash(npackets=5): """random string data of a random length""" for _ in range(npackets): yield get_bytes(64, random_data())
def sequence(npackets=100): words = iter(map(chr, range(npackets * 100))) for i in range(npackets): yield get_bytes(64, words)
def random_word(size=4): yield get_bytes(size, random_data())