fvutils / pyvsc

Python packages providing a library for Verification Stimulus and Coverage
https://fvutils.github.io/pyvsc
Apache License 2.0
113 stars 26 forks source link

Set_val() and get_val() methods #22

Closed hodjat91 closed 4 years ago

hodjat91 commented 4 years ago

Hi Matthew,

Perhaps I'm missing something here, but I was trying to use get/set_val methods for a scalar attribute. Is this small piece of code valid?:

import vsc

x = vsc.int_t(8, 0xff)
print(x.__dir__()) # set_val() and get_val() are in the list
print("{}\n".format(x.get_val()))

Error: AttributeError: 'NoneType' object has no attribute 'get_val'

However, I can change the value of the object with x.val attribute.

Thanks, Hodjat

mballance commented 4 years ago

Hi Hodjat, Good catch, here. I didn't have any tests for using variables standalone, and they were only getting initialized when created inside a 'randobj' class. Perfectly sensible usecase, of course, so it works now (release 0.0.9). I've also added global randomize and randomize_with methods for randomizing these. Here's an example: https://github.com/fvutils/pyvsc/blob/dab2f170ffcadb39ed670e2bc8a0887f26c855b0/ve/unit/test_field_standalone.py#L26-L33

Best Regards, Matthew