ee_king的个人空间 https://blog.eetop.cn/1494617 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

Testbench/UsingFactoryOverrides

已有 698 次阅读| 2018-9-20 10:05 |系统分类:芯片设计

       UVM factory允许在构造时将类替换为派生类型的另一个类。这对于通过将一个类替换为另一个类而无需编辑或重新编译测试平台代码来更改测试平台的行为来说是非常有用的。为了使factory重载过程起作用,需要遵循许多编码约定先决条件,这些在UVM factory的文章中进行了解释。
       UVM factory可以被认为是查找表。当使用<type> :: type_id :: create(“<name>”,<parent>)方法(approach)进行“普通”组件构造时,会发生的是type_id用于为类选择factory组件包装器, 构造其内容并再次传回结果句柄。factory重载更改了查找的发生方式,因此查找原始的type_id会导致使用不同的type_id。因此,返回不同类型的构造对象的句柄。此技术依赖于多态性,即能够使用基本类型句柄引用派生类型的能力。实际上,只有当父类被类扩展层次结构中的一个子类重载时,重载才会起作用。

       Component Overrides 

     UVM中有两种类型的组件重载 - type overrides 和 instance overrides。  

       Component Type Overrides  

       type override意味着每次在测试平台层次结构中创建组件类type时,都会在其位置创建替换type。这适用于该组件类型的所有实例。以下代码片段中说明了此类重载的方法调用:

       //
       // Component type override example
       // ---------------------------------------------

       // Colour parent class
       class colour extends uvm_component;

       `uvm_component_utils(colour)

       //etc
       endclass: colour

       // Red child class
       class red extends colour;

       `uvm_component_utils(red)

       //etc
       endclass: red

       //
       // Factory type override syntax is:
       // 
       // <original_type>::type_id::set_type_override(<substitute_type>::get_type(), replace);
       //
       // Where replace is a bit which when ==1 enables the override of an existing override, otherwise
       // the existing override is honoured.

       // To override all instances of colour with red:
       colour::type_id::set_type_override(red::get_type(), 1);

       // This means that the following creation line returns a red, rather than a colour
       pixel = colour::type_id::create("pixel", this);

       参数化组件类也可以被重载,但必须注意确保重载类具有与被重载的类相同的参数值,否则它们不被认为是相关types:

        //
        // Type overrides for parameterised classes:
        // ----------------------------------------------------------

        // Base class type
        class bus_driver #(int BUS_WIDTH = 32) extends uvm_component;

        `uvm_component_param_utils(bus_driver #(BUS_WIDTH))
        // etc

        endclass: bus_driver

        // Derived class type
        class bus_conductor #(int BUS_WIDTH = 32) extends bus_driver #(BUS_WIDTH);

        `uvm_component_param_utils(bus_conductor #(BUS_WIDTH))
        // etc

        endclass: bus_conductor

        // The parameterised type override needs to keep the parameterisation consistent【重点记录下】

        bus_driver #(64)::type_id::set_type_override(bus_conductor #(64)::get_type(), 1); // This will succeed

        // Creation of a #(64) bus_driver results in a #(64) bus_conductor handle being returned:

        bus_person = bus_driver#(64)::type_id::create("bus_person", this);

        // Whereas creating a #(16) bus_driver results in a #(16) bus_driver handle being returned because
        // the matching type override is not found:

        bus_person = bus_driver#(16)::type_id::create("bus_person", this);

        // Similarly if a type override has non-matching parameters, then it will fail and return the original type

        bus_driver #(64)::type_id::set_type_override(bus_conductor #(32)::get_type(), 1); // Returns bus_driver #(64)
       

        Component Instance Overrides

        可以通过在uvm组件层次结构中指定其位置来重载特定组件实例。同样,这种方法可以与参数化类一起使用,只要注意匹配重载中涉及的两个类类型的参数:

        //
        // Component Instance Factory Override example
        // --------------------------------------------

        // Using red --> colour example from type override example
        //
        // Syntax for the instance override:
        //
        // <original_type>::type_id::set_inst_override(<substitute_type>::get_type(), <path_string>);
        //

        colour::type_id::set_inst_override(red::get_type(), "top.env.raster.spot");

        // And again for a parameterised type, the parameter values must match

        bus_driver #(64)::type_id::set_inst_override(bus_conductor #(64)::get_type(), "top.env.bus_agent.m_driver");

        Object Overrides

      Objects or sequence 相关 objects通常仅与type重载一起使用,因为instance重载方法涉及UVM测试平台组件层次结构中哪些objects不参与的位置。然而,有一个编码技巧可用于重载object的特定“instances”,这在overriding sequences的文章中有解释。

       object 重载的代码遵循与组件重载相同的形式。


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 2

    粉丝
  • 0

    好友
  • 0

    获赞
  • 6

    评论
  • 访问数
关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-25 10:29 , Processed in 0.029197 second(s), 18 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部