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