The Parts of a Testbench
A testbench is not one long block of code. It has parts: a generator, a driver, a monitor, a checker and coverage. Learn what each part is for, what breaks when one is missing, and see all of them in one small bench.
You Will Be Able To
- Name the parts of a testbench and the one job of each.
- Say what goes wrong when one part is missing.
- Find each part in a small bench and read what it reports.
- Lesson
- B2.2
- Time
- 20 min
- Runs on
- Your browser
- Check
- 5 questions
Every test of a FIFO passes, and the checker reports zero errors. Then a reviewer asks one question: "Did any test ever fill it?" Nobody knows, because no part of the bench was counting. The bench checked well and measured nothing.
- Control / FSM
- Driver
- DUT
- Monitor
- Test
- Report
- Control
- Data
- Analysis
- Generator
It decides the next operation, such as "push the byte 3c", without knowing how pins move.
- Driver
It turns that decision into pin values on the right clock edges.
Follow the calls, values and waits
- call push 3c: Generator → Driver
- Monitor
It watches the pins, never drives them, and reports whole transactions: "3c went in", "3c came out".
- Checker and coverage
The checker decides whether each result is right. Coverage counts which situations the run reached.
Read the diagram as text
- Generator: decides what to do next
- Driver: turns a decision into pin wiggles
- Design under test: fifo4
- Monitor: turns pin wiggles into transactions
- Checker: is each result right?
- Coverage: which situations happened?
- Generator → Driver: push 3c
- Driver → Design under test: pins
- Design under test → Monitor: pins
- Monitor → Checker: in 3c, out 3c
- Monitor → Coverage: what happened
The parts of a testbench for a FIFO. In bigger benches each box grows, but the jobs stay the same.
Before You Start
Read The Simplest Test That Can Fail first: every test drives, observes and decides. A FIFO hands out bytes in the order they came in; The Levels: Block, Subsystem, Chip, System used one.
| Question | |
|---|---|
| 1 | What are the parts of a testbench? |
| 2 | What is the one job of each part? |
| 3 | What goes wrong when a part is missing? |
| 4 | Why do the parts pass transactions instead of wires? |
| 5 | What can the coverage part tell you that the checker cannot? |
The Idea: Split the Work by Job
The test in the last lesson did everything in one task. It chose inputs, set pins, read outputs and compared. That is fine for an adder with eight cases. A FIFO with clocks, flags and random traffic needs more, and one long block of code becomes impossible to change.
So a testbench is split by job. One part decides what to do. One part moves pins. One part watches pins. One part decides right or wrong. One part counts what happened. Each part can be written, fixed and reused without touching the others.
The parts talk in transactions: whole operations such as "push the byte 3c". Only the driver and the monitor deal with pins and clock edges. Everything above them thinks in operations, which is how the specification thinks too.
New Words
| Word | Meaning |
|---|---|
| Transaction | One whole operation, such as "push 3c" or "3c came out", instead of the pin values that carry it. |
| Generator | The part that decides which transactions to send next. |
| Driver | The part that turns a transaction into pin values on the right clock edges. |
| Monitor | The part that watches pins, never drives them, and reports transactions. |
| Checker | The part that decides whether each result is right. A scoreboard is a common kind. |
| Coverage | The part that counts which situations the run reached, such as "the FIFO was full". |
| Seed | The starting number of a pseudo-random sequence. The same seed always gives the same sequence. |
What Breaks When a Part Is Missing
| Missing part | What happens |
|---|---|
| Generator | Every input is written by hand, so tests cover only what someone thought of. |
| Driver | Pin timing is copied into every test; one change of protocol breaks them all. |
| Monitor | Each check reads pins itself, and one of them samples at the wrong moment. |
| Checker | Nobody decides. The bench prints and a person must decide, as in the last lesson. |
| Coverage | Every check passes, and nobody knows which situations were never reached. |
The last row is the hook's story. A checker can only rule on what happened. If the run never filled the FIFO, the checker never saw a full FIFO, and it has nothing to complain about.
The Rules
Rule 1: One part, one job.
Deciding, driving, watching, judging and counting are separate parts.
Rule 2: Only the driver and the monitor touch pins.
Everything above them works in transactions.
Rule 3: A monitor never drives.
It only watches, so it can be reused wherever the same pins appear.
Rule 4: The checker rules on what happened; coverage records what happened.
A clean checker with empty coverage proves nothing about the empty cases.
Sources for These Rules
Spear and Tumbush (2012), section 1.9: the testbench wraps the DUT and is made of components that look like real neighbours. Section 1.10: the layered testbench. It has a signal layer and a command layer (driver, monitor, assertions). Above them sit a functional layer (agent, scoreboard, checker), a scenario layer (generator) and a test layer with functional coverage.
Spear and Tumbush (2012), section 1.11: the driver is a transactor, a loop that turns commands into signal changes.
Mehta (2018), section 15.5.2: the testbench instruments the DUT to provide stimulus and measure response.
The Verification Academy UVM Cookbook, "Testbench Architecture", draws the same parts in UVM. Only the idea of the picture is used here.
The Lab: Every Part, Labelled
The lab is one small bench around fifo4, with each part marked by a comment in capitals. Read it part by part. The generator decides each clock's operation from a pseudo-random sequence. Its numbers look random but follow a fixed rule from a starting number, the seed. The same seed gives the same traffic on every run. Random and Constrained-Random Stimulus says more about seeds.
task automatic next_op(output bit p, q, output logic [7:0] d);
lfsr = {lfsr[6:0], lfsr[7] ^ lfsr[5] ^ lfsr[4] ^ lfsr[3]};
p = lfsr[0]; q = lfsr[1]; d = lfsr;
endtaskThe monitor watches the pins at each rising clock edge and records two lists: bytes accepted in, and bytes handed out. seen_in [$] is a queue, a list that grows at the back and is read from the front.
always @(posedge clk) if (!rst) begin
if (push && !full) seen_in.push_back(din);
if (pop && !empty) seen_out.push_back(dout);
endThe checker takes the two lists and compares them in order: what went in first must come out first. Coverage counts three situations the plan cares about. They are a push while full, a pop while empty, and a push and a pop in the same clock.
checker: 23 bytes matched, 0 errors
coverage: push while full 0, pop while empty 0, push and pop together 13The checker line is clean: 23 bytes matched, 0 errors. Read the coverage line, though. A push while full happened 0 times, and so did a pop while empty. The run never tested what the FIFO does at either limit. Rule 4 says what that means: the checker's zero errors say nothing about full or empty.
This is why the coverage part exists. Without it, this run would look finished. With it, you know the next job: steer the generator so the FIFO fills and drains.
Why Transactions Between the Parts
Why not let the checker read the pins? Because then every check repeats the monitor's timing rules, and one of them gets it wrong. Worse, the checker would break whenever the pin protocol changed.
With transactions, the protocol lives in two places only: the driver and the monitor. Change the pins, and you change those two parts. The generator, the checker and coverage keep working, because "push 3c" means the same thing on any pins.
Traps
The first trap is the monitor that peeks at the driver. It is tempting to tell the checker what the driver sent, instead of what the pins showed. Then a driver bug and a design bug look the same, and some are never seen. A monitor reads the pins.
The second trap is the checker that samples at the wrong moment. Read a FIFO output just before the clock edge, or just after, and you get different bytes. Putting all pin timing in the monitor makes that mistake once, in one place, where it is easy to fix.
The third trap is the bench with no coverage, shown in the lab. Every number it prints is true, and none of them is about the cases it skipped.
At Scale
This section looks ahead. Methodologies such as UVM give each part a standard shape.
Agents
A driver, a monitor and the part that feeds the driver are packaged together for one interface. The package is reused on every bench with that interface.
Layers
Large benches stack generators: one makes a scenario, the next breaks it into transactions, the driver turns those into pins.
Where This Goes Next
This lesson named the parts. These lessons build each one.
| The idea from this page | Where it is taught |
|---|---|
| Writing the generator and the driver | Build the Generator and Driver |
| Writing the monitor and the scoreboard | Build the Monitor and Scoreboard |
| Letting the generator choose random inputs, and seeds | Random and Constrained-Random Stimulus |
| Counting the situations a plan asks for | Functional Coverage: What Was Tested |
| Writing coverage for the FIFO | Coverage and Tests for the Checker |
| The same parts as UVM components | From a Layered Bench to UVM |
| A monitor that reports what the design accepted | Monitor the Event the DUT Accepts |
Try It
Run the lab. Read the checker line, then the coverage line.
Change the seed to 8'hc3. Predict the coverage line before you run it.
Make the generator push more often than it pops (for example p = lfsr[0] | lfsr[2];). Does the full count change?
checker: 23 bytes matched, 0 errors coverage: push while full 0, pop while empty 0, push and pop together 13Check Yourself
Common Mistakes
Wrong Write the whole test as one block that sets pins and compares.
Every change to the protocol or the checks means rewriting every test.
Fix Split the bench into generator, driver, monitor, checker and coverage.
Wrong Let the checker learn what was sent from the driver.
A driver bug then hides a design bug, because both sides share the mistake.
Fix Let the monitor report what the pins really showed.
Wrong Leave out coverage because the checker is clean.
The checker rules only on what happened; skipped cases leave no trace.
Fix Count the situations the plan asks for, and read the counts.
Remember
- A testbench has parts: generator, driver, monitor, checker and coverage, one job each.
- Only the driver and the monitor touch pins; the rest works in transactions.
- A monitor never drives; a checker rules on what happened; coverage records what happened.
- A clean checker with empty coverage says nothing about the cases that never ran.