Testing Plan: Hardware Queue, Rotating Arbiter, Ready/Valid Link
System DesignModel answerLast updated
Plan the verification of three small digital blocks (a FIFO, a round-robin arbiter and a valid/ready link) covering testbench structure, random stimulus, assertions and coverage.
You are given the spec of a small digital block and asked to explain how you would prove it correct before tape-out. Describe the verification environment (stimulus, monitors, a checking model), how you would randomize inputs under constraints, which corner cases you would hit on purpose, which SystemVerilog assertions (SVA) you would write, and what functional coverage you would collect.
Three blocks are on the table. All share one clock clk and an active-low reset rst_n. Sizes are parameters: DEPTH and WIDTH for the FIFO, N for the arbiter. Pseudo-code or SystemVerilog is fine; the reasoning matters more than syntax.
Questions you should settle (or state assumptions for) before starting
- Is a push into a full FIFO, or a pop from an empty one, ignored, flagged as an error, or forbidden stimulus?
- Does read data appear in the pop cycle (first-word fall-through) or one cycle later?
- Is the arbiter's grant combinational or registered? Must a requester hold its request until granted?
Part 1: Synchronous FIFO
Inputs are push, din[WIDTH-1:0] and pop. Outputs are dout[WIDTH-1:0], full and empty. Cover the reference model and scoreboard, the stimulus constraints, the corner cases, the assertions and the coverage. Stimulus should reach full and empty often, not just the middle occupancies.
Part 2: Round-robin arbiter
Requesters drive req[N-1:0] and the arbiter returns gnt[N-1:0] using rotating priority. State the properties that make an arbiter correct (safety, work conservation, fairness), then describe the checking approach, stimulus, assertions and coverage. Compare a cycle-accurate model with property-only checking.
Part 3: Valid/ready handshake
A sender drives valid and data, and a receiver drives ready. A transfer occurs in every cycle where both are high. State the protocol rules, the assertions for each side, a scoreboard for a block that uses this interface, the back-pressure stimulus and the coverage.
Hints
Hint 1
Separate what is checked every cycle (assertions on local rules such as flags, one-hot grants and stable data) from what is checked end to end (a scoreboard comparing the ordered stream of accepted items with the predicted stream).
Hint 2
Do not rely on uniform random stimulus to reach corners. Bias the push/pop and valid/ready probabilities in phases (fill-heavy, drain-heavy, balanced, stalled), then use coverage crosses to prove that the corners were really hit.
Hint 3
Every assertion and model must handle reset (`disable iff (!rst_n)`, with the model flushed on reset). Fairness properties need an assumption, namely that a request is held until it is granted, otherwise they cannot be stated or proven.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Common architecture
Use a layered environment that treats the DUT as a black box:
- Driver turns randomized transaction objects into pin wiggles. Monitors passively sample the pins and publish what actually happened, so checking never trusts the driver.
- Reference model consumes the monitored inputs and predicts outputs.
- Scoreboard compares predicted and observed results. It handles ordering, content and, where the spec requires it, timing.
- Bound assertions (via
bind) check local, cycle-level rules without touching the RTL. - Coverage collectors sample the monitor stream.
- Division of labour: assertions catch protocol and flag errors at the exact cycle they occur. The scoreboard catches data loss, duplication and reordering over long runs.
- Reset: wrap every property in
disable iff (!rst_n), flush models on reset, and inject reset mid-traffic as its own test.
Part 1: FIFO
Assumptions to state: push when full and pop when empty are ignored and counted as "attempted illegal" events (or are never driven, if the spec forbids them). Simultaneous push and pop when full is a spec decision. I would confirm it and then encode it in the model.
Model and scoreboard: a SystemVerilog queue q[$]. On each monitored cycle, if push && !full then q.push_back(din). If pop && !empty then pop the front and compare it with dout (at the right cycle for the read-latency convention). Also compare flags with the model: full == (q.size()==DEPTH) and empty == (q.size()==0). At end of test, check that the model queue is empty or equal to the DUT's remaining content.
Stimulus: run phases with different weights for push and pop, for example 80/20 to fill, 20/80 to drain, 50/50, and bursts of back-to-back pushes. Add idle gaps, random data with some walking-ones and all-zeros/all-ones patterns, and reset in the middle of traffic. Parameterize DEPTH to small values (1, 2, 3, power-of-two and non-power-of-two) because bugs in pointer wrap often hide there.
Corner cases:
- Push at full and pop at empty
- Simultaneous push and pop at empty, at one entry, at DEPTH-1 and at full
- Pointer wrap-around, repeated many times
- Fill to full then drain to empty, and the reverse
- DEPTH = 1
- Reset while full
- Back-to-back flag toggles
Assertions:
a_no_both: assert property (@(posedge clk) disable iff (!rst_n) !(full && empty));
a_reset: assert property (@(posedge clk) !rst_n |=> empty && !full);
a_no_ovf: assert property (@(posedge clk) disable iff (!rst_n)
(full && push && !pop) |=> $stable(count));
a_no_unf: assert property (@(posedge clk) disable iff (!rst_n)
(empty && pop && !push) |=> $stable(count));
a_full_next: assert property (@(posedge clk) disable iff (!rst_n)
(count == DEPTH-1 && push && !pop) |=> full);
Flag assertions should be written against a testbench-side count, not an internal signal, so they survive refactoring.
Coverage: a cross of occupancy bins (0, 1, mid, DEPTH-1, DEPTH) with operation (idle, push only, pop only, both, and the attempted-illegal variants). Add transition coverage for empty→non-empty and full→non-full, pointer wrap hits, and consecutive-full-cycle length bins.
Part 2: Round-robin arbiter
Properties that define correctness:
- Safety:
$onehot0(gnt)and(gnt & ~req) == 0. - Work conservation: if
|reqthen|gnt(in the same cycle for a combinational grant, or the following cycle for a registered one). Nothing is wasted while someone waits. - Rotation: after granting index
i, the highest priority moves toi+1 mod N, so the next grant goes to the first requester at or after that position. - Fairness (bounded wait): assuming a requester holds
req[i]until it is granted, it is granted within at mostNgrant opportunities. Without that assumption, a requester that drops its request can legitimately be skipped, so the property is meaningless. State this as anassumein formal runs and as a driver constraint in simulation.
Checking approach: a cycle-accurate model keeps a last pointer, computes the expected grant from req and last, and compares it every cycle. This catches subtle ordering bugs but locks the testbench to one implementation. If the spec allows variations (for example, whether the pointer moves when the grant is not accepted), use property-only checking (rules 1 to 4) plus a per-requester wait counter. I would use the model for the primary regression and keep the properties as always-on assertions, because they also work in formal.
Stimulus: random request vectors with varied density (sparse, dense, all ones), plus directed patterns: a single requester, all requesters held constantly, a requester toggling every cycle, and one requester hogging while the others join late. Randomize N across runs.
Assertions:
a_onehot: assert property (@(posedge clk) disable iff (!rst_n) $onehot0(gnt));
a_subset: assert property (@(posedge clk) disable iff (!rst_n) (gnt & ~req) == '0);
a_work: assert property (@(posedge clk) disable iff (!rst_n) (|req) |-> (|gnt));
// per requester i, under the hold-until-granted assumption:
a_wait: assert property (@(posedge clk) disable iff (!rst_n)
req[i] && !gnt[i] |-> ##[1:N] gnt[i]);
Coverage: each requester granted (N bins), grant-to-grant transitions (N×N cross, which shows rotation including wrap from N-1 to 0), request-pattern bins (single, two, all, none), pointer wrap events, and "requester i loses to j but wins next" scenarios.
Part 3: Valid/ready handshake
Rules as properties:
- Transfer occurs when
valid && ready. - Sender rule: once
validis high andreadyis low,validmust stay high anddatamust stay stable until the transfer happens. - Receiver rule:
readymay go high or low freely, and it must not be required to wait forvalid. A receiver that waits forvalidbefore raisingreadyis legal. Two sides each waiting on the other is a deadlock bug, so add a liveness check with a timeout. - Nothing is "in flight" after reset:
validlow or defined in the reset spec.
a_hold_valid: assert property (@(posedge clk) disable iff (!rst_n)
valid && !ready |=> valid);
a_hold_data: assert property (@(posedge clk) disable iff (!rst_n)
valid && !ready |=> $stable(data));
a_no_x: assert property (@(posedge clk) disable iff (!rst_n)
valid |-> !$isunknown(data));
a_progress: assert property (@(posedge clk) disable iff (!rst_n)
valid |-> ##[0:MAX_STALL] ready);
The first three check the sender (assert on the sender, assume on the receiver in a formal setup, and vice versa for the opposite side). The progress property is checked only with a receiver that is guaranteed to eventually accept.
Scoreboard for a block using this interface: monitor both the input and output interfaces and record an item only on cycles with valid && ready. Push input items into an expected queue (through a transform model if the block alters data). For each output transfer, pop and compare. A mismatch in content means corruption. An output with an empty expected queue means duplication or spurious data. Leftover items at end of test mean drops. Reordering shows as content mismatches, and tagging items with sequence IDs helps pinpoint it.
Stimulus: independently randomize the sender's gaps between beats (zero-gap streaming, short and long idles) and the receiver's ready pattern (always ready, never ready for long stretches, random 50%, periodic). Run the cross of these modes, because the interesting bugs live where a full-rate source meets a stalling sink and the reverse. Also drive ready-before-valid, valid-before-ready and same-cycle arrival.
Coverage: the four (valid, ready) states, transitions between them, stall-length bins (1, 2, 3 to 8, longer than 8), back-to-back transfers, a stall followed immediately by a transfer, and a cross of sender mode against receiver mode.
Common mistakes
- Writing assertions that ignore reset, producing false failures on the first cycles.
- Reading internal RTL signals in the checker so it repeats the design's own bug.
- Relying on uniform random stimulus and never confirming that full, empty or long stalls actually occurred.
- Stating a fairness property without the hold-request assumption.
- Collecting code coverage only. It shows lines executed, not that the spec's scenarios were exercised.
- Sampling on the driver instead of on a monitor, which hides driver bugs.
Closing the loop: run constrained-random regressions, review coverage holes, add directed tests or tighter constraints for the holes, and use formal on the small blocks to prove the safety assertions exhaustively.