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

randomize() function returns None #16

Closed aneels3 closed 4 years ago

aneels3 commented 4 years ago

I think object.randomize() should return True (1) or False(0) on successful and unsuccessfull randomization respectively. Such that we can call the randomize() function with the class instance by checking it in the if ... else condition to check the possible randomization failure.

mballance commented 4 years ago

Hi @aneels3, The current implementation throws an exception on randomization failure, so instead of if/else for detecting an error you should use try/catch. I realize that the use of exceptions is different than SystemVerilog, but would like to understand if it presents other use-model challenges.

Thanks, Matthew

aneels3 commented 4 years ago

Hi @mballance I was trying to implement the

assert(instance.randomize());

In this case I am assuming the assertions are turn on.

When assertion are turn off we can achieve the same with if else but as per your suggestion we can achieve this by try except block as well.

May be we can implement this when we have support for assertion in PyVSC.

mballance commented 4 years ago

Hi @aneels3, There's another issue that will likely prevent us from ever having randomize return a boolean: the randomize_with pattern used by PyVSC doesn't allow us to return a value to the user. An exception is the only way to signal that something has gone wrong. For consistency, randomize() should behave the same.

Best Regards, Matthew