Chargement…
Chargement…
Assemble transactions, a generator, driver, monitors, reference model, scoreboard, and coverage into an extensible testbench.
A layered bench lets scenarios reuse the same protocol and oracle. Each layer keeps one responsibility, making failures easier to locate.
The test selects configuration. The generator produces independent transactions. The driver applies them; monitors reconstruct accepted exchanges. The reference predicts from observed input. The scoreboard matches and compares; coverage measures exercised situations.
The monitor never drives and the driver never judges results. The model stays independent of internal DUT signals.
interface stream_if(input logic clk);
logic rst_n;
logic valid;
logic ready;
logic [31:0] data;
clocking drv_cb @(posedge clk);
default input #1step output #0;
output valid, data;
input ready;
endclocking
clocking mon_cb @(posedge clk);
default input #1step;
input rst_n, valid, ready, data;
endclocking
modport drv (clocking drv_cb, input rst_n);
modport mon (clocking mon_cb);
endinterface
typedef virtual stream_if.drv stream_drv_vif_t;
typedef virtual stream_if.mon stream_mon_vif_t;The top instantiates clock, DUT, and interface. Classes receive virtual interfaces with the intended modport through construction or configuration. Clocking blocks centralize timing; drive their outputs with <=.
class stream_item;
rand logic [31:0] data;
rand int unsigned idle_cycles;
constraint legal_idle { idle_cycles inside {[0:8]}; }
function stream_item copy();
stream_item result = new();
result.data = data;
result.idle_cycles = idle_cycles;
return result;
endfunction
endclassThe generator checks randomize() on a blueprint and sends copy() through a mailbox. This preserves any randc history without changing objects already in flight.
class stream_driver;
stream_drv_vif_t vif;
mailbox #(stream_item) inbox;
int unsigned driven_count;
function new(stream_drv_vif_t vif,
mailbox #(stream_item) inbox);
this.vif = vif;
this.inbox = inbox;
endfunction
task run();
stream_item item;
forever begin
inbox.get(item);
repeat (item.idle_cycles) @vif.drv_cb;
vif.drv_cb.valid <= 1'b1;
vif.drv_cb.data <= item.data;
do @vif.drv_cb; while (vif.drv_cb.ready !== 1'b1);
vif.drv_cb.valid
The driver translates transactions into handshakes. This is a minimal fragment: initialize outputs and handle reset waiting and reset during a transfer. Do not treat unknown ready as acknowledgement.
task run();
forever begin
@vif.mon_cb;
if (vif.mon_cb.rst_n === 1'b1 &&
vif.mon_cb.valid === 1'b1 && vif.mon_cb.ready === 1'b1) begin
stream_item observed = new();
observed.data = vif.mon_cb.data;
observed_mb.put(observed);
end
end
endtaskThe monitor publishes accepted transfers outside reset. Use input and output monitors for a transforming block. Predictions start from observed input because reset or error injection may change what the generator intended to send.
Use a queue for ordered responses, an associative array for unique identifiers, or a checked search when necessary. Compare before removing an expectation, and count expected, observed, matched, and erroneous transactions separately. Diagnostics include identifier, values, time, and context.
build() constructs without starting threads; run() performs timed activity; wrap_up() checks counts and leftovers.
task run();
fork : environment_threads
generator.run(transaction_count);
driver.run();
input_monitor.run();
output_monitor.run();
reference_model.run();
scoreboard.run();
join_none
wait (generator.done);
wait (driver.driven_count == generator.generated_count &&
input_monitor.accepted_count == generator.generated_count);
wait (scoreboard.expected_count == input_monitor.accepted_count);
wait (scoreboard.compared_count == scoreboard.expected_count);
disable environment_threads;
endtaskThis outline assumes exactly one response per command and needs an external watchdog. Waiting only for an empty queue could finish before the first expectation exists. Wait for accepted commands, created expectations, and completed comparisons.
Comparison counts advance on wrong results too, producing FAIL rather than a misleading timeout. Missing responses trigger the watchdog. No comparisons or pending expectations fail the report.
A test changes constraints, configuration, derived types, or callbacks without copying the environment. Perturbations happen before transfer; prediction and coverage use observed acceptance. Publications to several subscribers need stable objects or separate copies.
Inject wrong, missing, and duplicate responses to check the scoreboard, timeout, and final report. Only valid runs contribute to campaign coverage.
📝 Test your knowledge - Chapter quiz