Hi All
I have a class that defines a packet. I am now adding the ability to force errors. The error type is defined in a integer enum. The distribution is a a dynamic array of unsigned inegers that I want the user to be able to set. Because I want the code to be easily expandable I want to use a foreach inside a constraint to set the dist on the error variable:
rand pkt_err_t pkt_err;
int unsigned pkt_err_dist;
bit enable_errors = 0;
constraint c_error_select { pkt_err dist { foreach(pkt_err_dist[i]) i := pkt_err_dist[i] }; }
The problem here is the compiler doesnt like the foreach inside the dist. My intention is that if more errors are added in the future, they are added to the enum and it all cascades neatly into the class, and I dont need an explicit dist assignment here, like this:
constraint c_error_select { pkt_err dist { ERROR_1_E := pkt_err_dist[ERROR_1_E], ERROR_2_E = pkt_err_dist[ERROR_2_E] }; }
Because doing this would require an update to the enum and to the error distribution table.
So can I do what Im trying to do above?