UVM: Hello World Example

UVM Focuses in:
  • Reducing verification coding effort
  • Enhancing code reuse
    • Standard testbench structure
    • Standard stimulus generation
To achieve the above, UVM Provides 4 service mechanisms:
  • Reporter
  • Factory
  • Configuration database
  • Simulation execution manager
Example: 
program automatic test_program; //can be a module
 import uvm_pkg::*;
  initial begin
 `uvm_info("DEMO", "HelloWorld!", UVM_MEDIUM); //macro
 end
endprogram

Here, 
"Hello World!" = Message
"DEMO" = ID
UVM_MEDIUM = Verbosity

Simulation>>>> UVM_INFO ./test.sv(4)@ 0: reporter[] Hello World!

test.sv = File Name
(4) = Line Number
[DEMO] = ID
Hello World! = Message
reporter = Name of object printing message
0: = Simulation time
UVM_INFO = Message type


The 4 Service mechanisms are enabled when you import the package.
  • uvm_report_server class name is Reporter service
  • uvm_factory class name is Factory  service
  • uvm_root is the class name for Simulation execution manager
  • uvm_config_db is the class name for Configuration database service
When you are using the uvm_info macro, you are using the UVM Reporter service mechanism. You can use this report mechanism in any code, including RTL (provided that the code has access to the uvm package). uvm report service issues report service for you.

Using other 3 service mechanisms in code> Test Example:

program automatic test_program; //can be a module
 import uvm_pkg::*;

class hello_world_test extends uvm_test;
 `uvm_component_utils(hello_world_test)
 function new(string name, uvm_component parent);
  super.new(name, parent);
 endfunction

  virtual task run_phase(uvm_phase phase); //the run_phase method will be executed automatically by the UVM simulation manager
 `uvm_info("DEMO", "HelloWorld!", UVM_MEDIUM); //macro
  endtask
 endclass
 initial begin //to enable UVM route (to automatically enable) for you
  run_test();
 end
endprogram
-------------------------------------------------
After Compilation (vcs): 
vcs -sverilog -ntb_opts uvm test.sv
Simulate with:
simv +UVM_TESTNAME=hello_world_test
-------------------------------------------------

  • So what is happening here in general is? On using the UVM Environment here, when you simulate the code with a +UVM_TESTNAME, the result (below) displays the new message automatically saving your time (which is a very useful automation technique and saves a lot of your time).
Result:
---------------------------------------------------------------------------------
UVM_INFO @ 0: reporter [RNTST] Running test new_world_test..
UVM_INFO ./test.sv(9) @ 0: uvm_test_top [DEMO] New World!
---------------------------------------------------------------------------------

UVM Configuration Database Example: Here, instead of "Hello World" a string variable msg is used. Compilation and Simulation will produce the same result. But now, we can use a UVM runtime switch to change the message to what we want for that simulation without running another test.

The uvm_config_db requires 3 arguments. 1> Specifies name of the uvm object you want to configure.

program automatic test_program; //can be a module
 import uvm_pkg::*;

class hello_world_test extends uvm_test;
 `uvm_component_utils(hello_world_test)
 String msg;
 function new(string name, uvm_component parent);
  super.new(name, parent);
  msg = "Hello World!";
 endfunction
  virtual task run_phase(uvm_phase phase); //the run_phase method 
will be executed automatically by the UVM simulation manager
uvm_config_db#(string)::get(this/*Target*/, "", "message", msg);
 `uvm_info("DEMO", msg, UVM_MEDIUM);
  endtask
 endclass
 initial begin //to enable UVM route (to automatically enable) for you
  run_test();
 end
endprogram

--------------------------------------
Simulate with:
simv +UVM_TESTNAME=hello_world_test \
+uvm_set_config_string=uvm_test_top,message,New\ World!
--------------------------------------

Arguments:
uvm_test_top = Target
message = Database entry key => It must match with the 3rd argument of the get method -- get(). The Retrieval from the Database is based on this entry key. 
Set value = the Last argument that you want to store in the Database. If the target and the entry key matches, then you get the Result.

Comments