Cannot constrain size of randsz_list_t using an unsigned variable that is wider than 16 bits.
@mballance,
I am constraining the size of a random-size list using a variable. If the variable happens to be wider than 16 bits then PyVSC throws a confusing error that does not make the root cause clear to a test writer. Shrinking the variable width to 16 bits or less fixes the problem. I suggest either fixing this limitation or making the error more explanatory. I am using PyVSC version 0.6.3.
The example code below illustrates the error.
import vsc
@vsc.randobj
class Selector:
def __init__(self):
# Because maxListSize is a uint32_t, which is wider than 16 bits,
# using it to constrain the size of a list will throw an error.
self.maxListSize = vsc.uint32_t(10)
self.aList = vsc.randsz_list_t(vsc.uint32_t())
@vsc.constraint
def list_c(self):
self.aList.size >= 1
self.aList.size <= self.maxListSize
selector = Selector()
selector.randomize()
aStr = "A:"
for a in selector.aList:
aStr += "\t" + str(a)
print(aStr)
Traceback (most recent call last):
File "/data/cf/sshot/u/mcgrathm/silicon-validation/experiment/pyvsc/constrDebug11.py", line 19, in <module>
selector.randomize()
File "/data/cf/sshot/u/mcgrathm/silicon-validation/.venv/lib64/python3.6/site-packages/vsc/rand_obj.py", line 168, in randomize
solve_fail_debug=solve_fail_debug)
File "/data/cf/sshot/u/mcgrathm/silicon-validation/.venv/lib64/python3.6/site-packages/vsc/model/randomizer.py", line 837, in do_randomize
fm, bounds_v.bound_m))
File "/data/cf/sshot/u/mcgrathm/silicon-validation/.venv/lib64/python3.6/site-packages/vsc/visitors/array_constraint_builder.py", line 47, in build
m.accept(builder)
File "/data/cf/sshot/u/mcgrathm/silicon-validation/.venv/lib64/python3.6/site-packages/vsc/model/field_composite_model.py", line 154, in accept
v.visit_composite_field(self)
File "/data/cf/sshot/u/mcgrathm/silicon-validation/.venv/lib64/python3.6/site-packages/vsc/model/model_visitor.py", line 64, in visit_composite_field
fi.accept(self)
File "/data/cf/sshot/u/mcgrathm/silicon-validation/.venv/lib64/python3.6/site-packages/vsc/model/field_array_model.py", line 197, in accept
v.visit_field_scalar_array(self)
File "/data/cf/sshot/u/mcgrathm/silicon-validation/.venv/lib64/python3.6/site-packages/vsc/visitors/array_constraint_builder.py", line 156, in visit_field_scalar_array
raise Exception("Max size for array " + f.name + " (" + str(max_size) + " exceeds 100000")
Exception: Max size for array aList (4294967295 exceeds 100000
As the code comment indicates, setting maxListSize to vsc.uint32_t(10) causes the problem. Using the type vsc.bit_t(17, 10) causes a similar problem with a slightly different error message, while the types vsc.uint16_t(10) and vsc.bit_t(16, 10) work as expected.
I can workaround the error while keeping the original variable width by changing my constraint to use the inside operator rather than >= and <= operators, as shown below:
@vsc.constraint
def list_c(self):
self.aList.size.inside(vsc.rangelist(vsc.rng(1, self.maxListSize)))
However, this workaround might not be applicable in all tests.
@msmftc, Interesting... I would have expected the result to be driven by the literal assigned to the maxListSize variable, and not the width. Thanks for sharing the testcase, I'll have a look.