UVM——控制打印信息

通过控制component打印信息的行为,提高日志的可读性。

uvm_component 直接继承自uvm_report_object,所以component继承了一些设置report的函数。

打印信息的宏有:

  1. `uvm_info(id,mess,verbosity).
  2. `uvm_warning(id,mess)
  3. `uvm_error(id,mess)
  4. `uvm_fatal(id,mess)

1. 设置信息冗余度阈值 verbosity level

冗余度等于低于阈值的信息可以打印出来,否则不会显示。

uvm_verbosity
UVM_NONE Report is always printed. Verbosity level setting can not disable it.
UVM_LOW Report is issued if configured verbosity is set to UVM_LOW or above.
UVM_MEDIUM Report is issued if configured verbosity is set to UVM_MEDIUM or above.
UVM_HIGH Report is issued if configured verbosity is set to UVM_HIGH or above.
UVM_FULL Report is issued if configured verbosity is set to UVM_FULL or above.
1
2
3
4
5
6
7
8
tyypedef enum{
UVM_NONE=0,
UVM_LOW=100,
UVM_MEDIUM=200,
UVM_HIGH=300,
UVM_FULL = 400,
UVM_DEBUG=500
} uvm_verbosity
1
2
// get_verbosity_level()
$display("env's verbosity is %0d",env.get_verbosity_level());
1
2
3
// set_report_verbosity_level(UVM_LOW)
// 设置某个component的verbosity level
env.set_report_verbosity_level(UVM_HIGH);
1
2
// set_report_verbosity_level_hier(UVM_LOW)
// 递归设置
1
2
3
4
5
6
7
8
9
10
11
// set_report_id_verbosity("env",UVM_LOW)
//设置只打印某个id的报告,不是这个id的不打印
// 比如在env中有如下代码:
// `uvm_info("ID1","THIS IS ID1 UVM_LOW",UVM_LOW)
// `uvm_info("ID1","THIS IS ID1 UVM_HIGH",UVM_HIGH)
// `uvm_info("ID2","THIS IS ID2",UVM_LOW)
// 设置:
env.set_report_id_verbosity("env",UVM_LOW);
// 打印结果:
// THIS IS ID1 UVM_LOW
// 这个方法既对id进行过滤,也过滤verbosity level
1
// set_report_id_verbosity_hier("env",UVM_LOW)

也可以在仿真的时候添加仿真选项:

1
2
./simv +UVM_VERBOSITY=UVM_HIGH
// 为整个验证平台设置verbosity level

2. 重载打印信息严重性 severity

uvm有四种信息严重性:

  1. UVM_INFO
  2. UVM_WARNING
  3. UVM_ERROR
  4. UVM_FATAL

这四种可以相互重载

1
2
3
// set_report_severity_override(UVM_WARNING,UVM_ERROR)
env.set_report_severity_override(UVM_WARNING,UVM_ERROR);
// 将env的UVM_WARNING设置成UVM_ERROR
1
2
// set_report_severity_id_override(UVM_WARNING,UVM_ERROR)
// 针对component的某个id起作用

也可以在仿真时候设置,设置选项如下:

1
+uvm_set_severity=<comp>,<id>,<current_severity>,<new_severity>

使用:

1
./simv +uvm_set_severity="uvm_base_top.env,env,UVM_WARNING,UVM_ERROR"

2.1 观察打印信息

1
UVM_INFO my_env.sv(17) @ 0: uvm_test_top.env [my_env] my_env is created !!

