什么是UVM environment?
UVM environment包含多個(gè)可重用的驗(yàn)證組件,并根據(jù)test case的需求進(jìn)行相應(yīng)的配置。例如,UVM environment可能具有多個(gè)agent(對(duì)應(yīng)不同的interface)、scoreboard、functional coverage collector和一些checker。
對(duì)于一個(gè)復(fù)雜的數(shù)字系統(tǒng),UVM environment可能還集成其他一些較小的UVM environment,這些相對(duì)較小的驗(yàn)證環(huán)境用于對(duì)各個(gè)子系統(tǒng)/模塊進(jìn)行驗(yàn)證。所以,被集成的子模塊/系統(tǒng)驗(yàn)證環(huán)境中的很多組件和sequence都是可以復(fù)用的。
為什么驗(yàn)證組件不直接放在test case中?
從技術(shù)上講,一些驗(yàn)證組件可以直接在用戶定義的testcase(uvm_test類)中實(shí)例化。
class base_test extends uvm_test;
`uvm_component_utils(base_test)
apb_agent m_apb_agent;
spi_agent m_spi_agent;
base_scoreboard m_base_scbd;
virtual function void build_phase(uvm_phase phase);
// Instantiate agents and scoreboard
endfunction
endclass
但是,不建議這樣做:test case不能夠復(fù)用,因?yàn)樗鼈円蕾囉谔囟ǖ尿?yàn)證環(huán)境,針對(duì)每個(gè)testcase都開發(fā)一個(gè)uvm environment比較低效。 簡(jiǎn)單來說,uvm environment存在的意義就是不同的testcase都使用同一套驗(yàn)證環(huán)境代碼 ,是為了驗(yàn)證環(huán)境的復(fù)用性考慮的。
因此,始終建議開發(fā)一個(gè)比較通用的,適用所有test case的驗(yàn)證環(huán)境, 然后在多個(gè)test case中實(shí)例化該驗(yàn)證環(huán)境類uvm environment。此外,不同的testcase可以配置、啟動(dòng)、禁用驗(yàn)證環(huán)境中的各種配置,可能是激勵(lì)的隨機(jī)機(jī)制、agent的active/passive模式,也可能是scoreboard的開關(guān)。
創(chuàng)建 UVM environment的步驟
- 創(chuàng)建一個(gè)繼承自u(píng)vm_env的自定義類,注冊(cè)到工廠,并調(diào)用 new函數(shù)
// my_env is user-given name for this class that has been derived from "uvm_env"
class my_env extends uvm_env;
// [Recommended] Makes this driver more re-usable
`uvm_component_utils (my_env)
// This is standard code for all components
function new (string name = "my_env", uvm_component parent = null);
super.new (name, parent);
endfunction
// Code for rest of the steps come here
endclass
聲明和構(gòu)建驗(yàn)證環(huán)境中各個(gè)驗(yàn)證組件
// apb_agnt and other components are assumed to be user-defined classes that already exist in TBapb_agnt m_apb_agnt;
func_cov m_func_cov;
scbd m_scbd;
env_cfg m_env_cfg;
// Build components within the "build_phase"
virtual function void build_phase (uvm_phase phase);
super.build_phase (phase);
m_apb_agnt = apb_agnt::type_id::create ("m_apb_agnt", this);
m_func_cov = func_cov::type_id::create ("m_func_cov", this);
m_scbd = scbd::type_id::create ("m_scbd", this);
// [Optional] Collect configuration objects from the test class if applicable
if (uvm_config_db #(env_cfg)::get(this, "", "env_cfg", m_env_cfg))
`uvm_fatal ("build_phase", "Did not get a configuration object for env")
// [Optional] Pass other configuration objects to sub-components via uvm_config_db
endfunction
在自定義uvm_env類的connect_phase中根據(jù)需要連接各個(gè)驗(yàn)證組件
virtual function void connect_phase (uvm_phase phase); // A few examples:
// Connect analysis ports from agent to the scoreboard
// Connect functional coverage component analysis ports
// ...
endfunction
UVM Environment 示例(對(duì)應(yīng)上面提到的的驗(yàn)證環(huán)境圖)
class my_top_env extends uvm_env;
`uvm_component_utils (my_env)
agent_apb m_apb_agt;
agent_wishbone m_wb_agt;
env_register m_reg_env;
env_analog m_analog_env [2];
scoreboard m_scbd;
function new (string name = "my_env", uvm_component parent);
super.new (name, parent);
endfunction
virtual function void build_phase (uvm_phase phase);
super.build_phase (phase);
// Instantiate different agents and environments here
m_apb_agt = agent_apb::type_id::create ("m_apb_agt", this);
m_wb_agt = agent_wishbone::type_id::create ("m_wb_agt", this);
m_reg_env = env_register::type_id::create ("m_reg_env", this);
foreach (m_analog_env[i])
m_analog_env[i] = env_analog::type_id::create ($sformatf("m_analog_env%0d",m_analog_env[i]), this);
m_scbd = scoreboard::type_id::create ("m_scbd", this);
endfunction
virtual function void connect_phase (uvm_phase phase);
// Connect between different environments, agents, analysis ports, and scoreboard here
endfunction
endclass
其中env_analog或env_register中也可以有一些agent和scoreboard。 可以看到UVM在可重用性方面很強(qiáng)大,主要取決于這種分層結(jié)構(gòu)和TLM連接。 也正是因?yàn)檫@種復(fù)用,可以分別獨(dú)立驗(yàn)證env_analog和env_register,而在更加上層的驗(yàn)證環(huán)境my_top_env中,可能只需要關(guān)注子系統(tǒng)之間的交互。
-
UVM
+關(guān)注
關(guān)注
0文章
182瀏覽量
19171 -
代碼
+關(guān)注
關(guān)注
30文章
4788瀏覽量
68616 -
數(shù)字系統(tǒng)
+關(guān)注
關(guān)注
0文章
143瀏覽量
20851
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論