Specify transfers and build an independent oracle
Use the one-entry buffer below as a small DUT. It has a single clock, 8-bit data, and active-high synchronous reset. A transfer occurs on a rising edge with valid && ready. Input data and valid must remain unchanged while the producer is stalled. A reset edge discards a pending item.
The scoreboard must compare accepted outputs against accepted inputs, in order. Do not build the expected result by copying the DUT's internal state transitions: that can reproduce the same bug. A queue of accepted transactions is an independent model of the interface contract.
This lab intentionally uses plain SystemVerilog, without UVM, to make driver, monitor, and checker responsibilities visible before the framework chapters.
The DUT: one-entry elastic buffer
module elastic_buffer (
input logic clk, rst,
input logic [7:0] in_data,
input logic in_valid,
output logic in_ready,
output logic [7:0] out_data,
output logic out_valid,
input logic out_ready
);
assign in_ready = !out_valid || out_ready;
always_ff @(posedge clk) begin
if (rst) out_valid <= 1'b0;
else if (in_ready) begin
out_valid <= in_valid;
if (in_valid) out_data <= in_data;
end
end
endmodule
out_data need not be meaningful while out_valid is zero. An occupied stalled buffer holds its data. Simultaneous input and output handshakes replace the item with no empty cycle. This circuit has a combinational ready path and is not an asynchronous FIFO.
Drive, sample, compare, drain, and terminate
Place this testbench beside the DUT in a simulator supporting SystemVerilog queues and timing. Drive at the falling edge and sample accepted transfers at the rising edge. This avoids driving on the same edge the DUT samples.
module buffer_tb;
timeunit 1ns; timeprecision 1ps;
logic clk = 0;
logic rst = 1;
logic [7:0] in_data = 0;
logic in_valid = 0, out_ready = 0;
wire in_ready, out_valid;
wire [7:0] out_data;
byte unsigned expected[$];
byte unsigned wanted;
bit accepted = 0;
int seed = 12345;
int unsigned unused_random;
int sent = 0, received = 0;
elastic_buffer dut(.*);
always #5 clk = !clk;
task automatic sample_transfers();
if (out_valid && out_ready) begin
if (expected.size() == 0) $fatal(1, "Unexpected output");
wanted = expected.pop_front();
if (out_data !== wanted) $fatal(1, "Data mismatch");
received++;
end
accepted = in_valid && in_ready;
if (accepted) begin
expected.push_back(in_data);
sent++;
end
endtask
initial begin
if (!$value$plusargs("SEED=%d", seed)) seed = 12345;
$display("SEED=%0d", seed);
unused_random = $urandom(seed);
repeat (2) @(posedge clk);
@(negedge clk); rst = 0;
repeat (200) begin
@(negedge clk);
if (!in_valid || accepted) begin
in_valid = $urandom_range(0, 1);
in_data = $urandom_range(0, 255);
end
out_ready = $urandom_range(0, 1);
@(posedge clk); sample_transfers();
end
repeat (4) begin
@(negedge clk);
if (accepted) in_valid = 0;
out_ready = 1;
@(posedge clk); sample_transfers();
end
if (expected.size() != 0 || sent != received)
$fatal(1, "Did not drain: sent=%0d received=%0d", sent, received);
$display("PASS: %0d ordered transfers", received);
$finish;
end
initial begin
#10000;
$fatal(1, "Watchdog timeout");
end
endmodule
The checker observes the values defining transfers at the sampling edge, before the DUT's NBA updates. It checks data only on accepted output transfers. Logging the initial seed lets you repeat the run within the same simulator/version/source configuration; identical random streams across different tools are not promised.
Prove the checker works: Change the DUT's stored data to in_data ^ 8'h01. The test must fail. Restore the DUT. Then add a midstream reset: clear the expected queue on the reset sampling edge and track discarded items separately so the count invariant still matches the specification.