Lesson 7: How Do You Verify a FIFO End to End?
Verifying a FIFO end to end takes four things working together: random traffic that drives it full and empty, a reference model (a queue) that predicts every read, assertions that check the flags on every clock, and coverage that proves the corners were reached. This project brings Lessons 1 to 5 together on the synchronous FIFO from the projects section, then plants a bug to see which check catches it first.
What you'll learn
- Writing a verification plan before the testbench
- A queue as a reference model, and the timing trap in it
- Assertions for full and empty
- Coverage that proves full and empty were reached
- Reading the results of a planted bug
Conventions and assumptions
Every lesson tests the same small design: a registered 8-bit ALU (add, sub, and, or, xor) whose 9-bit result appears one clock after in_valid; the final project moves on to the synchronous FIFO. All code was compiled and run in AMD Vivado xsim 2025.2, and the output shown is copied from those runs. The complete files are in the site's repository under scripts/verification.
Step 1: the plan
| Feature | How it is checked |
|---|---|
| Data comes out in order, unchanged | Queue model compares every read |
| full and empty are never both true | Assertion a_not_both |
| full exactly when 16 entries are held | Assertion a_full |
| empty exactly when nothing is held | Assertion a_empty |
| A write when full is dropped | Assertion a_hold, and the model ignores it |
| Full, empty and push/pop at both | Covergroup: count bins crossed with operations |
Step 2: the reference model
The model pushes on every accepted write and pops on every accepted read, and predicts that the popped value appears on rd_data one clock later. There is one trap. The first version popped before checking whether the write fit, so on a clock with both a read and a write while full, the model accepted the write and the FIFO (correctly) did not. The fix is to decide both operations from the occupancy before the clock, just as the DUT's flags do.
// Reference model: a queue. Read data appears the clock after rd_en.
logic [W-1:0] model[$];
logic [W-1:0] expect_q;
logic expect_valid = 0;
int pushes = 0, pops = 0, errors = 0, n;
always @(posedge clk) begin
if (rst) begin model.delete(); expect_valid <= 0; end
else begin
if (expect_valid && rd_data !== expect_q) begin
errors++;
if (errors <= 3) $display("%0t: read %0d, expected %0d", $time, rd_data, expect_q);
end
n = model.size(); // occupancy before this clock, as the DUT's flags see it
expect_valid <= 0;
if (rd_en && n > 0) begin expect_q <= model.pop_front(); expect_valid <= 1; pops++; end
if (wr_en && n < D) begin model.push_back(wr_data); pushes++; end
end
end
Step 3: assertions and coverage
The assertions tie the flags to the count; the covergroup crosses the count (empty, low, high, full) with the four push and pop combinations, ignoring the middle bins, so it asks specifically for a push at full, a pop at empty, and both at once at each end.
// Assertions on the flags (explicit disable iff: xsim has no default form).
a_not_both: assert property (@(posedge clk) disable iff (rst) !(full && empty));
a_full: assert property (@(posedge clk) disable iff (rst) full == (count == D))
else $error("full = %0b with count %0d", full, count);
a_empty: assert property (@(posedge clk) disable iff (rst) empty == (count == 0));
a_hold: assert property (@(posedge clk) disable iff (rst) full && wr_en && !rd_en |=> full)
else $error("a write when full changed the state");
covergroup fifo_cg @(posedge clk iff !rst);
cp_count: coverpoint count { bins empty = {0}; bins low = {[1:7]}; bins high = {[8:15]}; bins full = {16}; }
cp_ops: coverpoint {wr_en, rd_en} { bins idle = {0}; bins rd = {1}; bins wr = {2}; bins both = {3}; }
full_x_ops: cross cp_count, cp_ops {
ignore_bins mid = binsof(cp_count.low) || binsof(cp_count.high);
}
endgroup
fifo_cg cg = new();
Step 4: traffic
Three phases of 400 clocks: 70% write and 30% read to fill it, then 30% and 70% to drain it, then 50% each. Biasing the traffic is what gets the FIFO to full; balanced random traffic hovers in the middle.
What the runs showed
| Design | Result |
|---|---|
| Correct FIFO | 434 pushes, 419 pops, 0 data errors, 100% coverage, no assertion failures |
| Full flag ignores the wrap bit (+define+BUG) | a_full failed at 25 ns, the first clock out of reset; 418 data errors; coverage 58.3% (count bins 25%) |
The planted bug makes full true whenever the two pointers' address bits match, which includes the empty FIFO, so every write is dropped. The assertion pointed at it on the first clock. The scoreboard also failed, but 418 data errors say only that something is wrong. Coverage told the third part of the story: the count never left zero, so the 'full' and 'high' bins were never hit. A test that passed with coverage like that would prove nothing.
Extend the project
- Add a covergroup bin for a write at full with a simultaneous read, and check it is hit.
- Rebuild the testbench in UVM using Lesson 6's structure.
- Make the FIFO depth a parameter of the testbench and run it at depths 4 and 64.
- Plant a different bug (rd_data updated on an empty read) and see which check catches it.
Common mistakes
- A model that applies the read and write in the wrong order on the same clock.
- Only balanced traffic, so the FIFO is never full.
- Trusting zero errors without looking at coverage.
- Checking the flags only at the end of the test, instead of every clock.
- Forgetting that read data is one clock late.
Check your understanding
- Q1. Why did the first model disagree with a correct FIFO? Answer: it popped before checking space, so it accepted a write that the full FIFO correctly dropped.
- Q2. Which check found the planted bug first, and when? Answer: the a_full assertion, at 25 ns.
- Q3. What did coverage add that the scoreboard didn't? Answer: it showed the FIFO never held anything, so the test hadn't exercised full or high occupancy at all.
The course
Related
Last verified
Run in Vivado xsim 2025.2 on 16 November 2026, with and without +define+BUG; outputs copied from those runs. The FIFO is scripts/projects/fifo/sync_fifo.v, unchanged.