Protected Course Page
Enter the password to view Day 28 of the UVM 30-Day plan.
Day 28: Capstone Project (Day 2 of 3) — Build the Testbench and Get the Smoke Test Passing
A 30-day SystemVerilog/UVM verification series. Yesterday you planned. Today you build. Tomorrow you prove. The build is the day most capstones fail, so today is also the day to be very disciplined about order.
Forty files, one working testbench at the end. If you sit down and write them all at once, you will have a working testbench at the end only if nothing goes wrong. Since something always goes wrong, the strategy is compile-and-run after every step. A testbench that has never run is a testbench that will take ten hours to debug.
Today's build order is chosen so that each step produces a runnable state. Do not skip ahead.
1. Step 1 — Top Module and Interfaces
Start with what you can prove without any UVM: the DUT resets and idles. No run_test() yet. Just the DUT, the interface, and a clock.
module fifo_capstone_tb_top;
// Clock and reset
bit clk;
bit rst_n;
initial clk = 0;
always #5 clk = ~clk;
initial begin
rst_n = 0;
#100 rst_n = 1;
end
// Interfaces
apb_if apb_vif(.pclk(clk), .presetn(rst_n));
fifo_data_if data_vif(.clk(clk), .rst_n(rst_n));
// DUT
fifo_with_apb_regs dut (
.pclk (clk),
.presetn (rst_n),
.paddr (apb_vif.paddr),
.pwrite (apb_vif.pwrite),
.psel (apb_vif.psel),
.penable (apb_vif.penable),
.pwdata (apb_vif.pwdata),
.prdata (apb_vif.prdata),
.pready (apb_vif.pready),
.data_in (data_vif.data_in),
.data_out(data_vif.data_out),
.wr_en (data_vif.wr_en),
.rd_en (data_vif.rd_en),
.full (data_vif.full),
.empty (data_vif.empty)
);
// No run_test() yet — just reset and idle
initial begin
#1000;
$display("Step 1 complete: DUT reset and idling");
$finish;
end
endmodule
Compile and run. If the DUT resets and idles without Xs, step 1 is done.
2. Step 2 — APB Agent
Instantiate the APB agent, wire it to apb_vif, and drive one write through the factory. This proves the driver, sequencer, and APB protocol are working before you add anything else.
class apb_drv_test extends uvm_test;
`uvm_component_utils(apb_drv_test)
apb_agent apb_agent_inst;
apb_agent_cfg apb_cfg;
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
apb_cfg = apb_agent_cfg::type_id::create("apb_cfg");
apb_cfg.vif = apb_vif; // set from tb_top
apb_cfg.is_active = UVM_ACTIVE;
uvm_config_db#(apb_agent_cfg)::set(this, "apb_agent_inst", "cfg", apb_cfg);
apb_agent_inst = apb_agent::type_id::create("apb_agent_inst", this);
endfunction
virtual task run_phase(uvm_phase phase);
apb_write_seq seq;
phase.raise_objection(this);
seq = apb_write_seq::type_id::create("seq");
seq.addr = 'h00;
seq.data = 'h03;
seq.start(apb_agent_inst.sqr);
#500;
phase.drop_objection(this);
endtask
endclass
Run. Look at the waveform. You should see one APB write transaction complete. If yes, step 2 is done.
3. Step 3 — Data Path Monitor
Add the data path monitor and connect it to a trivial scoreboard that just prints transactions. No comparison yet — just confirm the monitor publishes what the DUT does.
class data_pass_through_sb extends uvm_scoreboard;
`uvm_component_utils(data_pass_through_sb)
uvm_analysis_imp #(fifo_tx, data_pass_through_sb) exp_imp;
function new(string name, uvm_component parent);
super.new(name, parent);
exp_imp = new("exp_imp", this);
endfunction
function void write(fifo_tx tr);
`uvm_info("SB", $sformatf("data tx: wr=%0d rd=%0d din=0x%0h dout=0x%0h",
tr.wr_en, tr.rd_en, tr.data_in, tr.data_out), UVM_LOW)
endfunction
endclass
Run. After the APB write from step 2, you should see one data-path transaction (a push) in the log. If yes, step 3 is done.
4. Step 4 — Register Model and Adapter
Add the RAL block and adapter. Wire the model to the APB agent's sequencer. Do not run any register sequences yet — just verify the model builds, locks, and prints a correct map.
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
// ... existing agent ...
reg_model = fifo_reg_block::type_id::create("reg_model", this);
reg_model.build();
reg_model.lock_model();
// Print the map for cross-check
reg_model.print();
reg_model.default_map.print();
endfunction
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
reg_model.default_map.set_sequencer(apb_agent_inst.sqr, reg_adapter);
reg_model.default_map.set_auto_predict(1);
endfunction
Run. Compare the printed map against the register plan from Day 27. Every address and every reset value must match. Fix before continuing — a wrong map is indistinguishable from a wrong DUT.
5. Step 5 — First Register Access
Write a tiny test that does one register read and one register write, through RAL. This is the first proof that the whole chain — model, adapter, sequencer, driver, DUT, monitor — is connected.
virtual task run_phase(uvm_phase phase);
uvm_status_e status;
uvm_reg_data_t value;
phase.raise_objection(this);
// Write CTRL.ENABLE = 1
reg_model.ctrl.write(status, 8'h01);
if (status != UVM_IS_OK) `uvm_error("STEP5", "ctrl write failed")
// Read STATUS
reg_model.status.read(status, value);
if (status != UVM_IS_OK) `uvm_error("STEP5", "status read failed")
`uvm_info("STEP5", $sformatf("status = 0x%0h", value), UVM_LOW)
phase.drop_objection(this);
endtask
Run. If status reads back a plausible value and no fatal fires, step 5 is done.
6. Step 6 — Reference Model and Scoreboard
Now wire the real reference model. It watches APB register writes (specifically pushes to DATA) and predicts the data-path transactions. The data-path scoreboard compares the model's output against the monitor's observations.
class fifo_ref_model extends uvm_component;
`uvm_component_utils(fifo_ref_model)
uvm_analysis_imp #(apb_transaction, fifo_ref_model) apb_imp;
uvm_analysis_port #(fifo_tx) apb_out; // expected data-path transactions
fifo_reg_block reg_model; // to detect DATA writes
// internal FIFO model
bit [7:0] model_q[$];
function void write(apb_transaction tr);
// Only pushes to DATA (offset 0x08) matter
if (tr.addr == 'h08 && tr.we && reg_model.ctrl.enable.get() == 1'b1) begin
model_q.push_back(tr.data);
// Publish the expected data-path event
fifo_tx tx = fifo_tx::type_id::create("tx");
tx.wr_en = 1;
tx.data_in = tr.data;
apb_out.write(tx);
end
// Pops from DATA — expected read side
if (tr.addr == 'h08 && !tr.we) begin
if (model_q.size() > 0) begin
fifo_tx tx = fifo_tx::type_id::create("tx");
tx.rd_en = 1;
tx.data_out = model_q.pop_front();
apb_out.write(tx);
end
end
endfunction
endclass
The data-path scoreboard receives two streams: the reference model's expected transactions (from APB) and the monitor's observed transactions (from the data path). It compares them.
class fifo_data_scoreboard extends uvm_scoreboard;
`uvm_component_utils(fifo_data_scoreboard)
`uvm_analysis_imp_decl(_exp)
`uvm_analysis_imp_decl(_obs)
uvm_analysis_imp_exp #(fifo_tx, fifo_data_scoreboard) exp_export;
uvm_analysis_imp_obs #(fifo_tx, fifo_data_scoreboard) obs_export;
fifo_tx expected [$];
int mismatches, orphans;
function void write_exp(fifo_tx tr);
expected.push_back(tr);
endfunction
function void write_obs(fifo_tx tr);
fifo_tx e;
if (expected.size() == 0) begin
`uvm_error("DSB", "observed tx with no expected")
orphans++;
return;
end
e = expected.pop_front();
if (tr.wr_en && tr.data_in !== e.data_in) begin
mismatches++;
`uvm_error("DSB", $sformatf("wr mismatch: exp 0x%0h got 0x%0h",
e.data_in, tr.data_in))
end
if (tr.rd_en && tr.data_out !== e.data_out) begin
mismatches++;
`uvm_error("DSB", $sformatf("rd mismatch: exp 0x%0h got 0x%0h",
e.data_out, tr.data_out))
end
endfunction
function void check_phase(uvm_phase phase);
if (mismatches) `uvm_error("DSB", $sformatf("%0d mismatches", mismatches))
if (orphans) `uvm_error("DSB", $sformatf("%0d orphans", orphans))
if (expected.size()) `uvm_error("DSB",
$sformatf("%0d expected never observed", expected.size()))
endfunction
endclass
Run the write_read sequence. The data-path scoreboard should report zero mismatches. If it does, the reference model and the scoreboard are wired correctly — you now have a self-checking testbench.
7. Step 7 — Env and Full Smoke Test
Move everything into a proper env, wrap it in a base test, and run a full sequence that does reset + a few register reads/writes + a data-path push/pop pattern. This is the smoke test.
class fifo_capstone_env extends uvm_env;
`uvm_component_utils(fifo_capstone_env)
apb_agent apb_agent_inst;
fifo_data_monitor data_mon;
fifo_reg_block reg_model;
apb_reg_adapter reg_adapter;
fifo_ref_model ref_model;
fifo_data_scoreboard data_sb;
fifo_capstone_vseqr vseqr;
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
apb_agent_inst = apb_agent::type_id::create("apb_agent_inst", this);
data_mon = fifo_data_monitor::type_id::create("data_mon", this);
reg_model = fifo_reg_block::type_id::create("reg_model", this);
reg_model.build(); reg_model.lock_model();
reg_adapter = apb_reg_adapter::type_id::create("reg_adapter");
ref_model = fifo_ref_model::type_id::create("ref_model", this);
data_sb = fifo_data_scoreboard::type_id::create("data_sb", this);
vseqr = fifo_capstone_vseqr::type_id::create("vseqr", this);
endfunction
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
// APB → reg_model, ref_model
apb_agent_inst.mon.ap.connect(reg_model.default_map);
apb_agent_inst.mon.ap.connect(ref_model.apb_imp);
// Data path → data_sb (observed side)
data_mon.ap.connect(data_sb.obs_export);
// Ref model → data_sb (expected side)
ref_model.apb_out.connect(data_sb.exp_export);
// RAL wiring
reg_model.default_map.set_sequencer(apb_agent_inst.sqr, reg_adapter);
reg_model.default_map.set_auto_predict(0);
// Virtual sequencer handles
vseqr.apb_sqr = apb_agent_inst.sqr;
endfunction
endclass
Run the smoke test. It should complete in under 10µs of simulated time and produce zero UVM_ERROR. That is the Day 28 goal.
8. What Day 29 Will Add
Tomorrow: Capstone Project (Day 3 of 3) — Close. You have a working smoke test. Tomorrow you add the full sequence library (full, empty, wrap), wire up the coverage collector, run the regression, look at the coverage report, and close the remaining holes. By end of day you have a self-checking, coverage-driven testbench for a real DUT — which is what the last 29 days have been building toward.
9. Quiz
Ten questions on the capstone build — order, wiring, and debugging.
Coming Up Next: Day 29 — Capstone Project (Day 3 of 3) — Close
- Full sequence library — full, empty, wrap, error injection.
- Coverage collector — wire the covergroups from Day 27's plan.
- Regression — ten seeds, all tests, merged coverage.
- Coverage closure — the loop from Day 25, applied to the capstone.
Series: 30 days of SystemVerilog/UVM verification. Day 28's build order.
No comments:
Post a Comment