class jelly_bean_sb_subscriber extends uvm_subscriber#( jelly_bean_transaction );
function void write( jelly_bean_transaction t );
`uvm_info( get_name(), { "using uvm_default_printer\n",t.sprint() }, UVM_LOW ) // use uvm_default_printer
`uvm_info( get_name(), { "using uvm_default_table_printer\n", t.sprint( uvm_default_table_printer ) }, UVM_LOW )
`uvm_info( get_name(), { "using uvm_default_tree_printer\n", t.sprint( uvm_default_tree_printer ) }, UVM_LOW )
`uvm_info( get_name(), { "using uvm_default_line_printer\n", t.sprint( uvm_default_line_printer ) }, UVM_LOW )
`uvm_info( get_name(), { "using convert2string",t.convert2string() }, UVM_LOW )
endfunction: write
// ...
endclass: jelly_bean_sb_subscriber
1 Output of sprint using uvm_default_printer
`uvm_info( get_name(), { "using uvm_default_printer\n",t.sprint() }, UVM_LOW )
UVM_INFO env.svh(136) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using uvm_default_printer ----------------------------------------------------------------- Name Type Size Value ----------------------------------------------------------------- jb_tx sugar_free_jelly_bean_transaction - @861 name string 5 jb_tx flavor string 10 BUBBLE_GUM color string 3 RED sugar_free integral 1 'h1 sour integral 1 'h1 taste string 5 YUMMY -----------------------------------------------------------------
2 Output of sprint using uvm_default_table_printer
`uvm_info( get_name(), { "using uvm_default_table_printer\n", t.sprint( uvm_default_table_printer ) }, UVM_LOW )
This output is exactly same as the above.
UVM_INFO env.svh(138) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using uvm_default_table_printer ----------------------------------------------------------------- Name Type Size Value ----------------------------------------------------------------- jb_tx sugar_free_jelly_bean_transaction - @861 name string 5 jb_tx flavor string 10 BUBBLE_GUM color string 3 RED sugar_free integral 1 'h1 sour integral 1 'h1 taste string 5 YUMMY ----------------------------------------------------------------- 3 Output of sprint using uvm_default_tree_printerThe uvm_default_tree_printer outputs the object in a tree form. |
UVM_INFO env.svh(140) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using uvm_default_tree_printer jb_tx: (sugar_free_jelly_bean_transaction@861) { name: jb_tx flavor: BUBBLE_GUM color: RED sugar_free: 'h1 sour: 'h1 taste: YUMMY } |
4 Output of sprint using uvm_default_line_printer
The uvm_default_line_printer
outputs the same information as the uvm_default_tree_printer
does, but in one line.
`uvm_info( get_name(), { "using uvm_default_line_printer\n", t.sprint( uvm_default_line_printer ) }, UVM_LOW )
UVM_INFO env.svh(142) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using uvm_default_line_printer jb_tx: (sugar_free_jelly_bean_transaction@861) { name: jb_tx flavor: BUBBLE_GUM color: RED sugar_free: 'h1 sour: 'h1 taste: YUMMY }
5 Output of convert2string
There is another function available in uvm_object
called convert2string
that will return a string instead of printing the contents in a predefined format. This allows you to define the output into a format you like. For example, we can simply print contents into a single line as shown.
xclass Object extends uvm_object;
rand e_bool m_bool;
rand bit[3:0] m_mode;
rand byte m_data[4];
rand shortint m_queue[$];
string m_name;
constraint c_queue { m_queue.size() == 3; }
function new(string name = "Object");
super.new(name);
m_name = name;
endfunction
// Use "do_print" instead of the automation macro
`uvm_object_utils(Object)
virtual function string convert2string();
string contents = "";
$sformat(contents, "%s m_name=%s", contents, m_name);
$sformat(contents, "%s m_bool=%s", contents, m_bool.name());
$sformat(contents, "%s m_mode=0x%0h", contents, m_mode);
foreach(m_data[i]) begin
$sformat(contents, "%s m_data[%0d]=0x%0h", contents, i, m_data[i]);
end
return contents;
endfunction
class base_test extends uvm_test;
`uvm_component_utils(base_test)
function new(string name = "base_test", uvm_component parent=null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
Object obj = Object::type_id::create("obj");
obj.randomize();
`uvm_info(get_type_name(), $sformatf("convert2string: %s", obj.convert2string()), UVM_LOW)
endfunction
endclass
module tb;
initial begin
run_test("base_test");
end
endmodule
ncsim> run UVM_INFO /playground_lib/uvm-1.2/src/base/uvm_root.svh(392) @ 0: reporter [UVM/RELNOTES] ---------------------------------------------------------------- UVM-1.2 (C) 2007-2014 Mentor Graphics Corporation (C) 2007-2014 Cadence Design Systems, Inc. (C) 2006-2014 Synopsys, Inc. (C) 2011-2013 Cypress Semiconductor Corp. (C) 2013-2014 NVIDIA Corporation ---------------------------------------------------------------- UVM_INFO @ 0: reporter [RNTST] Running test base_test... UVM_INFO testbench.sv(99) @ 0: uvm_test_top [base_test] convert2string: m_name=obj m_bool=TRUE m_mode=0xe m_data[0]=0xf4 m_data[1]=0xe m_data[2]=0x58 m_data[3]=0xbd UVM_INFO /playground_lib/uvm-1.2/src/base/uvm_report_server.svh(847) @ 0: reporter [UVM/REPORT/SERVER] --- UVM Report Summary ---