File dumping in sequence

Hi,

I am facing issues while dumping the packets into the file in the sequence class.

Actually, I am creating a packet in the sequence class and then randomizing it
and dumping their fields in the file and finally i am sending those packets to the driver class.

But no data get dumped into the file.

So, my question is it allowed to dump the data in the file in the sequence class?

Code is:

class seq extends uvm_sequence#(uvm_sequence_item)

  integer fd;

  virtual task body();
	//---------------------------------------------------------------------------------
	packet                     pkt;
					
	pkt              	=  packet::type_id::create("pkt");
	//---------------------------------------------------------------------------------

           assert(pkt.randomize());   
           //////////////////////////////////////////////////////////////////////////////////
              if(fd == 0) begin
                 fd = $fopen("data_write.txt", "w");
              end   

             $fwrite(fd, "%h %h", pkt.type, pkt.value);   

           //////////////////////////////////////////////////////////////////////////////////
           pkt.print();
           
           start_item(ordered_set_pkt);
           finish_item(ordered_set_pkt);
        endfunction

In reply to shankar_logic:

afaik, there is no such restriction

In reply to shankar_logic:

Did you find a solution to this?

In reply to shankar_logic:

You are using the commands in your body task in the wrong order.
The correct one is:

start_item(req);
void’(req.randomize);
finish_item(req);

In reply to shankar_logic:

Hi,

You can do that, but why you open file handle in body method that take time in long run,
you can move that to any other appropriate task/function or you can create individual API for this.