How would you debug a randomization failure in SystemVerilog?
How would you debug a randomization failure in SystemVerilog?
Model answer
randomize() returns 0 when the constraints cannot all be satisfied. The random variables then keep their previous values, and post_randomize() is not called. To debug it: Check the return value: always test the result of randomize(), so that a failure is caught where it happens. Read the solver message: simulators usually report which constraints conflict. Print the state variables: non-rand variables used in constraints are often the cause. Isolate the constraints: disable them one at a time with constraint_mode(0) until randomization succeeds. Check random variables: confirm that rand_mode() has not turned off a variable that needs to change. Check inherited and inline constraints: a derived class or a randomize() with clause may conflict with the base constraints. Reproduce it: rerun with the same seed. Retrying does not help with a true contradiction, because it fails every time.