[CU]uvm base test
资料来源
(1) https://github.com/Practical-UVM-Step-By-Step/Practical-UVM-Step-By-Step
(2) 《Practical UVM step by step with IEEE》
1. 测试用例的作用
base_test所做的事情因公司而异,常见的使用如下:
(1) 实例化top-level env;
(2) 通过config_db设置验证平台中某些参数的值,或使用factory override机制配置环境;
(3) 通过调用UVM sequences施加激励;
(4) 在report_phase根据UVM_ERROR的数量打印不同信息;
注1:注意uvm_report_server的使用;
(5) 设置整个验证平台的超时退出时间;
通常,只有一个uvm_base_test,在其中实现env以及其他组件的例化; 其他tests均派生于base_test;
1 class base_test extends uvm_test; 2 my_env env; 3 4 function new(string name="base_test", uvm_component parent=null); 5 super.new(name,parent); 6 endfunction 7 8 extern virtual function void build_phase(uvm_phase phase); 9 extern virtual function void report_phase(uvm_phase phase); 10 11 endclass 12 13 function void base_test::build_phase(uvm_phase phase); 14 super.build_phase(phase); 15 env=my_env::type_id::create("env",this); 16 uvm_config_db#(uvm_object_wrapper)::set(this,"env.i_agt.sqr.main_phase","default_sequence",my_sequence::type_id::get()); 17 endfunction 18 19 function void base_test::report_phase(uvm_phase phase); 20 uvm_report_server server; 21 int err_num; 22 super.report_phase(phase); 23 24 server=get_report_server(); //uvm_report_server srvr; srvr=uvm_report_server::get_server(); 25 err_num=server.get_severity_count(UVM_ERROR); 26 27 if(err_num!=0) begin //通常不这么使用,而是使用UVM_MAX_QUIT_COUNT,一旦由多少个错误,就退出仿真; 28 $display("TEST CASE FAILED!"); 29 end 30 else begin 31 $display("TEST CASE PASSED!"); 32 end 33 34 endfunction
1 class wb_env_base_test extends uvm_test; 2 3 wb_config wb_master_config; 4 wb_config wb_slave_config; 5 6 `uvm_component_utils(wb_env_base_test) 7 8 wb_env env; 9 10 function new(string name, uvm_component parent); 11 super.new(name, parent); 12 endfunction 13 14 virtual function void build_phase(uvm_phase phase); 15 super.build_phase(phase); 16 env = wb_env::type_id::create("env", this); 17 wb_master_config = new("wb_master_config"); 18 wb_slave_config = new("wb_slave_config"); 19 20 wb_master_config.max_n_wss = 10; 21 wb_master_config.min_addr = 0; 22 wb_master_config.max_addr = 10000000; 23 24 wb_slave_config.max_n_wss = 10; 25 wb_slave_config.min_addr = 0; 26 wb_slave_config.max_addr = 10000000; 27 28 begin: configure 29 uvm_config_db #(uvm_object_wrapper)::set(this, "env.rst_agent.mast_sqr.reset_phase", "default_sequence", reset_sequence::get_type()); 30 uvm_config_db #(uvm_object_wrapper)::set(this, "env.master_agent.mast_sqr.main_phase", "default_sequence", sequence_1::get_type()); 31 uvm_config_db #(uvm_object_wrapper)::set(this, "env.slave_agent.slv_seqr.run_phase", "default_sequence", ram_sequence::get_type()); 32 33 uvm_config_db #(wb_config)::set(this, "env.master_agent", "config", wb_master_config); 34 uvm_config_db #(wb_config)::set(this, "env.slave_agent", "config", wb_slave_config); 35 end 36 endfunction 37 38 endclass : wb_env_base_test
2. 测试用例的启动
(1) 在top_tb中更改run_test的参数,跑不同的测试用例;
1 //top_tb.sv 2 initial begin 3 run_test("my_case0"); 4 end 5 6 initial begin 7 run_test("my_case1"); 8 end
(2) UVM提供对不加参数的run_test_的支持; 在这种情况下, UVM会利用UVM_TESTNAME从命令行中寻找测试用例的名字,创建它的实例并运行.
注1:在同一仿真中,如果及指定了run_test的参数,又在命令行传递了UVM_TESTNAME,后者的优先级更高;
1 //top_tb.sv 2 initial begin 3 run_test(); 4 end 5 6 //<sim command> 7 ... +UVM_TESTNAME=my_case0 8 9 //<sim command> 10 ... +UVM_TESTNAME=my_case1
3. 测试用例的执行流程
1 启动验证平台 2 | 3 v 4 根据UVM_TESTNAME产生my_case的实例 5 | 6 v 7 依次执行build_phase,形成完整的UVM树 8 | 9 v 10 顺序执行UVM树各节点的connect_phase,main_phase等 11 | 12 v 13 所有phase执行完毕,结束仿真