通過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