通过uvm_config_db
类访问的UVM配置数据库,是在多个测试平台组件之间传递不同对象的绝佳方式。
methods
有两个主要函数用于从数据库中放入和检索项目,分别是 set() 和 get()。
static function void set ( uvm_component cntxt,string inst_name,string field_name,T value);static function bit get ( uvm_component cntxt,string inst_name,string field_name,inout T value);
rules
为 inst_name 中的 field_name 在 cntxt 下创建或更新配置设置;
该设置在 cntxt 下生效,完整作用域为 {cntxt, ".", inst_name};
若 cntxt 为空,则 inst_name 提供设置的完整作用域信息;
field_name 是目标字段;
inst_name 和 field_name 均可采用通配符风格或正则表达式风格的匹配模式;
来自更高层级结构的设置具有更高优先级;
同一层级结构的设置遵循"最后设置生效"语义;
how to debug uvm_config_db
The best way to understand how the combination of cntxt, inst_name and field_name works is by enabling the commandline debug +UVM_CONFIG_DB_TRACE
switch for UVM that dumps information on all the set()
and get()
calls within a simulation.
$> irun <all_other_options> +UVM_CONFIG_DB_TRACE
example
我们将观察当从不同层级调用set
和get
方法时,两个测试平台环境的行为表现。
1. Test and Env
要了解config_db如何验证表达式,我们将建立一个带有空环境的小型测试台结构,如下所示。表达式从测试类中设置,并在环境的build_phase阶段获取。
Case #1
我们将 cntxt
设为 null
并将 inst_name
设为 uvm_test_top
,以表明测试中的所有组件都能访问该条目。为简化操作,我们将放入一个标记为 Friend
的字符串条目。
class base_env extends uvm_env;...string name;virtual function void build_phase (uvm_phase phase);super.build_name ();// Retrieve the string that was set in config_db from the test classif (uvm_config_db #(string) :: get (null, "uvm_test_top", "Friend", name))`uvm_info ("ENV", $sformatf ("Found %s", name), UVM_MEDIUM)endfunction
endclassclass base_test extends uvm_test;...base_env m_env;virtual function void build_phase (uvm_phase phase);...// Set this string into config_dbuvm_config_db #(string) :: set (null, "uvm_test_top", "Friend", "Joey");endfunction
endclass
很明显,第一个参数cntxt
只能是uvm_component
对象。从以下仿真日志可以看出,当+UVM_CONFIG_DB_TRACE
作为命令行开关时,仿真会将所有对set
和get
的函数调用记录到日志中。其中我们关注的行已用颜色高亮显示:黄色代表set
调用,绿色代表成功的get
调用。由于set
和get
调用时的cntxt
、inst_name
与field_name
组合完全匹配,数据库成功找到并返回了标记为"Frie