Recently a UVM user pondered over the following question:
randomization NOT happening for seq_item variable if uvm_field_* is NOT enabled?
To appreciate the issue, consider the code snippet as below:
Since both hdr and pkt_len are declared rand, one expects them to be randomized. Note that one of the `uvm_field_int is commented – to demo the issue.
Now a recipient/consumer of this transaction does a copy/clone at destination. See a code snippet:
So far so good, let’s see what happens in a typical Questa simulation:
The above results of hdr being NOT generated occurs consistently for all seeds (See the forum post if needed). So a typical user suspects that the missing uvm_field_int macro does control the randomization – though not intuitive/true. This could consume quite a few debug cycles (recall that the macro above is commented for demo only, in actual work, as reported in that forum posting, user forgot to add that at the first place).
A Debug assistant
Now as in our regular VSV training sessions (www.cvcblr.com/trainings) , we showcase the potential applications of post_randomize and one of the prominent ones is to “debug” the generated fields. See below code snippet:
With the above code added, here is what our friendly Questa has to show for us in simulation:
So clearly the hdr field does get randomly generated. It is only when a copy of the container class being created, it skips the “copy process”. And this has to do with the lack of macro. Focus on the missing/commented macro below:
Hope the above makes it self-explanatory – add the macro, you get copy/clone enabled for that specific field. So 2 lessons learnt today:
1. Use field macros consistently
2. More importantly, use post_randomize as your friendly, automated debug assistant for random generation!