0
votes

I have two class handles inside my sequence item. One of the classes contains a handle for the other class. pseudo code looks like this:

class seq_item extends uvm_sequence_item;
    rand class_a a;
    rand class_b b;
endclass// seq_item  

class class_a extends uvm_object;
    rand bit field_1;
    rand bit field_2; 
endclass//class_a

class class_b extends uvm_object;
    class_a a_handle;
    rand bit field_3;
    rand bit field_4;
endclass // class_b

So, when I randomize; I'd like a_handle to have field_1 and field_2 values as that of 'a' from seq_item. I tried cloning ($cast(b.a_handle, a.clone()) inside post_randomize of seq_item, but it isn't working. How do I make sure that values of b.a_handle.field_1, b.a_handle.field_2 are same as that of a.field_1, a.field_2 ?

1
It would help to explain what "It isn't working" means. Compiler error or results different from what you expect? - dave_59
I have a_handle.field_1 accessed inside class_b method. At run time, I am getting 'Null object access error' on a_handle.field_1 from that method. - Pri
I was able to fix, 'Null object access' error. I was trying to 'new' class_b.a_handle inside seq_item's pre_randomize method, which was incorrect I guess. I moved it to class_b's 'new' method. - Pri

1 Answers

0
votes

You can have a constraint do this for you inside seq_item

constraint fields {
  a.field_1 == b.a_handle.field_1;
  a.field_2 == b.a_handle.field_2;
}

You also need to declare a_handle as rand in class_b