The harness

A harness is any module made the DUT of its own HwSystem:

from examples.mem_copy.mem_copy import MemCopy        # the example's kernel
from waveflow.hw.harness import harness               # the framework's

sysm = harness(MemCopy, workload="test")              # an HwSystem: the kernel, a stand-in per port
for port, stand_in in sysm.stand_ins.items():
    print(port, type(stand_in).__name__, stand_in.name)
m_in MemoryMod memory
m_out MemoryMod memory
s_cmd StreamDriver s_cmd_driver
s_done StreamSink s_done_sink

harness takes a module class or an instance. The DUT is a fresh copy: the module’s class and its build parameters (HwParam fields), on a new Simulation. So a module inside a larger system is harnessed without disturbing it, and the copy is a root, as a system’s DUT must be (the HwSystem rules). sysm.stand_ins maps each boundary port to the testbench participant that faces it.

A stand-in per port type

The testbench is generated from the module’s boundary, port by port. Each stand-in is a pysim object with an RTL twin – its bfm_model() – so the same harness runs in pysim and under XSI:

the module’s port stand-in (pysim) RTL twin (XSI)
a stream input (StreamIFSlave) StreamDriver, playing vectors/<port> AxisMaster
a stream output (StreamIFMaster) StreamSink, recording vectors/<port> AxisSlave
a credit stream it produces into CreditSink: takes everything, reports credit CreditSink
a credit stream it consumes CreditSource: plays bursts when the window has room CreditSource
its memory-master ports (MMIFReadMaster, MMIFWriteMaster) one MemoryMod behind all of them, on a zero-latency crossbar one FlatMemory arena, served to each m_axi bundle by AxiMmReadSlave or AxiMmWriteSlave

The C++ classes are in waveflow/build/xsi/xsi_bfm.h; which one answers which kind of port is the table BFM_DUALS (BFM models).

A credit port’s window is compiled into the producer’s RTL, so the module states it – credit_links = {port: {"depth": .., "crd_every": ..}} – and the harness refuses to guess.

The memory stand-in

A kernel’s memory-master ports all face one memory, as its m_axi bundles do at RTL: MemCopy reads its sources on m_in and writes its destinations on m_out, in the same arena. The memory is a MemoryMod at byte address 0; at RTL it is the FlatMemory its bfm_model() declares, constructed once and handed to each bundle’s slave model – the memory mem_copy’s system puts behind the same two bundles.

  • Its image is in the workload, under one of the memory ports: words from byte address 0, and its length is the arena’s size. With no image the arena is 4096 words of zeros. The ports share one memory, so an image under two of them is refused.
  • It loads the image from vectors/mem_init and dumps the arena it ends with to vectors/mem, a recording compared RTL against pysim (Reading a harness’s recordings).
  • Its ports must share one width, of 8 to 64 bits. A bare MMIFMaster (no direction) runs in pysim, but has no RTL lowering: the direction is the port’s type, so declare a read or a write master.
  • It is polite: the RTL slave models have no stall policy (Hostile stand-ins).

Other port kinds – a device’s AXI-MM slave group, an interrupt – have no stand-in: a device is harnessed with its host on a direct link (the polynomial on a bus).

A memory’s own harness

A memory’s slave port is the other way around: the memory is the DUT and its host is a script. memory_harness(make, script) puts the memory make(sim) builds behind a direct link, driven by MmScript, a scripted AXI-MM master (C++ twin MmScript) that records its read data and when each read and write ran. Markov’s memory is harnessed this way (markov_memory, mem_script).

The scenario: workload(kind)

The module supplies its scenarios, so a harness needs no testbench code. workload(kind) returns {input port: bursts} – each burst a StreamBurst – and, under one memory port, the memory’s image. kind names the scenario: "test" for verification, "calib" for calibration. MemCopy’s is the XSI gate’s sixteen copies (mem_copy.py):

def workload(self, kind: str = "test") -> dict:
    w = int(self.mem_dwidth)
    cmds = [StreamBurst(np.asarray(CopyCmd(src_off=j.src_off, dst_off=j.dst_off,
                                           n_words=j.n_words, tx_id=k).serialize(word_bw=w),
                                   dtype=np.uint64))
            for k, j in enumerate(XSI_JOBS)]
    image, _golden = copy_arena(XSI_JOBS, w)
    return {"s_cmd": cmds, "m_in": image}

When the bursts arrive is part of the scenario too. StreamBurst(words, gap_before=n) makes the input’s driver wait n idle cycles before that burst – the first included, so one client’s first job can come late while another’s are already in flight. The harness turns a port’s gaps into its driver’s start_gap_cycles and burst_gaps, which the pysim driver and the RTL AxisMaster both play, so the build’s own scenario carries them; a workload with no gaps is generated exactly as before.

A one-off scenario is passed as the dict itself: harness(MemRStream, workload={"s_cmd": [...], "m_mem": image}) (test_harness_memory.py). A workload that names a port the module has no input of is refused.

Through the system flow

A harness’s DUT is a root, so add_system_steps runs it through the whole system flow: csynth, the RTL run, and the comparison of the stand-ins’ recordings, RTL against pysim. mem_copy’s DAG adds its kernel’s harness beside its system (mem_copy_system_build.py):

add_system_steps(dag, harness(MemCopy, workload="test"), work_dir=work_dir, top="mem_copy_unit",
                 tcls={"mem_copy": Path("mem_copy.tcl")}, prefix="unit_")
python -m examples.mem_copy.mem_copy_system_build --through unit_compare

harness(module, workload=..., n_cycles=4000): n_cycles bounds the RTL run, in clock cycles. A scenario that needs longer is cut short at RTL and its compare fails on the missing words, so a long workload (thousands of samples at one per cycle) raises it.

At RTL (Vitis/Vivado 2025.1) the harness’s memory and completions match pysim word for word, and the last completion lands at cycle 3000 – the number mem_copy’s system gates on, since the testbench is the same: a driver, a sink and one memory behind both bundles (test_mem_copy_unit_xsi.py).