Skip to content

Commit 96283b6

Browse files
committed
XX
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
1 parent 846cd0a commit 96283b6

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

doc/source/debug.rst

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#####
2+
Debug
3+
#####
4+
5+
There are several situations in which you may need to enable or
6+
configure debug with PyVSC. The most common is when a set of
7+
constraints fails to solve, and diagnostics must be enabled
8+
to help understand the reason for the failure. PyVSC targets
9+
execution speed over verbosity, so default behavior is to
10+
create no diagnostics when a solve failure occurs.
11+
12+
Enabling Solve-Fail Debug
13+
=========================
14+
15+
PyVSC provides an optional argument to the `randomize` and
16+
`randomize_with` method to enable solve-fail debug on a
17+
per-call basis.
18+
19+
.. code-block:: python3
20+
21+
class my_e(IntEnum):
22+
A = auto()
23+
B = auto()
24+
C = auto()
25+
26+
@vsc.randobj
27+
class my_c(object):
28+
29+
def __init__(self):
30+
self.e = vsc.rand_enum_t(my_e)
31+
self.a = vsc.rand_uint8_t()
32+
33+
@vsc.constraint
34+
def a_c(self):
35+
self.a == 1
36+
with vsc.if_then(self.a == 2):
37+
self.e == my_e.A
38+
39+
it = my_c()
40+
41+
with it.randomize_with(solve_fail_debug=1):
42+
it.a == 2
43+
44+
In the example above, the class-level constraint set
45+
forces a==1, while the user's inline constraints forces
46+
a==2. The `randomize_with` call sets solve_fail_debug=1,
47+
which triggers creation of diagnostic information when
48+
a solve failure occurs.
49+
50+
In this case, the output is of the following form:
51+
52+
.. code-block::
53+
54+
Problem Set: 2 constraints
55+
<unknown>:
56+
(a == 1);
57+
<unknown>:
58+
(a == 2);
59+
60+
Enabling solve-fail debug can also be enabled globally
61+
by calling `vsc.vsc_solvefail_debug(1)` from Python code.
62+
The environment variable VSC_SOLVEFAIL_DEBUG can also
63+
be set to 1.
64+
65+
Capturing Source Information
66+
============================
67+
Note that no source information is available for the constraints.
68+
This is because querying source information in Python is quite
69+
time-consuming.
70+
71+
Enabling the capture of source information for constraints can be
72+
done in two ways: via the `randobj` decorator, and via an
73+
environment variable.
74+
75+
.. code-block:: python3
76+
77+
class my_e(IntEnum):
78+
A = auto()
79+
B = auto()
80+
C = auto()
81+
82+
@vsc.randobj(srcinfo=True)
83+
class my_c(object):
84+
85+
def __init__(self):
86+
self.e = vsc.rand_enum_t(my_e)
87+
self.a = vsc.rand_uint8_t()
88+
89+
@vsc.constraint
90+
def a_c(self):
91+
self.a == 1
92+
with vsc.if_then(self.a == 2):
93+
self.e == my_e.A
94+
95+
it = my_c()
96+
97+
with it.randomize_with(solve_fail_debug=1):
98+
it.a == 2
99+
100+
101+
In the code-block above, the `srcinfo` parameter to the
102+
`randobj` decorator causes source information to be
103+
collected for constraints in the class. The solve-fail
104+
diagnostics will now be of the following form:
105+
106+
.. code-block::
107+
108+
Problem Set: 2 constraints
109+
/project/fun/pyvsc/pyvsc-partsel-rand/ve/unit/test_solve_failure.py:30:
110+
(a == 1);
111+
/project/fun/pyvsc/pyvsc-partsel-rand/ve/unit/test_solve_failure.py:38:
112+
(a == 2);
113+
114+
115+
Source-information capture may also be enabled globally
116+
via an environment variable. Set VSC_CAPTURE_SRCINFO=1 to cause
117+
all source information for all random classes to be captured.
118+

0 commit comments

Comments
 (0)