Day 7: Week 1 Review + Mini-Project — Build a Complete FIFO UVM Testbench
A 30-day SystemVerilog/UVM verification series. Six days of concepts. Today you build the whole thing yourself — no new ideas, just muscle memory.
Week 1 is behind you. You have seen UVM architecture, phases, sequences, TLM, config_db, factory, and agents — each in isolation. That knowledge is worth exactly nothing until it compiles and runs as one testbench, because real UVM bugs live in the seams: an override that doesn't apply, a config that goes to the wrong instance, a monitor that reuses one handle across fifty transactions.
Today has no new concept. It has a checklist, a build order, a reference testbench, and a small set of deliberately introduced bugs to find. By the end you should have a working FIFO environment that passes a smoke test, catches a broken DUT, and runs faster than your attention span.
1. The Week 1 Checklist
Before you build, audit yourself. If any of these answers is "not sure," reread that day.
| From | Concept | Can you explain it in one sentence? |
|---|---|---|
| Day 1 | Components vs objects; creation order | Why is the driver a uvm_component and the transaction a uvm_object? |
| Day 2 | Phase order; build top-down, connect bottom-up | Why can't a child read a config that its parent sets in connect_phase? |
| Day 3 | start_item/finish_item; get_next_item/item_done | Why does randomize() go between start_item and finish_item? |
| Day 4 | Analysis port broadcast, reference semantics | Why must the monitor create a fresh transaction per write()? |
| Day 5 | config_db paths; factory overrides | Why does new() silently defeat every override? |
| Day 6 | Agent boundaries; active/passive | Why does the scoreboard live in the env, not the agent? |
2. What You Are Building
A self-checking FIFO testbench. Same DUT as before, but built from scratch on a clean directory:
fifo_tb/
├── fifo_if.sv // virtual interface, clocking blocks
├── fifo_tx.sv // transaction (sequence item)
├── fifo_sequencer.sv // one-line, but explicit
├── fifo_driver.sv // pulls items, drives pins
├── fifo_monitor.sv // samples pins, publishes
├── fifo_agent.sv // active/passive wrapper
├── fifo_agent_cfg.sv // vif + is_active
├── fifo_scoreboard.sv // shadow queue, writes vs reads
├── fifo_seq_lib.sv // write_seq, read_seq, write_then_read_seq
├── fifo_env.sv // wr_agent + rd_agent + scoreboard
├── fifo_base_test.sv // creates env, starts sequence
├── fifo_tb_top.sv // instantiates DUT + interface + run_test
Same file names as Days 1–6. Today you type them in the right order, from a blank directory, with no copy-paste. That is the whole point.
3. Build Order
Build in this order. Each step compiles on its own before you move to the next. If a step fails to compile, fix it before starting the next — cascading fixes hide the real bug.
- Interface and DUT wrapper. Instantiate the DUT, drive clock and reset from the top module. Run with
run_test()absent — just confirm the DUT resets and idles. - Transaction. Fields, constraints,
`uvm_object_utils. Compile only. - Sequencer. One-line class. Compile only.
- Driver.
get_next_item, drive pins,item_done. No monitor yet. - Write sequence. One item, then ten. Run it against the driver with a hand-built env. Confirm the write pulses appear on the waveform.
- Monitor. Sample the pins, publish one transaction per cycle. Compile only.
- Agent. Wrap driver + sequencer + monitor. Config object with vif and is_active. Run again — nothing should change.
- Scoreboard. Analysis import, shadow queue,
check_phase. Wire the monitor to it in the env. Run — you should see writes counted. - Read sequence + read agent. Second agent in passive mode. Wire its monitor to the scoreboard's read side.
- Write-then-read test. Env with both agents, virtual-sequenced from a base test. Run.
4. The Reference Environment (skeleton)
Here is the minimal shape of every file, so you know what "correct" looks like. Fill in the bodies yourself — that is the exercise.
fifo_if.sv — the virtual interface with clocking blocks:
interface fifo_if (input bit clk);
logic rst_n;
logic wr_en;
logic [7:0] wdata;
logic rd_en;
logic [7:0] rdata;
logic full;
logic empty;
clocking drv_cb @(posedge clk);
output rst_n, wr_en, wdata, rd_en;
input rdata, full, empty;
endclocking
clocking mon_cb @(posedge clk);
input rst_n, wr_en, wdata, rd_en, rdata, full, empty;
endclocking
endinterface
fifo_tx.sv — the transaction:
class fifo_tx extends uvm_sequence_item;
rand bit wr_en;
rand bit rd_en;
rand bit [7:0] wdata;
bit [7:0] rdata;
`uvm_object_utils_begin(fifo_tx)
`uvm_field_int(wr_en, UVM_ALL_ON)
`uvm_field_int(rd_en, UVM_ALL_ON)
`uvm_field_int(wdata, UVM_ALL_ON)
`uvm_field_int(rdata, UVM_ALL_ON)
`uvm_object_utils_end
function new(string name = "fifo_tx");
super.new(name);
endfunction
constraint c_no_simul { !(wr_en && rd_en); }
endclass
fifo_driver.sv — the handshake:
class fifo_driver extends uvm_driver #(fifo_tx);
`uvm_component_utils(fifo_driver)
virtual fifo_if vif;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual fifo_if)::get(this, "", "vif", vif))
`uvm_fatal("NOVIF", "no vif")
endfunction
virtual task run_phase(uvm_phase phase);
forever begin
seq_item_port.get_next_item(req);
@(vif.drv_cb);
vif.drv_cb.wr_en <= req.wr_en;
vif.drv_cb.rd_en <= req.rd_en;
vif.drv_cb.wdata <= req.wdata;
seq_item_port.item_done();
end
endtask
endclass
fifo_monitor.sv — one fresh transaction per publish:
class fifo_monitor extends uvm_monitor;
`uvm_component_utils(fifo_monitor)
uvm_analysis_port #(fifo_tx) ap;
virtual fifo_if vif;
function new(string name, uvm_component parent);
super.new(name, parent);
ap = new("ap", this);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db#(virtual fifo_if)::get(this, "", "vif", vif))
`uvm_fatal("NOVIF", "no vif")
endfunction
virtual task run_phase(uvm_phase phase);
fifo_tx tr;
forever begin
@(vif.mon_cb);
if (vif.mon_cb.wr_en || vif.mon_cb.rd_en) begin
tr = fifo_tx::type_id::create("tr"); // fresh object
tr.wr_en = vif.mon_cb.wr_en;
tr.rd_en = vif.mon_cb.rd_en;
tr.wdata = vif.mon_cb.wdata;
tr.rdata = vif.mon_cb.rdata;
ap.write(tr);
end
end
endtask
endclass
fifo_agent.sv — active/passive wrapper (see Day 6):
class fifo_agent extends uvm_agent;
`uvm_component_utils(fifo_agent)
fifo_driver drv;
fifo_sequencer sqr;
fifo_monitor mon;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
mon = fifo_monitor::type_id::create("mon", this);
if (get_is_active() == UVM_ACTIVE) begin
drv = fifo_driver::type_id::create("drv", this);
sqr = fifo_sequencer::type_id::create("sqr", this);
end
endfunction
virtual function void connect_phase(uvm_phase phase);
if (get_is_active() == UVM_ACTIVE)
drv.seq_item_port.connect(sqr.seq_item_export);
endfunction
endclass
fifo_scoreboard.sv — shadow queue and check_phase (see Day 4):
class fifo_scoreboard extends uvm_scoreboard;
`uvm_component_utils(fifo_scoreboard)
uvm_analysis_imp #(fifo_tx, fifo_scoreboard) exp_imp;
fifo_tx model_q[$];
int writes, reads, mismatches;
function new(string name, uvm_component parent);
super.new(name, parent);
exp_imp = new("exp_imp", this);
endfunction
function void write(fifo_tx tr);
fifo_tx expected;
if (tr.wr_en) begin
model_q.push_back(tr);
writes++;
end
if (tr.rd_en) begin
if (model_q.size() == 0) begin
`uvm_error("SB", "read on empty FIFO")
return;
end
expected = model_q.pop_front();
reads++;
if (tr.rdata !== expected.wdata) begin
mismatches++;
`uvm_error("SB", $sformatf("read mismatch: exp %0h got %0h",
expected.wdata, tr.rdata))
end
end
endfunction
function void check_phase(uvm_phase phase);
if (writes == 0 && reads == 0)
`uvm_error("SB", "no traffic observed")
if (mismatches != 0)
`uvm_error("SB", $sformatf("%0d mismatches total", mismatches))
endfunction
endclass
fifo_env.sv — wire everything (see Day 6):
class fifo_env extends uvm_env;
`uvm_component_utils(fifo_env)
fifo_agent wr_agent;
fifo_agent rd_agent;
fifo_scoreboard sb;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
wr_agent = fifo_agent::type_id::create("wr_agent", this);
rd_agent = fifo_agent::type_id::create("rd_agent", this);
sb = fifo_scoreboard::type_id::create("sb", this);
endfunction
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
wr_agent.mon.ap.connect(sb.exp_imp);
rd_agent.mon.ap.connect(sb.exp_imp);
endfunction
endclass
tr.wr_en and tr.rd_en to know which side the transaction came from. That works because the FIFO's write and read share a clock and the scoreboard can tell them apart by the enable. In Day 9, you'll learn the two-import pattern for cases where you can't.
fifo_base_test.sv — the top-level test:
class fifo_base_test extends uvm_test;
`uvm_component_utils(fifo_base_test)
fifo_env env;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = fifo_env::type_id::create("env", this);
endfunction
virtual task run_phase(uvm_phase phase);
fifo_write_then_read_seq seq;
phase.raise_objection(this);
seq = fifo_write_then_read_seq::type_id::create("seq");
seq.start(env.wr_agent.sqr);
phase.drop_objection(this);
endtask
endclass
5. Three Deliberate Bugs to Reproduce
Before you finish Week 1, reproduce each of these bugs in your own testbench and fix it. Do not read the fix until you have seen the symptom.
Bug 1 — Config goes to the wrong place
In the test, set the virtual interface with uvm_config_db#(virtual fifo_if)::set(this, "env.rd_agent.drv", "vif", rd_vif);. Then have the write driver also try to get the same field. Watch the write driver fatal with "no vif." Then change the set to "*" and watch both drivers grab the same interface — which is worse, because now nothing errors but every "write" goes to the wrong port.
Bug 2 — The monitor reuses one handle
Change tr = fifo_tx::type_id::create("tr"); inside the monitor loop to a single tr = fifo_tx::type_id::create("tr"); before the forever, and just mutate fields inside. Run. The scoreboard's shadow queue will contain many pointers to the same object. If the last write to that object happened to be a write of 0xFF, the scoreboard will report mismatches on every read, or nothing at all.
Bug 3 — The factory override is set after create
In fifo_err_test, put super.build_phase(phase) before the set_type_override call. Watch your error driver never appear. Move the override above super and watch it take effect.
6. Week 1 Self-Assessment
Before you move to Day 8, every one of these should be true:
- The environment compiles with zero warnings from your own code.
- A smoke test runs to completion in under one second of simulated time.
- The scoreboard prints a clean "writes=N reads=N mismatches=0" line.
- Deliberately flipping the FIFO's
fullbehavior in the DUT causes a fail, and the scoreboard tells you which read mismatched. - Swapping the write driver for an error-injecting driver via factory override works without touching the agent.
- Putting the read agent in passive mode disables only its driver, not its monitor.
If any of these is not true, you are not ready for Week 2. That is fine — that is what today is for. Fix it and continue tomorrow.
7. What Day 8 Will Add
Tomorrow begins Week 2 with virtual sequences and virtual sequencers. You will take today's two-agent env and add a virtual sequencer that holds both agents' sequencer handles, plus a virtual sequence that coordinates them: write on one, wait, read on the other, verify. This is the first step from "I built an environment" to "I can drive a real DUT's behaviour."
8. Quiz
Ten questions spanning all of Week 1. If you get any wrong, revisit that day before continuing.
Coming Up Next: Day 8 — Virtual Sequences and Virtual Sequencers
- Virtual sequencer — a plain
uvm_sequencerthat holds the real sequencers' handles. - Virtual sequence — a sequence with no item port of its own, whose
body()starts sub-sequences on the sequencers held by the virtual sequencer. `uvm_declare_p_sequencer— how the virtual sequence gets access top_sequencerand the sub-sequencer handles.- Coordinating write-then-read — driving one agent, waiting, driving another, and closing the loop in a scoreboard.
Series: 30 days of SystemVerilog/UVM verification. Day 1 built the skeleton. Day 2 wired the lifecycle. Day 3 put it in motion. Day 4 wired the plumbing. Day 5 installed the knobs. Day 6 made it modular. Day 7 made it yours.
No comments:
Post a Comment