马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 leine 于 2021-2-15 18:12 编辑
今天小白我在公司代码里看到了对config_db应用的这样一种情况:
test:在顶层test对sequencer中的变量var进行了set
uvm_config_db#(T)::set(this , "sequencer" , "var" , value);
sqr:在sequencer中并没有声明任何变量包括变量var
seq:sequence的m_sqr已经指向了同一个sqr。然后在seq中去get在sqr中并不存在的变量var
uvm_config_db#(T)::get(m_sqr , "" , "var" , value);
---------------------------------------------------------------
代码运行的结果是pass了的。
所以这里就有一个问题:config_db看网上的介绍就是一个全局的关联数组。那这是不是意味着使用时,只要确保这个关联数组的key是一致的即可保证set与get的运行正确,而无需真正的声明某一个变量?
---------------------------------------------------------------
之后小白我用了这个在线仿真的平台(https://www.edaplayground.com/)对下面的代码进行测试。
如下uvm拓扑结构只包含一个basetest、env和comp。在basetest对env中不存在的变量str进行设置,然后再comp再去获取env中不存在的变量str的值。comp中声明了m_env变量指向了env。
- `include "uvm_macros.svh"
- import uvm_pkg::*;
- //to avoid type undefined
- typedef class comp;
- typedef class env;
- //comp declartion
- class comp extends uvm_component;
- env m_env; //basetest will assign this m_env handle pointed to env
- string str = "default"; //use a string variable to get. If it is failed to get value from config_db, this variable will print "default"
- `uvm_component_utils(comp)
- function new(string name = "comp",uvm_component parent=null );
- super.new(name,parent);
- endfunction
-
- function void build_phase(uvm_phase phase);
- `uvm_info(get_full_name(),"build_phase of comp is entered",UVM_NONE)
- uvm_config_db#(string)::get(m_env,"","str",str); //get str's value from m_env.Note there is no str variable defined in env.
- $display("str = %s",str); //print the value of str
- `uvm_info(get_full_name(),"build_phase of comp is exited",UVM_NONE)
- endfunction
- endclass
- //env declartion
- class env extends uvm_env;
- comp comp1; //only define a comp as sub_component
- `uvm_component_utils(env)
- function new(string name = "env",uvm_component parent=null );
- super.new(name,parent);
- comp1= comp::type_id::create("comp1",this);
- endfunction
-
- function void build_phase(uvm_phase phase);
- `uvm_info(get_full_name(),"build_phase of env is entered",UVM_NONE)
- `uvm_info(get_full_name(),"build_phase of env is exited",UVM_NONE)
- endfunction
- endclass
- //basetest declartion
- class basetest extends uvm_test;
- env env1; //only define a env as sub_component
- `uvm_component_utils(basetest)
- function new(string name = "basetest",uvm_component parent=null );
- super.new(name,parent);
- env1 = env::type_id::create("env1",this);
- endfunction
-
- function void build_phase(uvm_phase phase);
- `uvm_info(get_full_name(),"build_phase of basetest is entered",UVM_NONE)
- env1.comp1.m_env = env1;//assign the comp1.m_env handle to env1
- uvm_config_db#(string)::set(this,"env1","str","Greetings!"); //set str's value in m_env.Note there is no str variable defined in env.
- `uvm_info(get_full_name(),"build_phase of basetest is exited",UVM_NONE)
- endfunction
-
- endclass
- module test;
- initial begin
- run_test("basetest");
- end
- endmodule
复制代码 如果开启config_db,那么str会打印Greetings
如果注释掉config_fb,那么str会打印default
|