Override in UVM
Use the below eda link as a reference :
https://www.edaplayground.com/x/5fXJ
Why to override ??????
For example: In your environment, you have a driver component. You would like the extend the driver component for error injection scenario. After defining the extended driver class with error injection, how will you replace the base driver component which is deep in the hierarchy of your environment ? Using hierarchical path, you could replace the driver object with the extended driver. This could not be easy if there are many driver objects. Then you should also take care of its connections with the other components of testbenchs like scoreboard etc.
Using the uvm fatroy, it is very easy to solve the above requirements. Only class extended from uvm_object and uvm_component are supported for this.
There are three basic steps to be followed for using uvm factory.
1) Registration
The factory makes it is possible to override the type of uvm component /object or instance of a uvm component/object in 2 ways.
inst_override_by_type :
Syntax :
a) a1 = A::type_id::create("a1", this); (In environment)
factory.set_inst_override_by_type(A::get_type(), A_ovr::get_type(), {get_full_name, ".","env.a1"}); (In test)
or
b) a1 = A::type_id::create("a1", , "path1"); (In environment)
factory.set_inst_override_by_type(A::get_type(), A_ovr::get_type(), "path1.a1"); (In test)
inst_override_by_name :
Syntax :
a) a1 = A::type_id::create("a1", this); (In environment)
factory.set_inst_override_by_type(A, A_ovr, {get_full_name, ".","env.a1"}); (In test)
or
b) a1 = A::type_id::create("a1", , "path1"); (In environment)
factory.set_inst_override_by_type(A, A_ovr, "path1.a1"); (In test)
Description :
type_override_by_type :
Syntax :
a) factory.set_type_override_by_type(A::get_type(), A_ovr::get_type()); (In test)
or
b) A::type_id::set_type_override(A_ovr::get_type() , 0); (In test)
type_override_by_name :
Syntax :
factory.set_type_override_by_name("A", "A_ovr"); (In test)
Description :
override_through_command_line :
By using below run time option one can use over ride through command line.
+uvm_set_inst_override=A,A_override,uvm_test_top.env.a1
+uvm_set_inst_override=A,A_ovr,path1.a1
+uvm_set_type_override=A,A_ovr
+uvm_set_type_override=A,A_override
Reference : http://www.testbench.in/UT_06_UVM_FACTORY.html
https://www.edaplayground.com/x/5fXJ
Why to override ??????
For example: In your environment, you have a driver component. You would like the extend the driver component for error injection scenario. After defining the extended driver class with error injection, how will you replace the base driver component which is deep in the hierarchy of your environment ? Using hierarchical path, you could replace the driver object with the extended driver. This could not be easy if there are many driver objects. Then you should also take care of its connections with the other components of testbenchs like scoreboard etc.
Using the uvm fatroy, it is very easy to solve the above requirements. Only class extended from uvm_object and uvm_component are supported for this.
There are three basic steps to be followed for using uvm factory.
1) Registration
- While defining a class , its type has to be registered with the uvm factory. To do this job easier, uvm has predefined macros.
`uvm_component_utils(class_type_name)
- To construct a uvm based component or uvm based objects, static method create() should be used. This function constructs the appropriate object based on the overrides and constructs the object and returns it. So while constructing the uvm based components or uvm based objects , do not use new() constructor.
- If required, user could override the registered classes or objects. User can override based of name string or class-type.
There are 4 methods defined for overriding:
The factory makes it is possible to override the type of uvm component /object or instance of a uvm component/object in 2 ways.
inst_override_by_type :
Syntax :
a) a1 = A::type_id::create("a1", this); (In environment)
factory.set_inst_override_by_type(A::get_type(), A_ovr::get_type(), {get_full_name, ".","env.a1"}); (In test)
or
b) a1 = A::type_id::create("a1", , "path1"); (In environment)
factory.set_inst_override_by_type(A::get_type(), A_ovr::get_type(), "path1.a1"); (In test)
inst_override_by_name :
Syntax :
a) a1 = A::type_id::create("a1", this); (In environment)
factory.set_inst_override_by_type(A, A_ovr, {get_full_name, ".","env.a1"}); (In test)
or
b) a1 = A::type_id::create("a1", , "path1"); (In environment)
factory.set_inst_override_by_type(A, A_ovr, "path1.a1"); (In test)
Description :
- Here we just need to provide three arguments first whom to override , by which to override and path of particular instance that you want to override.
- If you have create particular component using this method then you should use first method for overriding and if you have created particular comp using path method then you should use second method for overriding.
type_override_by_type :
Syntax :
a) factory.set_type_override_by_type(A::get_type(), A_ovr::get_type()); (In test)
or
b) A::type_id::set_type_override(A_ovr::get_type() , 0); (In test)
type_override_by_name :
Syntax :
factory.set_type_override_by_name("A", "A_ovr"); (In test)
Description :
- In type_override_by_type there are two methods
- a) Here you do not require to pass exact path as we were giving in inst_override
- b) Same but with this syntax you can control override operation in hierarchy. If the last argument is 0 then once its override in up hierarchy then down hierarchy comp will not be able to override it.So you can override it just once. While if its value is 1 then you can override it in down hierarchy.
- In type_override_by_name one can simply override the component just by using its name.
override_through_command_line :
By using below run time option one can use over ride through command line.
+uvm_set_inst_override=A,A_override,uvm_test_top.env.a1
+uvm_set_inst_override=A,A_ovr,path1.a1
+uvm_set_type_override=A,A_ovr
+uvm_set_type_override=A,A_override
Reference : http://www.testbench.in/UT_06_UVM_FACTORY.html
Comments
Post a Comment