I am trying to override a class to change a minor functionality for my project.
I have a class in a package that I want to override with another class in a different package. The files look something like this:
original_pkg.sv
→
class class_to_override #(type T = apples, type VI = some_if) extend uvm_monitor;
new_pkg.sv
→
class new_class #(type T = apples, type VI = some_if) extend class_to_override;
and in my uvm_test start_of_simulation_phase, I have
class_to_override#()::type_id::set_type_override( new_class#()::get_type() );
It doesn’t seem to perform the override, is it because I’m missing some syntax? Do I have to put the type parameters in my set_type_override line?
There doesn’t seem to be any errors during the simulation but it is clear to me that class_to_override still runs instead of new_class from `uvm_info monitoring
In reply to jimmyhuang0904:
There is also a second argument that should be passed to set_type_override method i.e, replace bit, if it is 1 then it enables overriding.
You can try once writing like
class_to_override#()::type_id::set_type_override( new_class#()::get_type(), 1 );
In reply to jimmyhuang0904:
Performing the override in the start_simulation_phase is too late for UVM components. In this phase your environment exist and cannot modified anymore. For objects like seq_items and sequences you can make the override in the run_phase.
In reply to chr_sue:
Do you suggest always doing your type overrides in build_phase since that is the earliest you can declare your override?
In reply to Shipra_s:
Even with that extra argument in the build_phase, it doesn’t seem to override the class, yet there are no error warnings…
Also… I was under the impression that without the replace bit, it would set the override by default and what you’re suggesting is that every time you override a type, you should have that bit enabled?
In reply to jimmyhuang0904:
It would help the people try ing to help you if you showed some more context. Where are you doing the override and where are you doing the creation? Need to know which method and environmental context?
In reply to dave_59:
I am doing the override in my build_phase of my uvm_test so it would look something like…:
UVM TEST
package my_test_pkg;
import uvm_pkg::*;
import class_inside_pkg::*; // This is where class class_to_override exists
import override_class_inside_pkg::*; // This is where class new_class exists
class my_test extends uvm_test;
...
function void build_phase(uvm_phase phase);
super.build_phase(phase);
// Suggested solution
class_to_override#()::type_id::set_type_override( new_class#()::get_type(), 1 );
...
endfunction : build_phase
endpackage
class_inside_pkg
class class_to_override #(type T = apples, type VI = some_if) extend uvm_monitor;
...
virtual function void my_function_called_by_run_phase(void);
// It does more functionalities but this is how I tell it's still being called
`uvm_info("asdf", "hi", UVM_LOW)
override_class_inside_pkg
class new_class #(type T = apples, type VI = some_if) extend class_to_override;
...
virtual function void my_function_called_by_run_phase(void);
`uvm_info("asdf", "bye", UVM_LOW)
As an extra… if it matters, my testbench looks like this:
module my_tb;
import uvm_pkg::*;
import my_test_pkg::*;
import class_inside_pkg::*;
import override_class_inside_pkg::*; // EDIT: I actual do import this
...
initial begin
...
run_test();
end
endmodule
Hopefully that is more clear
EDIT: and yes, I am making sure my_test is being ran and not some other test
In reply to jimmyhuang0904:
Your module my_tb only needs to import uvm_pkg and my_test_pkg.
You have not shown all you parameter overrides correctly. That is critical to get matching overrides.
class new_class #(type T = apples, type VI = some_if) extend class_to_override#(T,V);
And you did not show the creation. The parameter types need to be shown there as well
mon = class_to_override#(T,V)::type_id::create("mon",this);
Do the parameters in the override match the parameters of the override?
In reply to dave_59:
My creation,
m_monitor = class_to_override#(T, VI)::type_id::create("m_monitor", this);
exists in the agent in my uvm_env and not the uvm_test itself. I think this should be fine
I have changed the new_class declaration to your suggestion:
class new_class #(type T = apples, type VI = some_if) extend class_to_override#(T,VI);
It still doesn’t seem to be overriding… Is there a way to check if the factory set_type_override or any equivalent to see if it is working? Like a status return check sort of thing.
Any other suggestions would be helpful, I am still currently investigating this problem…
The solution was to make sure during the type override, you also pass in the exact same parameters that would have been created in your original class.
type_id::create is just a look-up table and seems like if you don’t declare the exact type, it would register the override for some other class that has not even been defined.
In the override, you would have to add:
class_to_override#(<type of apples that you know will be passed in>, <type of some_if you know will be passed in>)::type_id::set_type_override( new_class#(<type of apples that you know will be passed in>, <type of some_if you know will be passed in>)::get_type(), 1 );