Set_type_override_by_type

Hi,
Could someone please provide me some sample code for set_type_override_by_type(). I tried using it but it didnt produce the desired effect. Perhaps I am doing something wrong.
My intention is to add a constraint to an already existing class. I want that the existing instance of the class can be used instead of creating another instance of the derived class.

Regards,
Sujit

Hi,
Could someone please provide me some sample code for set_type_override_by_type(). I tried using it but it didnt produce the desired effect. Perhaps I am doing something wrong.
My intention is to add a constraint to an already existing class. I want that the existing instance of the class can be used instead of creating another instance of the derived class.
Regards,
Sujit

Hi Sujit,

 ex: class driver;
        rand bit [3:0]var;
        constraint c1 {var==3;}
      endclass

 class driver1 extends driver;
      constraint c1 {var==6;}
 endclass

and in u r test extends ovm_test;
function build();
set_type_override_by_type(driver::get_type(),
driver1::get_type());

          endfunction

And it should work.

Hi,
Here is my complete code.

////////////////////////////////////////////
//example for adding constarints to already existing classes
//irun -ovm extend.sv
////////////////////////////////////////////
module extend;
`include “ovm.svh”

class my_packet extends ovm_object;
rand bit [31:0] a;
rand bit [3:0] b;
rand bit [7:0] c;

ovm_object_utils_begin(my_packet) ovm_field_int(a, OVM_ALL_ON)
ovm_field_int(b, OVM_ALL_ON) ovm_field_int(c, OVM_ALL_ON)
`ovm_object_utils_end
function new(input string name=“my_packet”,ovm_component parent=null);
super.new(name);
endfunction
endclass : my_packet

class my_packet_test extends my_packet;
constraint c1 { a == 5;}
`ovm_object_utils(my_packet_test)
function new(input string name=“my_packet_test”,ovm_component parent=null );
super.new(name,parent);
endfunction
endclass : my_packet_test

class testcase extends ovm_test;

`ovm_component_utils(testcase)

my_packet pkt; 
bit flag;

function new(string name = “testcase”, ovm_component parent=null);
super.new(name, parent);
endfunction : new

 virtual function void build();
  super.build();
  pkt = my_packet::type_id::create("my_packet", this);
  factory.set_type_override_by_type(my_packet::get_type(),my_packet_test::get_type());

endfunction : build

virtual task run();
flag = pkt.randomize();
if (flag == 0) begin
$display (“could not randomize: 1”);
end
pkt.print();

  flag = pkt.randomize();
  if (flag == 0) begin
     $display ("could not randomize: 2");
  end
  pkt.print();

endtask : run

endclass : testcase
initial begin
run_test();
end
endmodule : extend

Here is the output that I get

Name Type Size Value

my_packet my_packet - @612
a integral 32 'h4fa1579f
b integral 4 'ha
c integral 8 'h78


Name Type Size Value

my_packet my_packet - @612
a integral 32 'hd3cc9aa7
b integral 4 'h5
c integral 8 'h96

I am expecting that the value of “a” be 5 always.The new constraint is not taken into account I guess. Could you please let me know where I am going wrong.

Regards,
Sujit

Hello,

You must register the override (type or instance) before you call the create().

Move your set_type_override…() to before the create() call.

JF

Thank you John. I got the desired result now.

Regards,
Sujit

Hi,

I have a related question.

I extend a class with an analysis port. In build() of my test I do override (as discussed above). In connect() of my test I try to connect the created port to elsewhere. The compilation fails to recognise the new port. Although, I can see the created port in the simvision (after commenting out the connection), but compilation fails to recognise the port.

Can you please comment.

Thanks,

Alok

How to use the same concept in ovm to avoid the more number of sequences.

please give me some example.

regards,
Lal Kumar

In reply to jfowler:

Actually i have a sequnce item svt_transaction. i have a sequence svt_random_sequence in which object for the class svt_transaction has been created and randomized.
Now i have extended a class as cust_svt_transaction from base class svt_transaction and modified the constraints.
Now for a specific test suppose svt_random_test, i want to randomize the extended sequence item (cust_svt_transaction) instead of base sequence item (svt_transaction) in the sequence svt_random_sequence (not changing anything in the sequence)
i want to make this from the test as follows:
class svt_random_test extends base_test;


virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
factory.set_type_override_by_type(svt_transaction::get_type(),cust_svt_transaction::get_type());
uvm_config_db#(uvm_object_wrapper)::set(this, “env.agent1.sequencer1.main_phase”, “default_sequence”, svt_random_sequence::type_id::get());
endfunction : build_phase


endclass

Is this right?..

Actually i have a sequnce item svt_transaction. i have a sequence svt_random_sequence in which object for the class svt_transaction has been created and randomized.
Now i have extended a class as cust_svt_transaction from base class svt_transaction and modified the constraints.
Now for a specific test suppose svt_random_test, i want to randomize the extended sequence item (cust_svt_transaction) instead of base sequence item (svt_transaction) in the sequence svt_random_sequence (not changing anything in the sequence)
i want to make this from the test as follows:
class svt_random_test extends base_test;


virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
factory.set_type_override_by_type(svt_transaction::get_type(),cust_svt_transaction::get_type());
uvm_config_db#(uvm_object_wrapper)::set(this, “env.agent1.sequencer1.main_phase”, “default_sequence”, svt_random_sequence::type_id::get());
endfunction : build_phase


endclass

Is this right?..

In reply to jfowler:

Hi,
I have a problem when I use the ‘set_type_override_by_type’ this way :
(where y_test_seq is same as & extends from x_test_seq with a slight update in the sequence.
x_test_seq is used in test_seq_v)

Can you please tell me where I am going wrong ?

 test extends uvm_test;
  virtual function void build();
        super.build();

        uvm_config_db#(uvm_object_wrapper)::set(this, "ve.virtual_sequencer_inst.run_phase","default_sequence",default_pkg::test_seq_v::type_id::get());
        
  factory.set_type_override_by_type(x_pkg::x_test_seq_v::get_type(), y_pkg::y_test_seq_v::get_type());

        ve  = top_sve::type_id::create("ve",this);
    endfunction