Writing Tests¶
Rules for a test that runs on IVL_UVM today:
Derive tests from
uvm_test, environments fromuvm_env, agents fromuvm_agent, monitors fromuvm_monitor, scoreboards fromuvm_scoreboard, subscribers fromuvm_subscriberand other components fromuvm_component. All of these are abstract, so you always need your own derived class. Derive drivers fromuvm_driver #(<item>)and sequences fromuvm_sequence #(<item>).Use the standard constructor
new(string name, uvm_component parent).Register every test and component with
uvm_component_utils(<class>)inside the class, and every object or transaction withuvm_object_utils(<class>)(or the*_begin/*_endform with field macros).Put the classes in a package that imports
ivl_uvm_pkg::*.End the file list with
ivl_uvm_top.svhto get the final report summary (see Getting Started).Create components and objects with
<class>::type_id::create. Create child components inbuild_phasewiththisas the parent; they take part in all the phases that follow.The
run_phasetasks of all components run in parallel. Hold the run phase open withraise_objectionanddrop_objection; once the objections are dropped, the tasks still running are stopped. See Phasing: How run_test Runs the Phases.Do not use the field macros for arrays, queues or associative arrays; they are not ported yet.
Write
this.in front of calls to inherited methods inside your methods (see Differences from Standard UVM).
A test with a child component¶
package my_pkg;
import ivl_uvm_pkg::*;
class my_env extends uvm_env;
`uvm_component_utils(my_env)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info("ENV", {"build in ", this.get_full_name()}, UVM_LOW)
endfunction : build_phase
endclass : my_env
class my_test extends uvm_test;
`uvm_component_utils(my_test)
my_env env;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
env = my_env::type_id::create("env", this);
endfunction : build_phase
task run_phase(uvm_phase phase);
phase.raise_objection(this);
#10;
phase.drop_objection(this);
endtask : run_phase
endclass : my_test
endpackage : my_pkg
module top;
import ivl_uvm_pkg::*;
import my_pkg::*;
initial begin
run_test("my_test");
$finish;
end
endmodule : top
The raise_objection and drop_objection calls hold the run phase open for the 10 time units
between them. Raise the objection in the first time step of the run phase (see Phasing: How run_test Runs the Phases).
Sequences, sequencer and driver¶
A sequence creates the items, the sequencer hands them one at a time to the driver, and the agent
connects the sequencer and the driver. Two things differ from standard UVM because of Icarus (see
Differences from Standard UVM): handles are copied into local variables first, because Icarus cannot reach
through two class handles, and inherited methods are called with this..
class my_item extends uvm_sequence_item;
`uvm_object_utils(my_item)
int val;
function new(string name = "my_item");
super.new(name);
endfunction : new
endclass : my_item
typedef uvm_sequencer #(my_item) my_sequencer;
class my_seq extends uvm_sequence #(my_item);
`uvm_object_utils(my_seq)
function new(string name = "my_seq");
super.new(name);
endfunction : new
task body();
my_item it;
for (int i = 1; i <= 3; i++) begin
it = my_item::type_id::create("it");
this.start_item(it);
it.val = i;
this.finish_item(it);
end
endtask : body
endclass : my_seq
class my_driver extends uvm_driver #(my_item);
`uvm_component_utils(my_driver)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction : new
task run_phase(uvm_phase phase);
my_item it;
forever begin
seq_item_port.get_next_item(req);
it = req;
`uvm_info("DRV", $sformatf("val = %0d", it.val), UVM_LOW)
#10;
seq_item_port.item_done();
end
endtask : run_phase
endclass : my_driver
class my_agent extends uvm_agent;
`uvm_component_utils(my_agent)
my_sequencer sqr;
my_driver drv;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
sqr = my_sequencer::type_id::create("sqr", this);
drv = my_driver::type_id::create("drv", this);
endfunction : build_phase
function void connect_phase(uvm_phase phase);
my_driver d;
my_sequencer s;
super.connect_phase(phase);
d = drv;
s = sqr;
d.seq_item_port.connect(s.seq_item_export);
endfunction : connect_phase
endclass : my_agent
The test starts the sequence while it holds an objection. This is its run_phase, for a test
whose env holds the agent agt:
task run_phase(uvm_phase phase);
my_seq seq;
my_env e;
my_agent a;
my_sequencer s;
phase.raise_objection(this);
seq = my_seq::type_id::create("seq");
e = env;
a = e.agt;
s = a.sqr;
seq.start(s);
phase.drop_objection(this);
endtask : run_phase
randomize is not available, so set the item fields yourself, for example with $urandom. The
test t44_sequence is the complete example.
Messages¶
`uvm_info("MY_ID", "hello", UVM_MEDIUM)
`uvm_warning("MY_ID", "careful")
`uvm_error("MY_ID", "something failed")
`uvm_fatal("MY_ID", "cannot continue")
Run with +UVM_VERBOSITY=UVM_HIGH (or UVM_DEBUG) to see more. Call report_summarize()
at the end of a test to print the totals.
Example tests¶
The tests under ivl_uvm_tests/ are small, incremental examples. They are listed on the
Regression page. t21_run_test_phases is a good first one to read: it looks like the first
test a UVM user writes.