UVM糖果爱好者教程 - 6.品尝

这篇文章揭示了糖果爱好者系列UVM教程的预期成果。使用创建的验证组件并写出测试用例,然后实际软件仿真运行。

Test

这个特殊的例子将告诉你如何开发一系列各种无糖的jelly_beans。测试类如下所述。

class jelly_bean_test extends uvm_test;
   `uvm_component_utils(jelly_bean_test)
 
   jelly_bean_env jb_env;
 
   function new(string name, uvm_component parent);
      super.new(name, parent);
   endfunction: new
 
   function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      begin
         jelly_bean_configuration jb_cfg;
 
         jb_cfg = new;
         assert(jb_cfg.randomize());
         uvm_config_db#(jelly_bean_configuration)::set
           (.cntxt(this), .inst_name("*"), .field_name("config"), .value(jb_cfg));
         jelly_bean_transaction::type_id::set_type_override(sugar_free_jelly_bean_transaction::get_type());
         jb_env = jelly_bean_env::type_id::create(.name("jb_env"), .parent(this));
      end
   endfunction: build_phase
 
   task run_phase(uvm_phase phase);
      gift_boxed_jelly_beans_sequence jb_seq;
 
      phase.raise_objection(.obj(this));
      jb_seq = gift_boxed_jelly_beans_sequence::type_id::create(.name("jb_seq"), .contxt(get_full_name()));
      assert(jb_seq.randomize());
      `uvm_info("jelly_bean_test", { "\n", jb_seq.sprint() }, UVM_LOW)
      jb_seq.start(jb_env.jb_agent.jb_seqr);
      #10ns ;
      phase.drop_objection(.obj(this));
   endtask: run_phase
endclass: jelly_bean_test

build_phase执行三个动作:

  • 将配置类注册到config数据库(第17行)
  • 使用sugar_free_jelly_bean事务,而不是jelly_bean_transaction。用set_type_override实现(第19行)
  • 创建jelly_bean_env(第20行)

第13行至第18行为将来添加更丰富的配置使用,并添加为占位符。由于缺乏配置需求,本系列中的配置解释被省略。如果您对此主题感兴趣,请参阅以后的configuration章节。

在run_phase中,创建gift_boxed_jelly_beans_sequence,并调用start开始运行。

Configuration

作为参考,下面插入jelly_bean_configuration类的源代码。

class jelly_bean_configuration extends uvm_object;
   `uvm_object_utils(jelly_bean_configuration)
 
   function new(string name = "");
      super.new(name);
   endfunction: new
endclass: jelly_bean_configuration

Top

在继续进行仿真之前,需要编写实例化DUT模块的顶层模块,将jelly_bean_if注册到资源数据库中,并运行测试。顶级模块也负责时钟生成。

更新(2014年4月2日):在本教程中,我们使用了uvm_resource_db来存储jelly_bean_if(第15和16行)。 UVM建议使用uvm_config_db而不是uvm_resource_db,因为前者更健壮。你可以用15行和16行代替:

module top;
   import uvm_pkg::*;
 
   reg clk;
   jelly_bean_if     jb_slave_if(clk);
   jelly_bean_taster jb_taster(jb_slave_if);
 
   initial begin // clock generation
      clk = 0;
      #5ns ;
      forever #5ns clk = ! clk;
   end
 
   initial begin
      uvm_resource_db#(virtual jelly_bean_if)::set
        (.scope("ifs"), .name("jelly_bean_if"), .val(jb_slave_if));
      run_test();
   end
endmodule: top

Simulation

作为压轴的一部分,现在是编译和运行仿真的时候了。下面发布的是仿真结果。

UVM_INFO @ 0: reporter [RNTST] Running test jelly_bean_test...
UVM_INFO jb.sv(481) @ 0: uvm_test_top [jelly_bean_test]
-----------------------------------------------------------------------
Name                      Type                             Size  Value
-----------------------------------------------------------------------
jb_seq                    gift_boxed_jelly_beans_sequence  -     @772
  num_jelly_bean_flavors  integral                         32    'h2
  req                     object                           -
  rsp                     object                           -
-----------------------------------------------------------------------
 
UVM_INFO jb.sv(406) @ 40: uvm_test_top.jb_env.jb_sb [jelly_bean_scoreboard] You have a good sense of taste.
----------------------------------------------------------------
Name          Type                               Size  Value
----------------------------------------------------------------
jb_tx         sugar_free_jelly_bean_transaction  -     @818
  flavor      flavor_e                           3     CHOCOLATE
  color       color_e                            2     RED
  sugar_free  integral                           1     'h1
  sour        integral                           1     'h1
  taste       taste_e                            2     YUCKY
----------------------------------------------------------------
 
UVM_INFO jb.sv(406) @ 60: uvm_test_top.jb_env.jb_sb [jelly_bean_scoreboard] You have a good sense of taste.
----------------------------------------------------------------
Name          Type                               Size  Value
----------------------------------------------------------------
jb_tx         sugar_free_jelly_bean_transaction  -     @834
  flavor      flavor_e                           3     CHOCOLATE
  color       color_e                            2     GREEN
  sugar_free  integral                           1     'h1
  sour        integral                           1     'h0
  taste       taste_e                            2     YUMMY
----------------------------------------------------------------
 
UVM_INFO jb.sv(406) @ 80: uvm_test_top.jb_env.jb_sb [jelly_bean_scoreboard] You have a good sense of taste.
------------------------------------------------------------
Name          Type                               Size  Value
------------------------------------------------------------
jb_tx         sugar_free_jelly_bean_transaction  -     @842
  flavor      flavor_e                           3     APPLE
  color       color_e                            2     GREEN
  sugar_free  integral                           1     'h1
  sour        integral                           1     'h1
  taste       taste_e                            2     YUMMY
------------------------------------------------------------
 
UVM_INFO jb.sv(406) @ 100: uvm_test_top.jb_env.jb_sb [jelly_bean_scoreboard] You have a good sense of taste.
------------------------------------------------------------
Name          Type                               Size  Value
------------------------------------------------------------
jb_tx         sugar_free_jelly_bean_transaction  -     @850
  flavor      flavor_e                           3     APPLE
  color       color_e                            2     RED
  sugar_free  integral                           1     'h1
  sour        integral                           1     'h0
  taste       taste_e                            2     YUMMY
------------------------------------------------------------

有了这六篇文章,基本的UVM教程就完成了。虽然这种jelly-bean机器是假想的,但它有能力与其他DUT一起改写。如果有机会,我想回顾这些帖子中省略的其他主题,例如virtual sequence。我希望本教程能帮助你进一步理解UVM。


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值