Hi,
I have an issue with a piece of code that I am reusing:
In scoreboard, after finishing the comparison of current object, there is a function free_memory called to delete all dynamic fields of the expected and received objects.
packet_obj packet_queue_owr[$]; // define a queue
ovm_analysis_imp_sent_obj_pkt #(packet_obj, scoreboard) driver_obj2sb_port; //declare a scoreboard port for driver obj
ovm_analysis_imp_rcvd_pkt #(packet_obj, scoreboard) receiver_obj2sb_port; //declare a scoreboard port for receiver obj
extern function new(string name, ovm_component parent);
extern function void write_sent_obj_pkt(input packet_obj pkt ); //This function is used to put sent packet in Queue
extern function void write_rcvd_pkt(input packet_obj pkt); //This function is used to compare received and sent packets
extern function void free_obj_memory(packet_obj pkt_obj_source, packet_obj pkt_obj_received);
//...
function void scoreboard::free_obj_memory(packet_obj pkt_obj_source, packet_obj pkt_obj_received);
pkt_obj_source.free_memory();
pkt_obj_received.free_memory();
endfunction : free_obj_memory
function void scoreboard::write_sent_obj_pkt(input packet_obj pkt );
packet_queue_owr.push_back(pkt);
endfunction : write_sent_obj_pkt
function void scoreboard::write_rcvd_pkt(input packet_obj pkt);
packet_obj expected_obj;
expected_obj = packet_queue_owr.pop_front();
//comparison
free_obj_memory(expected_obj, pkt);
and inside transaction_obj class, free_memory is defined as:
function void packet_obj::free_memory();
this.dynamic_field1.delete();
this.dynamic_field2.delete();
//...
this.dynamic_fieldN.delete();
endfunction : free_memory
I am testing a case where one input object is sent to the design but is written twice in the scoreboard (Queue packet_queue_owr).
These two objects are then sent by the design as two seperate objects.
While the reception of the first one is ok, the comparison of the second object fails.
The problem is that expected object is corrupted: all its dynamic fields are empty (size = 0).
I did a print of packet_queue_owr[0] before and after free_obj_memory 's call and I found that the source of the problem is here.
Why the content of the Queue packet_queue_owr is modified after calling the function free_obj_memory ?
Thank you.