上面是`uvm_info宏输出的信息:

  1. UVM_INFO: 信息severity
  2. my_env.sv(17): code中的位置
  3. @ 0: 仿真事件
  4. uvm_test_top.env : 层次路径
  5. [my_env]: 设置的id
  6. my_env is created !!:要打印的信息

3. 错误信息到一定数量结束仿真

当UVM_FATAL发生时,立即结束仿真;但UVM_ERROR则需要到了一定数量才会结束仿真。

可以设置达到几个error就结束仿真。

1
2
3
4
5
6
// set_report_max_quit(5) 
function void base_test::build_phase(uvm_phase phase);
super.build_phase(phase);
env = my_env::type_id::create("env", this);
set_report_max_quit_count(5); //5个ERROR结束仿真 $finish
endfunction

也可以在仿真选项中设置:

1
2
./simv +UVM_MAX_QUIT_COUNT=5,NO
// NO表示这个值不可以被后面的设置语句覆盖
1
2
3
//get_max_quit_count()
// 返回int值,表示当前的最大推出值
// 如果返回0,表示无论多少个error都不会结束仿真

4. 设置计数目标

上一节中UVM_ERROR到达一定值后结束仿真,也可以把UVM_WARNING也加入计数目标,error和warning的达到最大值就退出仿真。

1
2
3
// function void set_report_severity_action (uvm_severity severity,uvm_action action)
env.set_report_severity_action(UVM_WARNING,UVM_DISPLAY|UVM_COUNT);
// 将UVM_WARNING也加入到计数中。
1
// function void set_report_severity_action_hier (uvm_severity severity,uvm_action action)

也可以针对某个ID计数

1
2
//function void set_report_id_action (string 	id,uvm_action 	action	)
//function void set_report_id_action_hier (string id,uvm_action action )

也可把id和severity联合起来进行设置

1
2
// function void set_report_severity_id_action (uvm_severity severity,string id,uvm_action 	action	)
// function void set_report_severity_id_action_hier (uvm_severity severity,string id,uvm_action action )
uvm_action description
UVM_NO_ACTION No action is taken
UVM_DISPLAY Sends the report to the standard output
UVM_LOG Sends the report to the file(s) for this (severity,id) pair
UVM_COUNT Counts the number of reports with the COUNT attribute. When this value reaches max_quit_count, the simulation terminates
UVM_EXIT Terminates the simulation immediately.
UVM_CALL_HOOK Callback the report hook methods
UVM_STOP Causes $stop to be executed, putting the simulation into interactive mode.

5. UVM断点

执行到断点,停止仿真。

设置出现UVM_WARNING的时候停止仿真:

1
env.set_report_severity_action(UVM_WARNING,UVM_DISPLAY|UVM_STOP);

6. 将输出信息写入到文件

1
2
3
4
5
6
function void set_report_severity_file (uvm_severity severity,UVM_FILE file)
function void set_report_id_file ( string id,UVM_FILE file )
function void set_report_severity_id_file (uvm_severity severity,string id,UVM_FILE file)
function void set_report_severity_file_hier (uvm_severity severity,UVM_FILE file)
function void set_report_id_file_hier ( string id,UVM_FILE file )
function void set_report_severity_id_file_hier (uvm_severity severity,string id,UVM_FILE file)

6.1 将不同severity的信息打印到不同的文件中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 创建文件句柄
// 写入方式打开文件
//为不同severity设置保存文件
//设置打印的行为UVM_LOG

UVM_FILE info_log; // 创建文件句柄
UVM_FILE warning_log;
UVM_FILE error_log;
UVM_FILE fatal_log;
virtual function void connect_phase(uvm_phase phase);
info_log = $fopen("info.log", "w"); // 写入方式打开文件
warning_log = $fopen("warning.log", "w");
error_log = $fopen("error.log", "w");
fatal_log = $fopen("fatal.log", "w");
env.i_agt.drv.set_report_severity_file(UVM_INFO, info_log);//为不同severity设置保存文件
env.i_agt.drv.set_report_severity_file(UVM_WARNING, warning_log);
env.i_agt.drv.set_report_severity_file(UVM_ERROR, error_log);
env.i_agt.drv.set_report_severity_file(UVM_FATAL, fatal_log);
env.i_agt.drv.set_report_severity_action(UVM_INFO, UVM_DISPLAY | UVM_LOG);//设置打印的行为UVM_LOG
env.i_agt.drv.set_report_severity_action(UVM_WARNING, UVM_DISPLAY | UVM_LOG);
env.i_agt.drv.set_report_severity_action(UVM_ERROR, UVM_DISPLAY | UVM_COUNT | UVM_LOG);
env.i_agt.drv.set_report_severity_action(UVM_FATAL, UVM_DISPLAY | UVM_EXIT | UVM_LOG);

//env.i_agt.set_report_severity_file_hier(UVM_INFO, info_log);
//env.i_agt.set_report_severity_file_hier(UVM_WARNING, warning_log);
//env.i_agt.set_report_severity_file_hier(UVM_ERROR, error_log);
//env.i_agt.set_report_severity_file_hier(UVM_FATAL, fatal_log);
//env.i_agt.set_report_severity_action_hier(UVM_INFO, UVM_DISPLAY| UVM_LOG);
//env.i_agt.set_report_severity_action_hier(UVM_WARNING, UVM_DISPLAY| UVM_LOG);
//env.i_agt.set_report_severity_action_hier(UVM_ERROR, UVM_DISPLAY| UVM_COUNT | UVM_LOG);
//env.i_agt.set_report_severity_action_hier(UVM_FATAL, UVM_DISPLAY| | UVM_EXIT | UVM_LOG);
endfunction
virtual function void final_phase(uvm_phase phase);
$fclose(info_log);
$fclose(warning_log);
$fclose(error_log);
$fclose(fatal_log);
endfunction

6.2 将不同id的信息打印到不同的文件中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
UVM_FILE driver_log;
UVM_FILE drv_log;
virtual function void connect_phase(uvm_phase phase);
driver_log = $fopen("driver.log", "w");
drv_log = $fopen("drv.log", "w");
env.i_agt.drv.set_report_severity_id_file(UVM_WARNING, "my_driver", driver_log);
env.i_agt.drv.set_report_severity_id_file(UVM_INFO, "my_drv", drv_log);
env.i_agt.drv.set_report_id_action("my_driver", UVM_DISPLAY| UVM_LOG);
env.i_agt.drv.set_report_id_action("my_drv", UVM_DISPLAY| UVM_LOG);
//env.i_agt.set_report_severity_id_file_hier(UVM_WARNING, "my_driver", driver_log);
//env.i_agt.set_report_severity_id_file_hier(UVM_INFO, "my_drv", drv_log);
//env.i_agt.set_report_id_action_hier("my_driver", UVM_DISPLAY| UVM_LOG);
//env.i_agt.set_report_id_action_hier("my_drv", UVM_DISPLAY| UVM_LOG);
endfunction
virtual function void final_phase(uvm_phase phase);
$fclose(driver_log);
$fclose(drv_log);
endfunction

7. 信息的打印行为 action

前面大都是通过设置action来控制打印信息。

uvm_action description
UVM_NO_ACTION No action is taken
UVM_DISPLAY Sends the report to the standard output
UVM_LOG Sends the report to the file(s) for this (severity,id) pair
UVM_COUNT Counts the number of reports with the COUNT attribute. When this value reaches max_quit_count, the simulation terminates
UVM_EXIT Terminates the simulation immediately.
UVM_CALL_HOOK Callback the report hook methods
UVM_STOP Causes $stop to be executed, putting the simulation into interactive mode.
1
2
3
4
5
6
7
8
9
10
typedef enum
{
UVM_NO_ACTION = 'b000000,
UVM_DISPLAY = 'b000001,
UVM_LOG = 'b000010,
UVM_COUNT = 'b000100,
UVM_EXIT = 'b001000,
UVM_CALL_HOOK = 'b010000,
UVM_STOP = 'b100000
} uvm_action_type;

8. 打印UVM树结构

1
uvm_top.print_topology();

可以把它写在base_test中

1
2
3
4
function void base_test::report_phase(uvm_phase phase);
super.report_phase(phase);
uvm_top.print_topology();
endfunction

打印输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
UVM_INFO @ 43550000: reporter [UVMTOP] UVM testbench topology:
------------------------------------------------------------------
Name Type Size Value
------------------------------------------------------------------
uvm_test_top case0 - @460
env enviroment - @468
agt2mdl uvm_tlm_analysis_fifo #(T) - @492
analysis_export uvm_analysis_imp - @536
get_ap uvm_analysis_port - @527
get_peek_export uvm_get_peek_imp - @509
put_ap uvm_analysis_port - @518
put_export uvm_put_imp - @500
i_agt agent - @480
drv driver - @545
rsp_port uvm_analysis_port - @562
seq_item_port uvm_seq_item_pull_port - @553
mon_apb monitor_apb - @694
ap uvm_analysis_port - @702
sqr sequencer - @571
rsp_export uvm_analysis_export - @579
seq_item_export uvm_seq_item_pull_imp - @685
arbitration_queue array 0 -
lock_queue array 0 -
num_last_reqs integral 32 'd1
num_last_rsps integral 32 'd1


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!