Let say I have these two classes:
class random_packet extends uvm_sequence_item;
rand int cmd;
...
endclass
and its extension:
class good_packet extends random_packet;
constraint good_constr {
cmd inside {0,1,2};
}
...
endclass
(Here I am not going to create good_packet
object, but I just want to use its constraint as a reference)
Then I instantiate random_packet object and randomize it:
random_packet pkt;
pkt = random_packet::type_id::create("pkt");
pkt.randomize();
My question: Is there a simpler way by utilizing its derived class good_packet
's constraint to check whether the resultant pkt.cmd
fall in category of good_packet
constraint ?
It would be better than writing redundant codes like:
if (pkt.cmd == 0 || pkt.cmd == 1 || pkt.cmd == 2) $display("good");
else $display("bad");