The capstone. Write a self-checking bench for a FIFO four entries deep, with directed and random stimulus, two checks and two hit counts. It must pass the correct FIFO and fail each of eight FIFOs with a hidden bug.
Hardware context: A saturating counter, then a FIFO with hidden bugs. A complete block-level bench.
This is the whole track on one small design. You write the bench, not the FIFO: its stimulus, its model, its checks and its coverage. Nobody tells you where the bugs are. A bench built from a plan finds them.
This is a Verify problem. Your module fifo_bench drives the FIFO's inputs and reads its outputs. It adds 1 to errors for each wrong thing it sees, and counts two kinds of clock for coverage. It sets done when it has finished.
The check builds one copy of your bench for the correct FIFO and one for each of eight broken ones. All run on one clock in one simulation. Your bench passes when errors stays 0 on the correct FIFO and rises above 0 on every broken one. A last row checks your two hit counts on the correct FIFO against the check's own count of the same clocks.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
variant | 4 | input of each check |
Full specification
module fifo_bench (
input logic clk, // the fixture's clock: period 10 ns, rising edges at 5, 15, 25 ns
output logic rst, push, pop, // drive these just after a falling edge
output logic [7:0] din,
input logic [7:0] dout, // the oldest entry (only meaningful when the FIFO is not empty)
input logic full, empty,
output int errors, // add 1 for each wrong thing your checks see
output int hits_full, // rising edges with rst = 0, push = 1 and full = 1
output int hits_both, // rising edges with rst = 0, push = 1 and pop = 1
output logic done // set to 1 when your test has finished
);
// your stimulus, model, checks and counts
endmodule
| The FIFO's rules | Detail |
|---|---|
| Depth | Four entries. Empty after reset. |
| A push | Taken at a rising edge when the FIFO is not full. |
| A pop | Taken at a rising edge when the FIFO is not empty; it removes the oldest entry. |
| Both at once | Each is decided by the count before the edge: at empty only the push is taken, at full only the pop. |
| rst | Synchronous, active high: at a rising edge with rst = 1 the FIFO becomes empty. |
| Outputs | full is 1 with four entries, empty with none; dout shows the oldest entry while the FIFO is not empty. |
| Your bench | Must |
|---|---|
| errors | Start at 0. Add 1 for each wrong thing a check sees. Never count down. |
| hits_full, hits_both | Count the rising edges with rst = 0 where push and full are both 1, and where push and pop are both 1. Each must be above 0. |
| done | Set to 1 when the test has finished, within 30 microseconds of simulated time. |
| Inputs | Change rst, push, pop and din just after a falling edge of clk, so every rising edge sees steady values. |
The plan of the lesson is a good start. It needs directed corners, random traffic, a model, and a check on the flags and on the data. You may reuse the ideas of the corner lesson and of the capstone lesson.
Examples
Example 1
The Correct FIFO Must Not Raise an Alarm- Input
FIFO: the correct design
- Output
alarm = no
On the correct FIFO every check agrees with your model, so errors stays 0, and done must be 1 by the end.
Example 2
A FIFO Whose Full Never Rises- Input
FIFO: full never rises
- Output
alarm = yes
Its data is right; only a check of full against your model sees it.
Example 3
A FIFO That Forgets a Pop- Input
FIFO: A push and a pop together forget the pop
- Output
alarm = yes
Only a push and a pop in the same clock, with entries inside, reaches it. The last row then checks your hit counts.
Constraints and Contract
- Use only your ports. Names from the fixture, $root and instance names (%m) are refused before the run.
- Seed any random draws inside your bench, so the run is the same every time.
Hints
Hint 1
Keep a queue that holds what the FIFO should hold, and update it by the same rules at every rising edge.
Hint 2
Two checks: full and empty against the size of your queue, and dout against its front while it is not empty.
Hint 3
Directed corners: four pushes and one more, and a pop past empty. Add a push and a pop together at empty and at full, and a reset with data inside. Then run a few hundred random clocks.
What the grader checks: Your bench runs once per design: the correct FIFO and eight FIFOs with one planted bug each. All run in one simulation on one clock. Rows report whether your bench counted an error (and finished). The last row compares your two hit counts on the correct FIFO with the check's own count. The check cannot see how good your plan is beyond these nine designs.
10 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path