Saturday, 30 April 2016

Override in UVM using factory with Example

One of the main advantage of UVM is Creating each components using factory enables them to be overridden in different tests or environments without changing underlying code base.

uvm_factory provides four different methods to override particular instance or all instances of particular class.
set_inst_override_by_type
set_inst_override_by_name
set_type_override_by_type
set_type_override_by_name


Let's go through example of each one of above four ways.

set_inst_override_by_type
-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------


set_inst_override_by_name

-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------


set_type_override_by_type
-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------


set_type_override_by_name
-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------

set_inst_override_* has high precedence than set_type_override_*.
i.e. If any particular instance of class is override by using set_inst_override_* and type of same class is overridden by using set_type_override_* then that particular instance of class is overridden by set_inst_override_* and rest other instances are overridden by set_type_override_*

-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------



UVM also support override through command line,
+uvm_set_inst_override=,,
+uvm_set_type_override=,[,]

work like the name based overrides in the factory--factory.set_inst_override_by_name() and factory.set_type_override_by_name().

Let's implement same example as above using command line arguments.
-------------------------------------------------------

-------------------------------------------------------

Simulation time argument:
+uvm_set_inst_override=A,A_override,uvm_test_top.env.a3 \
+uvm_set_inst_override=B,B_ovr,path1.b1 \
+uvm_set_type_override=A,A_ovr \
+uvm_set_type_override=B,B_override
-------------------------------------------------------

-------------------------------------------------------

11 comments:

  1. Great post. I see some of the code is commented and for some you said not working. Is that something you tried before coming out with a working example.

    On a related note, can you add examples for parameterized class overrides ?

    ReplyDelete
    Replies
    1. Thanks :)
      Yes, I have tried commented code where I have mentioned not working.
      As of now I don't have example ready for parameterized class. I will try to do it.

      Delete
  2. Also, running the examples as it is gives error as uvm.svh is not inside package or module ?

    ReplyDelete
    Replies
    1. To Run examples, you explicitly need to give $UVM_HOME (path of UVM library) in compilation command.

      Delete
  3. Very nice article. many many thanks

    ReplyDelete
  4. you should not call set_override function , after creating environment.
    you should call it before.

    ReplyDelete
  5. Hi Sagar,
    Just wanted to know. if by any chance you tried the above overriding example for parameterized class

    ReplyDelete
  6. One more way :

    B_driver::type_id::set_type_override(D_driver::get_type());

    ReplyDelete
  7. Thank You Sagar...these are nice articles to understanding UVM fundamentals.as per your examples what ever content is not working might be a tool problem.I have tested not working code from your examples with latest version of VCS and I can see it is working after adding below code.
    uvm_factory factory; //declaration in test class
    //in build_phase function just call below line to resolve factory object
    factory = uvm_factory::get();

    also Anonymous mentioned in above chat.That would be UVM coding guide line.once we do required object overriding,then we can construct env based on new overridden objects(at least from this example).

    ReplyDelete
  8. i am facing error in set_int_override_type example

    Error (suppressible): (vsim-13215) factory_type_override.sv(121): Cannot assign an unpacked type 'class work.uvm_pkg::uvm_object_registry #(class work.factory_type_override_sv_unit::B_ovr, "B_ovr")' to a packed type 'reg'.

    Unresolved reference to 'factory' in $root.factory.print.

    i am not able to resole

    ReplyDelete
    Replies
    1. declare uvm_factory factory and write factory= uvm_factory::get(), this will work.

      Delete