This document describes different approaches to debug constraint failures or subtle randomization mistakes from the command line. This is especially helpful in cases where very subtle and not-so-obvious randomization errors occur, or when randomization doesn’t yield the expected results.
If you’re using Cadence xmsim, adding the following option will enable you to log the whole randomization process during a single simulation:
- -xceligen utrace
After the test is completed, all the .randomize() calls and solving steps will be shown one by one in the simulation log (xmsim.log). Information about a solved assignment should appear in blocks similar to the following:
In a single block, you can see which constraint expressions are being solved as well as a table with the information of all the variables participating in this expression – their name, type, status, and value. You can use these blocks to trace through the assignments and check if a wrong value was assigned to any of the variables.
In the example block, variables skip_max_num, array_len and overflow are randomized. The intent of the constraint expression was to set skip_max_num to be equal to array_len if overflow is 1, or array_len – 1 if overflow is 0, all when array_len is greater than 2. Log shows that overflow was first assigned 0 and then array_len was assigned 45. We’re expecting the value of skip_max_num to be 44 in that case, but at the end of the block we can see that 46 was assigned to it instead. The mismatch is found and now we can see exactly which constraint expression causes this unwanted behavior.
Using utrace option on its own, will log all randomization calls in a simulation. There are a couple more options to filter only some particular .randomize() calls we want to observe:
- -xceligen utrace,trace_single=<call_id> – only log a single randomize call with a given call_id
- -xceligen utrace,trace_begin=<begin_call_id>,trace_end=<end_call_id> – log only randomize calls with call ids are in a range between begin_call_id and end_call_id.
You can also find more xmsim constraint debug options with the command:
- xmhelp xmsim RNDOCS
Synopsys VCS include the following plusargs for tracing the randomization solving. You can conduct either of the below options in order to get a complete trace of all randomized calls:
- +ntb_solver_debug=trace +ntb_solver_debug_filter=all
If only a specific call is needed, just change the value of the ntb_solver_debug_filter argument to a specific call id (Synopsys call them “random serial numbers”). For example if we need to trace only call id 2, we can use:
- +ntb_solver_debug=trace +ntb_solver_debug_filter=2